Skip to content

Commit

Permalink
Fix up translation function
Browse files Browse the repository at this point in the history
  • Loading branch information
denniskigen committed May 16, 2024
1 parent 813bbc9 commit 3c044b9
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/post-submission-actions/program-enrollment-action.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import dayjs from 'dayjs';
import { showToast } from '@openmrs/esm-framework';
import { showToast, translateFrom } from '@openmrs/esm-framework';
import { createProgramEnrollment, getPatientEnrolledPrograms, updateProgramEnrollment } from '../api/api';
import { type PostSubmissionAction, type ProgramEnrollmentPayload } from '../types';
import { moduleName } from 'src/globals';

export const ProgramEnrollmentSubmissionAction: PostSubmissionAction = {
applyAction: async function ({ patient, encounters, sessionMode }, config) {
const encounter = encounters[0];
const encounterLocation = encounter.location['uuid'];
const t = window.i18next.t;

const translateFn = (key, defaultValue?) => translateFrom(moduleName, key, defaultValue);

// only do this in enter or edit mode.
if (sessionMode === 'view') {
Expand Down Expand Up @@ -36,10 +38,11 @@ export const ProgramEnrollmentSubmissionAction: PostSubmissionAction = {
);
if (hasActiveEnrollment) {
showToast({
title: t('enrollmentFailed', 'Enrollment failed'),
title: translateFn('enrollmentFailed', 'Enrollment failed'),
kind: 'error',
critical: false,
description: t(
description: translateFrom(
moduleName,
'cannotEnrollPatientToProgram',
'This patient is already enrolled in the selected program',
),
Expand All @@ -53,17 +56,17 @@ export const ProgramEnrollmentSubmissionAction: PostSubmissionAction = {
showToast({
critical: true,
kind: 'success',
description: t('enrolledToProgram', 'Patient enrolled into ${programName}'),
title: t('enrollmentSaved', 'Enrollment saved'),
description: translateFn('enrolledToProgram', 'Patient enrolled into ${programName}'),
title: translateFn('enrollmentSaved', 'Enrollment saved'),
});
}
},
(err) => {
showToast({
title: t('errorEnrolling', 'Error saving enrollment'),
title: translateFn('errorEnrolling', 'Error saving enrollment'),
kind: 'error',
critical: false,
description: t(err?.message),
description: translateFn(err?.message),
});
},
);
Expand All @@ -86,14 +89,17 @@ export const ProgramEnrollmentSubmissionAction: PostSubmissionAction = {
showToast({
critical: true,
kind: 'success',
description: t('enrollmentUpdateSuccess', 'Updates to the program enrollment were made successfully'),
title: t('enrollmentUpdated', 'Enrollment updated'),
description: translateFn(
'enrollmentUpdateSuccess',
'Updates to the program enrollment were made successfully',
),
title: translateFn('enrollmentUpdated', 'Enrollment updated'),
});
}
},
(err) => {
showToast({
title: t('errorSavingEnrollment', 'Error saving enrollment'),
title: translateFn('errorSavingEnrollment', 'Error saving enrollment'),
kind: 'error',
critical: false,
description: err?.message,
Expand Down

0 comments on commit 3c044b9

Please sign in to comment.