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>
This commit is contained in:
@@ -6,6 +6,7 @@ import { apiFetch } from '@/lib/api/client';
|
||||
import { useUIStore } from '@/stores/ui-store';
|
||||
import { KPITile } from '@/components/ui/kpi-tile';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { formatCurrency } from '@/lib/utils/currency';
|
||||
import { WidgetErrorBoundary } from './widget-error-boundary';
|
||||
|
||||
interface KpiData {
|
||||
@@ -15,13 +16,7 @@ interface KpiData {
|
||||
occupancyRate: number;
|
||||
}
|
||||
|
||||
function formatCurrency(value: number): string {
|
||||
return new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency: 'USD',
|
||||
maximumFractionDigits: 0,
|
||||
}).format(value);
|
||||
}
|
||||
const formatUsd = (value: number) => formatCurrency(value, 'USD', { maxFractionDigits: 0 });
|
||||
|
||||
function formatPercent(value: number): string {
|
||||
return `${value.toFixed(1)}%`;
|
||||
@@ -81,7 +76,7 @@ export function KpiCards() {
|
||||
},
|
||||
{
|
||||
label: 'Pipeline Value',
|
||||
value: isError ? '-' : formatCurrency(data?.pipelineValueUsd ?? 0),
|
||||
value: isError ? '-' : formatUsd(data?.pipelineValueUsd ?? 0),
|
||||
accent: 'success',
|
||||
},
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { CardSkeleton } from '@/components/shared/loading-skeleton';
|
||||
import { stageLabel } from '@/lib/constants';
|
||||
import { formatCurrency } from '@/lib/utils/currency';
|
||||
import { WidgetErrorBoundary } from './widget-error-boundary';
|
||||
|
||||
interface StageBreakdownRow {
|
||||
@@ -21,13 +22,7 @@ interface ForecastData {
|
||||
weightsSource: 'db' | 'default';
|
||||
}
|
||||
|
||||
function formatCurrency(value: number): string {
|
||||
return new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency: 'USD',
|
||||
maximumFractionDigits: 0,
|
||||
}).format(value);
|
||||
}
|
||||
const formatUsd = (value: number) => formatCurrency(value, 'USD', { maxFractionDigits: 0 });
|
||||
|
||||
function RevenueForecastInner() {
|
||||
const { data, isLoading } = useQuery<ForecastData>({
|
||||
@@ -56,7 +51,7 @@ function RevenueForecastInner() {
|
||||
<CardContent className="space-y-4">
|
||||
<div>
|
||||
<p className="text-xs text-muted-foreground">Weighted Pipeline Value</p>
|
||||
<p className="text-2xl font-bold">{formatCurrency(data?.totalWeightedValue ?? 0)}</p>
|
||||
<p className="text-2xl font-bold">{formatUsd(data?.totalWeightedValue ?? 0)}</p>
|
||||
</div>
|
||||
|
||||
{activeStages.length > 0 && (
|
||||
@@ -67,7 +62,7 @@ function RevenueForecastInner() {
|
||||
{stageLabel(s.stage)}
|
||||
<span className="ml-1 text-xs">({s.count})</span>
|
||||
</span>
|
||||
<span className="font-medium tabular-nums">{formatCurrency(s.weightedValue)}</span>
|
||||
<span className="font-medium tabular-nums">{formatUsd(s.weightedValue)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user