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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fixed dates rendering in the browser's timezone instead of the store's
Damian Legawiec96097b5e24ad
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.tsxindex c9e13d2b46..9ea8028f27 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,4 +1,5 @@import type { Order } from '@spree/admin-sdk'+import { formatStoreDateTime, useStore } from '@spree/dashboard-core'import {Card,CardHeader,@@ -13,7 +14,6 @@ import {} from '@spree/dashboard-ui'import { BanknoteIcon } from '@spree/dashboard-ui/icons'import { Link } from '@tanstack/react-router'-import i18n from 'i18next'import { useTranslation } from 'react-i18next'import { useSellerTransfers } from '../../../hooks/use-seller-ledger'@@ -25,6 +25,9 @@ import { useSellerTransfers } from '../../../hooks/use-seller-ledger'*/export function SellerTransfersCard({ order }: { order: Order }) {const { t } = useTranslation()+ // Every admin reads the same instant the same way, whatever their browser+ // is set to — the store's timezone is what an order's dates mean.+ const { timezone } = useStore()const { data } = useSellerTransfers({ order_id_eq: order.id })const transfers = data?.data ?? []@@ -53,7 +56,7 @@ export function SellerTransfersCard({ order }: { order: Order }) {{transfers.map((transfer) => (<TableRow key={transfer.id}><TableCell className="whitespace-nowrap">- {new Date(transfer.created_at).toLocaleDateString(i18n.language)}+ {formatStoreDateTime(transfer.created_at, timezone)}</TableCell><TableCell>{t(`admin.payouts.kinds.${transfer.kind}`, { defaultValue: transfer.kind })}diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/sellers/payouts/$payoutId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/sellers/payouts/$payoutId.tsxindex b54efa0ea0..4f9afb0a1d 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/sellers/payouts/$payoutId.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/sellers/payouts/$payoutId.tsx@@ -1,4 +1,11 @@-import { adminClient, PageHeader, Subject, usePermissions } from '@spree/dashboard-core'+import {+ adminClient,+ formatStoreDateTime,+ PageHeader,+ Subject,+ usePermissions,+ useStore,+} from '@spree/dashboard-core'import {Button,Card,@@ -18,7 +25,6 @@ import {} from '@spree/dashboard-ui'import { HandCoinsIcon } from '@spree/dashboard-ui/icons'import { createFileRoute, Link } from '@tanstack/react-router'-import i18n from 'i18next'import { useState } from 'react'import { useTranslation } from 'react-i18next'import { ResourceDetailSkeleton } from '../../../../../components/spree/route-pending'@@ -43,6 +49,7 @@ function PayoutDetailPage() {const { t } = useTranslation()const { payoutId } = Route.useParams()const { permissions } = usePermissions()+ const { timezone } = useStore()const [completing, setCompleting] = useState(false)const [page, setPage] = useState(1)@@ -137,7 +144,7 @@ function PayoutDetailPage() {<TableBody>{rows.map((transfer) => (<TableRow key={transfer.id}>- <TableCell>{formatDate(transfer.created_at)}</TableCell>+ <TableCell>{formatStoreDateTime(transfer.created_at, timezone)}</TableCell><TableCell>{transfer.order_id ? (<Link@@ -180,7 +187,7 @@ function PayoutDetailPage() {<ReadRow label={t('admin.payouts.columns.provider')}>{payout.provider}</ReadRow><ReadRow label={t('admin.payouts.detail.period')}>{payout.period_start && payout.period_end- ? `${formatDate(payout.period_start)} – ${formatDate(payout.period_end)}`+ ? `${formatStoreDateTime(payout.period_start, timezone)} – ${formatStoreDateTime(payout.period_end, timezone)}`: null}</ReadRow></div>@@ -192,12 +199,3 @@ function PayoutDetailPage() {</>)}--function formatDate(iso: string | null | undefined) {- if (!iso) return '—'- return new Date(iso).toLocaleDateString(i18n.language, {- month: 'short',- day: 'numeric',- year: 'numeric',- })-}diff --git a/packages/dashboard/src/tables/seller-ledger.tsx b/packages/dashboard/src/tables/seller-ledger.tsxindex a9bdcc8ede..22584bccab 100644--- a/packages/dashboard/src/tables/seller-ledger.tsx+++ b/packages/dashboard/src/tables/seller-ledger.tsx@@ -1,11 +1,24 @@import type { SellerPayout, SellerTransfer } from '@spree/admin-sdk'-import { defineTable } from '@spree/dashboard-core'+import { defineTable, formatStoreDateTime, 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 { sellerAutocompleteProps } from '../hooks/use-sellers'+/**+ * A ledger row's date in the store's timezone.+ *+ * Its own component because a table definition is module-level and has no+ * store context, while `render` is called inside the table's JSX — so a cell+ * may use hooks like any other component.+ */+function LedgerDate({ iso }: { iso: string }) {+ const { timezone } = useStore()++ return <>{formatStoreDateTime(iso, timezone)}</>+}+const LEDGER_STATUSES = ['pending', 'processing', 'completed', 'failed', 'unresolved'] as constconst TRANSFER_KINDS = ['earning', 'refund_reversal'] as const@@ -37,7 +50,7 @@ defineTable<SellerTransfer>('seller-transfers', {filterType: 'date',quickFilter: true,default: true,- render: (transfer) => new Date(transfer.created_at).toLocaleDateString(i18n.language),+ render: (transfer) => <LedgerDate iso={transfer.created_at} />,},{key: 'seller_name',@@ -149,7 +162,7 @@ defineTable<SellerPayout>('seller-payouts', {<ResourceNameCellid={payout.id}dataAttr="data-payout-id"- name={new Date(payout.created_at).toLocaleDateString(i18n.language)}+ name={<LedgerDate iso={payout.created_at} />}/>),},diff --git a/packages/seller-dashboard/src/components/orders/order-cards.tsx b/packages/seller-dashboard/src/components/orders/order-cards.tsxindex 9166c64fa9..b03fd3818b 100644--- a/packages/seller-dashboard/src/components/orders/order-cards.tsx+++ b/packages/seller-dashboard/src/components/orders/order-cards.tsx@@ -1,4 +1,4 @@-import { AddressFormDialog } from '@spree/dashboard-core'+import { AddressFormDialog, formatStoreDateTime } from '@spree/dashboard-core'import {AddressBlock,Button,@@ -15,11 +15,11 @@ import {} from '@spree/dashboard-ui'import { EllipsisVerticalIcon, PencilIcon } from '@spree/dashboard-ui/icons'import type { Order, OrderAddressParams } from '@spree/seller-sdk'-import i18n from 'i18next'import { type ReactNode, useState } from 'react'import { useTranslation } from 'react-i18next'import { sellerClient } from '../../api-client'import { useOrderMutation } from '../../hooks/use-order'+import { useStoreTimezone } from '../../hooks/use-store-timezone'function SummaryRow({label,@@ -48,17 +48,12 @@ function SummaryRow({)}-function formatDate(iso: string | null | undefined) {+// The marketplace's zone, not the browser's: a seller trading away from the+// marketplace would otherwise see an order fall on the wrong day.+function formatDate(iso: string | null | undefined, timezone: string) {if (!iso) return '—'- // The panel's own locale, not the browser's — otherwise a seller reading- // German sees day and month in the other order.- return new Date(iso).toLocaleDateString(i18n.language, {- month: 'short',- day: 'numeric',- year: 'numeric',- hour: 'numeric',- minute: '2-digit',- })++ return formatStoreDateTime(iso, timezone)}/**@@ -74,6 +69,7 @@ function formatDate(iso: string | null | undefined) {*/export function OrderSummaryCard({ order }: { order: Order }) {const { t } = useTranslation()+ const timezone = useStoreTimezone()const amount = (value: string | null | undefined) => Number.parseFloat(value ?? '0')const outstanding = amount(order.amount_due)@@ -86,11 +82,14 @@ export function OrderSummaryCard({ order }: { order: Order }) {</CardHeader><div className="py-1">- <SummaryRow label={t('orders.summary.created_at')} value={formatDate(order.created_at)} />+ <SummaryRow+ label={t('orders.summary.created_at')}+ value={formatDate(order.created_at, timezone)}+ />{order.completed_at && (<SummaryRowlabel={t('orders.summary.completed_at')}- value={formatDate(order.completed_at)}+ value={formatDate(order.completed_at, timezone)}/>)}@@ -99,7 +98,7 @@ export function OrderSummaryCard({ order }: { order: Order }) {<Separator /><SummaryRowlabel={t('orders.summary.canceled_at')}- value={formatDate(order.canceled_at)}+ value={formatDate(order.canceled_at, timezone)}/>{order.cancel_reason_name && (<SummaryRowdiff --git a/packages/seller-dashboard/src/components/orders/order-earnings-card.tsx b/packages/seller-dashboard/src/components/orders/order-earnings-card.tsxindex 73dca642d0..32222e8b62 100644--- a/packages/seller-dashboard/src/components/orders/order-earnings-card.tsx+++ b/packages/seller-dashboard/src/components/orders/order-earnings-card.tsx@@ -1,3 +1,4 @@+import { formatStoreDateTime } from '@spree/dashboard-core'import {Card,CardContent,@@ -14,9 +15,9 @@ import {import { BanknoteIcon } from '@spree/dashboard-ui/icons'import type { Order } from '@spree/seller-sdk'import { Link, useParams } from '@tanstack/react-router'-import i18n from 'i18next'import { useTranslation } from 'react-i18next'import { useTransfers } from '../../hooks/use-ledger'+import { useStoreTimezone } from '../../hooks/use-store-timezone'/*** What this order earned the seller: the sale less the marketplace's@@ -30,6 +31,7 @@ import { useTransfers } from '../../hooks/use-ledger'export function OrderEarningsCard({ order }: { order: Order }) {const { t } = useTranslation()const { sellerId } = useParams({ from: '/_authenticated/$sellerId' })+ const timezone = useStoreTimezone()const { data } = useTransfers({ order_id_eq: order.id })const transfers = data?.data ?? []@@ -59,7 +61,7 @@ export function OrderEarningsCard({ order }: { order: Order }) {{transfers.map((transfer) => (<TableRow key={transfer.id}><TableCell className="whitespace-nowrap">- {new Date(transfer.created_at).toLocaleDateString(i18n.language)}+ {formatStoreDateTime(transfer.created_at, timezone)}</TableCell><TableCell>{t(`earnings.kinds.${transfer.kind}`, { defaultValue: transfer.kind })}diff --git a/packages/seller-dashboard/src/hooks/use-store-timezone.ts b/packages/seller-dashboard/src/hooks/use-store-timezone.tsnew file mode 100644index 0000000000..be2b2a25e5--- /dev/null+++ b/packages/seller-dashboard/src/hooks/use-store-timezone.ts@@ -0,0 +1,26 @@+import { useQuery } from '@tanstack/react-query'+import { useParams } from '@tanstack/react-router'+import { sellerClient } from '../api-client'++/**+ * The marketplace's timezone, as every date in this panel is read in.+ *+ * A seller keeps no clock of their own — a settlement period is decided by+ * the marketplace's day, so a timestamp rendered in whichever zone the+ * seller's browser sits in would put an earning on the wrong date for+ * anyone trading away from the marketplace.+ *+ * Falls back to the browser's zone only until the profile arrives, matching+ * what the operator dashboard's `useStore` does.+ */+export function useStoreTimezone(): string {+ const { sellerId } = useParams({ from: '/_authenticated/$sellerId' })++ const { data: profile } = useQuery({+ queryKey: ['seller', sellerId, 'profile'],+ queryFn: () => sellerClient().profile.get(),+ enabled: Boolean(sellerId),+ })++ return profile?.preferred_timezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone ?? 'UTC'+}diff --git a/packages/seller-dashboard/src/pages/order.tsx b/packages/seller-dashboard/src/pages/order.tsxindex 72ce8c8df5..e976ac4cbb 100644--- a/packages/seller-dashboard/src/pages/order.tsx+++ b/packages/seller-dashboard/src/pages/order.tsx@@ -1,8 +1,7 @@-import { PageHeader } from '@spree/dashboard-core'+import { formatStoreDateTime, PageHeader } from '@spree/dashboard-core'import { DropdownMenuItem, ResourceLayout, StatusBadge } from '@spree/dashboard-ui'import { XCircleIcon } from '@spree/dashboard-ui/icons'import { useParams } from '@tanstack/react-router'-import i18n from 'i18next'import { useState } from 'react'import { useTranslation } from 'react-i18next'import { CenteredMessage } from '../components/centered-message'@@ -16,6 +15,7 @@ import { ClaimsCard, ExchangesCard } from '../components/orders/post-sale-cards'import { ReturnsCard } from '../components/orders/returns-card'import { RetryableError } from '../components/retryable-error'import { useOrder } from '../hooks/use-order'+import { useStoreTimezone } from '../hooks/use-store-timezone'/*** One order, as the seller needs it to pack, post, and put right.@@ -28,6 +28,7 @@ import { useOrder } from '../hooks/use-order'export function OrderPage() {const { t } = useTranslation()const { orderId } = useParams({ from: '/_authenticated/$sellerId/orders/$orderId' })+ const timezone = useStoreTimezone()const [canceling, setCanceling] = useState(false)const { data: order, isLoading, isError, refetch } = useOrder(orderId)@@ -53,15 +54,7 @@ export function OrderPage() {title={order.number}backTo="orders"subtitle={- order.completed_at- ? new Date(order.completed_at).toLocaleDateString(i18n.language, {- month: 'short',- day: 'numeric',- year: 'numeric',- hour: 'numeric',- minute: '2-digit',- })- : undefined+ order.completed_at ? formatStoreDateTime(order.completed_at, timezone) : undefined}badges={<>diff --git a/packages/seller-dashboard/src/pages/payout.tsx b/packages/seller-dashboard/src/pages/payout.tsxindex d96032ebac..3f77fdd639 100644--- a/packages/seller-dashboard/src/pages/payout.tsx+++ b/packages/seller-dashboard/src/pages/payout.tsx@@ -1,4 +1,4 @@-import { PageHeader } from '@spree/dashboard-core'+import { formatStoreDateTime, PageHeader } from '@spree/dashboard-core'import {Card,CardHeader,@@ -16,13 +16,13 @@ import {} from '@spree/dashboard-ui'import { HandCoinsIcon } from '@spree/dashboard-ui/icons'import { Link, useParams } from '@tanstack/react-router'-import i18n from 'i18next'import { useState } from 'react'import { useTranslation } from 'react-i18next'import { CenteredMessage } from '../components/centered-message'import { ReadRow } from '../components/read-row'import { RetryableError } from '../components/retryable-error'import { usePayout, useTransfers } from '../hooks/use-ledger'+import { useStoreTimezone } from '../hooks/use-store-timezone'/*** One settlement, and the earnings it covers.@@ -34,6 +34,7 @@ export function PayoutPage() {const { t } = useTranslation()const { sellerId, payoutId } = useParams({ from: '/_authenticated/$sellerId/payouts/$payoutId' })+ const timezone = useStoreTimezone()const [page, setPage] = useState(1)const { data: payout, isLoading, isError, refetch } = usePayout(payoutId)@@ -54,7 +55,7 @@ export function PayoutPage() {header={<PageHeadertitle={payout.display_amount}- subtitle={formatDate(payout.created_at)}+ subtitle={formatStoreDateTime(payout.created_at, timezone)}backTo="payouts"badges={<StatusBadge@@ -102,7 +103,7 @@ export function PayoutPage() {<TableBody>{rows.map((transfer) => (<TableRow key={transfer.id}>- <TableCell>{formatDate(transfer.created_at)}</TableCell>+ <TableCell>{formatStoreDateTime(transfer.created_at, timezone)}</TableCell><TableCell>{transfer.order_id ? (<Link@@ -142,7 +143,7 @@ export function PayoutPage() {<ReadRow label={t('payouts.columns.reference')}>{payout.reference}</ReadRow><ReadRow label={t('payouts.detail.period')}>{payout.period_start && payout.period_end- ? `${formatDate(payout.period_start)} – ${formatDate(payout.period_end)}`+ ? `${formatStoreDateTime(payout.period_start, timezone)} – ${formatStoreDateTime(payout.period_end, timezone)}`: null}</ReadRow></div>@@ -151,12 +152,3 @@ export function PayoutPage() {/>)}--function formatDate(iso: string | null | undefined) {- if (!iso) return '—'- return new Date(iso).toLocaleDateString(i18n.language, {- month: 'short',- day: 'numeric',- year: 'numeric',- })-}diff --git a/packages/seller-dashboard/src/tables/orders.tsx b/packages/seller-dashboard/src/tables/orders.tsxindex d080d6d9a2..25fe8061ef 100644--- a/packages/seller-dashboard/src/tables/orders.tsx+++ b/packages/seller-dashboard/src/tables/orders.tsx@@ -1,8 +1,21 @@-import { defineTable } from '@spree/dashboard-core'+import { defineTable, formatStoreDateTime } from '@spree/dashboard-core'import { ResourceNameCell, StatusBadge } from '@spree/dashboard-ui'import { PackageIcon } from '@spree/dashboard-ui/icons'import type { Order } from '@spree/seller-sdk'import i18n from 'i18next'+import { useStoreTimezone } from '../hooks/use-store-timezone'++/**+ * An order date in the marketplace's timezone.+ *+ * Its own component because a table definition is module-level and has no+ * access to hooks, while `render` is called inside the table's JSX.+ */+function OrderDate({ iso }: { iso: string }) {+ const timezone = useStoreTimezone()++ return <>{formatStoreDateTime(iso, timezone)}</>+}/** Mirrors the operator dashboard's order status vocabularies. */const FULFILLMENT_STATUSES = [@@ -49,8 +62,7 @@ defineTable<Order>('seller-orders', {filterType: 'date',quickFilter: true,default: true,- render: (order) =>- order.completed_at ? new Date(order.completed_at).toLocaleDateString() : '—',+ render: (order) => (order.completed_at ? <OrderDate iso={order.completed_at} /> : '—'),},{key: 'fulfillment_status',diff --git a/packages/seller-dashboard/src/tables/payouts.tsx b/packages/seller-dashboard/src/tables/payouts.tsxindex 3d3c8394f4..4a6214cc26 100644--- a/packages/seller-dashboard/src/tables/payouts.tsx+++ b/packages/seller-dashboard/src/tables/payouts.tsx@@ -1,8 +1,22 @@-import { defineTable } from '@spree/dashboard-core'+import { defineTable, formatStoreDateTime } from '@spree/dashboard-core'import { ResourceNameCell, StatusBadge } from '@spree/dashboard-ui'import { HandCoinsIcon } from '@spree/dashboard-ui/icons'import type { Payout } from '@spree/seller-sdk'import i18n from 'i18next'+import { useStoreTimezone } from '../hooks/use-store-timezone'++/**+ * A ledger row's date in the marketplace's timezone.+ *+ * Its own component because a table definition is module-level and has no+ * access to hooks, while `render` is called inside the table's JSX — so a+ * cell may use them like any other component.+ */+function LedgerDate({ iso }: { iso: string }) {+ const timezone = useStoreTimezone()++ return <>{formatStoreDateTime(iso, timezone)}</>+}const STATUSES = ['pending', 'processing', 'completed', 'failed', 'unresolved'] as const@@ -26,7 +40,7 @@ defineTable<Payout>('seller-payouts', {<ResourceNameCellid={payout.id}dataAttr="data-payout-id"- name={new Date(payout.created_at).toLocaleDateString(i18n.language)}+ name={<LedgerDate iso={payout.created_at} />}/>),},diff --git a/packages/seller-dashboard/src/tables/transfers.tsx b/packages/seller-dashboard/src/tables/transfers.tsxindex be3164e5c3..ca2b72fbdc 100644--- a/packages/seller-dashboard/src/tables/transfers.tsx+++ b/packages/seller-dashboard/src/tables/transfers.tsx@@ -1,9 +1,10 @@-import { defineTable, useTenantId } from '@spree/dashboard-core'+import { defineTable, formatStoreDateTime, useTenantId } from '@spree/dashboard-core'import { StatusBadge } from '@spree/dashboard-ui'import { BanknoteIcon } from '@spree/dashboard-ui/icons'import type { Transfer } from '@spree/seller-sdk'import { Link } from '@tanstack/react-router'import i18n from 'i18next'+import { useStoreTimezone } from '../hooks/use-store-timezone'/*** The sale behind an earning — what a seller checking a figure wants next.@@ -29,6 +30,19 @@ function OrderCell({ transfer }: { transfer: Transfer }) {)}+/**+ * A ledger row's date in the marketplace's timezone.+ *+ * Its own component because a table definition is module-level and has no+ * access to hooks, while `render` is called inside the table's JSX — so a+ * cell may use them like any other component.+ */+function LedgerDate({ iso }: { iso: string }) {+ const timezone = useStoreTimezone()++ return <>{formatStoreDateTime(iso, timezone)}</>+}+const STATUSES = ['pending', 'processing', 'completed', 'failed', 'unresolved'] as constconst KINDS = ['earning', 'refund_reversal'] as const@@ -51,7 +65,7 @@ defineTable<Transfer>('seller-transfers', {filterType: 'date',quickFilter: true,default: true,- render: (transfer) => new Date(transfer.created_at).toLocaleDateString(i18n.language),+ render: (transfer) => <LedgerDate iso={transfer.created_at} />,},{key: 'order_number',