Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit b9c42a4

Browse files
committed
fix: adjusted code as requests in pr and fixed linting errors
1 parent f0df64a commit b9c42a4

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ logs
55
npm-debug.log*
66
yarn-debug.log*
77
yarn-error.log*
8-
.idea
8+
99

1010
# Runtime data
1111
pids
@@ -58,6 +58,7 @@ typings/
5858

5959
# dotenv environment variables file
6060
.env
61+
.idea
6162

6263
# next.js build output
6364
.next

src/locales/en-US/translation.json

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
"states": {
5353
"success": "Success!"
5454
},
55+
"errors": {
56+
"patientNameRequired": "No patient name entered!"
57+
},
5558
"scheduling": {
5659
"label": "Scheduling",
5760
"appointments": {

src/patients/new/NewPatientForm.tsx

+24-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react'
22
import { useTranslation } from 'react-i18next'
3-
import { Button, Checkbox } from '@hospitalrun/components'
3+
import { Alert, Button, Checkbox } from '@hospitalrun/components'
44
import { startOfDay, subYears } from 'date-fns'
55
import SelectWithLabelFormGroup from '../../components/input/SelectWithLableFormGroup'
66
import TextFieldWithLabelFormGroup from '../../components/input/TextFieldWithLabelFormGroup'
@@ -19,7 +19,7 @@ const NewPatientForm = (props: Props) => {
1919
const [isEditable] = useState(true)
2020
const { onCancel, onSave } = props
2121
const [approximateAge, setApproximateAge] = useState(0)
22-
const [errorMessage, setError] = useState('')
22+
const [errorMessage, setErrorMessage] = useState('')
2323
const [patient, setPatient] = useState({
2424
givenName: '',
2525
familyName: '',
@@ -38,27 +38,28 @@ const NewPatientForm = (props: Props) => {
3838
})
3939

4040
const onSaveButtonClick = async () => {
41-
if (!patient.givenName && !patient.familyName) {
42-
return setError("No patient name entered!")
43-
}
44-
const newPatient = {
45-
prefix: patient.prefix,
46-
familyName: patient.familyName,
47-
givenName: patient.givenName,
48-
suffix: patient.suffix,
49-
sex: patient.sex,
50-
dateOfBirth: patient.dateOfBirth,
51-
isApproximateDateOfBirth: patient.isApproximateDateOfBirth,
52-
type: patient.type,
53-
occupation: patient.occupation,
54-
preferredLanguage: patient.preferredLanguage,
55-
phoneNumber: patient.phoneNumber,
56-
email: patient.email,
57-
address: patient.address,
58-
fullName: getPatientName(patient.givenName, patient.familyName, patient.suffix),
59-
} as Patient
41+
if (!patient.givenName) {
42+
setErrorMessage(t('errors.patientNameRequired'))
43+
} else {
44+
const newPatient = {
45+
prefix: patient.prefix,
46+
familyName: patient.familyName,
47+
givenName: patient.givenName,
48+
suffix: patient.suffix,
49+
sex: patient.sex,
50+
dateOfBirth: patient.dateOfBirth,
51+
isApproximateDateOfBirth: patient.isApproximateDateOfBirth,
52+
type: patient.type,
53+
occupation: patient.occupation,
54+
preferredLanguage: patient.preferredLanguage,
55+
phoneNumber: patient.phoneNumber,
56+
email: patient.email,
57+
address: patient.address,
58+
fullName: getPatientName(patient.givenName, patient.familyName, patient.suffix),
59+
} as Patient
6060

61-
onSave(newPatient)
61+
onSave(newPatient)
62+
}
6263
}
6364

6465
const onFieldChange = (key: string, value: string) => {
@@ -97,6 +98,7 @@ const NewPatientForm = (props: Props) => {
9798
<div>
9899
<form>
99100
<h3>{t('patient.basicInformation')}</h3>
101+
{errorMessage && <Alert className="alert" color="danger" message={t(errorMessage)} />}
100102
<div className="row">
101103
<div className="col-md-2">
102104
<TextInputWithLabelFormGroup
@@ -278,9 +280,6 @@ const NewPatientForm = (props: Props) => {
278280
/>
279281
</div>
280282
</div>
281-
{errorMessage && (
282-
<div className="alert alert-danger" role="alert">{t(errorMessage)}</div>
283-
)}
284283
{isEditable && (
285284
<div className="row">
286285
<Button onClick={onSaveButtonClick}> {t('actions.save')}</Button>

0 commit comments

Comments
 (0)