From b3d1c5aa821d1d92cf6f4504cff51864261e4ffc Mon Sep 17 00:00:00 2001 From: AJAL ODORA JONATHAN <43242517+ODORA0@users.noreply.github.com> Date: Thu, 22 Feb 2024 22:40:14 +0300 Subject: [PATCH] PR comments --- src/bill-history/bill-history.component.tsx | 8 +++---- src/billing-form/billing-form.component.tsx | 23 ++++++++------------- src/config-schema.ts | 8 +++++++ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/bill-history/bill-history.component.tsx b/src/bill-history/bill-history.component.tsx index cd6ec94..02b66ec 100644 --- a/src/bill-history/bill-history.component.tsx +++ b/src/bill-history/bill-history.component.tsx @@ -37,13 +37,12 @@ interface BillHistoryProps { } const BillHistory: React.FC = ({ patientUuid }) => { - const PAGE_SIZE = 10; const { t } = useTranslation(); const { bills, isLoading, error } = useBills(patientUuid); const layout = useLayoutType(); const responsiveSize = isDesktop(layout) ? 'sm' : 'lg'; - const { paginated, goTo, results, currentPage } = usePagination(bills, PAGE_SIZE); - const { pageSizes } = usePaginationInfo(PAGE_SIZE, bills?.length, currentPage, results?.length); + const { paginated, goTo, results, currentPage } = usePagination(bills); + const { pageSize } = useConfig(); const headerData = [ { @@ -180,8 +179,7 @@ const BillHistory: React.FC = ({ patientUuid }) => { forwardText={t('nextPage', 'Next page')} backwardText={t('previousPage', 'Previous page')} page={currentPage} - pageSize={PAGE_SIZE} - pageSizes={pageSizes} + pageSize={pageSize._default} totalItems={bills.length} className={styles.pagination} size={responsiveSize} diff --git a/src/billing-form/billing-form.component.tsx b/src/billing-form/billing-form.component.tsx index b178ae7..319cd63 100644 --- a/src/billing-form/billing-form.component.tsx +++ b/src/billing-form/billing-form.component.tsx @@ -14,9 +14,10 @@ import { } from '@carbon/react'; import styles from './billing-form.scss'; import { useTranslation } from 'react-i18next'; -import { showSnackbar } from '@openmrs/esm-framework'; +import { showSnackbar, useConfig } from '@openmrs/esm-framework'; import { useFetchSearchResults, processBillItems } from '../billing.resource'; import { mutate } from 'swr'; +import { convertToCurrency } from '../helpers'; type BillingFormProps = { patientUuid: string; @@ -38,26 +39,20 @@ const BillingForm: React.FC = ({ patientUuid, closeWorkspace } }; const calculateTotal = (event, itemName) => { - const Qnty = event.target.value; - const price = document.getElementById(`${event.target.id}Price`).innerHTML; - const total = parseInt(price) * Qnty; - + const quantity = parseInt(event.target.value); const updatedItems = billItems.map((item) => { if (item.Item.toLowerCase().includes(itemName.toLowerCase())) { - item.Qnty = Qnty; - item.Total = total; + const price = item.Price; + const total = price * quantity; + return { ...item, Qnty: quantity, Total: total }; } return item; }); setBillItems(updatedItems); - const totals = Array.from(document.querySelectorAll('[id$="Total"]')); - let addUpTotals = 0; - totals.forEach((tot) => { - addUpTotals += parseInt(tot.innerHTML); - }); - setGrandTotal(addUpTotals); + const updatedGrandTotal = updatedItems.reduce((acc, item) => acc + item.Total, 0); + setGrandTotal(updatedGrandTotal); }; const calculateTotalAfterAddBillItem = () => { @@ -244,7 +239,7 @@ const BillingForm: React.FC = ({ patientUuid, closeWorkspace } Grand Total: - {grandTotal} + {convertToCurrency(grandTotal)} diff --git a/src/config-schema.ts b/src/config-schema.ts index 2d7cb38..f47328a 100644 --- a/src/config-schema.ts +++ b/src/config-schema.ts @@ -33,10 +33,18 @@ export const configSchema = { _description: 'The default currency for the application. Specify the currency code (e.g., KES, UGX, GBP).', _default: 'KES', }, + + pageSize: { + _type: Type.String, + _description: 'The default page size', + _default: 10, + }, }; export interface ConfigObject { patientCatergory: Object; defaultCurrency: string; catergoryConcepts: Object; + pageSize; + object; }