import React, { useState, useEffect } from 'react'; import { Button, Form, Input, Modal, Radio, type FormInstance } from 'antd'; interface Values { title?: string; description?: string; modifier?: string; } interface CollectionCreateFormProps { initialValues: Values; onFormInstanceReady: (instance: FormInstance) => void; } const CollectionCreateForm: React.FC = ({ initialValues, onFormInstanceReady, }) => { const [form] = Form.useForm(); useEffect(() => { onFormInstanceReady(form); }, []); return (
Public Private
); }; interface CollectionCreateFormModalProps { open: boolean; onCreate: (values: Values) => void; onCancel: () => void; initialValues: Values; } const CollectionCreateFormModal: React.FC = ({ open, onCreate, onCancel, initialValues, }) => { const [formInstance, setFormInstance] = useState(); return ( { try { const values = await formInstance?.validateFields(); formInstance?.resetFields(); onCreate(values); } catch (error) { console.log('Failed:', error); } }} > { setFormInstance(instance); }} /> ); }; const App: React.FC = () => { const [formValues, setFormValues] = useState(); const [open, setOpen] = useState(false); const onCreate = (values: Values) => { console.log('Received values of form: ', values); setFormValues(values); setOpen(false); }; return ( <>
{JSON.stringify(formValues, null, 2)}
setOpen(false)} initialValues={{ modifier: 'public' }} /> ); }; export default App;