Files
pn-new-crm/src/components/shared/currency-select.tsx
Matt ee2da8f67e feat(currency): centralise money formatting + curated currency picker
New `src/lib/utils/currency.ts` is the single source of truth for
display formatting (`formatCurrency`) and the supported-currency
catalog (`SUPPORTED_CURRENCIES`, 10 codes covering the marina market).

New shared components:
- `<CurrencyInput>` — number input with leading symbol prefix and
  decimal inputMode, raw number value out via onChange.
- `<CurrencySelect>` — Select dropdown over `SUPPORTED_CURRENCIES`
  with symbol + code + label per row, replaces the free-text 3-letter
  inputs that let reps type "EURO" or "$$$" into a 3-char ISO column.

Threaded through every money input + display:
- Forms: berth (price/currency), expense (amount/currency), invoice
  (currency Select + line-items unit-price + step-3 review totals).
- Reads: berth-card / berth-columns / invoice-card / expense-card /
  dashboard KPIs / dashboard revenue-forecast / portal-invoices page.
  Each had its own ad-hoc `Intl.NumberFormat` wrapper with slightly
  different fallbacks; collapsed onto the shared helper.

`InvoiceLineItems` gained a `currency` prop so the unit-price input
prefix and the subtotal use the parent invoice's currency rather than
hard-coded `en-US` formatting.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 04:24:46 +02:00

49 lines
1.3 KiB
TypeScript

'use client';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { SUPPORTED_CURRENCIES } from '@/lib/utils/currency';
interface CurrencySelectProps {
value: string | undefined;
onValueChange: (value: string) => void;
disabled?: boolean;
id?: string;
className?: string;
}
/**
* Select dropdown over the curated `SUPPORTED_CURRENCIES` list. Replaces
* the free-text `<Input maxLength={3}>` price-currency spots so reps
* can't typo "EURO" or "$$$" into a 3-letter ISO column.
*/
export function CurrencySelect({
value,
onValueChange,
disabled,
id,
className,
}: CurrencySelectProps) {
return (
<Select value={value} onValueChange={onValueChange} disabled={disabled}>
<SelectTrigger id={id} className={className}>
<SelectValue placeholder="Select currency" />
</SelectTrigger>
<SelectContent>
{SUPPORTED_CURRENCIES.map((c) => (
<SelectItem key={c.code} value={c.code}>
<span className="tabular-nums mr-2">{c.symbol}</span>
<span className="font-medium">{c.code}</span>
<span className="text-muted-foreground ml-2 text-xs">{c.label}</span>
</SelectItem>
))}
</SelectContent>
</Select>
);
}