From e4359f4ce0e54560c57c9525743885956f1a1efd Mon Sep 17 00:00:00 2001 From: samau3 Date: Tue, 10 Sep 2024 21:30:22 -0700 Subject: [PATCH] Refactor and organize registration form components --- .../pages/patients/PatientRegistration.jsx | 68 ++++++++++--------- .../{ => inputs}/HealthcareChoicesSearch.jsx | 0 .../{ => inputs}/MedicalDataSearch.jsx | 0 .../{ => inputs}/SearchDatabaseInputField.jsx | 0 4 files changed, 35 insertions(+), 33 deletions(-) rename client/src/pages/patients/{ => inputs}/HealthcareChoicesSearch.jsx (100%) rename client/src/pages/patients/{ => inputs}/MedicalDataSearch.jsx (100%) rename client/src/pages/patients/{ => inputs}/SearchDatabaseInputField.jsx (100%) diff --git a/client/src/pages/patients/PatientRegistration.jsx b/client/src/pages/patients/PatientRegistration.jsx index b4b27b1e..15ce4edb 100644 --- a/client/src/pages/patients/PatientRegistration.jsx +++ b/client/src/pages/patients/PatientRegistration.jsx @@ -17,6 +17,14 @@ const TABS = [ 'codeStatus', ]; +const ERROR_SECTION_MAP = { + patientData: 'Patient Data', + contactData: 'Emergency Contact', + medicalData: 'Medical Information', + healthcareChoices: 'Healthcare Choices', + codeStatus: 'Advanced Directive', +}; + /** * Patients page component * @@ -267,6 +275,30 @@ export default function PatientRegistration() { } } + /** + * + * @param {object} errors + */ + function handleErrors(errors) { + // Set focus to the first error field + const firstErrorPath = Object.keys(errors)[0]; + form.getInputNode(firstErrorPath)?.focus(); + setOpenedSection(firstErrorPath.split('.')[0]); + + // Create a message for which sections have errors + const errorKeys = Object.keys(errors).map((key) => key.split('.')[0]); + const errorSets = new Set(errorKeys); + + let errorSections = []; + errorSets.forEach((key) => { + errorSections.push(ERROR_SECTION_MAP[key]); + }); + + showErrorNotification( + `Please fix the following sections: ${errorSections.join(', ')}`, + ); + } + /** * * @param {object} data @@ -341,7 +373,9 @@ export default function PatientRegistration() { console.log(value, openedSection, active, TABS.indexOf(value)); console.log(value); - value === null ? navigate('') : navigate(`#${value}`); + value === null + ? navigate('', { replace: true }) + : navigate(`#${value}`, { replace: true }); if (!openedSection) { setOpenedSection(value); @@ -385,38 +419,6 @@ export default function PatientRegistration() { } } - /** - * - * @param {object} errors - */ - function handleErrors(errors) { - // Set focus to the first error field - const firstErrorPath = Object.keys(errors)[0]; - form.getInputNode(firstErrorPath)?.focus(); - setOpenedSection(firstErrorPath.split('.')[0]); - - // Create a message for which sections have errors - const errorKeys = Object.keys(errors).map((key) => key.split('.')[0]); - const errorSets = new Set(errorKeys); - - const errorSectionMap = { - patientData: 'Patient Data', - contactData: 'Emergency Contact', - medicalData: 'Medical Information', - healthcareChoices: 'Healthcare Choices', - codeStatus: 'Advanced Directive', - }; - - let errorSections = []; - errorSets.forEach((key) => { - errorSections.push(errorSectionMap[key]); - }); - - showErrorNotification( - `Please fix the following sections: ${errorSections.join(', ')}`, - ); - } - return (

Register Patient

diff --git a/client/src/pages/patients/HealthcareChoicesSearch.jsx b/client/src/pages/patients/inputs/HealthcareChoicesSearch.jsx similarity index 100% rename from client/src/pages/patients/HealthcareChoicesSearch.jsx rename to client/src/pages/patients/inputs/HealthcareChoicesSearch.jsx diff --git a/client/src/pages/patients/MedicalDataSearch.jsx b/client/src/pages/patients/inputs/MedicalDataSearch.jsx similarity index 100% rename from client/src/pages/patients/MedicalDataSearch.jsx rename to client/src/pages/patients/inputs/MedicalDataSearch.jsx diff --git a/client/src/pages/patients/SearchDatabaseInputField.jsx b/client/src/pages/patients/inputs/SearchDatabaseInputField.jsx similarity index 100% rename from client/src/pages/patients/SearchDatabaseInputField.jsx rename to client/src/pages/patients/inputs/SearchDatabaseInputField.jsx