import { Form } from 'antd'; import React, { useCallback, useEffect, useMemo } from 'react'; import { Input, Modal } from '@src/alchemy-components'; export interface FormData { url: string; label: string; } interface Props { open: boolean; initialValues?: Partial; variant: 'create' | 'update'; onSubmit: (formData: FormData) => void; onCancel: () => void; } export const LinkFormModal = ({ open, initialValues, variant, onSubmit, onCancel }: Props) => { const [form] = Form.useForm(); const onCancelHandler = useCallback(() => { onCancel(); }, [onCancel]); // Reset form state to initial values when the form opened/closed useEffect(() => { form.resetFields(); }, [open, form]); const title = useMemo(() => (variant === 'create' ? 'Add Link' : 'Update Link'), [variant]); const submitButtonText = useMemo(() => (variant === 'create' ? 'Create' : 'Update'), [variant]); return ( form.submit() }, ]} >
); };