Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(refactor) Add translations for error messages in order forms #2178

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -8,7 +8,7 @@ import {
useOrderType,
priorityOptions,
} from '@openmrs/esm-patient-common-lib';
import { translateFrom, useLayoutType, useSession, useConfig, ExtensionSlot } from '@openmrs/esm-framework';
import { useLayoutType, useSession, ExtensionSlot } from '@openmrs/esm-framework';
import {
Button,
ButtonSet,
Expand All @@ -25,7 +25,6 @@ import { useTranslation } from 'react-i18next';
import { Controller, type FieldErrors, useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { moduleName } from '@openmrs/esm-patient-chart-app/src/constants';
import styles from './general-order-form.scss';
import type { ConfigObject } from '../../../config-schema';
import { ordersEqual, prepOrderPostData } from '../resources';
Expand Down Expand Up @@ -60,22 +59,18 @@ export function OrderForm({
z.object({
instructions: z.string().optional(),
urgency: z.string().refine((value) => value !== '', {
message: translateFrom(moduleName, 'addLabOrderPriorityRequired', 'Priority is required'),
message: t('priorityRequired', 'Priority is required'),
}),
accessionNumber: z.string().optional(),
concept: z.object(
{ display: z.string(), uuid: z.string() },
{
required_error: translateFrom(moduleName, 'addOrderableConceptRequired', 'Orderable concept is required'),
invalid_type_error: translateFrom(
moduleName,
'addOrderableConceptRequired',
'Orderable concept is required',
),
required_error: t('orderableConceptRequired', 'Orderable concept is required'),
invalid_type_error: t('orderableConceptRequired', 'Orderable concept is required'),
},
),
}),
[],
[t],
);

const {
Expand Down
2 changes: 2 additions & 0 deletions packages/esm-patient-orders-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"onDate": "on",
"or": "or",
"order": "Order",
"orderableConceptRequired": "Orderable concept is required",
"orderActionDiscontinue": "Discontinue",
"orderActionIncomplete": "Incomplete",
"orderActionNew": "New",
Expand Down Expand Up @@ -76,6 +77,7 @@
"printedBy": "Printed by",
"printOrder": "Print order",
"priority": "Priority",
"priorityRequired": "Priority is required",
"quantity": "Quantity",
"reasonForCancellation": "Reason for cancellation",
"reasonForCancellationRequired": "Reason for cancellation is required",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useOrderBasket,
useOrderType,
} from '@openmrs/esm-patient-common-lib';
import { ExtensionSlot, translateFrom, useConfig, useLayoutType, useSession } from '@openmrs/esm-framework';
import { ExtensionSlot, useConfig, useLayoutType, useSession } from '@openmrs/esm-framework';
import { prepTestOrderPostData, useOrderReasons } from '../api';
import {
Button,
Expand All @@ -25,7 +25,6 @@ import { ordersEqual, priorityOptions } from './test-order';
import { Controller, type FieldErrors, useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { moduleName } from '@openmrs/esm-patient-chart-app/src/constants';
import { type ConfigObject } from '../../config-schema';
import styles from './test-order-form.scss';
import type { TestOrderBasketItem } from '../../types';
Expand Down Expand Up @@ -64,32 +63,25 @@ export function LabOrderForm({
z.object({
instructions: z.string().optional(),
urgency: z.string().refine((value) => value !== '', {
message: translateFrom(moduleName, 'addLabOrderPriorityRequired', 'Priority is required'),
message: t('priorityRequired', 'Priority is required'),
}),
accessionNumber: z.string().nullable(),
testType: z.object(
{ label: z.string(), conceptUuid: z.string() },
{
required_error: translateFrom(moduleName, 'addLabOrderLabTestTypeRequired', 'Test type is required'),
invalid_type_error: translateFrom(moduleName, 'addLabOrderLabReferenceRequired', 'Test type is required'),
required_error: t('testTypeRequired', 'Test type is required'),
invalid_type_error: t('testTypeRequired', 'Test type is required'),
},
),
orderReason: orderReasonRequired
? z
.string({
required_error: translateFrom(
moduleName,
'addLabOrderLabOrderReasonRequired',
'Order reason is required',
),
required_error: t('orderReasonRequired', 'Order reason is required'),
})
.refine(
(value) => !!value,
translateFrom(moduleName, 'addLabOrderLabOrderReasonRequired', 'Order reason is required'),
)
.refine((value) => !!value, t('orderReasonRequired', 'Order reason is required'))
: z.string().optional(),
}),
[orderReasonRequired],
[orderReasonRequired, t],
);

const {
Expand Down
3 changes: 3 additions & 0 deletions packages/esm-patient-tests-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"orderActionRevise": "Modify",
"ordered": "Ordered",
"orderReason": "Order reason",
"orderReasonRequired": "Order reason is required",
"other": "Other",
"overTime": "Over time",
"panel": "Panel",
Expand All @@ -53,6 +54,7 @@
"printedBy": "Printed by",
"printTestResults": "Print test results",
"priority": "Priority",
"priorityRequired": "Priority is required",
"recentResults": "Recent Results",
"recentTestResults": "recent test results",
"referenceNumber": "Reference number",
Expand Down Expand Up @@ -86,6 +88,7 @@
"testResultsData": "Test results data",
"tests": "Tests",
"testType": "Test type",
"testTypeRequired": "Test type is required",
"timeline": "Timeline",
"timelineData_lower": "timeline data",
"tree": "Tree",
Expand Down
Loading