diff --git a/packages/esm-billing-app/package.json b/packages/esm-billing-app/package.json index af66d5c..b807903 100644 --- a/packages/esm-billing-app/package.json +++ b/packages/esm-billing-app/package.json @@ -1,6 +1,6 @@ { "name": "@ehospital/esm-billing-app", - "version": "1.2.8", + "version": "1.3.0", "description": "Billing frontend module for use in O3", "browser": "dist/ehospital-esm-billing-app.js", "main": "src/index.ts", @@ -121,5 +121,5 @@ "*.{js,jsx,ts,tsx}": "eslint --cache --fix" }, "packageManager": "yarn@4.1.1", - "gitHead": "7c7b1efa438601ea3b1f2697a6c96c57b46f9b9c" + "gitHead": "309055b8757f9eca2383037d81b0b3a25c8a185d" } diff --git a/packages/esm-billing-app/src/payment-modes/payment-mode-dashboard.component.tsx b/packages/esm-billing-app/src/payment-modes/payment-mode-dashboard.component.tsx index 0287b66..c23e70d 100644 --- a/packages/esm-billing-app/src/payment-modes/payment-mode-dashboard.component.tsx +++ b/packages/esm-billing-app/src/payment-modes/payment-mode-dashboard.component.tsx @@ -55,9 +55,11 @@ const PaymentModeDashboard: React.FC = () => { }); }; - const createPaymentModeModal = () => { + const createPaymentModeModal = (paymentMode: PaymentMode, modalTitle: string) => { const dispose = showModal('create-payment-mode', { closeModal: () => dispose(), + initialPaymentMode: paymentMode, + modalTitle, }); } @@ -112,10 +114,9 @@ const PaymentModeDashboard: React.FC = () => {
@@ -160,12 +161,7 @@ const PaymentModeDashboard: React.FC = () => { - launchWorkspace('payment-mode-workspace', { - workspaceTitle: t('editPaymentMode', 'Edit Payment Mode'), - initialPaymentMode: paymentModes[index], - }) - } + onClick={() => createPaymentModeModal(paymentModes[index], t('editPaymentMode', 'Edit Payment Mode')) } itemText={t('edit', 'Edit')} /> { test('should validate and submit correct form payload', async () => { const user = userEvent.setup(); - render(); + const mockCloseModal = jest.fn(); + render(); const nameInput = screen.getByRole('textbox', { name: /Payment mode name/i }); const descriptionInput = screen.getByRole('textbox', { name: /Payment mode description/i }); const submitButton = screen.getByRole('button', { name: /Save & Close/i }); @@ -48,6 +49,7 @@ describe('PaymentModeWorkspace', () => { test('should show error message when submitting form fails', async () => { const user = userEvent.setup(); + const mockCloseModal = jest.fn() mockCreatePaymentMode.mockRejectedValue({ responseBody: { error: { @@ -55,7 +57,7 @@ describe('PaymentModeWorkspace', () => { }, }, }); - render(); + render(); const nameInput = screen.getByRole('textbox', { name: /Payment mode name/i }); const descriptionInput = screen.getByRole('textbox', { name: /Payment mode description/i }); const submitButton = screen.getByRole('button', { name: /Save & Close/i }); @@ -75,7 +77,8 @@ describe('PaymentModeWorkspace', () => { test('should submit payload with attributeTypes', async () => { const user = userEvent.setup(); - render(); + const mockCloseModal = jest.fn() + render(); // key in name, description and retired const nameInput = screen.getByRole('textbox', { name: /Payment mode name/i }); diff --git a/packages/esm-billing-app/src/payment-modes/payment-mode.workspace.tsx b/packages/esm-billing-app/src/payment-modes/payment-mode.workspace.tsx index 53f2440..ef042d4 100644 --- a/packages/esm-billing-app/src/payment-modes/payment-mode.workspace.tsx +++ b/packages/esm-billing-app/src/payment-modes/payment-mode.workspace.tsx @@ -12,14 +12,22 @@ import usePaymentModeFormSchema from './usePaymentModeFormSchema'; import PaymentModeAttributeFields from './payment-attributes/payment-mode-attributes.component'; import { Add } from '@carbon/react/icons'; -const CreatePaymentMode = ({ closeModal }) => { +type CreatePaymentModeModalProps = { + closeModal: () => void; + initialPaymentMode?: PaymentMode; + modalTitle: string + }; + +const CreatePaymentMode : React.FC = ({ closeModal, initialPaymentMode = {} as PaymentMode, modalTitle }) => { const { t } = useTranslation(); const { paymentModeFormSchema } = usePaymentModeFormSchema(); type PaymentModeFormSchema = z.infer; + const formDefaultValues = Object.keys(initialPaymentMode).length > 0 ? initialPaymentMode : {}; const formMethods = useForm({ resolver: zodResolver(paymentModeFormSchema), mode: 'all', + defaultValues: formDefaultValues, }); const { errors, isSubmitting } = formMethods.formState; @@ -54,7 +62,7 @@ const CreatePaymentMode = ({ closeModal }) => { }; try { - const response = await createPaymentMode(payload, ''); + const response = await createPaymentMode(payload, initialPaymentMode?.uuid ?? ''); if (response.ok) { showSnackbar({ title: t('paymentModeCreated', 'Payment mode created successfully'), @@ -96,7 +104,7 @@ const CreatePaymentMode = ({ closeModal }) => { return (
- Create Payment Mode + {modalTitle} { {isSubmitting ? ( <> - {t('creating', 'Creating')} + {t('submitting', 'Submitting...')} ) : ( - t('create', 'Create') + t('saveAndClose', 'Save & close') )} diff --git a/packages/esm-billing-app/src/routes.json b/packages/esm-billing-app/src/routes.json index f0d6f76..9a81812 100644 --- a/packages/esm-billing-app/src/routes.json +++ b/packages/esm-billing-app/src/routes.json @@ -155,6 +155,10 @@ "name": "clock-out-modal", "component": "clockOutModal" }, + { + "name": "create-payment-mode", + "component": "createPaymentMode" + }, { "name": "delete-payment-mode-modal", "component": "deletePaymentModeModal" @@ -166,10 +170,6 @@ { "name": "paid-bill-receipt-print-preview-modal", "component": "paidBillReceiptPrintPreviewModal" - }, - { - "name": "create-payment-mode", - "component": "createPaymentMode" } ] }