import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Button, Form, FormGroup, ModalBody, ModalFooter, ModalHeader, Stack, TextInput } from '@carbon/react'; import { showSnackbar } from '@openmrs/esm-framework'; import type { Schema } from '@types'; interface NewFormModalProps { schema: Schema; onSchemaChange: (schema: Schema) => void; closeModal: () => void; } const NewFormModal: React.FC = ({ schema, onSchemaChange, closeModal }) => { const { t } = useTranslation(); const [formName, setFormName] = useState(''); const [formDescription, setFormDescription] = useState(''); const updateSchema = (updates: Partial) => { try { const updatedSchema = { ...schema, ...updates }; onSchemaChange(updatedSchema); showSnackbar({ title: t('success', 'Success!'), kind: 'success', isLowContrast: true, subtitle: t('formCreated', 'New form created'), }); } catch (error) { if (error instanceof Error) { showSnackbar({ title: t('errorCreatingForm', 'Error creating form'), kind: 'error', subtitle: error?.message, }); } } }; const handleCreateForm = () => { if (formName) { updateSchema({ name: formName, description: formDescription, }); closeModal(); } }; return ( <>
event.preventDefault()}> ) => setFormName(event.target.value)} /> ) => setFormDescription(event.target.value)} />
); }; export default NewFormModal;