From 72a5bede7862c72eecb068c0c20141ef619a8f27 Mon Sep 17 00:00:00 2001 From: Jack Meyer Date: Wed, 3 Jun 2020 22:15:58 -0500 Subject: [PATCH] feat(care plan): fix internationalization --- src/__tests__/patients/patient-slice.test.ts | 20 +++++++++---------- .../enUs/translations/patient/index.ts | 10 ++++++++++ src/patients/care-plans/CarePlanForm.tsx | 16 +++++++-------- src/patients/patient-slice.ts | 20 +++++++++---------- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/__tests__/patients/patient-slice.test.ts b/src/__tests__/patients/patient-slice.test.ts index 1d7d4b426b..9ce0c2ddf6 100644 --- a/src/__tests__/patients/patient-slice.test.ts +++ b/src/__tests__/patients/patient-slice.test.ts @@ -686,15 +686,15 @@ describe('patients slice', () => { it('should validate the required fields', async () => { const expectedError = { - message: 'patient.carePlans.error.unableToAdd', - title: 'patient.carePlans.error.titleRequired', - description: 'patient.carePlans.error.descriptionRequired', - status: 'patient.carePlans.error.statusRequired', - intent: 'patient.carePlans.error.intentRequired', - startDate: 'patient.carePlans.error.startDateRequired', - endDate: 'patient.carePlans.error.endDateRequired', - condition: 'patient.carePlans.error.conditionRequired', - note: 'patient.carePlans.error.noteRequired', + message: 'patient.carePlan.error.unableToAdd', + title: 'patient.carePlan.error.titleRequired', + description: 'patient.carePlan.error.descriptionRequired', + status: 'patient.carePlan.error.statusRequired', + intent: 'patient.carePlan.error.intentRequired', + startDate: 'patient.carePlan.error.startDateRequired', + endDate: 'patient.carePlan.error.endDateRequired', + condition: 'patient.carePlan.error.conditionRequired', + note: 'patient.carePlan.error.noteRequired', } const store = mockStore() const expectedCarePlan = {} as CarePlan @@ -719,7 +719,7 @@ describe('patients slice', () => { expect(store.getActions()[0]).toEqual( addCarePlanError( expect.objectContaining({ - endDate: 'patient.carePlans.error.endDateMustBeAfterStartDate', + endDate: 'patient.carePlan.error.endDateMustBeAfterStartDate', }), ), ) diff --git a/src/locales/enUs/translations/patient/index.ts b/src/locales/enUs/translations/patient/index.ts index 9f331021a8..e8ca987bd9 100644 --- a/src/locales/enUs/translations/patient/index.ts +++ b/src/locales/enUs/translations/patient/index.ts @@ -104,6 +104,16 @@ export default { startDate: 'Start Date', endDate: 'End Date', note: 'Note', + error: { + unableToAdd: 'Unable to add a new care plan.', + titleRequired: 'Title is required.', + descriptionRequired: 'Description is required.', + conditionRequired: 'Condition is required.', + statusRequired: 'Status is required.', + intentRequired: 'Intent is required.', + startDate: 'Start date is required.', + endDate: 'End date is required', + } }, types: { charity: 'Charity', diff --git a/src/patients/care-plans/CarePlanForm.tsx b/src/patients/care-plans/CarePlanForm.tsx index 95d8ecebee..0845250a40 100644 --- a/src/patients/care-plans/CarePlanForm.tsx +++ b/src/patients/care-plans/CarePlanForm.tsx @@ -44,7 +44,7 @@ const CarePlanForm = (props: Props) => { return (
- {carePlanError?.message && } + {carePlanError?.message && } { value={carePlan.title} label={t('patient.carePlan.title')} name="title" - feedback={carePlanError?.title} + feedback={t(carePlanError?.title || '')} isInvalid={!!carePlanError?.title} isEditable={!disabled} onChange={(event) => onFieldChange('title', event.currentTarget.value)} @@ -66,7 +66,7 @@ const CarePlanForm = (props: Props) => { value={carePlan.description} label={t('patient.carePlan.description')} name="description" - feedback={carePlanError?.description} + feedback={t(carePlanError?.description || '')} isInvalid={!!carePlanError?.description} isEditable={!disabled} onChange={(event) => onFieldChange('description', event.currentTarget.value)} @@ -80,7 +80,7 @@ const CarePlanForm = (props: Props) => { value={carePlan.diagnosisId} label={t('patient.carePlan.condition')} name="condition" - feedback={carePlanError?.condition} + feedback={t(carePlanError?.condition || '')} isInvalid={!!carePlanError?.condition} isEditable={!disabled} onChange={(event) => onFieldChange('diagnosisId', event.currentTarget.value)} @@ -95,7 +95,7 @@ const CarePlanForm = (props: Props) => { value={carePlan.status} label={t('patient.carePlan.status')} name="status" - feedback={carePlanError?.status} + feedback={t(carePlanError?.status || '')} isInvalid={!!carePlanError?.status} isEditable={!disabled} options={Object.values(CarePlanStatus).map((v) => ({ label: v, value: v }))} @@ -108,7 +108,7 @@ const CarePlanForm = (props: Props) => { value={carePlan.intent} label={t('patient.carePlan.intent')} name="intent" - feedback={carePlanError?.intent} + feedback={t(carePlanError?.intent || '')} isInvalid={!!carePlanError?.intent} isEditable={!disabled} options={Object.values(CarePlanIntent).map((v) => ({ label: v, value: v }))} @@ -123,7 +123,7 @@ const CarePlanForm = (props: Props) => { value={carePlan.startDate ? new Date(carePlan.startDate) : new Date()} label={t('patient.carePlan.startDate')} name="startDate" - feedback={carePlanError?.startDate} + feedback={t(carePlanError?.startDate || '')} isInvalid={!!carePlanError?.startDate} isEditable={!disabled} onChange={(date) => onFieldChange('startDate', date.toISOString())} @@ -135,7 +135,7 @@ const CarePlanForm = (props: Props) => { value={carePlan.endDate ? new Date(carePlan.endDate) : new Date()} label={t('patient.carePlan.endDate')} name="endDate" - feedback={carePlanError?.endDate} + feedback={t(carePlanError?.endDate || '')} isInvalid={!!carePlanError?.endDate} isEditable={!disabled} onChange={(date) => onFieldChange('endDate', date.toISOString())} diff --git a/src/patients/patient-slice.ts b/src/patients/patient-slice.ts index 3f8b80b5ee..2e98e75b89 100644 --- a/src/patients/patient-slice.ts +++ b/src/patients/patient-slice.ts @@ -401,41 +401,41 @@ function validateCarePlan(carePlan: CarePlan): AddCarePlanError { const error: AddCarePlanError = {} if (!carePlan.title) { - error.title = 'patient.carePlans.error.titleRequired' + error.title = 'patient.carePlan.error.titleRequired' } if (!carePlan.description) { - error.description = 'patient.carePlans.error.descriptionRequired' + error.description = 'patient.carePlan.error.descriptionRequired' } if (!carePlan.status) { - error.status = 'patient.carePlans.error.statusRequired' + error.status = 'patient.carePlan.error.statusRequired' } if (!carePlan.intent) { - error.intent = 'patient.carePlans.error.intentRequired' + error.intent = 'patient.carePlan.error.intentRequired' } if (!carePlan.startDate) { - error.startDate = 'patient.carePlans.error.startDateRequired' + error.startDate = 'patient.carePlan.error.startDateRequired' } if (!carePlan.endDate) { - error.endDate = 'patient.carePlans.error.endDateRequired' + error.endDate = 'patient.carePlan.error.endDateRequired' } if (carePlan.startDate && carePlan.endDate) { if (isBefore(new Date(carePlan.endDate), new Date(carePlan.startDate))) { - error.endDate = 'patient.carePlans.error.endDateMustBeAfterStartDate' + error.endDate = 'patient.carePlan.error.endDateMustBeAfterStartDate' } } if (!carePlan.diagnosisId) { - error.condition = 'patient.carePlans.error.conditionRequired' + error.condition = 'patient.carePlan.error.conditionRequired' } if (!carePlan.note) { - error.note = 'patient.carePlans.error.noteRequired' + error.note = 'patient.carePlan.error.noteRequired' } return error @@ -459,7 +459,7 @@ export const addCarePlan = ( await dispatch(updatePatient(patient, onSuccess)) } else { - carePlanError.message = 'patient.carePlans.error.unableToAdd' + carePlanError.message = 'patient.carePlan.error.unableToAdd' dispatch(addCarePlanError(carePlanError)) } }