Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Moved money formatting into the shared dashboard package

Damian Legawiec1efbb16f8fe8
diff --git a/packages/dashboard-core/src/components/money.tsx b/packages/dashboard-core/src/components/money.tsx
new file mode 100644
index 0000000000..18906be8f7
--- /dev/null
+++ b/packages/dashboard-core/src/components/money.tsx
@@ -0,0 +1,23 @@
+import { formatAmount } from '../lib/formatters'
+import { useMoneyLocale } from '../products/use-money-locale'
+import { useOptionalStore } from '../providers/store-provider'
+
+/**
+ * An API amount shown in the admin's own number format. Without a currency it
+ * is shown in the store's default currency, for figures the API states in it
+ * (a customer's total spent); the seller panel, which mounts no store, always
+ * passes one.
+ */
+export function Money({
+ amount,
+ currency,
+ fallback,
+}: {
+ amount: string | null | undefined
+ currency?: string | null
+ fallback?: string
+}) {
+ const locale = useMoneyLocale()
+ const store = useOptionalStore()
+ return <>{formatAmount(amount, currency ?? store?.defaultCurrency, locale, fallback)}</>
+}
diff --git a/packages/dashboard-core/src/index.ts b/packages/dashboard-core/src/index.ts
index c28197ede7..7648d3d1f3 100644
--- a/packages/dashboard-core/src/index.ts
+++ b/packages/dashboard-core/src/index.ts
@@ -33,6 +33,7 @@ export * from './components/locale-select'
export * from './components/market-combobox'
export * from './components/media-picker-sheet'
export * from './components/mobile-top-bar'
+export * from './components/money'
export * from './components/nav-main'
export * from './components/page-header'
export * from './components/page-tabs'
diff --git a/packages/dashboard-core/src/lib/formatters.ts b/packages/dashboard-core/src/lib/formatters.ts
index 7785c3bc7f..828758292e 100644
--- a/packages/dashboard-core/src/lib/formatters.ts
+++ b/packages/dashboard-core/src/lib/formatters.ts
@@ -42,6 +42,25 @@ export function formatMoney(
}).format(amount as unknown as number)
}
+/**
+ * Formats an API amount (a decimal string) in its currency, falling back to
+ * the bare number for a currency `Intl` does not know, and to `fallback` when
+ * either is missing.
+ */
+export function formatAmount(
+ amount: string | null | undefined,
+ currency: string | null | undefined,
+ locale?: string,
+ fallback = '—',
+): string {
+ if (amount === null || amount === undefined || amount === '' || !currency) return fallback
+ try {
+ return formatMoney(amount, currency, locale) || fallback
+ } catch {
+ return `${amount} ${currency}`
+ }
+}
+
export function formatStoreDateTime(iso: string, timezone: string) {
return formatInTimeZone(parseISO(iso), timezone, 'PPP p')
}
diff --git a/packages/dashboard/src/components/spree/catalog-price-columns.tsx b/packages/dashboard/src/components/spree/catalog-price-columns.tsx
index 3b6d3f8003..730723e93d 100644
--- a/packages/dashboard/src/components/spree/catalog-price-columns.tsx
+++ b/packages/dashboard/src/components/spree/catalog-price-columns.tsx
@@ -1,4 +1,5 @@
import type { CatalogPrice } from '@spree/admin-sdk'
+import { Money } from '@spree/dashboard-core'
import type { ProductMembershipRow, SubRowLayout } from '@spree/dashboard-ui'
import {
Badge,
@@ -9,7 +10,6 @@ import {
TooltipTrigger,
} from '@spree/dashboard-ui'
import i18n from 'i18next'
-import { Money } from './money'
const AGREEMENT_SOURCES = ['explicit', 'automatic'] as const
diff --git a/packages/dashboard/src/components/spree/customers/customer-last-order-card.tsx b/packages/dashboard/src/components/spree/customers/customer-last-order-card.tsx
index 5350ea62d3..289e938a3f 100644
--- a/packages/dashboard/src/components/spree/customers/customer-last-order-card.tsx
+++ b/packages/dashboard/src/components/spree/customers/customer-last-order-card.tsx
@@ -1,4 +1,5 @@
import type { Order } from '@spree/admin-sdk'
+import { Money } from '@spree/dashboard-core'
import {
Card,
CardContent,
@@ -10,7 +11,6 @@ import {
} from '@spree/dashboard-ui'
import { Link } from '@tanstack/react-router'
import { useTranslation } from 'react-i18next'
-import { Money } from '../money'
export function CustomerLastOrderCard({ order }: { order: Order }) {
const { t } = useTranslation()
diff --git a/packages/dashboard/src/components/spree/customers/customer-lifetime-stats-card.tsx b/packages/dashboard/src/components/spree/customers/customer-lifetime-stats-card.tsx
index 71c6f1a3c5..8ae9b84535 100644
--- a/packages/dashboard/src/components/spree/customers/customer-lifetime-stats-card.tsx
+++ b/packages/dashboard/src/components/spree/customers/customer-lifetime-stats-card.tsx
@@ -1,9 +1,8 @@
import { type Customer, decimalPlaces } from '@spree/admin-sdk'
-import { isPositiveMoney, useMoneyLocale, useStore } from '@spree/dashboard-core'
+import { formatAmount, isPositiveMoney, useMoneyLocale, useStore } from '@spree/dashboard-core'
import { Card, CardContent, RelativeTime } from '@spree/dashboard-ui'
import type { ReactNode } from 'react'
import { useTranslation } from 'react-i18next'
-import { formatAmount } from '../../../lib/format-amount'
export function CustomerLifetimeStatsCard({ customer }: { customer: Customer }) {
const { t } = useTranslation()
diff --git a/packages/dashboard/src/components/spree/customers/customer-orders-card.tsx b/packages/dashboard/src/components/spree/customers/customer-orders-card.tsx
index 1efa3f5962..5fefba897c 100644
--- a/packages/dashboard/src/components/spree/customers/customer-orders-card.tsx
+++ b/packages/dashboard/src/components/spree/customers/customer-orders-card.tsx
@@ -1,4 +1,5 @@
import type { Customer, Order } from '@spree/admin-sdk'
+import { Money } from '@spree/dashboard-core'
import {
Badge,
Card,
@@ -17,7 +18,6 @@ import {
} from '@spree/dashboard-ui'
import { Link } from '@tanstack/react-router'
import { useTranslation } from 'react-i18next'
-import { Money } from '../money'
export function CustomerOrdersCard({
customer,
diff --git a/packages/dashboard/src/components/spree/customers/customer-store-credits-card.tsx b/packages/dashboard/src/components/spree/customers/customer-store-credits-card.tsx
index 6156abd1ad..e35e9b373f 100644
--- a/packages/dashboard/src/components/spree/customers/customer-store-credits-card.tsx
+++ b/packages/dashboard/src/components/spree/customers/customer-store-credits-card.tsx
@@ -1,4 +1,5 @@
import type { Customer, StoreCredit } from '@spree/admin-sdk'
+import { Money } from '@spree/dashboard-core'
import {
Badge,
Button,
@@ -23,7 +24,6 @@ import { EllipsisVerticalIcon, PencilIcon, PlusIcon, TrashIcon } from '@spree/da
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useDeleteCustomerStoreCredit } from '../../../hooks/use-customer-store-credits'
-import { Money } from '../money'
import { EditStoreCreditDialog } from '../store-credits/edit-store-credit-dialog'
import { IssueStoreCreditDialog } from '../store-credits/issue-store-credit-dialog'
diff --git a/packages/dashboard/src/components/spree/money.tsx b/packages/dashboard/src/components/spree/money.tsx
deleted file mode 100644
index 097c0a9798..0000000000
--- a/packages/dashboard/src/components/spree/money.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-import { useMoneyLocale, useStore } from '@spree/dashboard-core'
-import { formatAmount } from '../../lib/format-amount'
-
-/**
- * An API amount shown in the admin's own number format. Without a currency it
- * is shown in the store's default currency, for figures the API states in it
- * (a customer's total spent).
- */
-export function Money({
- amount,
- currency,
- fallback,
-}: {
- amount: string | null | undefined
- currency?: string | null
- fallback?: string
-}) {
- const locale = useMoneyLocale()
- const { defaultCurrency } = useStore()
- return <>{formatAmount(amount, currency ?? defaultCurrency, locale, fallback)}</>
-}
diff --git a/packages/dashboard/src/components/spree/order-post-sale-cards.tsx b/packages/dashboard/src/components/spree/order-post-sale-cards.tsx
index 6fc54ba841..4319dba417 100644
--- a/packages/dashboard/src/components/spree/order-post-sale-cards.tsx
+++ b/packages/dashboard/src/components/spree/order-post-sale-cards.tsx
@@ -1,5 +1,5 @@
import type { Claim, Exchange, Order } from '@spree/admin-sdk'
-import { isPositiveMoney } from '@spree/dashboard-core'
+import { isPositiveMoney, Money } from '@spree/dashboard-core'
import {
Badge,
Button,
@@ -38,7 +38,6 @@ import {
useOrderExchanges,
} from '../../hooks/use-post-sale'
import { variantLabel } from '../../lib/variant-label'
-import { Money } from './money'
import {
CreateClaimDialog,
CreateExchangeDialog,
diff --git a/packages/dashboard/src/components/spree/order-returns-card.tsx b/packages/dashboard/src/components/spree/order-returns-card.tsx
index b1dc2f3e1e..4dc5aef3f6 100644
--- a/packages/dashboard/src/components/spree/order-returns-card.tsx
+++ b/packages/dashboard/src/components/spree/order-returns-card.tsx
@@ -1,6 +1,7 @@
import type { Order, Return, ReturnLineItem } from '@spree/admin-sdk'
import {
currencyParts,
+ formatAmount,
isPositiveMoney,
returnOwesNothing,
returnRefundSummary,
@@ -40,7 +41,6 @@ import {
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useOrderReturns, useReturnActions } from '../../hooks/use-returns'
-import { formatAmount } from '../../lib/format-amount'
import { variantLabel } from '../../lib/variant-label'
import { ShippingDocuments } from './orders/shipping-documents'
import { ShippingLabelRow } from './orders/shipping-label-row'
diff --git a/packages/dashboard/src/components/spree/orders/fulfillment-edit-dialog.tsx b/packages/dashboard/src/components/spree/orders/fulfillment-edit-dialog.tsx
index 0cb543be14..7b73cdaaa4 100644
--- a/packages/dashboard/src/components/spree/orders/fulfillment-edit-dialog.tsx
+++ b/packages/dashboard/src/components/spree/orders/fulfillment-edit-dialog.tsx
@@ -1,12 +1,11 @@
import { type Fulfillment, isZeroMoney, type Order, SpreeError } from '@spree/admin-sdk'
-import { useMoneyLocale, useStockLocations } from '@spree/dashboard-core'
+import { formatAmount, useMoneyLocale, useStockLocations } from '@spree/dashboard-core'
import { FulfillmentEditDialog as SharedFulfillmentEditDialog } from '@spree/dashboard-ui'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useFulfillmentActions } from '../../../hooks/use-fulfillments'
import { useOrder } from '../../../hooks/use-order'
import { useStockCoverage } from '../../../hooks/use-stock-coverage'
-import { formatAmount } from '../../../lib/format-amount'
/**
* Where the fulfillment ships from and which priced service carries it.
diff --git a/packages/dashboard/src/components/spree/orders/fulfillments-card.tsx b/packages/dashboard/src/components/spree/orders/fulfillments-card.tsx
index 8835c4e343..2670fb513a 100644
--- a/packages/dashboard/src/components/spree/orders/fulfillments-card.tsx
+++ b/packages/dashboard/src/components/spree/orders/fulfillments-card.tsx
@@ -1,8 +1,10 @@
import type { Delivery, Fulfillment, Order } from '@spree/admin-sdk'
import {
type FulfillmentItemRow,
+ formatAmount,
fulfillmentItemRows,
isPositiveMoney,
+ Money,
unfulfilledItemRows,
useMoneyLocale,
useStockLocations,
@@ -60,9 +62,7 @@ import {
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useFulfillmentActions } from '../../../hooks/use-fulfillments'
-import { formatAmount } from '../../../lib/format-amount'
import { printPackingSlip } from '../../../lib/packing-slip'
-import { Money } from '../money'
import { FulfillmentDeliveries } from './fulfillment-deliveries'
import { FulfillmentDeliveryDialog } from './fulfillment-delivery-dialog'
import { FulfillmentEditDialog } from './fulfillment-edit-dialog'
diff --git a/packages/dashboard/src/components/spree/orders/order-adjustments-cards.tsx b/packages/dashboard/src/components/spree/orders/order-adjustments-cards.tsx
index 5c7a8b956a..5b24bc8b51 100644
--- a/packages/dashboard/src/components/spree/orders/order-adjustments-cards.tsx
+++ b/packages/dashboard/src/components/spree/orders/order-adjustments-cards.tsx
@@ -7,7 +7,7 @@ import {
type Order,
sumMoney,
} from '@spree/admin-sdk'
-import { adminClient, currencyParts, formatMoney, percentOf } from '@spree/dashboard-core'
+import { adminClient, currencyParts, formatMoney, Money, percentOf } from '@spree/dashboard-core'
import {
Badge,
Button,
@@ -71,7 +71,6 @@ import {
type TaxLineGroup,
} from '../../../lib/tax-line-groups'
import { FEE_KINDS, SYSTEM_FEE_KINDS } from '../../../schemas/order'
-import { Money } from '../money'
/** The API accepts any kind string, so unknown values fall back to the raw value. */
function feeKindLabel(kind: string) {
diff --git a/packages/dashboard/src/components/spree/orders/order-commission-lines-card.tsx b/packages/dashboard/src/components/spree/orders/order-commission-lines-card.tsx
index 9aa964aca2..4dc30eb31e 100644
--- a/packages/dashboard/src/components/spree/orders/order-commission-lines-card.tsx
+++ b/packages/dashboard/src/components/spree/orders/order-commission-lines-card.tsx
@@ -1,4 +1,5 @@
import type { CommissionLine, Order } from '@spree/admin-sdk'
+import { Money } from '@spree/dashboard-core'
import {
Card,
CardContent,
@@ -15,7 +16,6 @@ import { PercentIcon } from '@spree/dashboard-ui/icons'
import { useTranslation } from 'react-i18next'
import { useOrderCommissionLines } from '../../../hooks/use-order'
import { commissionRateLabel } from '../../../lib/commission-line-rate-label'
-import { Money } from '../money'
function commissionSubjectLabel(line: CommissionLine, order: Order, t: (key: string) => string) {
if (line.line_item_id) {
diff --git a/packages/dashboard/src/components/spree/orders/order-discounts-sidebar-card.tsx b/packages/dashboard/src/components/spree/orders/order-discounts-sidebar-card.tsx
index 7a6d999381..9033087c2e 100644
--- a/packages/dashboard/src/components/spree/orders/order-discounts-sidebar-card.tsx
+++ b/packages/dashboard/src/components/spree/orders/order-discounts-sidebar-card.tsx
@@ -1,6 +1,6 @@
import type { Order } from '@spree/admin-sdk'
import { isZeroMoney } from '@spree/admin-sdk'
-import { adminClient, useResourceKey } from '@spree/dashboard-core'
+import { adminClient, Money, useResourceKey } from '@spree/dashboard-core'
import {
Button,
Card,
@@ -27,7 +27,6 @@ import { useQuery } from '@tanstack/react-query'
import { type FormEvent, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useOrderMutation } from '../../../hooks/use-order'
-import { Money } from '../money'
export function DiscountsCard({ order }: { order: Order }) {
const { t } = useTranslation()
diff --git a/packages/dashboard/src/components/spree/orders/order-edit-items-table.tsx b/packages/dashboard/src/components/spree/orders/order-edit-items-table.tsx
index 951a4b40ea..7b3b6da593 100644
--- a/packages/dashboard/src/components/spree/orders/order-edit-items-table.tsx
+++ b/packages/dashboard/src/components/spree/orders/order-edit-items-table.tsx
@@ -1,4 +1,5 @@
import { compareMoney, isDecimalString, multiplyMoney } from '@spree/admin-sdk'
+import { Money } from '@spree/dashboard-core'
import {
Badge,
Button,
@@ -16,12 +17,10 @@ import { PackageIcon, RotateCcwIcon, Undo2Icon, XIcon } from '@spree/dashboard-u
import { Controller, type FieldArrayWithId, type UseFormReturn } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import {
- formatAmount,
type OrderEditFormValues,
projectedLineTotal,
projectedPrice,
} from '../../../schemas/order'
-import { Money } from '../money'
/**
* The staged items table. Every control writes to form state only; nothing is
@@ -255,14 +254,16 @@ function OrderEditItemRow({
projectedTotal === null ? (
'—'
) : (
- formatAmount(projectedTotal, currency)
+ <Money amount={projectedTotal} currency={currency} />
)
) : totalChanged ? (
<span className="flex items-center justify-end gap-2">
<span className="text-muted-foreground line-through">
<Money amount={row.total} currency={currency} />
</span>
- <span className="font-medium">{formatAmount(projectedTotal as string, currency)}</span>
+ <span className="font-medium">
+ <Money amount={projectedTotal} currency={currency} />
+ </span>
</span>
) : (
<Money amount={row.total} currency={currency} />
diff --git a/packages/dashboard/src/components/spree/orders/order-payments-card.tsx b/packages/dashboard/src/components/spree/orders/order-payments-card.tsx
index 20f71a0850..5b28d0c857 100644
--- a/packages/dashboard/src/components/spree/orders/order-payments-card.tsx
+++ b/packages/dashboard/src/components/spree/orders/order-payments-card.tsx
@@ -1,5 +1,5 @@
import type { Order } from '@spree/admin-sdk'
-import { adminClient, currencyParts } from '@spree/dashboard-core'
+import { adminClient, currencyParts, Money } from '@spree/dashboard-core'
import {
Badge,
Button,
@@ -54,7 +54,6 @@ import { type FormEvent, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useOrderMutation } from '../../../hooks/use-order'
import { useOrderGroup } from '../../../hooks/use-seller-ledger'
-import { Money } from '../money'
export function PaymentsCard({ order }: { order: Order }) {
const { t } = useTranslation()
diff --git a/packages/dashboard/src/components/spree/orders/order-seller-transfers-card.tsx b/packages/dashboard/src/components/spree/orders/order-seller-transfers-card.tsx
index e746c4dca9..20a1115f1e 100644
--- a/packages/dashboard/src/components/spree/orders/order-seller-transfers-card.tsx
+++ b/packages/dashboard/src/components/spree/orders/order-seller-transfers-card.tsx
@@ -1,5 +1,5 @@
import type { Order } from '@spree/admin-sdk'
-import { formatStoreDateTime, useStore } from '@spree/dashboard-core'
+import { formatStoreDateTime, Money, useStore } from '@spree/dashboard-core'
import {
Card,
CardHeader,
@@ -16,7 +16,6 @@ import { BanknoteIcon } from '@spree/dashboard-ui/icons'
import { Link } from '@tanstack/react-router'
import { useTranslation } from 'react-i18next'
import { useSellerTransfers } from '../../../hooks/use-seller-ledger'
-import { Money } from '../money'
/**
* What this order earned its seller, and what a refund has taken back.
diff --git a/packages/dashboard/src/components/spree/orders/order-summary-card.tsx b/packages/dashboard/src/components/spree/orders/order-summary-card.tsx
index 071f6c011c..2bebffffb8 100644
--- a/packages/dashboard/src/components/spree/orders/order-summary-card.tsx
+++ b/packages/dashboard/src/components/spree/orders/order-summary-card.tsx
@@ -1,13 +1,12 @@
import type { Order } from '@spree/admin-sdk'
import { isZeroMoney } from '@spree/admin-sdk'
-import { isPositiveMoney, LocaleLabel, useStore } from '@spree/dashboard-core'
+import { isPositiveMoney, LocaleLabel, Money, useStore } from '@spree/dashboard-core'
import { Card, CardHeader, CardTitle, cn, Separator } from '@spree/dashboard-ui'
import { Link } from '@tanstack/react-router'
import i18n from 'i18next'
import type { ReactNode } from 'react'
import { useTranslation } from 'react-i18next'
import { ActorLabel } from '../actor-label'
-import { Money } from '../money'
function formatDate(iso: string | null) {
if (!iso) return '—'
diff --git a/packages/dashboard/src/components/spree/orders/shipping-label-row.tsx b/packages/dashboard/src/components/spree/orders/shipping-label-row.tsx
index 0cbdc56399..14cd8b1482 100644
--- a/packages/dashboard/src/components/spree/orders/shipping-label-row.tsx
+++ b/packages/dashboard/src/components/spree/orders/shipping-label-row.tsx
@@ -1,5 +1,5 @@
import type { ShippingLabel } from '@spree/admin-sdk'
-import { downloadFromApi, getApiClient, useAuth } from '@spree/dashboard-core'
+import { downloadFromApi, getApiClient, Money, useAuth } from '@spree/dashboard-core'
import {
Badge,
Button,
@@ -13,7 +13,6 @@ import {
} from '@spree/dashboard-ui'
import { EllipsisVerticalIcon, PrinterIcon, ReceiptIcon, TrashIcon } from 'lucide-react'
import { useTranslation } from 'react-i18next'
-import { Money } from '../money'
/**
* The label bound to a parcel: what it cost, how to print it, and how to give
diff --git a/packages/dashboard/src/components/spree/sellers/payout-complete-dialog.tsx b/packages/dashboard/src/components/spree/sellers/payout-complete-dialog.tsx
index db4507fbc9..720959f576 100644
--- a/packages/dashboard/src/components/spree/sellers/payout-complete-dialog.tsx
+++ b/packages/dashboard/src/components/spree/sellers/payout-complete-dialog.tsx
@@ -1,5 +1,5 @@
import type { SellerPayout } from '@spree/admin-sdk'
-import { useMoneyLocale } from '@spree/dashboard-core'
+import { formatAmount, useMoneyLocale } from '@spree/dashboard-core'
import {
Button,
Dialog,
@@ -17,7 +17,6 @@ import {
import { type FormEvent, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useCompletePayout } from '../../../hooks/use-seller-ledger'
-import { formatAmount } from '../../../lib/format-amount'
/**
* The operator saying a settlement reached the seller's bank.
diff --git a/packages/dashboard/src/components/spree/sellers/seller-balance-card.tsx b/packages/dashboard/src/components/spree/sellers/seller-balance-card.tsx
index f74ec44c75..d9975e4bd8 100644
--- a/packages/dashboard/src/components/spree/sellers/seller-balance-card.tsx
+++ b/packages/dashboard/src/components/spree/sellers/seller-balance-card.tsx
@@ -1,5 +1,5 @@
import type { Seller } from '@spree/admin-sdk'
-import { isPositiveMoney, Subject, usePermissions } from '@spree/dashboard-core'
+import { isPositiveMoney, Money, Subject, usePermissions } from '@spree/dashboard-core'
import {
Button,
Card,
@@ -13,7 +13,6 @@ import {
import { Link } from '@tanstack/react-router'
import { useTranslation } from 'react-i18next'
import { useSellerBalances, useSettleSeller } from '../../../hooks/use-seller-ledger'
-import { Money } from '../money'
import { ReadRow } from './seller-read-row'
/**
diff --git a/packages/dashboard/src/lib/commission-line-rate-label.ts b/packages/dashboard/src/lib/commission-line-rate-label.ts
index d9175cfea2..6a43bc8979 100644
--- a/packages/dashboard/src/lib/commission-line-rate-label.ts
+++ b/packages/dashboard/src/lib/commission-line-rate-label.ts
@@ -1,7 +1,6 @@
import { type CommissionLine, isDecimalString, type Order } from '@spree/admin-sdk'
-import { prorateMoney } from '@spree/dashboard-core'
+import { formatAmount, prorateMoney } from '@spree/dashboard-core'
import i18n, { type TFunction } from 'i18next'
-import { formatAmount } from './format-amount'
function snapshottedFixedAmount(line: CommissionLine, order: Order, t: TFunction) {
if (line.line_item_id) {
diff --git a/packages/dashboard/src/lib/delivery-method-summary.ts b/packages/dashboard/src/lib/delivery-method-summary.ts
index 8c6239a735..ccb3a86c4f 100644
--- a/packages/dashboard/src/lib/delivery-method-summary.ts
+++ b/packages/dashboard/src/lib/delivery-method-summary.ts
@@ -1,6 +1,6 @@
import { type DeliveryMethodRule, isDecimalString, isZeroMoney } from '@spree/admin-sdk'
+import { formatAmount } from '@spree/dashboard-core'
import type { TFunction } from 'i18next'
-import { formatAmount } from './format-amount'
/**
* A stored preference as a decimal string. The API answers with strings; a
@@ -181,8 +181,6 @@ export function flatAmount(preferences: Record<string, unknown> | null | undefin
return toDecimal(preferences?.amount)
}
-export { formatAmount }
-
/**
* The glance price for a calculator-priced method on the delivery profile
* list. Each stored amount is formatted in its own currency; zero-only or
diff --git a/packages/dashboard/src/lib/format-amount.ts b/packages/dashboard/src/lib/format-amount.ts
deleted file mode 100644
index aa5ffd8fec..0000000000
--- a/packages/dashboard/src/lib/format-amount.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { formatMoney } from '@spree/dashboard-core'
-
-/**
- * Formats an API amount (a decimal string) in its currency, falling back to
- * the bare number for a currency `Intl` does not know, and to `fallback` when
- * either is missing.
- */
-export function formatAmount(
- amount: string | null | undefined,
- currency: string | null | undefined,
- locale?: string,
- fallback = '—',
-): string {
- if (amount === null || amount === undefined || amount === '' || !currency) return fallback
- try {
- return formatMoney(amount, currency, locale) || fallback
- } catch {
- return `${amount} ${currency}`
- }
-}
diff --git a/packages/dashboard/src/lib/packing-slip.ts b/packages/dashboard/src/lib/packing-slip.ts
index d1948defa5..001889d439 100644
--- a/packages/dashboard/src/lib/packing-slip.ts
+++ b/packages/dashboard/src/lib/packing-slip.ts
@@ -7,10 +7,9 @@ import {
type Order,
sumMoney,
} from '@spree/admin-sdk'
-import { fulfillmentItemRows } from '@spree/dashboard-core'
+import { formatAmount, fulfillmentItemRows } from '@spree/dashboard-core'
import type { TFunction } from 'i18next'
import i18n from 'i18next'
-import { formatAmount } from '../schemas/order'
function escapeHtml(value: string): string {
return value
@@ -114,8 +113,8 @@ function buildRows(order: Order, fulfillment: Fulfillment): PackingSlipRow[] {
const lineTotal = !canPrice
? null
: row.quantity === lineItem.quantity
- ? formatAmount(lineItem.total, currency)
- : formatAmount(multiplyMoney(unitPrice, row.quantity, currency), currency)
+ ? formatAmount(lineItem.total, currency, i18n.language)
+ : formatAmount(multiplyMoney(unitPrice, row.quantity, currency), currency, i18n.language)
return {
key: row.key,
@@ -123,7 +122,9 @@ function buildRows(order: Order, fulfillment: Fulfillment): PackingSlipRow[] {
optionsText: row.optionsText,
thumbnailUrl: row.thumbnailUrl,
sku: lineItem?.variant?.sku ?? null,
- displayUnitPrice: canPrice ? formatAmount(unitPrice, currency) : row.displayPrice,
+ displayUnitPrice: canPrice
+ ? formatAmount(unitPrice, currency, i18n.language)
+ : row.displayPrice,
displayLineTotal: lineTotal,
quantity: row.quantity,
}
@@ -150,34 +151,34 @@ function buildSummary(
const lines: SummaryLine[] = [
{
label: key('packing_slip_subtotal'),
- value: formatAmount(order.item_total, order.currency),
+ value: formatAmount(order.item_total, order.currency, i18n.language),
emphasized: false,
},
]
if (!isZeroMoney(order.delivery_total)) {
lines.push({
label: key('packing_slip_shipping'),
- value: formatAmount(order.delivery_total, order.currency),
+ value: formatAmount(order.delivery_total, order.currency, i18n.language),
emphasized: false,
})
}
if (!isZeroMoney(order.discount_total)) {
lines.push({
label: key('packing_slip_discount'),
- value: formatAmount(order.discount_total, order.currency),
+ value: formatAmount(order.discount_total, order.currency, i18n.language),
emphasized: false,
})
}
if (!isZeroMoney(order.tax_total)) {
lines.push({
label: key('packing_slip_tax'),
- value: formatAmount(order.tax_total, order.currency),
+ value: formatAmount(order.tax_total, order.currency, i18n.language),
emphasized: false,
})
}
lines.push({
label: key('packing_slip_total'),
- value: formatAmount(order.total, order.currency),
+ value: formatAmount(order.total, order.currency, i18n.language),
emphasized: true,
})
return lines
@@ -190,7 +191,7 @@ function buildSummary(
}),
order.currency,
)
- const formatted = formatAmount(subtotal, order.currency)
+ const formatted = formatAmount(subtotal, order.currency, i18n.language)
return [
{ label: key('packing_slip_subtotal'), value: formatted, emphasized: false },
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/loyalty/gift-cards.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/loyalty/gift-cards.tsx
index 432be9fd28..07ccac350d 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/loyalty/gift-cards.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/loyalty/gift-cards.tsx
@@ -61,7 +61,7 @@ import {
giftCardSingleValuesToParams,
} from '../../../../schemas/gift-card'
import '../../../../tables/gift-cards'
-import { Money } from '../../../../components/spree/money'
+import { Money } from '@spree/dashboard-core'
const giftCardsSearchSchema = resourceSearchSchema.extend({
edit: z.string().optional(),
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/loyalty/store-credits.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/loyalty/store-credits.tsx
index 5c560dfe39..08828b72f6 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/loyalty/store-credits.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/loyalty/store-credits.tsx
@@ -2,6 +2,8 @@ import type { StoreCredit, StoreCreditCurrencyTotal } from '@spree/admin-sdk'
import { isZeroMoney } from '@spree/admin-sdk'
import {
Can,
+ formatAmount,
+ Money,
PageHeader,
ResourceTable,
resourceSearchSchema,
@@ -34,7 +36,6 @@ import { createFileRoute, Link, useNavigate } from '@tanstack/react-router'
import { useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { z } from 'zod/v4'
-import { Money } from '../../../../components/spree/money'
import { EditStoreCreditDialog } from '../../../../components/spree/store-credits/edit-store-credit-dialog'
import { IssueStoreCreditDialog } from '../../../../components/spree/store-credits/issue-store-credit-dialog'
import { useDeleteCustomerStoreCredit } from '../../../../hooks/use-customer-store-credits'
@@ -44,7 +45,6 @@ import {
useStoreCreditEvents,
} from '../../../../hooks/use-store-credits'
import { erasedFieldValue } from '../../../../lib/erased-customer'
-import { formatAmount } from '../../../../lib/format-amount'
import { originLabel } from '../../../../tables/store-credits'
const storeCreditsSearchSchema = resourceSearchSchema.extend({
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit.tsx
index 8ae2c0734a..9f5e6acb7d 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/edit.tsx
@@ -4,6 +4,7 @@ import {
adminClient,
GONE_STATUSES,
isPositiveMoney,
+ Money,
mapSpreeErrorsToForm,
PageHeader,
} from '@spree/dashboard-core'
@@ -28,13 +29,11 @@ import { createFileRoute, useNavigate } from '@tanstack/react-router'
import { type ReactNode, useEffect, useState } from 'react'
import { useFieldArray, useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
-import { Money } from '../../../../../components/spree/money'
import { AddLineItemDialog } from '../../../../../components/spree/orders/line-item-dialogs'
import { OrderEditItemsTable } from '../../../../../components/spree/orders/order-edit-items-table'
import { useOrder, useOrderMutation } from '../../../../../hooks/use-order'
import {
buildOrderItemsPayload,
- formatAmount,
type OrderEditFormValues,
type OrderEditItemValues,
type OrderItemsPayload,
@@ -86,7 +85,7 @@ function OrderTotalsCard({ order, items }: { order: Order; items: OrderEditItemV
<Money amount={order.item_total} currency={order.currency} />
</span>
<span className="font-medium">
- {formatAmount(projected as string, order.currency)}
+ <Money amount={projected} currency={order.currency} />
</span>
</span>
) : (
@@ -134,7 +133,9 @@ function OrderTotalsCard({ order, items }: { order: Order; items: OrderEditItemV
<span className="font-normal text-muted-foreground line-through">
<Money amount={order.total} currency={order.currency} />
</span>
- <span>{formatAmount(projected as string, order.currency)}</span>
+ <span>
+ <Money amount={projected} currency={order.currency} />
+ </span>
</span>
) : (
<Money amount={order.total} currency={order.currency} />
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/purchase-orders/$purchaseOrderId/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/purchase-orders/$purchaseOrderId/index.tsx
index 8ff776a2ae..43af0e896d 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/purchase-orders/$purchaseOrderId/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/purchase-orders/$purchaseOrderId/index.tsx
@@ -2,6 +2,7 @@ import type { PurchaseOrder, PurchaseOrderItem } from '@spree/admin-sdk'
import {
adminClient,
Can,
+ Money,
PageHeader,
Slot,
Subject,
@@ -38,7 +39,6 @@ import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { CloseShortDialog } from '../../../../../components/spree/close-short-dialog'
import { InventoryStatusBadge } from '../../../../../components/spree/inventory-status-badge'
-import { Money } from '../../../../../components/spree/money'
import { ReceiveDeliveryCard } from '../../../../../components/spree/receive-delivery-card'
import { ResourceDetailSkeleton } from '../../../../../components/spree/route-pending'
import { StockHistoryCard } from '../../../../../components/spree/stock-history-card'
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/sellers/payouts/$payoutId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/sellers/payouts/$payoutId.tsx
index 09bb4502b0..20d6b7e8da 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/sellers/payouts/$payoutId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/sellers/payouts/$payoutId.tsx
@@ -1,6 +1,7 @@
import {
adminClient,
formatStoreDateTime,
+ Money,
PageHeader,
Slot,
Subject,
@@ -28,7 +29,6 @@ import { HandCoinsIcon } from '@spree/dashboard-ui/icons'
import { createFileRoute, Link } from '@tanstack/react-router'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
-import { Money } from '../../../../../components/spree/money'
import { ResourceDetailSkeleton } from '../../../../../components/spree/route-pending'
import { PayoutCompleteDialog } from '../../../../../components/spree/sellers/payout-complete-dialog'
import { ReadRow } from '../../../../../components/spree/sellers/seller-read-row'
diff --git a/packages/dashboard/src/schemas/order.ts b/packages/dashboard/src/schemas/order.ts
index a33a7bbd41..e8762fc448 100644
--- a/packages/dashboard/src/schemas/order.ts
+++ b/packages/dashboard/src/schemas/order.ts
@@ -5,12 +5,7 @@ import {
type OrderUpdateParams,
sumMoney,
} from '@spree/admin-sdk'
-import {
- formatMoney,
- fulfilledQuantities,
- type GroupableFulfillment,
- i18n,
-} from '@spree/dashboard-core'
+import { fulfilledQuantities, type GroupableFulfillment, i18n } from '@spree/dashboard-core'
import { z } from 'zod/v4'
/**
@@ -175,11 +170,6 @@ export function orderToEditForm(
return { items: items.map((item) => lineItemToEditRow(item, fulfilled.get(item.id) ?? 0)) }
}
-/** Formats a client-computed preview amount. */
-export function formatAmount(amount: string, currency: string): string {
- return formatMoney(amount, currency, i18n.language)
-}
-
/** The price a row lands on once saved, or null when it cannot be known. */
export function projectedPrice(item: OrderEditItemValues): string | null {
const source = item.revert_price ? item.catalog_price : item.price
diff --git a/packages/dashboard/src/search/default.tsx b/packages/dashboard/src/search/default.tsx
index 2cb359619c..1c13d81845 100644
--- a/packages/dashboard/src/search/default.tsx
+++ b/packages/dashboard/src/search/default.tsx
@@ -12,6 +12,7 @@ import type {
import {
adminClient,
defineSearchEntry,
+ formatAmount,
Subject,
searchRegistry,
useMoneyLocale,
@@ -28,7 +29,6 @@ import {
UsersRoundIcon,
} from '@spree/dashboard-ui/icons'
import { useTranslation } from 'react-i18next'
-import { formatAmount } from '../lib/format-amount'
// Each entry teaches the command palette how to search one resource: how to
// fetch matches, render a result row, and where a row navigates. Resources are
diff --git a/packages/dashboard/src/tables/customers.tsx b/packages/dashboard/src/tables/customers.tsx
index 302569c320..bbb535ca7a 100644
--- a/packages/dashboard/src/tables/customers.tsx
+++ b/packages/dashboard/src/tables/customers.tsx
@@ -1,9 +1,8 @@
-import { defineTable } from '@spree/dashboard-core'
+import { defineTable, Money } from '@spree/dashboard-core'
import { ActiveBadge, Badge, RelativeTime, TagList } from '@spree/dashboard-ui'
import { UsersIcon } from '@spree/dashboard-ui/icons'
import { Link } from '@tanstack/react-router'
import i18n from 'i18next'
-import { Money } from '../components/spree/money'
import { companyAutocompleteProps } from '../hooks/use-companies'
import { customerGroupAutocompleteProps } from '../hooks/use-customer-groups'
import { customerDisplayName, erasedFieldValue } from '../lib/erased-customer'
diff --git a/packages/dashboard/src/tables/gift-cards.tsx b/packages/dashboard/src/tables/gift-cards.tsx
index 7e80b035c8..7cc1a4da1d 100644
--- a/packages/dashboard/src/tables/gift-cards.tsx
+++ b/packages/dashboard/src/tables/gift-cards.tsx
@@ -1,9 +1,8 @@
import type { GiftCard } from '@spree/admin-sdk'
-import { defineTable } from '@spree/dashboard-core'
+import { defineTable, Money } from '@spree/dashboard-core'
import { Badge, RelativeTime, ResourceNameCell, StatusBadge } from '@spree/dashboard-ui'
import { GiftIcon } from '@spree/dashboard-ui/icons'
import i18n from 'i18next'
-import { Money } from '../components/spree/money'
import { adminUserAutocompleteProps } from '../hooks/use-admin-users'
import { customerAutocompleteProps } from '../hooks/use-customers'
import { giftCardBatchAutocompleteProps } from '../hooks/use-gift-cards'
diff --git a/packages/dashboard/src/tables/orders.tsx b/packages/dashboard/src/tables/orders.tsx
index f480e679d1..bfbc287427 100644
--- a/packages/dashboard/src/tables/orders.tsx
+++ b/packages/dashboard/src/tables/orders.tsx
@@ -1,9 +1,8 @@
-import { defineTable } from '@spree/dashboard-core'
+import { defineTable, Money } from '@spree/dashboard-core'
import { RelativeTime, StatusBadge, TagList } from '@spree/dashboard-ui'
import { ShoppingCartIcon } from '@spree/dashboard-ui/icons'
import { Link } from '@tanstack/react-router'
import i18n from 'i18next'
-import { Money } from '../components/spree/money'
import { channelAutocompleteProps } from '../hooks/use-channels'
import { customerAutocompleteProps } from '../hooks/use-customers'
import { sellerAutocompleteProps } from '../hooks/use-sellers'
diff --git a/packages/dashboard/src/tables/post-sale.tsx b/packages/dashboard/src/tables/post-sale.tsx
index c4037c9406..ae4141d0fe 100644
--- a/packages/dashboard/src/tables/post-sale.tsx
+++ b/packages/dashboard/src/tables/post-sale.tsx
@@ -1,10 +1,9 @@
import type { Claim, Exchange, Return } from '@spree/admin-sdk'
-import { defineTable } from '@spree/dashboard-core'
+import { defineTable, Money } from '@spree/dashboard-core'
import { RelativeTime, StatusBadge } from '@spree/dashboard-ui'
import { RepeatIcon, RotateCcwIcon, ShieldAlertIcon } from '@spree/dashboard-ui/icons'
import { Link } from '@tanstack/react-router'
import i18n from 'i18next'
-import { Money } from '../components/spree/money'
import { translatedLabel } from '../lib/translated-label'
/**
diff --git a/packages/dashboard/src/tables/purchase-orders.tsx b/packages/dashboard/src/tables/purchase-orders.tsx
index ab21147897..415b00b820 100644
--- a/packages/dashboard/src/tables/purchase-orders.tsx
+++ b/packages/dashboard/src/tables/purchase-orders.tsx
@@ -1,9 +1,8 @@
import type { PurchaseOrder } from '@spree/admin-sdk'
-import { defineTable } from '@spree/dashboard-core'
+import { defineTable, Money } from '@spree/dashboard-core'
import { Badge, RelativeTime, ResourceNameCell, StatusBadge } from '@spree/dashboard-ui'
import { TruckIcon } from '@spree/dashboard-ui/icons'
import i18n from 'i18next'
-import { Money } from '../components/spree/money'
import { supplierAutocompleteProps } from '../hooks/use-suppliers'
import { isClosed, PURCHASE_ORDER_STATUSES } from '../schemas/inventory-operations'
diff --git a/packages/dashboard/src/tables/seller-ledger.tsx b/packages/dashboard/src/tables/seller-ledger.tsx
index 86076b2a55..64d242073b 100644
--- a/packages/dashboard/src/tables/seller-ledger.tsx
+++ b/packages/dashboard/src/tables/seller-ledger.tsx
@@ -1,10 +1,9 @@
import type { SellerPayout, SellerTransfer } from '@spree/admin-sdk'
-import { defineTable, formatStoreDateTime, useStore } from '@spree/dashboard-core'
+import { defineTable, formatStoreDateTime, Money, useStore } from '@spree/dashboard-core'
import { ResourceNameCell, StatusBadge } from '@spree/dashboard-ui'
import { BanknoteIcon, HandCoinsIcon } from '@spree/dashboard-ui/icons'
import { Link } from '@tanstack/react-router'
import i18n from 'i18next'
-import { Money } from '../components/spree/money'
import { sellerAutocompleteProps } from '../hooks/use-sellers'
/**
diff --git a/packages/dashboard/src/tables/store-credits.tsx b/packages/dashboard/src/tables/store-credits.tsx
index 5fb3362018..746a95f45f 100644
--- a/packages/dashboard/src/tables/store-credits.tsx
+++ b/packages/dashboard/src/tables/store-credits.tsx
@@ -1,9 +1,8 @@
import type { StoreCredit } from '@spree/admin-sdk'
-import { defineTable } from '@spree/dashboard-core'
+import { defineTable, Money } from '@spree/dashboard-core'
import { Badge, RelativeTime, ResourceNameCell } from '@spree/dashboard-ui'
import { BanknoteIcon } from '@spree/dashboard-ui/icons'
import i18n from 'i18next'
-import { Money } from '../components/spree/money'
import { adminUserAutocompleteProps } from '../hooks/use-admin-users'
import { customerAutocompleteProps } from '../hooks/use-customers'
import { erasedFieldValue } from '../lib/erased-customer'
diff --git a/packages/seller-dashboard/src/components/orders/order-earnings-card.tsx b/packages/seller-dashboard/src/components/orders/order-earnings-card.tsx
index 9c12d13cdb..1e55314cc0 100644
--- a/packages/seller-dashboard/src/components/orders/order-earnings-card.tsx
+++ b/packages/seller-dashboard/src/components/orders/order-earnings-card.tsx
@@ -1,4 +1,4 @@
-import { formatMoney, formatStoreDateTime, useMoneyLocale } from '@spree/dashboard-core'
+import { formatStoreDateTime, Money } from '@spree/dashboard-core'
import {
Card,
CardContent,
@@ -30,7 +30,6 @@ import { useStoreTimezone } from '../../hooks/use-store-timezone'
*/
export function OrderEarningsCard({ order }: { order: Order }) {
const { t } = useTranslation()
- const locale = useMoneyLocale()
const { sellerId } = useParams({ from: '/_authenticated/$sellerId' })
const timezone = useStoreTimezone()
const { data } = useTransfers({ order_id_eq: order.id })
@@ -90,7 +89,7 @@ export function OrderEarningsCard({ order }: { order: Order }) {
)}
</TableCell>
<TableCell className="text-right tabular-nums">
- {formatMoney(transfer.amount, transfer.currency, locale)}
+ <Money amount={transfer.amount} currency={transfer.currency} />
</TableCell>
</TableRow>
))}
diff --git a/packages/seller-dashboard/src/pages/payout.tsx b/packages/seller-dashboard/src/pages/payout.tsx
index eff8afb885..641799651d 100644
--- a/packages/seller-dashboard/src/pages/payout.tsx
+++ b/packages/seller-dashboard/src/pages/payout.tsx
@@ -1,6 +1,7 @@
import {
formatMoney,
formatStoreDateTime,
+ Money,
PageHeader,
Slot,
useMoneyLocale,
@@ -128,7 +129,7 @@ export function PayoutPage() {
{t(`earnings.kinds.${transfer.kind}`, { defaultValue: transfer.kind })}
</TableCell>
<TableCell className="text-right tabular-nums">
- {formatMoney(transfer.amount, transfer.currency, locale)}
+ <Money amount={transfer.amount} currency={transfer.currency} />
</TableCell>
</TableRow>
))}
@@ -148,7 +149,7 @@ export function PayoutPage() {
</CardHeader>
<div className="flex flex-col gap-3 px-6 pb-6">
<ReadRow label={t('payouts.columns.amount')}>
- {formatMoney(payout.amount, payout.currency, locale)}
+ <Money amount={payout.amount} currency={payout.currency} />
</ReadRow>
<ReadRow label={t('payouts.columns.reference')}>{payout.reference}</ReadRow>
<ReadRow label={t('payouts.detail.period')}>