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

feat(patients): add related persons form feedback #1957

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ describe('New Related Person Modal', () => {
wrapper.update()

const errorAlert = wrapper.find(Alert)

expect(onSaveSpy).not.toHaveBeenCalled()
expect(errorAlert).toHaveLength(1)
expect(errorAlert.prop('message')).toEqual(
'patient.relatedPersons.error.relatedPersonRequired patient.relatedPersons.error.relationshipTypeRequired',
'patient.relatedPersons.error.relatedPersonErrorBanner',
jackcmeyer marked this conversation as resolved.
Show resolved Hide resolved
)
})
})
Expand Down
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 @@ -25,6 +25,7 @@ export default {
relatedPerson: 'Related Person',
relatedPersons: {
error: {
relatedPersonErrorBanner: 'Unable to add new related person.',
jackcmeyer marked this conversation as resolved.
Show resolved Hide resolved
relatedPersonRequired: 'Related Person is required.',
relationshipTypeRequired: 'Relationship Type is required.',
},
Expand Down
22 changes: 17 additions & 5 deletions src/patients/related-persons/NewRelatedPersonModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const NewRelatedPersonModal = (props: Props) => {
const { show, toggle, onCloseButtonClick, onSave } = props
const { t } = useTranslation()
const [errorMessage, setErrorMessage] = useState('')
const [isRelatedPersonInvalid, setIsRelatedPersonInvalid] = useState(false)
const [isRelationshipInvalid, setIsRelationshipInvalid] = useState(false)
const [relatedPerson, setRelatedPerson] = useState({
patientId: '',
type: '',
Expand Down Expand Up @@ -49,11 +51,17 @@ const NewRelatedPersonModal = (props: Props) => {
searchAccessor="fullName"
placeholder={t('patient.relatedPerson')}
onChange={onPatientSelect}
isInvalid={isRelatedPersonInvalid}
onSearch={async (query: string) => PatientRepository.search(query)}
renderMenuItemChildren={(patient: Patient) => (
<div>{`${patient.fullName} (${patient.code})`}</div>
)}
/>
{isRelatedPersonInvalid && (
<div className="text-left ml-3 mt-1 text-small text-danger invalid-feedback d-block">
{t('patient.relatedPersons.error.relatedPersonRequired')}
</div>
)}
jackcmeyer marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
</div>
Expand All @@ -64,6 +72,8 @@ const NewRelatedPersonModal = (props: Props) => {
label={t('patient.relatedPersons.relationshipType')}
value={relatedPerson.type}
isEditable
isInvalid={isRelationshipInvalid}
feedback={t('patient.relatedPersons.error.relationshipTypeRequired')}
isRequired
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
onInputElementChange(event, 'type')
Expand Down Expand Up @@ -91,19 +101,21 @@ const NewRelatedPersonModal = (props: Props) => {
icon: 'add',
iconLocation: 'left',
onClick: () => {
let newErrorMessage = ''
let isValid = true
if (!relatedPerson.patientId) {
newErrorMessage += `${t('patient.relatedPersons.error.relatedPersonRequired')} `
isValid = false
setIsRelatedPersonInvalid(true)
}

if (!relatedPerson.type) {
newErrorMessage += `${t('patient.relatedPersons.error.relationshipTypeRequired')}`
isValid = false
setIsRelationshipInvalid(true)
}

if (!newErrorMessage) {
if (isValid) {
onSave(relatedPerson as RelatedPerson)
} else {
setErrorMessage(newErrorMessage.trim())
setErrorMessage(t('patient.relatedPersons.error.relatedPersonErrorBanner'))
}
},
}}
Expand Down