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
Restore the market locale the price editor reads
Damian Legawiec881f2625e4c6
diff --git a/packages/dashboard-core/src/api-client.ts b/packages/dashboard-core/src/api-client.tsindex 80dc702727..d60c1a199c 100644--- a/packages/dashboard-core/src/api-client.ts+++ b/packages/dashboard-core/src/api-client.ts@@ -156,12 +156,29 @@ export interface PanelApiClient {tags?: {list(params?: Record<string, unknown>): Promise<{ data: Array<{ name: string }> }>}+ /**+ * Currency-to-locale pairs, which is what tells a money field whether+ * `34,56` is thirty-four and a half or three thousand. The operator's+ * markets answer it; a panel that registers none falls back to the UI+ * language, the same answer the operator's hook gives for an unmatched+ * currency.+ */+ markets?: {+ list(params?: Record<string, unknown>): Promise<{ data: PanelMarket[] }>+ }}export interface PanelDeliveryProfile extends PanelNamedRecord {default?: boolean}+/** A market, as the money fields read it. */+export interface PanelMarket {+ id: string+ currency?: string | null+ default_locale?: string | null+}+/** A library file, as the picker lists it. */export interface PanelMediaRecord {id: stringdiff --git a/packages/dashboard-core/src/products/product-bulk-price-editor.tsx b/packages/dashboard-core/src/products/product-bulk-price-editor.tsxindex 9fe4447cfd..fcc1f78032 100644--- a/packages/dashboard-core/src/products/product-bulk-price-editor.tsx+++ b/packages/dashboard-core/src/products/product-bulk-price-editor.tsx@@ -6,7 +6,10 @@ import { useTranslation } from 'react-i18next'import { composeOptionsText } from '../products/variants-matrix'import { currencyParts } from './currency-parts'import { normalizeMoneyInput } from './normalize-money'-import { useFormOptionTypes as useOptionTypes } from './use-product-form-data'+import {+ useFormCurrencyLocale as useCurrencyLocale,+ useFormOptionTypes as useOptionTypes,+} from './use-product-form-data'interface Props {// eslint-disable-next-line @typescript-eslint/no-explicit-any@@ -36,10 +39,7 @@ export function ProductBulkPriceEditor({ form, currency, productName }: Props) {const variants = useWatch({ control: form.control, name: 'variants' }) ?? []const { data: optionTypesData } = useOptionTypes()const optionTypes = useMemo(() => optionTypesData?.data ?? [], [optionTypesData])- // Formatting locale is the operator dashboard's market lookup; without it- // Intl falls back to the browser's, which is the right answer for a panel- // that has no markets to consult.- const localeForCurrency = (_currency?: string): string | undefined => undefined+ const localeForCurrency = useCurrencyLocale()// Format the grid in the currency's market locale (e.g. EUR → `de`, comma// decimal). The same locale normalizes the merchant's input back to canonicaldiff --git a/packages/dashboard-core/src/products/use-product-form-data.ts b/packages/dashboard-core/src/products/use-product-form-data.tsindex 531ea5ca5f..958efa68b3 100644--- a/packages/dashboard-core/src/products/use-product-form-data.ts+++ b/packages/dashboard-core/src/products/use-product-form-data.ts@@ -2,6 +2,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'import type {PanelCollection,PanelDeliveryProfile,+ PanelMarket,PanelNamedRecord,PanelOptionType,PanelProductType,@@ -206,3 +207,30 @@ export function collectionAutocompleteProps(queryKey: string) {getOptionLabel: (collection: PanelCollection) => collection.name ?? collection.id,}}++/**+ * Resolves a currency to the locale its amounts are typed and shown in, so a+ * EUR field accepts `1.234,56` and normalizes it to `1234.56`. Mirrors the+ * operator dashboard's `useCurrencyLocale`, reading through the registered+ * client so the shared price editor works in either panel; a panel with no+ * markets answers undefined and callers fall back to the UI language.+ */+export function useFormCurrencyLocale(): (currency: string | undefined) => string | undefined {+ const client = getApiClient()++ const { data } = useQuery({+ queryKey: useResourceKey('panel-form-markets'),+ queryFn: async (): Promise<{ data: PanelMarket[] }> =>+ (await client.markets?.list({ limit: 100 })) ?? { data: [] },+ enabled: Boolean(client.markets),+ staleTime: FIVE_MINUTES,+ })++ const markets = data?.data ?? []++ return (currency) => {+ if (!currency) return undefined++ return markets.find((market) => market.currency === currency)?.default_locale ?? undefined+ }+}diff --git a/packages/dashboard/src/api-client-setup.ts b/packages/dashboard/src/api-client-setup.tsindex 6058c9e063..cc9e8d4e8b 100644--- a/packages/dashboard/src/api-client-setup.ts+++ b/packages/dashboard/src/api-client-setup.ts@@ -44,6 +44,7 @@ setApiClient({deliveryProfiles: { list: (params) => adminClient.deliveryProfiles.list(params) },deleteProductMedia: (productId, mediaId) => adminClient.products.media.delete(productId, mediaId),mediaLibrary: { list: (params) => adminClient.media.list(params) },+ markets: { list: (params) => adminClient.markets.list(params) },tags: {list: (params) => adminClient.tags.list(params as { taggable_type: string; q?: string }),},