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
Surface digital asset save errors and guard empty numeric settings
Damian Legawiec1dbbde883f61
diff --git a/packages/dashboard/src/components/spree/products/digital-asset-edit-sheet.tsx b/packages/dashboard/src/components/spree/products/digital-asset-edit-sheet.tsxindex 0a127fedbe..02f2df855c 100644--- a/packages/dashboard/src/components/spree/products/digital-asset-edit-sheet.tsx+++ b/packages/dashboard/src/components/spree/products/digital-asset-edit-sheet.tsx@@ -82,14 +82,21 @@ export function DigitalAssetEditSheet({return}- await updateAsset.mutateAsync({- id: asset!.id,- authorized_clicks: parsedClicks,- authorized_days: parsedDays,- ...(hasVariants && variantId ? { variant_id: variantId } : {}),- ...(settingsSchema.length > 0 ? { provider_settings: settings } : {}),- })- onOpenChange(false)+ setError(null)+ try {+ await updateAsset.mutateAsync({+ id: asset!.id,+ authorized_clicks: parsedClicks,+ authorized_days: parsedDays,+ ...(hasVariants && variantId ? { variant_id: variantId } : {}),+ ...(settingsSchema.length > 0 ? { provider_settings: settings } : {}),+ })+ onOpenChange(false)+ } catch (err) {+ // useResourceMutation suppresses the toast for a 422, so surface the+ // reason inline and keep the sheet open with the entered values.+ setError(err instanceof Error ? err.message : t('admin.errors.unexpected'))+ }}return (diff --git a/packages/dashboard/src/components/spree/products/digital-asset-provider-sheet.tsx b/packages/dashboard/src/components/spree/products/digital-asset-provider-sheet.tsxindex 96dceb6a30..5d17803322 100644--- a/packages/dashboard/src/components/spree/products/digital-asset-provider-sheet.tsx+++ b/packages/dashboard/src/components/spree/products/digital-asset-provider-sheet.tsx@@ -29,21 +29,32 @@ export function DigitalAssetProviderSheet({ productId, provider, onOpenChange, oconst { t } = useTranslation()const createAsset = useCreateDigitalAsset(productId)const [values, setValues] = useState<Record<string, unknown>>({})+ const [error, setError] = useState<string | null>(null)// Re-seed with the provider's defaults each time a source is picked.useEffect(() => {- if (provider) setValues(defaultProviderSettings(provider.settings_schema))+ if (provider) {+ setValues(defaultProviderSettings(provider.settings_schema))+ setError(null)+ }}, [provider])if (!provider) return nullasync function handleCreate() {- await createAsset.mutateAsync({- provider_type: provider!.type,- provider_settings: values,- })- onCreated()- onOpenChange(false)+ setError(null)+ try {+ await createAsset.mutateAsync({+ provider_type: provider!.type,+ provider_settings: values,+ })+ onCreated()+ onOpenChange(false)+ } catch (err) {+ // useResourceMutation suppresses the toast for a 422, so surface the+ // reason inline and keep the sheet open with the entered values.+ setError(err instanceof Error ? err.message : t('admin.errors.unexpected'))+ }}return (@@ -59,6 +70,8 @@ export function DigitalAssetProviderSheet({ productId, provider, onOpenChange, ovalues={values}onChange={setValues}/>++ {error && <p className="text-destructive text-sm">{error}</p>}</div><SheetFooter>diff --git a/packages/dashboard/src/components/spree/products/provider-settings-fields.tsx b/packages/dashboard/src/components/spree/products/provider-settings-fields.tsxindex 5e01685332..d79b94b19b 100644--- a/packages/dashboard/src/components/spree/products/provider-settings-fields.tsx+++ b/packages/dashboard/src/components/spree/products/provider-settings-fields.tsx@@ -79,9 +79,17 @@ export function ProviderSettingsFields({ schema, values, onChange }: Props) {id={id}type={field.type === 'number' ? 'number' : 'text'}value={value == null ? '' : String(value)}- onChange={(e) =>- set(field.key, field.type === 'number' ? e.target.valueAsNumber : e.target.value)- }+ onChange={(e) => {+ if (field.type !== 'number') {+ set(field.key, e.target.value)+ return+ }+ // An empty or invalid number input yields NaN, which would+ // serialize to null and silently clear the setting. Keep it+ // unset instead of writing a bogus value.+ const parsed = e.target.valueAsNumber+ set(field.key, Number.isFinite(parsed) ? parsed : undefined)+ }}/></Field>)diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsxindex c09219c968..e341375e82 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx@@ -90,8 +90,7 @@ function NewProductPage() {// server's Product#digital_assets= attaches them to the default variant// after the product is created.if (digital_assets && digital_assets.length > 0) {- // eslint-disable-next-line @typescript-eslint/no-explicit-any- ;(payload as any).digital_assets = digital_assets.map(({ signed_id }) => ({ signed_id }))+ payload.digital_assets = digital_assets.map(({ signed_id }) => ({ signed_id }))}// For simple products (single variant with no options) the merchant