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

Commit

Permalink
feat(care plan): fix internationalization
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Jun 4, 2020
1 parent 066e142 commit 72a5bed
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 28 deletions.
20 changes: 10 additions & 10 deletions src/__tests__/patients/patient-slice.test.ts
Expand Up @@ -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
Expand All @@ -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',
}),
),
)
Expand Down
10 changes: 10 additions & 0 deletions src/locales/enUs/translations/patient/index.ts
Expand Up @@ -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',
Expand Down
16 changes: 8 additions & 8 deletions src/patients/care-plans/CarePlanForm.tsx
Expand Up @@ -44,15 +44,15 @@ const CarePlanForm = (props: Props) => {

return (
<form>
{carePlanError?.message && <Alert color="danger" message={carePlanError.message} />}
{carePlanError?.message && <Alert color="danger" message={t(carePlanError.message)} />}
<Row>
<Column sm={12}>
<TextInputWithLabelFormGroup
isRequired
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)}
Expand All @@ -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)}
Expand All @@ -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)}
Expand All @@ -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 }))}
Expand All @@ -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 }))}
Expand All @@ -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())}
Expand All @@ -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())}
Expand Down
20 changes: 10 additions & 10 deletions src/patients/patient-slice.ts
Expand Up @@ -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
Expand All @@ -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))
}
}
Expand Down

0 comments on commit 72a5bed

Please sign in to comment.