From 59447dc391ed98b3a3c0ead3ede5e31448fc3c28 Mon Sep 17 00:00:00 2001 From: Author M-BenAli Date: Sun, 19 Jan 2020 23:46:24 +0100 Subject: [PATCH] fix: adjusted code as requests in pr and fixed linting errors --- .gitignore | 3 +- src/locales/en-US/translation.json | 3 ++ src/patients/new/NewPatientForm.tsx | 49 ++++++++++++++--------------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index ce252dab6d..769faaf7e5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ logs npm-debug.log* yarn-debug.log* yarn-error.log* -.idea + # Runtime data pids @@ -58,6 +58,7 @@ typings/ # dotenv environment variables file .env +.idea # next.js build output .next diff --git a/src/locales/en-US/translation.json b/src/locales/en-US/translation.json index 2ab2ae532b..3302ef48e3 100644 --- a/src/locales/en-US/translation.json +++ b/src/locales/en-US/translation.json @@ -52,6 +52,9 @@ "states": { "success": "Success!" }, + "errors": { + "patientNameRequired": "No patient name entered!" + }, "scheduling": { "label": "Scheduling", "appointments": { diff --git a/src/patients/new/NewPatientForm.tsx b/src/patients/new/NewPatientForm.tsx index 674b04e156..aa209f8cc0 100644 --- a/src/patients/new/NewPatientForm.tsx +++ b/src/patients/new/NewPatientForm.tsx @@ -1,6 +1,6 @@ import React, { useState } from 'react' import { useTranslation } from 'react-i18next' -import { Button, Checkbox } from '@hospitalrun/components' +import { Alert, Button, Checkbox } from '@hospitalrun/components' import { startOfDay, subYears } from 'date-fns' import SelectWithLabelFormGroup from '../../components/input/SelectWithLableFormGroup' import TextFieldWithLabelFormGroup from '../../components/input/TextFieldWithLabelFormGroup' @@ -19,7 +19,7 @@ const NewPatientForm = (props: Props) => { const [isEditable] = useState(true) const { onCancel, onSave } = props const [approximateAge, setApproximateAge] = useState(0) - const [errorMessage, setError] = useState('') + const [errorMessage, setErrorMessage] = useState('') const [patient, setPatient] = useState({ givenName: '', familyName: '', @@ -38,27 +38,28 @@ const NewPatientForm = (props: Props) => { }) const onSaveButtonClick = async () => { - if (!patient.givenName && !patient.familyName) { - return setError("No patient name entered!") - } - const newPatient = { - prefix: patient.prefix, - familyName: patient.familyName, - givenName: patient.givenName, - suffix: patient.suffix, - sex: patient.sex, - dateOfBirth: patient.dateOfBirth, - isApproximateDateOfBirth: patient.isApproximateDateOfBirth, - type: patient.type, - occupation: patient.occupation, - preferredLanguage: patient.preferredLanguage, - phoneNumber: patient.phoneNumber, - email: patient.email, - address: patient.address, - fullName: getPatientName(patient.givenName, patient.familyName, patient.suffix), - } as Patient + if (!patient.givenName) { + setErrorMessage(t('errors.patientNameRequired')) + } else { + const newPatient = { + prefix: patient.prefix, + familyName: patient.familyName, + givenName: patient.givenName, + suffix: patient.suffix, + sex: patient.sex, + dateOfBirth: patient.dateOfBirth, + isApproximateDateOfBirth: patient.isApproximateDateOfBirth, + type: patient.type, + occupation: patient.occupation, + preferredLanguage: patient.preferredLanguage, + phoneNumber: patient.phoneNumber, + email: patient.email, + address: patient.address, + fullName: getPatientName(patient.givenName, patient.familyName, patient.suffix), + } as Patient - onSave(newPatient) + onSave(newPatient) + } } const onFieldChange = (key: string, value: string) => { @@ -97,6 +98,7 @@ const NewPatientForm = (props: Props) => {

{t('patient.basicInformation')}

+ {errorMessage && }
{ />
- {errorMessage && ( -
{t(errorMessage)}
- )} {isEditable && (