diff --git a/apps/edr-freight-web/portal/src/lib/currency.ts b/apps/edr-freight-web/portal/src/lib/currency.ts index d41b4edda..270882fc8 100644 --- a/apps/edr-freight-web/portal/src/lib/currency.ts +++ b/apps/edr-freight-web/portal/src/lib/currency.ts @@ -1,23 +1,8 @@ -/** Currency code carried on invoices / dashboard figures (ETB, USD, DJF, …). */ -export type Currency = string; - -const SYMBOLS: Record = { - USD: "$", - ETB: "Br", - DJF: "DJF", -}; - /** - * Format a money amount with its currency symbol, e.g. `Br 12,500.00`. - * Unknown currency codes fall back to printing the raw code. + * Currency code carried on invoices / dashboard figures (ETB, USD, DJF, …). + * Re-exports the shared `@edr/ui-common` currency module so every currency + * gets the same symbol, decimals rule and formatting across both freight web + * apps — see that module for the source of truth. */ -export function formatCurrency( - amount: number, - currency: Currency = "ETB", -): string { - const symbol = SYMBOLS[currency] ?? currency; - return `${symbol} ${Number(amount ?? 0).toLocaleString(undefined, { - minimumFractionDigits: 2, - maximumFractionDigits: 2, - })}`; -} +export type { SupportedCurrency as Currency } from "@edr/ui-common"; +export { formatCurrency, currencySymbol, currencyDecimals, CURRENCY_CODES } from "@edr/ui-common"; diff --git a/apps/edr-freight-web/portal/src/pages/MyPortalPage/actions.ts b/apps/edr-freight-web/portal/src/pages/MyPortalPage/actions.ts index b33017976..0360c579b 100644 --- a/apps/edr-freight-web/portal/src/pages/MyPortalPage/actions.ts +++ b/apps/edr-freight-web/portal/src/pages/MyPortalPage/actions.ts @@ -1,6 +1,6 @@ import type { Freight } from "@edr/types"; -import { isUsdOfflineBooking } from "@/pages/bookings/payments/offline-payment"; +import { bookingCanPayOnline } from "@/pages/bookings/payments/offline-payment"; /** A pending customer action surfaced on the home "needs attention" card. */ export interface ActionItem { @@ -64,7 +64,10 @@ export function deriveActionItems( ? b.status === "FULLY_EXECUTED" : b.status === "SELECTED_FOR_BATCH"); if (canPay) { - const offlinePay = isUsdOfflineBooking(b); + // Online-only description unless the booking's currency has no online + // rail at all (USD) — DJF supports both, so it reads as a normal + // "payment due" like ETB rather than bank-transfer-only. + const offlinePay = !bookingCanPayOnline(b); items.push({ id: `pay-${b.id}`, kind: "pay", diff --git a/apps/edr-freight-web/portal/src/pages/billing/InvoiceDetailPage.tsx b/apps/edr-freight-web/portal/src/pages/billing/InvoiceDetailPage.tsx index b42a3cc8e..e3311d2f2 100644 --- a/apps/edr-freight-web/portal/src/pages/billing/InvoiceDetailPage.tsx +++ b/apps/edr-freight-web/portal/src/pages/billing/InvoiceDetailPage.tsx @@ -32,7 +32,7 @@ import { invoicesService } from "@/services/invoices.service"; import { useInvoicePayment } from "@/hooks/useInvoicePayment"; import { warehouseInvoicesService } from "@/services/warehouse-invoices.service"; import { PaymentMethodModal } from "@/pages/bookings/BookingDetailPage/components/PaymentMethodModal"; -import { isUsdCurrency } from "@/pages/bookings/payments/offline-payment"; +import { canPayOffline, canPayOnline } from "@/pages/bookings/payments/offline-payment"; import { saveBlob } from "@/utils/download"; import { formatCurrency } from "@/lib/currency"; import { BORDER, INK, MUTED } from "../contracts/contract-ui"; @@ -232,7 +232,7 @@ export default function InvoiceDetailPage() { Receipt )} - {payable && !isUsdCurrency(invoice.currency) && ( + {payable && canPayOnline(invoice.currency) && (