diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Domain/AddDomainForm/AddDomainForm.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Domain/AddDomainForm/AddDomainForm.component.tsx index 0e938dcf516..b40fb0eb01a 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Domain/AddDomainForm/AddDomainForm.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Domain/AddDomainForm/AddDomainForm.component.tsx @@ -303,7 +303,7 @@ const AddDomainForm = ({ delete (data as CreateDomain & { domains?: unknown }).domains; } - onSubmit(data).then(() => form.resetFields()); + onSubmit(data); }; return ( diff --git a/openmetadata-ui/src/main/resources/ui/src/components/common/atoms/drawer/useFormDrawer.tsx b/openmetadata-ui/src/main/resources/ui/src/components/common/atoms/drawer/useFormDrawer.tsx index 76c44a0463a..872b59ba461 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/common/atoms/drawer/useFormDrawer.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/common/atoms/drawer/useFormDrawer.tsx @@ -24,6 +24,7 @@ export interface FormDrawerConfig form: ReactNode; onSubmit: (data: T) => Promise | void; onCancel?: () => void; + onReset?: () => void; submitLabel?: string; cancelLabel?: string; loading?: boolean; @@ -84,6 +85,7 @@ export const useFormDrawer = (config: FormDrawerConfig) => { form, onSubmit, onCancel, + onReset, submitLabel = t('label.save'), cancelLabel = t('label.cancel'), loading = false, @@ -114,7 +116,10 @@ export const useFormDrawer = (config: FormDrawerConfig) => { label: cancelLabel, variant: 'text', testId: cancelTestId, - onClick: () => closeRef.current(), + onClick: () => { + closeRef.current(); + onReset?.(); // Reset form on cancel + }, }, primaryButton: { label: submitLabel, @@ -131,6 +136,7 @@ export const useFormDrawer = (config: FormDrawerConfig) => { // Form submission error handled by caller } finally { setIsSubmitting(false); + onReset?.(); // Reset form on submit } }, }, @@ -173,7 +179,11 @@ export const useFormDrawer = (config: FormDrawerConfig) => { */ export const useFormDrawerWithRef = ( config: FormDrawerConfig & { - formRef?: { submit: () => void; validateFields?: () => Promise }; + formRef?: { + submit: () => void; + validateFields?: () => Promise; + resetFields: () => void; + }; } ) => { const { formRef, onSubmit, ...restConfig } = config; @@ -198,6 +208,7 @@ export const useFormDrawerWithRef = ( const drawer = useFormDrawer({ ...restConfig, onSubmit: handleSubmit, + onReset: formRef?.resetFields, }); const submitForm = useCallback(() => {