Fix State Initialization

This commit is contained in:
Abhay
2025-01-06 12:07:39 +05:30
parent d0dac925e9
commit 85ef6310e2
4 changed files with 31 additions and 9 deletions

View File

@@ -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<PatientFormProps> = ({
nestedFormCallback,
initForm,
}) => {
const [form, setForm] = useState<PatientForm>({});
const [form, setForm] = useState<PatientForm>(
initForm[PATIENT_KEY]?.['human_patient'] || {},
);
const [openDate, setOpenDate] = useState<boolean>(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 (