From 466c1d628a38e5682dd8bd2eb931c3c6d22dff17 Mon Sep 17 00:00:00 2001 From: abertnamanya Date: Thu, 16 Oct 2025 09:08:53 +0300 Subject: [PATCH 01/10] O3-5121:Edit/Update Cashpoint --- .../billable-service.resource.ts | 22 +++++++++++ .../cash-point/add-cash-point.modal.tsx | 39 +++++++++++-------- .../cash-point-configuration.component.tsx | 36 +++++++++++++++-- src/types/index.ts | 2 +- translations/en.json | 1 + 5 files changed, 79 insertions(+), 21 deletions(-) diff --git a/src/billable-services/billable-service.resource.ts b/src/billable-services/billable-service.resource.ts index 5075ec18..723184e0 100644 --- a/src/billable-services/billable-service.resource.ts +++ b/src/billable-services/billable-service.resource.ts @@ -91,3 +91,25 @@ export const updateBillableService = (uuid: string, payload: any) => { }, }); }; + +export const createCashPoint = (payload: any) => { + const url = `${apiBasePath}cashPoint`; + return openmrsFetch(url, { + method: 'POST', + body: payload, + headers: { + 'Content-Type': 'application/json', + }, + }); +}; + +export const updateCashPoint = (uuid: string, payload: any) => { + const url = `${apiBasePath}/cashPoint/${uuid}`; + return openmrsFetch(url, { + method: 'POST', + body: JSON.stringify(payload), + headers: { + 'Content-Type': 'application/json', + }, + }); +}; diff --git a/src/billable-services/cash-point/add-cash-point.modal.tsx b/src/billable-services/cash-point/add-cash-point.modal.tsx index 0becde29..410c8437 100644 --- a/src/billable-services/cash-point/add-cash-point.modal.tsx +++ b/src/billable-services/cash-point/add-cash-point.modal.tsx @@ -5,6 +5,8 @@ import { z } from 'zod'; import { zodResolver } from '@hookform/resolvers/zod'; import { Button, Dropdown, Form, ModalBody, ModalFooter, ModalHeader, TextInput } from '@carbon/react'; import { showSnackbar, openmrsFetch, restBaseUrl, getCoreTranslation } from '@openmrs/esm-framework'; +import { type CashPoint } from '../../types'; +import { createCashPoint, updateCashPoint } from '../billable-service.resource'; type CashPointFormValues = { name: string; @@ -13,11 +15,12 @@ type CashPointFormValues = { }; interface AddCashPointModalProps { + cashPointToEdit?: CashPoint; closeModal: () => void; onCashPointAdded: () => void; } -const AddCashPointModal: React.FC = ({ closeModal, onCashPointAdded }) => { +const AddCashPointModal: React.FC = ({ cashPointToEdit, closeModal, onCashPointAdded }) => { const { t } = useTranslation(); const [locations, setLocations] = useState([]); @@ -41,9 +44,9 @@ const AddCashPointModal: React.FC = ({ closeModal, onCas } = useForm({ resolver: zodResolver(cashPointSchema), defaultValues: { - name: '', - uuid: '', - location: '', + name: cashPointToEdit?.name || '', + uuid: cashPointToEdit?.uuid || '', + location: cashPointToEdit?.location?.uuid || '', }, }); @@ -70,19 +73,12 @@ const AddCashPointModal: React.FC = ({ closeModal, onCas }, [fetchLocations]); const onSubmit = async (data: CashPointFormValues) => { + const payload = { + name: data.name, + uuid: data.uuid, + location: { uuid: data.location }, + }; try { - await openmrsFetch(`${restBaseUrl}/billing/cashPoint`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: { - name: data.name, - uuid: data.uuid, - location: { uuid: data.location }, - }, - }); - showSnackbar({ title: t('success', 'Success'), subtitle: t('cashPointSaved', 'Cash point was successfully saved.'), @@ -90,7 +86,16 @@ const AddCashPointModal: React.FC = ({ closeModal, onCas }); closeModal(); - reset({ name: '', uuid: '', location: '' }); + reset({ + name: cashPointToEdit?.name || '', + uuid: cashPointToEdit?.uuid || '', + location: cashPointToEdit?.location.uuid || '', + }); + if (cashPointToEdit) { + await updateCashPoint(cashPointToEdit.uuid, payload); + } else { + await createCashPoint(payload); + } onCashPointAdded(); } catch (err) { showSnackbar({ diff --git a/src/billable-services/cash-point/cash-point-configuration.component.tsx b/src/billable-services/cash-point/cash-point-configuration.component.tsx index c038edee..4c5f5a90 100644 --- a/src/billable-services/cash-point/cash-point-configuration.component.tsx +++ b/src/billable-services/cash-point/cash-point-configuration.component.tsx @@ -2,6 +2,8 @@ import React, { useState, useEffect, useCallback } from 'react'; import { Button, DataTable, + OverflowMenu, + OverflowMenuItem, Table, TableBody, TableCell, @@ -12,13 +14,23 @@ import { } from '@carbon/react'; import { Add } from '@carbon/react/icons'; import { useTranslation } from 'react-i18next'; -import { showSnackbar, openmrsFetch, restBaseUrl, showModal, getCoreTranslation } from '@openmrs/esm-framework'; +import { + showSnackbar, + openmrsFetch, + restBaseUrl, + showModal, + getCoreTranslation, + isDesktop, + useLayoutType, +} from '@openmrs/esm-framework'; import { CardHeader } from '@openmrs/esm-patient-common-lib'; import styles from './cash-point-configuration.scss'; +import { type CashPoint } from '../../types/index'; const CashPointConfiguration: React.FC = () => { const { t } = useTranslation(); const [cashPoints, setCashPoints] = useState([]); + const layout = useLayoutType(); const fetchCashPoints = useCallback(async () => { try { @@ -45,7 +57,15 @@ const CashPointConfiguration: React.FC = () => { }); }; - const rowData = cashPoints.map((point) => ({ + const handleEditCashPoint = (point: CashPoint) => { + const dispose = showModal('add-cash-point-modal', { + cashPointToEdit: point, + onCashPointAdded: fetchCashPoints, + closeModal: () => dispose(), + }); + }; + + const rowData = cashPoints.map((point: CashPoint) => ({ id: point.uuid, name: point.name, uuid: point.uuid, @@ -67,7 +87,7 @@ const CashPointConfiguration: React.FC = () => {
- + {({ rows, headers, getTableProps, getHeaderProps, getRowProps }) => ( @@ -78,6 +98,7 @@ const CashPointConfiguration: React.FC = () => { {header.header} ))} + @@ -86,6 +107,15 @@ const CashPointConfiguration: React.FC = () => { {row.cells.map((cell) => ( {cell.value} ))} + + + handleEditCashPoint(cashPoints.find((point) => point.uuid === row.id))} + /> + + ))} diff --git a/src/types/index.ts b/src/types/index.ts index 34ef0b95..69f966bb 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -31,7 +31,7 @@ interface Location { links: LocationLink[]; } -interface CashPoint { +export interface CashPoint { uuid: string; name: string; description: string; diff --git a/translations/en.json b/translations/en.json index ec3af7c6..966cf562 100644 --- a/translations/en.json +++ b/translations/en.json @@ -74,6 +74,7 @@ "editBillableService": "Edit billable service", "editBillableServices": "Edit Billable Services", "editBillLineItem": "Edit bill line item", + "editCashPoint": "Edit cash point", "editThisBillItem": "Edit this bill item", "enterAmount": "Enter amount", "enterConcept": "Associated concept", From 16aef2f29215338923147bc09d386533934cf12a Mon Sep 17 00:00:00 2001 From: abertnamanya Date: Thu, 16 Oct 2025 13:00:04 +0300 Subject: [PATCH 02/10] Update src/billable-services/billable-service.resource.ts Co-authored-by: Nethmi Rodrigo --- .../billable-service.resource.ts | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/billable-services/billable-service.resource.ts b/src/billable-services/billable-service.resource.ts index 55497143..ee5264b8 100644 --- a/src/billable-services/billable-service.resource.ts +++ b/src/billable-services/billable-service.resource.ts @@ -100,24 +100,16 @@ export const updateBillableService = (uuid: string, payload: UpdateBillableServi }); }; -export const createCashPoint = (payload: any) => { - const url = `${apiBasePath}cashPoint`; +export const updateCashPoint = (uuid: string | null, payload: CashPointPayload) => { + let url = `${apiBasePath}/cashPoint`; + if (uuid) { + url = `${apiBasePath}/cashPoint/${uuid}`; + } return openmrsFetch(url, { - method: 'POST', + method: uuid ? 'POST' : 'PUT', body: payload, headers: { 'Content-Type': 'application/json', }, }); }; - -export const updateCashPoint = (uuid: string, payload: any) => { - const url = `${apiBasePath}/cashPoint/${uuid}`; - return openmrsFetch(url, { - method: 'POST', - body: JSON.stringify(payload), - headers: { - 'Content-Type': 'application/json', - }, - }); -}; From 9dfb19bf624bb1d959a52233e5c07bd02b92a667 Mon Sep 17 00:00:00 2001 From: abertnamanya Date: Thu, 16 Oct 2025 13:00:32 +0300 Subject: [PATCH 03/10] Update src/billable-services/cash-point/add-cash-point.modal.tsx Co-authored-by: Nethmi Rodrigo --- src/billable-services/cash-point/add-cash-point.modal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/billable-services/cash-point/add-cash-point.modal.tsx b/src/billable-services/cash-point/add-cash-point.modal.tsx index 410c8437..25ff8630 100644 --- a/src/billable-services/cash-point/add-cash-point.modal.tsx +++ b/src/billable-services/cash-point/add-cash-point.modal.tsx @@ -73,7 +73,7 @@ const AddCashPointModal: React.FC = ({ cashPointToEdit, }, [fetchLocations]); const onSubmit = async (data: CashPointFormValues) => { - const payload = { + const payload: CashPointPayload = { name: data.name, uuid: data.uuid, location: { uuid: data.location }, From 360c4cfe9fa1503ced3f020613235a25e8252fee Mon Sep 17 00:00:00 2001 From: abertnamanya Date: Thu, 16 Oct 2025 13:00:51 +0300 Subject: [PATCH 04/10] Update src/billable-services/cash-point/add-cash-point.modal.tsx Co-authored-by: Nethmi Rodrigo --- src/billable-services/cash-point/add-cash-point.modal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/billable-services/cash-point/add-cash-point.modal.tsx b/src/billable-services/cash-point/add-cash-point.modal.tsx index 25ff8630..86fb2895 100644 --- a/src/billable-services/cash-point/add-cash-point.modal.tsx +++ b/src/billable-services/cash-point/add-cash-point.modal.tsx @@ -5,8 +5,8 @@ import { z } from 'zod'; import { zodResolver } from '@hookform/resolvers/zod'; import { Button, Dropdown, Form, ModalBody, ModalFooter, ModalHeader, TextInput } from '@carbon/react'; import { showSnackbar, openmrsFetch, restBaseUrl, getCoreTranslation } from '@openmrs/esm-framework'; -import { type CashPoint } from '../../types'; import { createCashPoint, updateCashPoint } from '../billable-service.resource'; +import type { CashPoint, CashPointPayload } from '../../types'; type CashPointFormValues = { name: string; From 2113069bfad7cb7b0caa6e871fa02169e3ad6cd6 Mon Sep 17 00:00:00 2001 From: abertnamanya Date: Thu, 16 Oct 2025 13:31:41 +0300 Subject: [PATCH 05/10] O3-5121:Edit/Update Cashpoint fixes --- src/billable-services/billable-service.resource.ts | 9 +++++---- .../cash-point/add-cash-point.modal.tsx | 12 ++++++------ src/types/index.ts | 8 ++++++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/billable-services/billable-service.resource.ts b/src/billable-services/billable-service.resource.ts index ee5264b8..041d9255 100644 --- a/src/billable-services/billable-service.resource.ts +++ b/src/billable-services/billable-service.resource.ts @@ -6,6 +6,7 @@ import { type ServiceConcept, type CreateBillableServicePayload, type UpdateBillableServicePayload, + type CashPointPayload, } from '../types'; import type { BillingConfig } from '../config-schema'; @@ -100,13 +101,13 @@ export const updateBillableService = (uuid: string, payload: UpdateBillableServi }); }; -export const updateCashPoint = (uuid: string | null, payload: CashPointPayload) => { - let url = `${apiBasePath}/cashPoint`; +export const updateOrCreateCashPoint = (uuid: string | null, payload: CashPointPayload) => { + let url = `${apiBasePath}cashPoint`; if (uuid) { - url = `${apiBasePath}/cashPoint/${uuid}`; + url = `${apiBasePath}cashPoint/${uuid}`; } return openmrsFetch(url, { - method: uuid ? 'POST' : 'PUT', + method: 'POST', body: payload, headers: { 'Content-Type': 'application/json', diff --git a/src/billable-services/cash-point/add-cash-point.modal.tsx b/src/billable-services/cash-point/add-cash-point.modal.tsx index 86fb2895..669d2424 100644 --- a/src/billable-services/cash-point/add-cash-point.modal.tsx +++ b/src/billable-services/cash-point/add-cash-point.modal.tsx @@ -5,7 +5,7 @@ import { z } from 'zod'; import { zodResolver } from '@hookform/resolvers/zod'; import { Button, Dropdown, Form, ModalBody, ModalFooter, ModalHeader, TextInput } from '@carbon/react'; import { showSnackbar, openmrsFetch, restBaseUrl, getCoreTranslation } from '@openmrs/esm-framework'; -import { createCashPoint, updateCashPoint } from '../billable-service.resource'; +import { updateOrCreateCashPoint } from '../billable-service.resource'; import type { CashPoint, CashPointPayload } from '../../types'; type CashPointFormValues = { @@ -85,17 +85,17 @@ const AddCashPointModal: React.FC = ({ cashPointToEdit, kind: 'success', }); + if (cashPointToEdit) { + await updateOrCreateCashPoint(cashPointToEdit.uuid, payload); + } else { + await updateOrCreateCashPoint(null, payload); + } closeModal(); reset({ name: cashPointToEdit?.name || '', uuid: cashPointToEdit?.uuid || '', location: cashPointToEdit?.location.uuid || '', }); - if (cashPointToEdit) { - await updateCashPoint(cashPointToEdit.uuid, payload); - } else { - await createCashPoint(payload); - } onCashPointAdded(); } catch (err) { showSnackbar({ diff --git a/src/types/index.ts b/src/types/index.ts index 414b2106..e438bbec 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -41,6 +41,14 @@ export interface CashPoint { location: Location; } +export interface CashPointPayload { + uuid: string; + name: string; + location: { + uuid: string; + }; +} + interface ProviderLink { rel: string; uri: string; From 298cd00dba6e9b1478afbd79ba9364ac176af781 Mon Sep 17 00:00:00 2001 From: abertnamanya Date: Mon, 20 Oct 2025 10:28:42 +0300 Subject: [PATCH 06/10] O3-5121:Edit/Update Cashpoint fixes --- .../cash-point/add-cash-point.modal.tsx | 21 +++++++++---------- .../cash-point-configuration.component.tsx | 7 ++++++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/billable-services/cash-point/add-cash-point.modal.tsx b/src/billable-services/cash-point/add-cash-point.modal.tsx index 1a90161f..c745fc9a 100644 --- a/src/billable-services/cash-point/add-cash-point.modal.tsx +++ b/src/billable-services/cash-point/add-cash-point.modal.tsx @@ -79,23 +79,18 @@ const AddCashPointModal: React.FC = ({ cashPointToEdit, location: { uuid: data.location }, }; try { + if (cashPointToEdit) { + await updateOrCreateCashPoint(cashPointToEdit.uuid, payload); + } else { + await updateOrCreateCashPoint(null, payload); + } showSnackbar({ title: t('success', 'Success'), subtitle: t('cashPointSaved', 'Cash point was successfully saved.'), kind: 'success', }); - if (cashPointToEdit) { - await updateOrCreateCashPoint(cashPointToEdit.uuid, payload); - } else { - await updateOrCreateCashPoint(null, payload); - } closeModal(); - reset({ - name: cashPointToEdit?.name || '', - uuid: cashPointToEdit?.uuid || '', - location: cashPointToEdit?.location.uuid || '', - }); onCashPointAdded(); } catch (err) { showSnackbar({ @@ -109,7 +104,10 @@ const AddCashPointModal: React.FC = ({ cashPointToEdit, return ( <> - +
= ({ cashPointToEdit, placeholder={t('cashPointUuidPlaceholder', 'Enter UUID')} invalid={!!errors.uuid} invalidText={errors.uuid?.message} + disabled={!!cashPointToEdit} {...field} /> )} diff --git a/src/billable-services/cash-point/cash-point-configuration.component.tsx b/src/billable-services/cash-point/cash-point-configuration.component.tsx index 2821e57a..91e433bc 100644 --- a/src/billable-services/cash-point/cash-point-configuration.component.tsx +++ b/src/billable-services/cash-point/cash-point-configuration.component.tsx @@ -112,7 +112,12 @@ const CashPointConfiguration: React.FC = () => { handleEditCashPoint(cashPoints.find((point) => point.uuid === row.id))} + onClick={() => { + const cashPoint = cashPoints.find((point) => point.uuid === row.id); + if (cashPoint) { + handleEditCashPoint(cashPoint); + } + }} /> From ff89adfd70e4746a148a65e8db39aa7d4e7eadf0 Mon Sep 17 00:00:00 2001 From: abertnamanya Date: Tue, 21 Oct 2025 11:58:28 +0300 Subject: [PATCH 07/10] conflict Merge fix --- src/billable-services/cash-point/add-cash-point.modal.tsx | 5 ++--- translations/en.json | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/billable-services/cash-point/add-cash-point.modal.tsx b/src/billable-services/cash-point/add-cash-point.modal.tsx index b7940ea0..8e432251 100644 --- a/src/billable-services/cash-point/add-cash-point.modal.tsx +++ b/src/billable-services/cash-point/add-cash-point.modal.tsx @@ -134,8 +134,8 @@ const AddCashPointModal: React.FC = ({ cashPointToEdit, labelText={t('cashPointUuid', 'Cash Point UUID')} placeholder={t('cashPointUuidPlaceholder', 'Enter UUID')} invalid={!!errors.uuid} - invalidText={errors.uuid?.message - disabled={!!cashPointToEdit} + invalidText={errors.uuid?.message} + disabled={!!cashPointToEdit} {...field} /> )} @@ -157,7 +157,6 @@ const AddCashPointModal: React.FC = ({ cashPointToEdit, )} /> -