Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions src/bill-item-actions/edit-bill-item.modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ const EditBillLineItemModal: React.FC<EditBillLineItemModalProps> = ({ bill, clo
}, [quantity, price]);

const onSubmit = async (data: BillLineItemForm) => {
if (bill?.status === 'PENDING') {
showSnackbar({
title: t('cannotEditThisBill', 'You can not edit this bill'),
subtitle: t('onlyPendingBillsCanBeEdited', 'Only pending bills can be edited'),
kind: 'error',
});
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think this is the proper place to trigger a snackbar. I don’t think we need to add a safeguard in this modal at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok let me have it removed

const url = `${apiBasePath}bill`;

const newItem = {
Expand Down
6 changes: 4 additions & 2 deletions src/billing.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import type {

export const mapBillProperties = (bill: PatientInvoice): MappedBill => {
const activeLineItems = bill?.lineItems?.filter((item) => !item.voided) || [];
const isSpecialStatus = bill.status === 'POSTED' || bill.status === 'PAID' || bill.status === 'ADJUSTED';

const status =
activeLineItems.length > 0
const status = isSpecialStatus
? bill.status
: activeLineItems.length > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t understand why we need to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we need it coz it ensures that if the backend has already marked a bill as a final state (POSTED, PAID, or ADJUSTED), the UI keeps that status instead of recalculating one from the line items. Coz to my observation previously, the UI always derived the status from line-item states, which overwrote important server-driven statuses and incorrectly made finalized bills appear editable. The isSpecialStatus check prevents that by preserving the backend’s status so the UI can correctly block edits unless the bill is truly PENDING. But maybe I miss understood the code functionality or it could be catered for in the backend.

? activeLineItems.some((item) => item.paymentStatus === 'PENDING')
? 'PENDING'
: 'PAID'
Expand Down
33 changes: 23 additions & 10 deletions src/invoice/invoice-table.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const InvoiceTable: React.FC<InvoiceTableProps> = ({ bill, isLoadingBill }) => {
const tableRows: Array<typeof DataTableRow> = useMemo(
() =>
filteredLineItems?.map((item, index) => {
const canEditBill = bill?.status === 'PENDING';
return {
no: `${index + 1}`,
id: `${item.uuid}`,
Expand All @@ -96,20 +97,32 @@ const InvoiceTable: React.FC<InvoiceTableProps> = ({ bill, isLoadingBill }) => {
total: convertToCurrency(item.price * item.quantity, defaultCurrency),
actionButton: (
<span>
<Button
data-testid={`edit-button-${item.uuid}`}
renderIcon={Edit}
hasIconOnly
kind="ghost"
iconDescription={t('editThisBillItem', 'Edit this bill item')}
tooltipPosition="left"
onClick={() => handleSelectBillItem(item)}
/>
{canEditBill ? (
<Button
data-testid={`edit-button-${item.uuid}`}
renderIcon={Edit}
hasIconOnly
kind="ghost"
iconDescription={t('editThisBillItem', 'Edit this bill item')}
tooltipPosition="left"
onClick={() => handleSelectBillItem(item)}
/>
) : (
<Button
data-tested={`edit-button-${item.uuid}`}
renderIcon={Edit}
hasIconOnly
kind="ghost"
disabled
iconDescription={t('cannotEditThisBill', 'You can not edit this bill')}
tooltipPosition="left"
/>
)}
Copy link
Contributor

@NethmiRodrigo NethmiRodrigo Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don’t need to conditionally render a ghost button. Just disabling the button is sufficient, like so:

Suggested change
{canEditBill ? (
<Button
data-testid={`edit-button-${item.uuid}`}
renderIcon={Edit}
hasIconOnly
kind="ghost"
iconDescription={t('editThisBillItem', 'Edit this bill item')}
tooltipPosition="left"
onClick={() => handleSelectBillItem(item)}
/>
) : (
<Button
data-tested={`edit-button-${item.uuid}`}
renderIcon={Edit}
hasIconOnly
kind="ghost"
disabled
iconDescription={t('cannotEditThisBill', 'You can not edit this bill')}
tooltipPosition="left"
/>
)}
<Button
data-testid={`edit-button-${item.uuid}`}
renderIcon={Edit}
hasIconOnly
kind=“ghost”
iconDescription={t('editThisBillItem', 'Edit this bill item’)}
tooltipPosition=“left”
onClick={() => handleSelectBillItem(item)}
disabled={bill?.status !== ‘PENDING’}
/>

</span>
),
};
}) ?? [],
[filteredLineItems, bill?.receiptNumber, defaultCurrency, t, handleSelectBillItem],
[filteredLineItems, bill?.receiptNumber, defaultCurrency, t, handleSelectBillItem, bill?.status],
);

if (isLoadingBill) {
Expand Down
4 changes: 3 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,7 @@
"uuidRequired": "UUID is required",
"validationError": "Validation error",
"visitTime": "Visit time",
"waiverForm": "Waiver form"
"waiverForm": "Waiver form",
"cannotEditThisBill" : "You can not edit this bill",
"onlyPendingBillsCanBeEdited": "Only PENDING bills can be edited"
}