diff --git a/components/PrescriptionCreator/AddressForm.tsx b/components/PrescriptionCreator/AddressForm.tsx index 73b06b5..cd03c96 100644 --- a/components/PrescriptionCreator/AddressForm.tsx +++ b/components/PrescriptionCreator/AddressForm.tsx @@ -13,18 +13,21 @@ interface AddressForm { interface AddressFormProps { nestedFormCallback: (tag: string, form: Object) => void; + initForm: {[key: string]: any}; } +const ADDRESS_KEY = 'Address'; export const AddressForm: React.FC = ({ nestedFormCallback, + initForm, }) => { - const [form, setForm] = useState({}); + const [form, setForm] = useState(initForm[ADDRESS_KEY] || {}); const handleTextChange = (tag: keyof AddressForm, text: string) => { let newForm = {...form}; newForm[tag] = text; setForm(newForm); - nestedFormCallback('Address', newForm); + nestedFormCallback(ADDRESS_KEY, newForm); }; return ( diff --git a/components/PrescriptionCreator/MedicineForm.tsx b/components/PrescriptionCreator/MedicineForm.tsx index 47e7bf3..9cb559d 100644 --- a/components/PrescriptionCreator/MedicineForm.tsx +++ b/components/PrescriptionCreator/MedicineForm.tsx @@ -12,20 +12,24 @@ interface MedicineForm { directions?: string; } +const MEDICINE_KEY = 'MedicationPrescribed'; + interface MedicineFormProps { nestedFormCallback: (tag: string, form: Object) => void; + initForm: {[key: string]: any}; } export const MedicineForm: React.FC = ({ nestedFormCallback, + initForm, }) => { - const [form, setForm] = useState({}); + const [form, setForm] = useState(initForm[MEDICINE_KEY] || {}); const handleTextChange = (tag: keyof MedicineForm, text: string) => { let newForm = {...form}; newForm[tag] = text; setForm(newForm); - nestedFormCallback('MedicationPrescribed', newForm); + nestedFormCallback(MEDICINE_KEY, newForm); }; return ( diff --git a/components/PrescriptionCreator/PatientForm.tsx b/components/PrescriptionCreator/PatientForm.tsx index 1e87a72..bb2c502 100644 --- a/components/PrescriptionCreator/PatientForm.tsx +++ b/components/PrescriptionCreator/PatientForm.tsx @@ -11,19 +11,25 @@ interface PatientForm { interface PatientFormProps { nestedFormCallback: (tag: string, form: Object) => void; + initForm: {[key: string]: any}; } +const PATIENT_KEY = 'patient'; + export const PatientForm: React.FC = ({ nestedFormCallback, + initForm, }) => { - const [form, setForm] = useState({}); + const [form, setForm] = useState( + initForm[PATIENT_KEY]?.['human_patient'] || {}, + ); const [openDate, setOpenDate] = useState(false); const handleTextChange = (tag: 'name' | 'date_of_birth', text: string) => { let newForm = {...form}; newForm[tag] = text; setForm(newForm); - nestedFormCallback('patient', {human_patient: newForm}); + nestedFormCallback(PATIENT_KEY, {human_patient: newForm}); }; return ( diff --git a/components/PrescriptionCreator/index.tsx b/components/PrescriptionCreator/index.tsx index 58f6e1c..3ee9dfe 100644 --- a/components/PrescriptionCreator/index.tsx +++ b/components/PrescriptionCreator/index.tsx @@ -171,13 +171,22 @@ export const PrescriptionCreator = () => {
{' '} - +
- +
- +