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
Fix Seller Requirement terms_effective_from to display as date field (#14651)
Damian Legawiec2624517912d4
diff --git a/packages/dashboard-core/src/components/preferences-form.tsx b/packages/dashboard-core/src/components/preferences-form.tsxindex c43b965261..3583ed13e6 100644--- a/packages/dashboard-core/src/components/preferences-form.tsx+++ b/packages/dashboard-core/src/components/preferences-form.tsx@@ -19,6 +19,7 @@ import { PlusIcon, TrashIcon } from '@spree/dashboard-ui/icons'import { useId, useMemo, useState } from 'react'import { useTranslation } from 'react-i18next'import { CurrencySelect } from './currency-select'+import { StoreDatePicker } from './store-date-picker'/*** Hydrates a `preferences` hash with each field's default. Used to seed@@ -64,6 +65,12 @@ interface PreferencesFormProps {* calculator set to one quotes no rate at all.*/currencyOptions?: string[]+ /**+ * Render date/datetime pickers inline instead of in a Popover portal.+ * Set this when the form is inside a `<Sheet>` — Base UI's Popover fails+ * to mount in deeply nested portal trees, so the calendar never appears.+ */+ inlineDatePickers?: boolean}/**@@ -85,6 +92,7 @@ export function PreferencesForm({redactPasswords = false,labelOverrides,currencyOptions,+ inlineDatePickers,}: PreferencesFormProps) {if (!schema?.length) return null@@ -104,6 +112,7 @@ export function PreferencesForm({onChange={(v) => setValue(field.key, v)}redactPasswords={redactPasswords}currencyOptions={currencyOptions}+ inlineDatePickers={inlineDatePickers}/>))}</FieldGroup>@@ -117,6 +126,7 @@ interface PreferenceFieldProps {onChange: (value: unknown) => voidredactPasswords?: booleancurrencyOptions?: string[]+ inlineDatePickers?: boolean}export function PreferenceField({@@ -126,6 +136,7 @@ export function PreferenceField({onChange,redactPasswords,currencyOptions,+ inlineDatePickers,}: PreferenceFieldProps) {const { t, i18n } = useTranslation()const id = `preference-${field.key}`@@ -192,6 +203,26 @@ export function PreferenceField({</Field>)+ // A date is a picker, never a text box: an operator typing "1 Jan 2026"+ // into a field the server parses as ISO-8601 gets a validation error with+ // no hint of the format wanted. `<StoreDatePicker>` also reads the store's+ // timezone, so a date means the same day for every admin.+ case 'date':+ case 'datetime':+ return (+ <Field>+ <FieldLabel htmlFor={id}>{displayLabel}</FieldLabel>+ <StoreDatePicker+ id={id}+ value={(value as string) ?? null}+ onChange={(next) => onChange(next)}+ includeTime={field.type === 'datetime'}+ inline={inlineDatePickers}+ />+ {description && <FieldDescription>{description}</FieldDescription>}+ </Field>+ )+case 'integer':case 'decimal':return (diff --git a/packages/dashboard-ui/src/ui/date-picker.tsx b/packages/dashboard-ui/src/ui/date-picker.tsxindex 37eb4c7cc9..96ba29ecbe 100644--- a/packages/dashboard-ui/src/ui/date-picker.tsx+++ b/packages/dashboard-ui/src/ui/date-picker.tsx@@ -37,6 +37,13 @@ interface DatePickerProps {* keep the default Popover behavior.*/inline?: boolean+ /**+ * Forwarded to the trigger button, so a `<FieldLabel htmlFor>` can name the+ * control. Without it the label sits next to the picker visually but is not+ * associated with it, and a screen reader announces only the formatted date+ * the trigger happens to show.+ */+ id?: string}const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/@@ -77,6 +84,7 @@ function DatePicker({includeTime = false,timezone,inline = false,+ id,}: DatePickerProps) {const [open, setOpen] = useState(false)const containerRef = useRef<HTMLDivElement | null>(null)@@ -211,6 +219,7 @@ function DatePicker({return (<div ref={containerRef} className={cn('relative', className)}><Button+ id={id}type="button"variant="outline"data-empty={!isValidDate}@@ -238,7 +247,13 @@ function DatePicker({return (<Popover open={open} onOpenChange={setOpen}><PopoverTrigger asChild disabled={disabled}>- <Button type="button" variant="outline" data-empty={!isValidDate} className={className}>+ <Button+ id={id}+ type="button"+ variant="outline"+ data-empty={!isValidDate}+ className={className}+ >{triggerChildren}</Button></PopoverTrigger>diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/seller-requirements.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/seller-requirements.tsxindex e5120fcb38..003d51be76 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/seller-requirements.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/seller-requirements.tsx@@ -526,6 +526,7 @@ function RequirementFields({schema={kindEntry.preference_schema as unknown as PreferenceField[]}values={values.preferences}onChange={onChange.setPreferences}+ inlineDatePickers/>)}diff --git a/spree/core/app/models/spree/seller_requirements/accept_terms.rb b/spree/core/app/models/spree/seller_requirements/accept_terms.rbindex e8f6292ff2..9b04d43dc3 100644--- a/spree/core/app/models/spree/seller_requirements/accept_terms.rb+++ b/spree/core/app/models/spree/seller_requirements/accept_terms.rb@@ -14,7 +14,11 @@ module Spree# drift. A seller agreement that is not the shopper-facing document# is written here instead.preference :terms_body, :text, default: nil, nullable: true- preference :terms_effective_from, :string, default: nil+ # `:date`, so the dashboard renders a date picker rather than a text box+ # an operator can type a malformed date into. The value stays a+ # `yyyy-MM-dd` string on the wire and in storage — see `effective_from`+ # for why the timezone is applied on read rather than at coercion.+ preference :terms_effective_from, :date, default: nil# A published copy of the same terms, for a marketplace that also# hosts them on a public page. Optional — the panel renders the# body above; this is the "open the full document" link.diff --git a/spree/core/lib/spree/core/preferences/preferable.rb b/spree/core/lib/spree/core/preferences/preferable.rbindex ed2c26c955..81e9abae8f 100644--- a/spree/core/lib/spree/core/preferences/preferable.rb+++ b/spree/core/lib/spree/core/preferences/preferable.rb@@ -220,6 +220,22 @@ module Spree::Preferences::Preferableelsevalue.to_timeend+ # Kept as the `yyyy-MM-dd` string it arrived as rather than coerced to a+ # Time. Preferences are YAML-serialized, and what a date *means* depends on+ # the store's timezone, which this method has no access to: coercing here+ # would freeze the value against the server's zone and move the operator's+ # deadline by hours. The reader owns that (see+ # `Spree::SellerRequirements::AcceptTerms#effective_from`); the type exists+ # so the admin form knows to render a date picker.+ when :date+ return nil if value.blank?++ case value+ when Date, Time, DateTime, ActiveSupport::TimeWithZone+ value.strftime('%Y-%m-%d')+ else+ value.to_s+ endelsevalueenddiff --git a/spree/core/spec/models/spree/preferences/preferable_spec.rb b/spree/core/spec/models/spree/preferences/preferable_spec.rbindex da113b696f..40cd87eed1 100644--- a/spree/core/spec/models/spree/preferences/preferable_spec.rb+++ b/spree/core/spec/models/spree/preferences/preferable_spec.rb@@ -334,6 +334,36 @@ describe Spree::Preferences::Preferable, type: :model doendend+ # Deliberately not coerced to a Date: a date's meaning depends on the+ # store's timezone, which the coercion has no access to, so the reader+ # applies the zone instead. The type exists so the admin form renders a+ # picker.+ context 'keeps date preferences as plain yyyy-mm-dd strings' do+ before do+ A.preference :effective_from, :date, default: nil+ end++ it 'keeps a date string as written' do+ @a.set_preference(:effective_from, '2026-01-01')+ expect(@a.preferences[:effective_from]).to eq('2026-01-01')+ end++ it 'keeps a full timestamp, so an existing stored value still reads back' do+ @a.set_preference(:effective_from, '2026-01-01T09:00:00Z')+ expect(@a.preferences[:effective_from]).to eq('2026-01-01T09:00:00Z')+ end++ it 'formats a Date object rather than storing the object itself' do+ @a.set_preference(:effective_from, Date.new(2026, 1, 1))+ expect(@a.preferences[:effective_from]).to eq('2026-01-01')+ end++ it 'treats a blank value as unset' do+ @a.set_preference(:effective_from, '')+ expect(@a.preferences[:effective_from]).to be_nil+ end+ end+context 'converts any preferences to any values' dobefore doA.preference :product_ids, :any, default: []