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
Add email settings in Dashboard
Damian Legawiecc9276a583aad
diff --git a/packages/admin-sdk/src/params.ts b/packages/admin-sdk/src/params.tsindex 1441fc4737..3271d34fcd 100644--- a/packages/admin-sdk/src/params.ts+++ b/packages/admin-sdk/src/params.ts@@ -7,6 +7,16 @@ export interface StoreUpdateParams {preferred_timezone?: stringpreferred_weight_unit?: stringpreferred_unit_system?: string+ /** Sender address used on all transactional emails (required by the model). */+ mail_from_address?: string+ /** Customer-facing reply-to address shown in the storefront/email footer. */+ customer_support_email?: string | null+ /** Recipient of "new order placed" admin notifications. */+ new_order_notifications_email?: string | null+ /** When false, transactional consumer emails (order confirmation, etc.) are suppressed. */+ preferred_send_consumer_transactional_emails?: boolean+ /** Active Storage signed_id from a direct upload — the logo embedded in transactional emails. */+ mailer_logo?: string | null}export interface OptionValueParams {diff --git a/packages/dashboard/e2e/store-settings.spec.ts b/packages/dashboard/e2e/store-settings.spec.tsnew file mode 100644index 0000000000..4342ee8520--- /dev/null+++ b/packages/dashboard/e2e/store-settings.spec.ts@@ -0,0 +1,111 @@+import { expect, test } from '@playwright/test'+import { login } from './helpers'++const STORE_PATH = (storeId: string) => `/${storeId}/settings/store`+const EMAILS_PATH = (storeId: string) => `/${storeId}/settings/emails`++// Both pages mutate a single shared resource (the default store). Run them+// serially so the email-suite doesn't observe a store name from+// store-settings mid-update.+test.describe.configure({ mode: 'serial' })++test.describe('store settings — general', () => {+ test('loads the store settings page', async ({ page }) => {+ const creds = await login(page)+ await page.goto(STORE_PATH(creds.store_id))++ await expect(page.getByRole('heading', { name: /^store settings$/i })).toBeVisible({+ timeout: 15_000,+ })+ await expect(page.locator('#store-name')).toBeVisible()+ })++ test('renames the store and persists across reload', async ({ page }) => {+ const creds = await login(page)+ await page.goto(STORE_PATH(creds.store_id))+ await expect(page.locator('#store-name')).toBeVisible({ timeout: 15_000 })++ const newName = `E2E Store ${Date.now()}`++ await page.locator('#store-name').fill(newName)+ await page.getByRole('button', { name: /^save$/i }).click()++ // Toast shows the success message. We don't depend on it being visible by+ // the time we navigate — the next assertion (reload + value match) is+ // what confirms persistence.+ await expect(page.locator('#store-name')).toHaveValue(newName)++ await page.reload()+ await expect(page.locator('#store-name')).toHaveValue(newName, { timeout: 15_000 })++ // Reset for the rest of the suite — keeps the shared DB clean.+ await page.locator('#store-name').fill(creds.store_name)+ await page.getByRole('button', { name: /^save$/i }).click()+ await expect(page.locator('#store-name')).toHaveValue(creds.store_name)+ })+})++test.describe('store settings — emails', () => {+ test('hides addresses + logo cards when consumer emails are turned off', async ({ page }) => {+ const creds = await login(page)+ await page.goto(EMAILS_PATH(creds.store_id))+ await expect(page.getByRole('heading', { name: /^email settings$/i })).toBeVisible({+ timeout: 15_000,+ })++ // Cards visible by default (consumer emails are enabled on a fresh store).+ await expect(page.locator('#store-mail-from-address')).toBeVisible()+ await expect(page.getByRole('heading', { name: /^logo$/i })).toBeVisible()++ // Toggle off → address + logo cards disappear.+ await page.locator('#store-send-consumer-emails').click()+ await expect(page.locator('#store-mail-from-address')).toHaveCount(0)+ await expect(page.getByRole('heading', { name: /^logo$/i })).toHaveCount(0)++ // Toggle back on → cards return without losing the seed value.+ await page.locator('#store-send-consumer-emails').click()+ await expect(page.locator('#store-mail-from-address')).toBeVisible()+ await expect(page.getByRole('heading', { name: /^logo$/i })).toBeVisible()+ })++ test('saves sender + support + notifications addresses and reloads them', async ({ page }) => {+ const creds = await login(page)+ await page.goto(EMAILS_PATH(creds.store_id))+ await expect(page.locator('#store-mail-from-address')).toBeVisible({ timeout: 15_000 })++ const suffix = Date.now()+ const sender = `sender-${suffix}@example.com`+ const support = `support-${suffix}@example.com`+ const ops = `ops-${suffix}@example.com`++ await page.locator('#store-mail-from-address').fill(sender)+ await page.locator('#store-customer-support-email').fill(support)+ await page.locator('#store-new-order-notifications-email').fill(ops)++ await page.getByRole('button', { name: /^save$/i }).click()++ // Re-fetch values after the mutation roundtrip. RHF re-seeds defaults on+ // success, so we don't need an explicit toast wait.+ await expect(page.locator('#store-mail-from-address')).toHaveValue(sender)++ await page.reload()+ await expect(page.locator('#store-mail-from-address')).toHaveValue(sender, { timeout: 15_000 })+ await expect(page.locator('#store-customer-support-email')).toHaveValue(support)+ await expect(page.locator('#store-new-order-notifications-email')).toHaveValue(ops)+ })++ test('flags an invalid mail_from_address inline', async ({ page }) => {+ const creds = await login(page)+ await page.goto(EMAILS_PATH(creds.store_id))+ await expect(page.locator('#store-mail-from-address')).toBeVisible({ timeout: 15_000 })++ await page.locator('#store-mail-from-address').fill('not-an-email')+ await page.getByRole('button', { name: /^save$/i }).click()++ // Zod resolver renders an inline error via the field's aria-invalid + the+ // accompanying FieldError component — assert the field reflects invalid+ // state. Specific copy varies by zod version, so we anchor on the+ // attribute rather than the message string.+ await expect(page.locator('#store-mail-from-address')).toHaveAttribute('aria-invalid', 'true')+ })+})diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.jsonindex 8f80aab41e..c48b775cfa 100644--- a/packages/dashboard/src/locales/en.json+++ b/packages/dashboard/src/locales/en.json@@ -429,6 +429,31 @@},"preferred_weight_unit": {"label": "Weight unit"+ },+ "mail_from_address": {+ "label": "Sender address",+ "placeholder": "[email protected]",+ "help": "Used as the From address on every transactional email."+ },+ "customer_support_email": {+ "label": "Customer support email",+ "placeholder": "[email protected]",+ "help": "Reply-to address shown to customers in storefront emails."+ },+ "new_order_notifications_email": {+ "label": "New order notifications",+ "placeholder": "[email protected]",+ "help": "Recipient of \"new order placed\" notifications. Leave blank to disable."+ },+ "preferred_send_consumer_transactional_emails": {+ "label": "Send transactional emails to customers",+ "help": "When off, no order confirmation, shipping, or refund emails are sent."+ },+ "mailer_logo": {+ "label": "Email logo",+ "help": "PNG or JPG with a transparent background. Embedded in transactional email headers."+ }+ },"webhook_endpoint": {"name": {"label": "Name",@@ -1033,6 +1058,20 @@"tab_general": "General","tab_standards": "Standards and formats"},+ "emails": {+ "title": "Email settings",+ "subtitle": "Sender addresses, notifications, and the logo embedded in transactional emails.",+ "section_delivery": "Delivery",+ "section_addresses": "Email addresses",+ "section_logo": "Logo",+ "logo_dimensions_help": "Recommended: 204×104 pixels.",+ "logo_upload_cta": "Upload logo",+ "logo_replace_cta": "Replace logo",+ "logo_remove_cta": "Remove logo",+ "logo_uploading": "Uploading…",+ "logo_upload_failed": "Failed to upload logo.",+ "load_failed_title": "Couldn't load email settings"+ },"webhooks": {"title": "Webhooks","subtitle": "Subscribe HTTPS endpoints to events fired by your store.",diff --git a/packages/dashboard/src/nav/settings.ts b/packages/dashboard/src/nav/settings.tsindex a80b701427..e7fa970785 100644--- a/packages/dashboard/src/nav/settings.ts+++ b/packages/dashboard/src/nav/settings.ts@@ -4,6 +4,7 @@ import {GlobeIcon,GlobeLockIcon,KeyRoundIcon,+ MailIcon,PercentIcon,RadioTowerIcon,StoreIcon,@@ -28,6 +29,16 @@ settingsNav.add({subject: Subject.Store,})+settingsNav.add({+ key: 'settings.emails',+ label: 'Emails',+ path: '/emails',+ icon: MailIcon,+ group: 'store',+ position: 125,+ subject: Subject.Store,+})+settingsNav.add({key: 'settings.channels',label: 'Sales channels',diff --git a/packages/dashboard/src/routeTree.gen.ts b/packages/dashboard/src/routeTree.gen.tsindex 7ad5396e2e..46655cc80b 100644--- a/packages/dashboard/src/routeTree.gen.ts+++ b/packages/dashboard/src/routeTree.gen.ts@@ -27,6 +27,7 @@ import { Route as AuthenticatedStoreIdSettingsStockLocationsRouteImport } from 'import { Route as AuthenticatedStoreIdSettingsStaffRouteImport } from './routes/_authenticated/$storeId/settings/staff'import { Route as AuthenticatedStoreIdSettingsPaymentMethodsRouteImport } from './routes/_authenticated/$storeId/settings/payment-methods'import { Route as AuthenticatedStoreIdSettingsMarketsRouteImport } from './routes/_authenticated/$storeId/settings/markets'+import { Route as AuthenticatedStoreIdSettingsEmailsRouteImport } from './routes/_authenticated/$storeId/settings/emails'import { Route as AuthenticatedStoreIdSettingsCustomFieldDefinitionsRouteImport } from './routes/_authenticated/$storeId/settings/custom-field-definitions'import { Route as AuthenticatedStoreIdSettingsChannelsRouteImport } from './routes/_authenticated/$storeId/settings/channels'import { Route as AuthenticatedStoreIdSettingsApiKeysRouteImport } from './routes/_authenticated/$storeId/settings/api-keys'@@ -152,6 +153,12 @@ const AuthenticatedStoreIdSettingsMarketsRoute =path: '/markets',getParentRoute: () => AuthenticatedStoreIdSettingsRoute,} as any)+const AuthenticatedStoreIdSettingsEmailsRoute =+ AuthenticatedStoreIdSettingsEmailsRouteImport.update({+ id: '/emails',+ path: '/emails',+ getParentRoute: () => AuthenticatedStoreIdSettingsRoute,+ } as any)const AuthenticatedStoreIdSettingsCustomFieldDefinitionsRoute =AuthenticatedStoreIdSettingsCustomFieldDefinitionsRouteImport.update({id: '/custom-field-definitions',@@ -341,6 +348,7 @@ export interface FileRoutesByTo {'/$storeId/settings/api-keys': typeof AuthenticatedStoreIdSettingsApiKeysRoute'/$storeId/settings/channels': typeof AuthenticatedStoreIdSettingsChannelsRoute'/$storeId/settings/custom-field-definitions': typeof AuthenticatedStoreIdSettingsCustomFieldDefinitionsRoute+ '/$storeId/settings/emails': typeof AuthenticatedStoreIdSettingsEmailsRoute'/$storeId/settings/markets': typeof AuthenticatedStoreIdSettingsMarketsRoute'/$storeId/settings/payment-methods': typeof AuthenticatedStoreIdSettingsPaymentMethodsRoute'/$storeId/settings/staff': typeof AuthenticatedStoreIdSettingsStaffRoute@@ -383,6 +391,7 @@ export interface FileRoutesById {'/_authenticated/$storeId/settings/api-keys': typeof AuthenticatedStoreIdSettingsApiKeysRoute'/_authenticated/$storeId/settings/channels': typeof AuthenticatedStoreIdSettingsChannelsRoute'/_authenticated/$storeId/settings/custom-field-definitions': typeof AuthenticatedStoreIdSettingsCustomFieldDefinitionsRoute+ '/_authenticated/$storeId/settings/emails': typeof AuthenticatedStoreIdSettingsEmailsRoute'/_authenticated/$storeId/settings/markets': typeof AuthenticatedStoreIdSettingsMarketsRoute'/_authenticated/$storeId/settings/payment-methods': typeof AuthenticatedStoreIdSettingsPaymentMethodsRoute'/_authenticated/$storeId/settings/staff': typeof AuthenticatedStoreIdSettingsStaffRoute@@ -425,6 +434,7 @@ export interface FileRouteTypes {| '/$storeId/settings/api-keys'| '/$storeId/settings/channels'| '/$storeId/settings/custom-field-definitions'+ | '/$storeId/settings/emails'| '/$storeId/settings/markets'| '/$storeId/settings/payment-methods'| '/$storeId/settings/staff'@@ -463,6 +473,7 @@ export interface FileRouteTypes {| '/$storeId/settings/api-keys'| '/$storeId/settings/channels'| '/$storeId/settings/custom-field-definitions'+ | '/$storeId/settings/emails'| '/$storeId/settings/markets'| '/$storeId/settings/payment-methods'| '/$storeId/settings/staff'@@ -504,6 +515,7 @@ export interface FileRouteTypes {| '/_authenticated/$storeId/settings/api-keys'| '/_authenticated/$storeId/settings/channels'| '/_authenticated/$storeId/settings/custom-field-definitions'+ | '/_authenticated/$storeId/settings/emails'| '/_authenticated/$storeId/settings/markets'| '/_authenticated/$storeId/settings/payment-methods'| '/_authenticated/$storeId/settings/staff'@@ -656,6 +668,13 @@ declare module '@tanstack/react-router' {preLoaderRoute: typeof AuthenticatedStoreIdSettingsMarketsRouteImportparentRoute: typeof AuthenticatedStoreIdSettingsRoute}+ '/_authenticated/$storeId/settings/emails': {+ id: '/_authenticated/$storeId/settings/emails'+ path: '/emails'+ fullPath: '/$storeId/settings/emails'+ preLoaderRoute: typeof AuthenticatedStoreIdSettingsEmailsRouteImport+ parentRoute: typeof AuthenticatedStoreIdSettingsRoute+ }'/_authenticated/$storeId/settings/custom-field-definitions': {id: '/_authenticated/$storeId/settings/custom-field-definitions'path: '/custom-field-definitions'@@ -811,6 +830,7 @@ interface AuthenticatedStoreIdSettingsRouteChildren {AuthenticatedStoreIdSettingsApiKeysRoute: typeof AuthenticatedStoreIdSettingsApiKeysRouteAuthenticatedStoreIdSettingsChannelsRoute: typeof AuthenticatedStoreIdSettingsChannelsRouteAuthenticatedStoreIdSettingsCustomFieldDefinitionsRoute: typeof AuthenticatedStoreIdSettingsCustomFieldDefinitionsRoute+ AuthenticatedStoreIdSettingsEmailsRoute: typeof AuthenticatedStoreIdSettingsEmailsRouteAuthenticatedStoreIdSettingsMarketsRoute: typeof AuthenticatedStoreIdSettingsMarketsRouteAuthenticatedStoreIdSettingsPaymentMethodsRoute: typeof AuthenticatedStoreIdSettingsPaymentMethodsRouteAuthenticatedStoreIdSettingsStaffRoute: typeof AuthenticatedStoreIdSettingsStaffRoute@@ -832,6 +852,8 @@ const AuthenticatedStoreIdSettingsRouteChildren: AuthenticatedStoreIdSettingsRouAuthenticatedStoreIdSettingsChannelsRoute,AuthenticatedStoreIdSettingsCustomFieldDefinitionsRoute:AuthenticatedStoreIdSettingsCustomFieldDefinitionsRoute,+ AuthenticatedStoreIdSettingsEmailsRoute:+ AuthenticatedStoreIdSettingsEmailsRoute,AuthenticatedStoreIdSettingsMarketsRoute:AuthenticatedStoreIdSettingsMarketsRoute,AuthenticatedStoreIdSettingsPaymentMethodsRoute:diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/emails.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/emails.tsxnew file mode 100644index 0000000000..eb3a21f533--- /dev/null+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/emails.tsx@@ -0,0 +1,375 @@+import { zodResolver } from '@hookform/resolvers/zod'+import { SpreeError, type Store, type StoreUpdateParams } from '@spree/admin-sdk'+import { mapSpreeErrorsToForm, PageHeader, useDirectUpload } from '@spree/dashboard-core'+import {+ Button,+ Card,+ CardContent,+ CardHeader,+ CardTitle,+ cn,+ ErrorState,+ Field,+ FieldDescription,+ FieldError,+ FieldGroup,+ FieldLabel,+ FormActions,+ Input,+ ResourceLayout,+ Skeleton,+ Switch,+ useFormSubmitShortcut,+} from '@spree/dashboard-ui'+import { createFileRoute } from '@tanstack/react-router'+import { ImageIcon, UploadCloudIcon } from 'lucide-react'+import { useEffect, useRef, useState } from 'react'+import { Controller, useForm } from 'react-hook-form'+import { useTranslation } from 'react-i18next'+import { toast } from 'sonner'+import { useStoreSettings, useUpdateStoreSettings } from '@/hooks/use-store-settings'+import { type StoreEmailsFormValues, storeEmailsFormSchema } from '@/schemas/store-emails'++export const Route = createFileRoute('/_authenticated/$storeId/settings/emails')({+ component: EmailSettingsPage,+})++function storeToFormValues(store: Store): StoreEmailsFormValues {+ return {+ mail_from_address: store.mail_from_address ?? '',+ customer_support_email: store.customer_support_email ?? '',+ new_order_notifications_email: store.new_order_notifications_email ?? '',+ preferred_send_consumer_transactional_emails:+ store.preferred_send_consumer_transactional_emails,+ mailer_logo_signed_id: null,+ mailer_logo_preview_url: null,+ mailer_logo_cleared: false,+ }+}++function formValuesToApiParams(values: StoreEmailsFormValues): StoreUpdateParams {+ const params: StoreUpdateParams = {+ mail_from_address: values.mail_from_address,+ customer_support_email: values.customer_support_email?.trim() || null,+ new_order_notifications_email: values.new_order_notifications_email?.trim() || null,+ preferred_send_consumer_transactional_emails:+ values.preferred_send_consumer_transactional_emails,+ }+ // Three states for the logo: untouched (omit), uploaded (send signed_id),+ // explicitly cleared (send null). Sending an empty value would be ambiguous.+ if (values.mailer_logo_signed_id) {+ params.mailer_logo = values.mailer_logo_signed_id+ } else if (values.mailer_logo_cleared) {+ params.mailer_logo = null+ }+ return params+}++function EmailSettingsPage() {+ const { t } = useTranslation()+ const { data: store, isLoading, error, refetch } = useStoreSettings()++ if (isLoading || !store) {+ return (+ <div className="flex flex-col gap-6">+ <Skeleton className="h-8 w-64" />+ <Skeleton className="h-64 w-full" />+ <Skeleton className="h-64 w-full" />+ </div>+ )+ }++ if (error) {+ return (+ <ErrorState+ title={t('admin.pages.settings.emails.load_failed_title')}+ description={error instanceof Error ? error.message : undefined}+ onRetry={() => refetch()}+ />+ )+ }++ return <EmailSettingsForm store={store} />+}++function EmailSettingsForm({ store }: { store: Store }) {+ const { t } = useTranslation()+ const updateMutation = useUpdateStoreSettings()++ const form = useForm<StoreEmailsFormValues>({+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ resolver: zodResolver(storeEmailsFormSchema) as any,+ defaultValues: storeToFormValues(store),+ })++ const onSubmit = async (values: StoreEmailsFormValues) => {+ try {+ await updateMutation.mutateAsync(formValuesToApiParams(values))+ toast.success(t('admin.messages.store_settings_updated'))+ // Re-seed the form from `values` so dirty state collapses; the next render+ // will reflect the server's mailer_logo_url through `store`.+ form.reset({+ ...values,+ mailer_logo_signed_id: null,+ mailer_logo_preview_url: null,+ mailer_logo_cleared: false,+ })+ } catch (err) {+ if (mapSpreeErrorsToForm(err, form.setError)) return+ if (err instanceof SpreeError) throw err+ toast.error(err instanceof Error ? err.message : t('admin.errors.failed_to_update_store'))+ }+ }++ useFormSubmitShortcut(form, onSubmit)++ const { errors } = form.formState+ // Mirror legacy behaviour: when consumer emails are off, hide the address ++ // logo cards. Their values stay in form state so toggling back doesn't+ // require re-entering anything.+ const sendConsumerEmails = form.watch('preferred_send_consumer_transactional_emails')++ return (+ <form onSubmit={form.handleSubmit(onSubmit)}>+ <ResourceLayout+ header={+ <PageHeader+ title={t('admin.pages.settings.emails.title')}+ subtitle={t('admin.pages.settings.emails.subtitle')}+ actions={<FormActions form={form} />}+ />+ }+ main={+ <>+ {errors.root?.message && (+ <p className="text-sm text-destructive" role="alert">+ {errors.root.message}+ </p>+ )}++ <Card>+ <CardHeader>+ <CardTitle>{t('admin.pages.settings.emails.section_delivery')}</CardTitle>+ </CardHeader>+ <CardContent>+ <Field>+ <div className="flex items-start justify-between gap-4">+ <div className="flex flex-col">+ <FieldLabel htmlFor="store-send-consumer-emails" className="cursor-pointer">+ {t('admin.fields.store.preferred_send_consumer_transactional_emails.label')}+ </FieldLabel>+ <FieldDescription>+ {t('admin.fields.store.preferred_send_consumer_transactional_emails.help')}+ </FieldDescription>+ </div>+ <Controller+ name="preferred_send_consumer_transactional_emails"+ control={form.control}+ render={({ field }) => (+ <Switch+ id="store-send-consumer-emails"+ checked={field.value}+ onCheckedChange={field.onChange}+ />+ )}+ />+ </div>+ </Field>+ </CardContent>+ </Card>++ {sendConsumerEmails && (+ <>+ <Card>+ <CardHeader>+ <CardTitle>{t('admin.pages.settings.emails.section_addresses')}</CardTitle>+ </CardHeader>+ <CardContent>+ <FieldGroup>+ <Field>+ <FieldLabel htmlFor="store-mail-from-address">+ {t('admin.fields.store.mail_from_address.label')}+ </FieldLabel>+ <Input+ id="store-mail-from-address"+ type="email"+ placeholder={t('admin.fields.store.mail_from_address.placeholder')}+ aria-invalid={!!errors.mail_from_address || undefined}+ {...form.register('mail_from_address')}+ />+ <FieldDescription>+ {t('admin.fields.store.mail_from_address.help')}+ </FieldDescription>+ <FieldError errors={[errors.mail_from_address]} />+ </Field>++ <Field>+ <FieldLabel htmlFor="store-customer-support-email">+ {t('admin.fields.store.customer_support_email.label')}+ </FieldLabel>+ <Input+ id="store-customer-support-email"+ type="email"+ placeholder={t('admin.fields.store.customer_support_email.placeholder')}+ aria-invalid={!!errors.customer_support_email || undefined}+ {...form.register('customer_support_email')}+ />+ <FieldDescription>+ {t('admin.fields.store.customer_support_email.help')}+ </FieldDescription>+ <FieldError errors={[errors.customer_support_email]} />+ </Field>++ <Field>+ <FieldLabel htmlFor="store-new-order-notifications-email">+ {t('admin.fields.store.new_order_notifications_email.label')}+ </FieldLabel>+ <Input+ id="store-new-order-notifications-email"+ type="email"+ placeholder={t(+ 'admin.fields.store.new_order_notifications_email.placeholder',+ )}+ aria-invalid={!!errors.new_order_notifications_email || undefined}+ {...form.register('new_order_notifications_email')}+ />+ <FieldDescription>+ {t('admin.fields.store.new_order_notifications_email.help')}+ </FieldDescription>+ <FieldError errors={[errors.new_order_notifications_email]} />+ </Field>+ </FieldGroup>+ </CardContent>+ </Card>++ <Card>+ <CardHeader>+ <CardTitle>{t('admin.pages.settings.emails.section_logo')}</CardTitle>+ </CardHeader>+ <CardContent>+ <LogoField form={form} initialLogoUrl={store.mailer_logo_url} />+ </CardContent>+ </Card>+ </>+ )}+ </>+ }+ />+ </form>+ )+}++function LogoField({+ form,+ initialLogoUrl,+}: {+ form: ReturnType<typeof useForm<StoreEmailsFormValues>>+ initialLogoUrl: string | null+}) {+ const { t } = useTranslation()+ const directUpload = useDirectUpload()+ const fileInputRef = useRef<HTMLInputElement | null>(null)+ const [uploading, setUploading] = useState(false)++ const previewUrl = form.watch('mailer_logo_preview_url')+ const cleared = form.watch('mailer_logo_cleared')+ const currentPreview = previewUrl ?? (cleared ? null : initialLogoUrl)++ // Track the latest blob URL via ref so the unmount cleanup sees the current+ // value without forcing the effect to re-subscribe on every replace.+ const previewUrlRef = useRef<string | null>(null)+ previewUrlRef.current = previewUrl ?? null+ useEffect(() => {+ return () => {+ if (previewUrlRef.current) URL.revokeObjectURL(previewUrlRef.current)+ }+ }, [])++ async function onFileChange(e: React.ChangeEvent<HTMLInputElement>) {+ const file = e.target.files?.[0]+ if (!file) return+ setUploading(true)+ try {+ const result = await directUpload.mutateAsync(file)+ if (previewUrl) URL.revokeObjectURL(previewUrl)+ form.setValue('mailer_logo_preview_url', result.previewUrl, { shouldDirty: true })+ form.setValue('mailer_logo_signed_id', result.signedId, { shouldDirty: true })+ form.setValue('mailer_logo_cleared', false, { shouldDirty: true })+ } catch (err) {+ toast.error(+ err instanceof Error ? err.message : t('admin.pages.settings.emails.logo_upload_failed'),+ )+ } finally {+ setUploading(false)+ if (fileInputRef.current) fileInputRef.current.value = ''+ }+ }++ function clear() {+ if (previewUrl) {+ URL.revokeObjectURL(previewUrl)+ form.setValue('mailer_logo_preview_url', null, { shouldDirty: true })+ }+ form.setValue('mailer_logo_signed_id', null, { shouldDirty: true })+ form.setValue('mailer_logo_cleared', true, { shouldDirty: true })+ }++ return (+ <Field>+ <FieldLabel>{t('admin.fields.store.mailer_logo.label')}</FieldLabel>+ <div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:gap-6">+ <div+ className={cn(+ 'flex h-26 w-52 shrink-0 items-center justify-center overflow-hidden rounded-md border border-dashed border-border bg-muted',+ 'transition-colors',+ )}+ >+ {currentPreview ? (+ <img src={currentPreview} alt="" className="size-full object-contain" />+ ) : (+ <div className="flex flex-col items-center gap-2 text-muted-foreground">+ {uploading ? (+ <UploadCloudIcon className="size-6 animate-pulse" />+ ) : (+ <ImageIcon className="size-6" />+ )}+ </div>+ )}+ </div>+ <div className="flex flex-col gap-2">+ <div className="flex flex-wrap items-center gap-2">+ <Button+ type="button"+ variant="outline"+ size="sm"+ onClick={() => fileInputRef.current?.click()}+ disabled={uploading}+ >+ {uploading+ ? t('admin.pages.settings.emails.logo_uploading')+ : currentPreview+ ? t('admin.pages.settings.emails.logo_replace_cta')+ : t('admin.pages.settings.emails.logo_upload_cta')}+ </Button>+ {currentPreview && (+ <Button type="button" variant="ghost" size="sm" onClick={clear} disabled={uploading}>+ {t('admin.pages.settings.emails.logo_remove_cta')}+ </Button>+ )}+ </div>+ <FieldDescription>+ {t('admin.pages.settings.emails.logo_dimensions_help')}{' '}+ {t('admin.fields.store.mailer_logo.help')}+ </FieldDescription>+ </div>+ <input+ ref={fileInputRef}+ type="file"+ accept="image/png,image/jpeg"+ className="hidden"+ onChange={onFileChange}+ />+ </div>+ </Field>+ )+}diff --git a/packages/dashboard/src/schemas/store-emails.ts b/packages/dashboard/src/schemas/store-emails.tsnew file mode 100644index 0000000000..9b976c6936--- /dev/null+++ b/packages/dashboard/src/schemas/store-emails.ts@@ -0,0 +1,26 @@+import { requiredMessage } from '@spree/dashboard-ui'+import { z } from 'zod/v4'++// Optional email fields use `.or(z.literal(''))` so the form can render an+// empty input without tripping the email validator. The mapper to API params+// converts empty strings to `null` so the backend treats them as cleared.+const optionalEmail = z.string().email().or(z.literal('')).optional()++export const storeEmailsFormSchema = z.object({+ mail_from_address: z+ .string()+ .min(1, { error: requiredMessage('store.mail_from_address') })+ .email(),+ customer_support_email: optionalEmail,+ new_order_notifications_email: optionalEmail,+ preferred_send_consumer_transactional_emails: z.boolean(),++ // Active Storage signed_id from a fresh direct upload. Frontend-only state.+ mailer_logo_signed_id: z.string().nullable().optional(),+ // Local blob URL for the just-picked file so the preview updates before save.+ mailer_logo_preview_url: z.string().nullable().optional(),+ // Tracks the user clicking "Remove logo" — collapses to `mailer_logo: null`.+ mailer_logo_cleared: z.boolean().optional(),+})++export type StoreEmailsFormValues = z.infer<typeof storeEmailsFormSchema>diff --git a/spree/api/app/serializers/spree/api/v3/admin/store_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/store_serializer.rbindex 41be6a5452..baffdd9d60 100644--- a/spree/api/app/serializers/spree/api/v3/admin/store_serializer.rb+++ b/spree/api/app/serializers/spree/api/v3/admin/store_serializer.rb@@ -8,6 +8,11 @@ module Spreesupported_currencies: [:string, multi: true],supported_locales: [:string, multi: true],logo_url: [:string, nullable: true],+ mailer_logo_url: [:string, nullable: true],+ mail_from_address: [:string, nullable: true],+ customer_support_email: [:string, nullable: true],+ new_order_notifications_email: [:string, nullable: true],+ preferred_send_consumer_transactional_emails: :boolean,preferred_admin_locale: [:string, nullable: true],preferred_timezone: :string,preferred_weight_unit: :string,@@ -18,6 +23,10 @@ module Spree:name,:default_currency,:default_locale,+ :mail_from_address,+ :customer_support_email,+ :new_order_notifications_email,+ :preferred_send_consumer_transactional_emails,:preferred_admin_locale,:preferred_timezone,:preferred_weight_unit,@@ -35,6 +44,10 @@ module Spreeattribute :logo_url do |store|image_url_for(store.logo)end++ attribute :mailer_logo_url do |store|+ image_url_for(store.mailer_logo)+ endendendenddiff --git a/spree/api/spec/controllers/spree/api/v3/admin/store_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/store_controller_spec.rbindex 1f94cdfd05..3487391410 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/store_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/store_controller_spec.rb@@ -66,6 +66,17 @@ RSpec.describe Spree::Api::V3::Admin::StoreController, type: :controller doexpect(json_response['supported_locales']).to be_an(Array)end+ it 'exposes the email-section attributes' do+ subject+ expect(json_response).to include(+ 'mail_from_address' => store.mail_from_address,+ 'customer_support_email' => store.customer_support_email,+ 'new_order_notifications_email' => store.new_order_notifications_email,+ 'preferred_send_consumer_transactional_emails' => store.preferred_send_consumer_transactional_emails+ )+ expect(json_response).to have_key('mailer_logo_url')+ end+context 'without authentication' dolet(:headers) { {} }@@ -110,6 +121,37 @@ RSpec.describe Spree::Api::V3::Admin::StoreController, type: :controller doendend+ context 'with email-section params' do+ let(:params) do+ {+ mail_from_address: '[email protected]',+ customer_support_email: '[email protected]',+ new_order_notifications_email: '[email protected]',+ preferred_send_consumer_transactional_emails: false+ }+ end++ it 'updates the email preferences and addresses' do+ subject+ expect(response).to have_http_status(:ok)+ store.reload+ expect(store.mail_from_address).to eq('[email protected]')+ expect(store.customer_support_email).to eq('[email protected]')+ expect(store.new_order_notifications_email).to eq('[email protected]')+ expect(store.preferred_send_consumer_transactional_emails).to eq(false)+ end+ end++ context 'with an invalid mail_from_address' do+ let(:params) { { mail_from_address: 'not-an-email' } }++ it 'returns a validation error' do+ subject+ expect(response).to have_http_status(:unprocessable_content)+ expect(json_response['error']['code']).to eq('validation_error')+ end+ end+context 'without authentication' dolet(:headers) { {} }let(:params) { { name: 'Renamed Store' } }