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:
@@ -22,8 +22,10 @@ import {
|
||||
} from '@/components/ui/select';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { OwnerPicker } from '@/components/shared/owner-picker';
|
||||
import { CurrencySelect } from '@/components/shared/currency-select';
|
||||
import { InvoiceLineItems } from '@/components/invoices/invoice-line-items';
|
||||
import { apiFetch } from '@/lib/api/client';
|
||||
import { formatCurrency } from '@/lib/utils/currency';
|
||||
import { createInvoiceSchema, type CreateInvoiceInput } from '@/lib/validators/invoices';
|
||||
|
||||
const PAYMENT_TERMS = [
|
||||
@@ -324,11 +326,10 @@ export default function NewInvoicePage() {
|
||||
|
||||
<div className="space-y-1">
|
||||
<Label>Currency</Label>
|
||||
<Input
|
||||
{...register('currency')}
|
||||
placeholder="USD"
|
||||
maxLength={3}
|
||||
className="uppercase w-24"
|
||||
<CurrencySelect
|
||||
value={watchedValues.currency ?? 'USD'}
|
||||
onValueChange={(v) => setValue('currency', v, { shouldDirty: true })}
|
||||
className="w-48"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -352,7 +353,7 @@ export default function NewInvoicePage() {
|
||||
<CardTitle className="text-base">Line Items</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<InvoiceLineItems name="lineItems" />
|
||||
<InvoiceLineItems name="lineItems" currency={watchedValues.currency ?? 'USD'} />
|
||||
{errors.lineItems && !Array.isArray(errors.lineItems) && (
|
||||
<p className="text-xs text-destructive mt-2">
|
||||
{(errors.lineItems as { message?: string }).message}
|
||||
@@ -415,8 +416,10 @@ export default function NewInvoicePage() {
|
||||
<div key={i} className="flex justify-between text-sm">
|
||||
<span>{li.description}</span>
|
||||
<span className="tabular-nums">
|
||||
{(Number(li.quantity) * Number(li.unitPrice)).toFixed(2)}{' '}
|
||||
{watchedValues.currency}
|
||||
{formatCurrency(
|
||||
Number(li.quantity) * Number(li.unitPrice),
|
||||
watchedValues.currency,
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
@@ -427,21 +430,21 @@ export default function NewInvoicePage() {
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">Subtotal</span>
|
||||
<span className="tabular-nums">
|
||||
{subtotal.toFixed(2)} {watchedValues.currency}
|
||||
{formatCurrency(subtotal, watchedValues.currency)}
|
||||
</span>
|
||||
</div>
|
||||
{isNet10 && (
|
||||
<div className="flex justify-between text-green-600">
|
||||
<span>Net 10 Discount (~2%)</span>
|
||||
<span className="tabular-nums">
|
||||
-{discountAmount.toFixed(2)} {watchedValues.currency}
|
||||
-{formatCurrency(discountAmount, watchedValues.currency)}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex justify-between font-semibold border-t pt-2 mt-1">
|
||||
<span>Total</span>
|
||||
<span className="tabular-nums">
|
||||
{total.toFixed(2)} {watchedValues.currency}
|
||||
{formatCurrency(total, watchedValues.currency)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user