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

Commit

Permalink
feat(patients): better form feedback for add allergy (#1945)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfiorini74 authored Mar 29, 2020
1 parent 19768a1 commit d6904e7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/patients/allergies/NewAllergyModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('New Allergy Modal', () => {

expect(wrapper.find(Alert)).toHaveLength(1)
expect(wrapper.find(Alert).prop('title')).toEqual('states.error')
expect(wrapper.find(Alert).prop('message')).toContain('patient.allergies.error.nameRequired')
expect(wrapper.find(Alert).prop('message')).toContain('patient.allergies.error.unableToAdd')
})
})
})
1 change: 1 addition & 0 deletions src/locales/enUs/translations/patient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default {
new: 'Add Allergy',
error: {
nameRequired: 'Name is required.',
unableToAdd: 'Unable to add allergy.',
},
warning: {
noAllergies: 'No Allergies',
Expand Down
8 changes: 7 additions & 1 deletion src/patients/allergies/NewAllergyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const NewAllergyModal = (props: NewAllergyModalProps) => {
const { show, onCloseButtonClick, onSave } = props
const [allergy, setAllergy] = useState({ name: '' })
const [errorMessage, setErrorMessage] = useState('')
const [isAllergyNameInvalid, setIsAllergynameInvalid] = useState(false)
const [nameRequiredFeedback, setNameRequiredFeedback] = useState('')
const { t } = useTranslation()

useEffect(() => {
Expand All @@ -29,7 +31,9 @@ const NewAllergyModal = (props: NewAllergyModalProps) => {
const onSaveButtonClick = () => {
let newErrorMessage = ''
if (!allergy.name) {
newErrorMessage += `${t('patient.allergies.error.nameRequired')} `
newErrorMessage += `${t('patient.allergies.error.unableToAdd')} `
setIsAllergynameInvalid(true)
setNameRequiredFeedback(`${t('patient.allergies.error.nameRequired')} `)
}

if (newErrorMessage) {
Expand All @@ -49,13 +53,15 @@ const NewAllergyModal = (props: NewAllergyModalProps) => {
{errorMessage && <Alert color="danger" title={t('states.error')} message={errorMessage} />}
<form>
<TextInputWithLabelFormGroup
feedback={nameRequiredFeedback}
name="name"
isRequired
label={t('patient.allergies.allergyName')}
isEditable
placeholder={t('patient.allergies.allergyName')}
value={allergy.name}
onChange={onNameChange}
isInvalid={isAllergyNameInvalid}
/>
</form>
</>
Expand Down

1 comment on commit d6904e7

@vercel
Copy link

@vercel vercel bot commented on d6904e7 Mar 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.