import React from 'react'; import { ClusterName, CleanupPolicy, TopicFormData, TopicName, } from 'redux/interfaces'; import { useForm, FormContext, ErrorMessage } from 'react-hook-form'; import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb'; import { clusterTopicsPath } from 'lib/paths'; import { TOPIC_NAME_VALIDATION_PATTERN, BYTES_IN_GB } from 'lib/constants'; import CustomParamsContainer from './CustomParams/CustomParamsContainer'; import TimeToRetain from './TimeToRetain'; 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 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.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
{/* eslint-disable react/jsx-props-no-spreading */}

); }; export default New;