diff --git a/packages/esm-patient-outcomes-app/src/smsform/common/types.ts b/packages/esm-patient-outcomes-app/src/smsform/common/types.ts index e0682f7..3c476a7 100644 --- a/packages/esm-patient-outcomes-app/src/smsform/common/types.ts +++ b/packages/esm-patient-outcomes-app/src/smsform/common/types.ts @@ -4,6 +4,7 @@ export type SmsFormData = { body: string; source: string; patientUuid: string; + locale: string; }; export type UpdateSmsPayload = SmsFormData & {}; diff --git a/packages/esm-patient-outcomes-app/src/smsform/send-sms-form.component.tsx b/packages/esm-patient-outcomes-app/src/smsform/send-sms-form.component.tsx index e073881..45c3aa4 100644 --- a/packages/esm-patient-outcomes-app/src/smsform/send-sms-form.component.tsx +++ b/packages/esm-patient-outcomes-app/src/smsform/send-sms-form.component.tsx @@ -7,12 +7,21 @@ import { first } from 'rxjs/operators'; import { useTranslation } from 'react-i18next'; import { z } from 'zod'; import { zodResolver } from '@hookform/resolvers/zod'; -import { ExtensionSlot, showSnackbar, useConnectivity, useLayoutType, usePatient } from '@openmrs/esm-framework'; +import { + ExtensionSlot, + showSnackbar, + useConnectivity, + useLayoutType, + usePatient, + useSession, +} from '@openmrs/esm-framework'; import { type DefaultPatientWorkspaceProps } from '@openmrs/esm-patient-common-lib'; import { type SmsFormData } from './common/types'; import styles from './send-sms-form.scss'; import { saveQuestionnaire } from './common'; import SendSmsField from './send-sms-input.componet'; +import { Select } from '@carbon/react'; +import { SelectItem } from '@carbon/react'; interface SendSmsFormProps extends DefaultPatientWorkspaceProps { showPatientHeader?: boolean; @@ -27,6 +36,7 @@ const SendSmsForm: React.FC = ({ const isTablet = useLayoutType() === 'tablet'; const isOnline = useConnectivity(); const { patientUuid, patient } = usePatient(); + const { locale, allowedLocales } = useSession(); const visitHeaderSlotState = useMemo(() => ({ patientUuid }), [patientUuid]); const [isSubmitting, setIsSubmitting] = useState(false); @@ -38,6 +48,7 @@ const SendSmsForm: React.FC = ({ const phoneValidation = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/; return z.object({ to: z.string().regex(phoneValidation, { message: 'Invalid phone number' }), + locale: z.string().min(1, { message: 'Language selection is required' }), }); }, []); @@ -58,6 +69,12 @@ const SendSmsForm: React.FC = ({ promptBeforeClosing(() => isDirty); }, [isDirty, promptBeforeClosing, patient]); + useEffect(() => { + if (locale) { + methods.setValue('locale', locale); + } + }, [locale]); + const onSubmit = useCallback( (data: SmsFormData, event: any) => { if (!patientUuid) { @@ -65,10 +82,10 @@ const SendSmsForm: React.FC = ({ } setIsSubmitting(true); + const { to, locale } = data; - const { to } = data; const guid = uuid(); - const body = window.location.host.concat(`/outcomes?pid=${guid}`); + const body = window.location.host.concat(`/outcomes?pid=${guid}&locale=${locale}`); const source = window.location.host; let payload: SmsFormData = { @@ -77,6 +94,7 @@ const SendSmsForm: React.FC = ({ body: body, source: source, patientUuid: patientUuid, + locale: locale, }; const abortController = new AbortController(); @@ -157,6 +175,18 @@ const SendSmsForm: React.FC = ({ inputFieldType="text" inputFieldPlaceholder={t('smsReceiver', 'SMS Recipient phone number')} /> +
+ +
{ render(); expect(screen.getByText(/Phone number/i)).toBeInTheDocument(); + expect(screen.getByRole('combobox', { name: /Select Language/i })).toBeInTheDocument(); expect(screen.getByRole('button', { name: /Send SMS/i })).toBeInTheDocument(); });