From 5c59855b5be4e83fc1f58801dd73e940b300b1d5 Mon Sep 17 00:00:00 2001 From: ghost2023 Date: Fri, 4 Sep 2026 11:53:01 +0300 Subject: [PATCH] feat(ui-common): shared currency formatting + DJF in CurrencySelector New lib/currency.ts is the single source of truth for currency display across both freight web apps: symbol, name and decimals per code (DJF is zero-decimal by convention, unlike ETB/USD). Portal's own currency lib and backoffice's ad-hoc formatters are rewired onto this in the next two commits instead of each guessing decimals. CurrencySelector gets an allowDjf prop mirroring the existing allowUsd gate, so import-shipment currency pickers can offer DJF the same way they offer USD. Claude-Session: https://claude.ai/code/session_01CZy77vCWhka3pnmVF9NDkL --- .../CurrencySelector/CurrencySelector.tsx | 24 ++++++++++- packages/ui-common/src/index.ts | 9 ++++ packages/ui-common/src/lib/currency.ts | 43 +++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 packages/ui-common/src/lib/currency.ts diff --git a/packages/ui-common/src/components/CurrencySelector/CurrencySelector.tsx b/packages/ui-common/src/components/CurrencySelector/CurrencySelector.tsx index f25a7b015..b24e18969 100644 --- a/packages/ui-common/src/components/CurrencySelector/CurrencySelector.tsx +++ b/packages/ui-common/src/components/CurrencySelector/CurrencySelector.tsx @@ -1,10 +1,12 @@ import { Box, Text } from "@mantine/core"; import { Check } from "lucide-react"; +import type { SupportedCurrency } from "../../lib/currency"; + export interface CurrencySelectorProps { /** Selected currency code, or "" when none picked yet. */ value: string; - onChange: (currency: "USD" | "ETB") => void; + onChange: (currency: SupportedCurrency) => void; disabled?: boolean; /** Validation error shown under the cards. */ error?: string; @@ -14,6 +16,12 @@ export interface CurrencySelectorProps { * USD is settled by bank transfer, never through the online gateway. */ allowUsd?: boolean; + /** + * Offer DJF alongside ETB (and USD, if also allowed). Same import-only + * gating as `allowUsd` — DJF is settled both online (WAAFI / CAC Bank) and + * by bank transfer. + */ + allowDjf?: boolean; } const ETB_OPTION = { @@ -30,6 +38,13 @@ const USD_OPTION = { hint: "Paid by bank transfer — send the slip to Finance", } as const; +const DJF_OPTION = { + code: "DJF", + symbol: "Fdj", + name: "Djibouti Franc", + hint: "Pay online, or by bank transfer — send the slip to Finance", +} as const; + /** * Card-style USD/ETB billing-currency picker. Renders unselected when `value` * is "" so a required choice never looks pre-made. @@ -40,8 +55,13 @@ export function CurrencySelector({ disabled = false, error, allowUsd = false, + allowDjf = false, }: CurrencySelectorProps) { - const options = allowUsd ? [ETB_OPTION, USD_OPTION] : [ETB_OPTION]; + const options = [ + ETB_OPTION, + ...(allowUsd ? [USD_OPTION] : []), + ...(allowDjf ? [DJF_OPTION] : []), + ]; return (