import React from 'react'; import { ClusterName, TopicName, TopicFormDataRaw } from 'redux/interfaces'; import { useForm, FormContext } from 'react-hook-form'; import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb'; import { clusterTopicsPath } from 'lib/paths'; import TopicForm from 'components/Topics/shared/Form/TopicForm'; interface Props { clusterName: ClusterName; isTopicCreated: boolean; createTopic: (clusterName: ClusterName, form: TopicFormDataRaw) => void; redirectToTopicPath: (clusterName: ClusterName, topicName: TopicName) => void; resetUploadedState: () => void; } const New: React.FC = ({ clusterName, isTopicCreated, createTopic, redirectToTopicPath, resetUploadedState, }) => { const methods = useForm(); const [isSubmitting, setIsSubmitting] = React.useState(false); React.useEffect(() => { if (isSubmitting && isTopicCreated) { const { name } = methods.getValues(); redirectToTopicPath(clusterName, name); } }, [isSubmitting, isTopicCreated, redirectToTopicPath, clusterName, methods]); const onSubmit = async (data: TopicFormDataRaw) => { // 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. Setting of isSubmitting after createTopic is a workaround, need to tweak loader logic createTopic(clusterName, data); setIsSubmitting(true); // Keep this action after createTopic to prevent redirect before create. }; return (
New Topic
{/* eslint-disable react/jsx-props-no-spreading */}
); }; export default New;