import React from 'react'; import { ClusterName, CleanupPolicy, TopicFormData, TopicName } from 'redux/interfaces'; import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb'; import { clusterTopicsPath } from 'lib/paths'; import { useForm, ErrorMessage } from 'react-hook-form'; import { TOPIC_NAME_VALIDATION_PATTERN, MILLISECONDS_IN_DAY, BYTES_IN_GB, } from 'lib/constants'; interface Props { clusterName: ClusterName; isTopicCreated: boolean; createTopic: (clusterName: ClusterName, form: TopicFormData) => void; redirectToTopicPath: (clusterName: ClusterName, topicName: TopicName) => void; resetUploadedState: () => void; } const New: React.FC = ({ clusterName, isTopicCreated, createTopic, redirectToTopicPath, resetUploadedState }) => { const {register, handleSubmit, errors, getValues} = useForm(); const [isSubmitting, setIsSubmitting] = React.useState(false); React.useEffect( () => { if (isSubmitting && isTopicCreated) { const {name} = getValues(); redirectToTopicPath(clusterName, name); } }, [isSubmitting, isTopicCreated, redirectToTopicPath, clusterName, getValues], ); const onSubmit = async (data: TopicFormData) => { //TODO: need to fix loader. After success loading the first time, we won't wait for creation any more, because state is //loaded, and we will try to get entity immediately after pressing the button, and we will receive null //going to object page on the second creation. Resetting loaded state is workaround, need to tweak loader logic resetUploadedState(); setIsSubmitting(true); createTopic(clusterName, data); }; return (
New Topic

); }; export default New;