Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Changed the seller files settings to a format picker

Damian Legawiec15eead99cbab
diff --git a/packages/dashboard/e2e/marketplace-settings.spec.ts b/packages/dashboard/e2e/marketplace-settings.spec.ts
index 6829ea5cc6..afeccd8700 100644
--- a/packages/dashboard/e2e/marketplace-settings.spec.ts
+++ b/packages/dashboard/e2e/marketplace-settings.spec.ts
@@ -48,11 +48,39 @@ test.describe('marketplace settings', () => {
const enabled = page.getByRole('switch', { name: /let sellers upload digital files/i })
const types = page.getByLabel(/accepted file types for sellers/i)
const review = page.getByRole('switch', { name: /review file changes on products/i })
- const originalTypes = await types.inputValue()
+ const chips = page.locator('[data-slot="combobox-chips"] [data-slot="combobox-chip"]')
const wasEnabled = (await enabled.getAttribute('aria-checked')) === 'true'
- if (!wasEnabled) await enabled.click()
- await types.fill('application/pdf\naudio/mpeg')
+ // The type list and the review rule only appear once sellers may upload.
+ if (!wasEnabled) {
+ await expect(types).toBeHidden()
+ await expect(review).toBeHidden()
+ await enabled.click()
+ }
+ await expect(types).toBeVisible()
+ const originalTypes = await chips.allInnerTexts()
+
+ const clearTypes = async () => {
+ while ((await chips.count()) > 0) {
+ await chips
+ .first()
+ .getByRole('button', { name: /^remove/i })
+ .click()
+ }
+ }
+ const addTypes = async (values: string[]) => {
+ for (const value of values) {
+ await types.fill(value)
+ await types.press('Enter')
+ await expect(chips.filter({ hasText: value })).toBeVisible()
+ }
+ }
+
+ await clearTypes()
+ // One from the dropdown, by its format name, and one typed in.
+ await types.fill('FLAC')
+ await page.getByRole('option', { name: /FLAC/ }).click()
+ await addTypes(['application/x-custom'])
await review.click()
await page.getByRole('button', { name: /^save$/i }).click()
await expect(page.getByText(/store settings updated/i).first()).toBeVisible({
@@ -61,13 +89,14 @@ test.describe('marketplace settings', () => {
await page.reload()
await expect(enabled).toHaveAttribute('aria-checked', 'true', { timeout: 15_000 })
- await expect(types).toHaveValue('application/pdf\naudio/mpeg')
+ await expect(chips).toHaveText(['audio/flac', 'application/x-custom'])
await expect(review).toHaveAttribute('aria-checked', 'false')
// Put the store back so the seller panel specs read the defaults.
- if (!wasEnabled) await enabled.click()
- await types.fill(originalTypes)
+ await clearTypes()
+ await addTypes(originalTypes)
await review.click()
+ if (!wasEnabled) await enabled.click()
await page.getByRole('button', { name: /^save$/i }).click()
await expect(page.getByRole('button', { name: /^save$/i })).toBeDisabled({ timeout: 15_000 })
})
diff --git a/packages/dashboard/src/components/spree/content-type-combobox.tsx b/packages/dashboard/src/components/spree/content-type-combobox.tsx
new file mode 100644
index 0000000000..24efb5ef66
--- /dev/null
+++ b/packages/dashboard/src/components/spree/content-type-combobox.tsx
@@ -0,0 +1,138 @@
+import {
+ Combobox,
+ ComboboxChip,
+ ComboboxChips,
+ ComboboxChipsInput,
+ ComboboxContent,
+ ComboboxEmpty,
+ ComboboxItem,
+ ComboboxList,
+ ComboboxValue,
+ useComboboxAnchor,
+} from '@spree/dashboard-ui'
+import { useCallback, useMemo, useState } from 'react'
+import { useTranslation } from 'react-i18next'
+import {
+ CONTENT_TYPE_FAMILIES,
+ DIGITAL_FILE_CONTENT_TYPES,
+ isMediaType,
+} from '../../schemas/marketplace'
+
+const KNOWN_FORMATS = new Map(DIGITAL_FILE_CONTENT_TYPES.map((type) => [type.value, type.format]))
+const FAMILY_WILDCARDS = CONTENT_TYPE_FAMILIES.map((family) => `${family}/*`)
+
+/**
+ * Chips picker for a list of content types. The dropdown offers the formats
+ * digital goods usually come in, named by format (`PDF`, `FLAC`) as well as by
+ * type, and a whole family at once (`audio/*`). A type that is not listed is
+ * typed in and added with Enter, as long as it has the `type/subtype` shape.
+ */
+export function ContentTypeCombobox({
+ id,
+ value,
+ onChange,
+ invalid,
+ disabled = false,
+}: {
+ /** Forwarded to the chips input so a `<FieldLabel htmlFor>` can target it. */
+ id?: string
+ value: string[]
+ onChange: (next: string[]) => void
+ invalid?: boolean
+ disabled?: boolean
+}) {
+ const { t } = useTranslation()
+ const anchorRef = useComboboxAnchor()
+ const [inputValue, setInputValue] = useState('')
+
+ const labelFor = useCallback(
+ (type: string): string => {
+ const family = type.endsWith('/*') ? type.slice(0, -2) : null
+ if (family) {
+ return t(`admin.fields.store.seller_digital_asset_content_types.families.${family}`, {
+ defaultValue: type,
+ })
+ }
+ const format = KNOWN_FORMATS.get(type)
+ return format ? `${format} · ${type}` : type
+ },
+ [t],
+ )
+
+ // The known list plus whatever is already selected, so a type added by hand
+ // or through the API keeps its chip. The typed value joins the list once it
+ // is a well-formed type, so it can be picked from the dropdown as well as
+ // added with Enter.
+ const typed = inputValue.trim().toLowerCase()
+ const items = useMemo(() => {
+ const set = new Set([...FAMILY_WILDCARDS, ...KNOWN_FORMATS.keys(), ...value])
+ if (typed && isMediaType(typed)) set.add(typed)
+ return Array.from(set)
+ }, [value, typed])
+
+ const addTyped = () => {
+ if (!typed || !isMediaType(typed)) return
+ if (!value.includes(typed)) onChange([...value, typed])
+ setInputValue('')
+ }
+
+ return (
+ <Combobox
+ multiple
+ items={items}
+ value={value}
+ onValueChange={(next: string[]) => {
+ onChange(next)
+ setInputValue('')
+ }}
+ itemToStringLabel={labelFor}
+ filter={(type: string, query: string) => {
+ const needle = query.trim().toLowerCase()
+ return !needle || type.includes(needle) || labelFor(type).toLowerCase().includes(needle)
+ }}
+ disabled={disabled}
+ >
+ <ComboboxChips ref={anchorRef}>
+ <ComboboxValue>
+ {(selected: string[]) =>
+ selected.map((type) => (
+ <ComboboxChip key={type} className="font-mono text-xs">
+ {type}
+ </ComboboxChip>
+ ))
+ }
+ </ComboboxValue>
+ <ComboboxChipsInput
+ id={id}
+ aria-invalid={invalid || undefined}
+ placeholder={t('admin.fields.store.seller_digital_asset_content_types.placeholder')}
+ value={inputValue}
+ onChange={(event) => setInputValue((event.target as HTMLInputElement).value)}
+ onKeyDown={(event) => {
+ if (event.key !== 'Enter' || !typed) return
+ event.preventDefault()
+ addTyped()
+ }}
+ autoComplete="off"
+ autoCorrect="off"
+ autoCapitalize="off"
+ spellCheck={false}
+ />
+ </ComboboxChips>
+ <ComboboxContent anchor={anchorRef}>
+ <ComboboxEmpty>
+ {t('admin.fields.store.seller_digital_asset_content_types.empty_hint')}
+ </ComboboxEmpty>
+ <ComboboxList>
+ {(type: string) => (
+ <ComboboxItem key={type} value={type}>
+ {KNOWN_FORMATS.has(type) || type.endsWith('/*') || value.includes(type)
+ ? labelFor(type)
+ : t('admin.fields.store.seller_digital_asset_content_types.add_option', { type })}
+ </ComboboxItem>
+ )}
+ </ComboboxList>
+ </ComboboxContent>
+ </Combobox>
+ )
+}
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 5a578b0a22..cc1632adf6 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -2345,9 +2345,17 @@
},
"seller_digital_asset_content_types": {
"label": "أنواع الملفات المقبولة من البائعين",
- "help": "نوع محتوى واحد في كل سطر، مثل application/pdf. يُتحقق منه من توقيع الملف نفسه إن وُجد، لا من اسمه. ملفاتك أنت غير مقيدة.",
- "placeholder": "application/pdf\napplication/zip\naudio/mpeg",
- "invalid": "يجب أن يكون كل سطر نوع محتوى مثل application/pdf."
+ "help": "اختر الصيغ التي يجوز للبائعين رفعها، أو اكتب نوع محتوى مثل application/pdf واضغط Enter. تُقبل أيضًا عائلة كاملة مثل audio/*. يُتحقق منه من توقيع الملف نفسه إن وُجد، لا من اسمه. ملفاتك أنت غير مقيدة.",
+ "placeholder": "ابحث عن صيغة أو اكتب نوع محتوى…",
+ "invalid": "يجب أن يكون كل عنصر نوع محتوى مثل application/pdf.",
+ "empty_hint": "لا توجد صيغة مطابقة. اكتب نوع محتوى مثل application/pdf واضغط Enter لإضافته.",
+ "add_option": "إضافة {{type}}",
+ "families": {
+ "audio": "أي ملف صوتي · audio/*",
+ "video": "أي ملف فيديو · video/*",
+ "image": "أي ملف صورة · image/*",
+ "text": "أي ملف نصي · text/*"
+ }
},
"review_seller_digital_asset_changes": {
"label": "مراجعة تغييرات الملفات في المنتجات المعروضة للبيع",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 8ae84a1ccb..79e0793816 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -2327,9 +2327,17 @@
},
"seller_digital_asset_content_types": {
"label": "Zulässige Dateitypen für Verkäufer",
- "help": "Ein Inhaltstyp pro Zeile, zum Beispiel application/pdf. Geprüft anhand der eigenen Signatur der Datei, wo sie eine hat, nicht anhand ihres Namens. Ihre eigenen Uploads sind nicht eingeschränkt.",
- "placeholder": "application/pdf\napplication/zip\naudio/mpeg",
- "invalid": "Jede Zeile muss ein Inhaltstyp wie application/pdf sein."
+ "help": "Wählen Sie die Formate, die Verkäufer hochladen dürfen, oder geben Sie einen Inhaltstyp wie application/pdf ein und drücken Sie die Eingabetaste. Eine ganze Familie wie audio/* ist ebenfalls zulässig. Geprüft anhand der eigenen Signatur der Datei, wo sie eine hat, nicht anhand ihres Namens. Ihre eigenen Uploads sind nicht eingeschränkt.",
+ "placeholder": "Formate suchen oder Inhaltstyp eingeben…",
+ "invalid": "Jeder Eintrag muss ein Inhaltstyp wie application/pdf sein.",
+ "empty_hint": "Kein passendes Format. Geben Sie einen Inhaltstyp wie application/pdf ein und drücken Sie die Eingabetaste, um ihn hinzuzufügen.",
+ "add_option": "{{type}} hinzufügen",
+ "families": {
+ "audio": "Alle Audiodateien · audio/*",
+ "video": "Alle Videodateien · video/*",
+ "image": "Alle Bilddateien · image/*",
+ "text": "Alle Textdateien · text/*"
+ }
},
"review_seller_digital_asset_changes": {
"label": "Dateiänderungen an bereits verkauften Produkten prüfen",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 67391e9c12..09ccef4e9c 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -2327,9 +2327,17 @@
},
"seller_digital_asset_content_types": {
"label": "Accepted file types for sellers",
- "help": "One content type per line, such as application/pdf. Checked against the file’s own signature where it has one, not its name. Your own uploads are not restricted.",
- "placeholder": "application/pdf\napplication/zip\naudio/mpeg",
- "invalid": "Each line must be a content type such as application/pdf."
+ "help": "Pick the formats sellers may upload, or type a content type such as application/pdf and press Enter. A whole family such as audio/* is also accepted. Checked against the file’s own signature where it has one, not its name. Your own uploads are not restricted.",
+ "placeholder": "Search formats or type a content type…",
+ "invalid": "Each entry must be a content type such as application/pdf.",
+ "empty_hint": "No matching format. Type a content type such as application/pdf and press Enter to add it.",
+ "add_option": "Add {{type}}",
+ "families": {
+ "audio": "Any audio file · audio/*",
+ "video": "Any video file · video/*",
+ "image": "Any image file · image/*",
+ "text": "Any text file · text/*"
+ }
},
"review_seller_digital_asset_changes": {
"label": "Review file changes on products already on sale",
diff --git a/packages/dashboard/src/locales/es.json b/packages/dashboard/src/locales/es.json
index b4d81d0a0c..c63e0a7647 100644
--- a/packages/dashboard/src/locales/es.json
+++ b/packages/dashboard/src/locales/es.json
@@ -2269,9 +2269,17 @@
},
"seller_digital_asset_content_types": {
"label": "Tipos de archivo aceptados para vendedores",
- "help": "Un tipo de contenido por línea, por ejemplo application/pdf. Se comprueba con la firma propia del archivo cuando la tiene, no con su nombre. Sus propias subidas no están restringidas.",
- "placeholder": "application/pdf\napplication/zip\naudio/mpeg",
- "invalid": "Cada línea debe ser un tipo de contenido como application/pdf."
+ "help": "Elija los formatos que los vendedores pueden subir, o escriba un tipo de contenido como application/pdf y pulse Intro. También se acepta una familia completa como audio/*. Se comprueba con la firma propia del archivo cuando la tiene, no con su nombre. Sus propias subidas no están restringidas.",
+ "placeholder": "Buscar formatos o escribir un tipo de contenido…",
+ "invalid": "Cada entrada debe ser un tipo de contenido como application/pdf.",
+ "empty_hint": "Ningún formato coincide. Escriba un tipo de contenido como application/pdf y pulse Intro para añadirlo.",
+ "add_option": "Añadir {{type}}",
+ "families": {
+ "audio": "Cualquier archivo de audio · audio/*",
+ "video": "Cualquier archivo de vídeo · video/*",
+ "image": "Cualquier archivo de imagen · image/*",
+ "text": "Cualquier archivo de texto · text/*"
+ }
},
"review_seller_digital_asset_changes": {
"label": "Revisar cambios de archivos en productos ya en venta",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 3c74f6297f..3fe167aaf7 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -2327,9 +2327,17 @@
},
"seller_digital_asset_content_types": {
"label": "Types de fichiers acceptés pour les vendeurs",
- "help": "Un type de contenu par ligne, par exemple application/pdf. Vérifié d’après la signature propre du fichier quand il en a une, pas son nom. Vos propres téléversements ne sont pas restreints.",
- "placeholder": "application/pdf\napplication/zip\naudio/mpeg",
- "invalid": "Chaque ligne doit être un type de contenu tel que application/pdf."
+ "help": "Choisissez les formats que les vendeurs peuvent téléverser, ou saisissez un type de contenu tel que application/pdf et appuyez sur Entrée. Une famille entière comme audio/* est aussi acceptée. Vérifié d’après la signature propre du fichier quand il en a une, pas son nom. Vos propres téléversements ne sont pas restreints.",
+ "placeholder": "Rechercher un format ou saisir un type de contenu…",
+ "invalid": "Chaque entrée doit être un type de contenu tel que application/pdf.",
+ "empty_hint": "Aucun format correspondant. Saisissez un type de contenu tel que application/pdf et appuyez sur Entrée pour l’ajouter.",
+ "add_option": "Ajouter {{type}}",
+ "families": {
+ "audio": "Tout fichier audio · audio/*",
+ "video": "Tout fichier vidéo · video/*",
+ "image": "Tout fichier image · image/*",
+ "text": "Tout fichier texte · text/*"
+ }
},
"review_seller_digital_asset_changes": {
"label": "Réexaminer les changements de fichiers sur les produits déjà en vente",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 1a5ed093f6..b9158cfc4c 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -2345,9 +2345,17 @@
},
"seller_digital_asset_content_types": {
"label": "Akceptowane typy plików dla sprzedawców",
- "help": "Jeden typ zawartości w wierszu, na przykład application/pdf. Sprawdzany na podstawie własnej sygnatury pliku, gdy ją ma, a nie jego nazwy. Twoje własne pliki nie podlegają ograniczeniom.",
- "placeholder": "application/pdf\napplication/zip\naudio/mpeg",
- "invalid": "Każdy wiersz musi być typem zawartości, na przykład application/pdf."
+ "help": "Wybierz formaty, które sprzedawcy mogą przesyłać, albo wpisz typ zawartości, na przykład application/pdf, i naciśnij Enter. Można też podać całą rodzinę, na przykład audio/*. Sprawdzane na podstawie własnej sygnatury pliku, gdy ją ma, a nie jego nazwy. Twoje własne pliki nie podlegają ograniczeniom.",
+ "placeholder": "Szukaj formatu lub wpisz typ zawartości…",
+ "invalid": "Każda pozycja musi być typem zawartości, na przykład application/pdf.",
+ "empty_hint": "Brak pasującego formatu. Wpisz typ zawartości, na przykład application/pdf, i naciśnij Enter, aby go dodać.",
+ "add_option": "Dodaj {{type}}",
+ "families": {
+ "audio": "Dowolny plik audio · audio/*",
+ "video": "Dowolny plik wideo · video/*",
+ "image": "Dowolny plik graficzny · image/*",
+ "text": "Dowolny plik tekstowy · text/*"
+ }
},
"review_seller_digital_asset_changes": {
"label": "Weryfikuj zmiany plików w produktach już w sprzedaży",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 3d3dd2da11..9fe92114e4 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -2322,9 +2322,17 @@
},
"seller_digital_asset_content_types": {
"label": "卖家可上传的文件类型",
- "help": "每行一个内容类型,例如 application/pdf。按文件自身的签名(如有)判断,而非文件名。您自己的上传不受限制。",
- "placeholder": "application/pdf\napplication/zip\naudio/mpeg",
- "invalid": "每行必须是一个内容类型,例如 application/pdf。"
+ "help": "选择卖家可以上传的格式,或输入内容类型(例如 application/pdf)后按 Enter。也可以填写整个类别,例如 audio/*。按文件自身的签名(如有)判断,而非文件名。您自己的上传不受限制。",
+ "placeholder": "搜索格式或输入内容类型…",
+ "invalid": "每一项必须是一个内容类型,例如 application/pdf。",
+ "empty_hint": "没有匹配的格式。输入内容类型(例如 application/pdf)后按 Enter 添加。",
+ "add_option": "添加 {{type}}",
+ "families": {
+ "audio": "任何音频文件 · audio/*",
+ "video": "任何视频文件 · video/*",
+ "image": "任何图片文件 · image/*",
+ "text": "任何文本文件 · text/*"
+ }
},
"review_seller_digital_asset_changes": {
"label": "审核在售商品的文件变更",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/marketplace.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/marketplace.tsx
index 6fa034bc43..39df268207 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/marketplace.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/marketplace.tsx
@@ -36,7 +36,6 @@ import {
SelectValue,
Skeleton,
Switch,
- Textarea,
toastManager,
useFormSubmitShortcut,
} from '@spree/dashboard-ui'
@@ -52,13 +51,13 @@ import {
useForm,
} from 'react-hook-form'
import { useTranslation } from 'react-i18next'
+import { ContentTypeCombobox } from '../../../../components/spree/content-type-combobox'
import {
usePayoutProviders,
useStoreSettings,
useUpdateStoreSettings,
} from '../../../../hooks/use-store-settings'
import {
- contentTypesFromLines,
type MarketplaceSettingsFormValues,
marketplaceSettingsFormSchema,
} from '../../../../schemas/marketplace'
@@ -105,9 +104,7 @@ function MarketplaceSettingsPage({ store }: { store: Store }) {
auto_approve_sellers: store.auto_approve_sellers ?? false,
auto_approve_seller_products: store.auto_approve_seller_products ?? false,
seller_digital_assets_enabled: store.seller_digital_assets_enabled ?? false,
- seller_digital_asset_content_types: (store.seller_digital_asset_content_types ?? []).join(
- '\n',
- ),
+ seller_digital_asset_content_types: store.seller_digital_asset_content_types ?? [],
review_seller_digital_asset_changes: store.review_seller_digital_asset_changes ?? true,
send_seller_transactional_emails: store.send_seller_transactional_emails ?? true,
commission_tax_rate_percentage:
@@ -165,9 +162,7 @@ function MarketplaceSettingsPage({ store }: { store: Store }) {
auto_approve_sellers: values.auto_approve_sellers,
auto_approve_seller_products: values.auto_approve_seller_products,
seller_digital_assets_enabled: values.seller_digital_assets_enabled,
- seller_digital_asset_content_types: contentTypesFromLines(
- values.seller_digital_asset_content_types,
- ),
+ seller_digital_asset_content_types: values.seller_digital_asset_content_types,
review_seller_digital_asset_changes: values.review_seller_digital_asset_changes,
send_seller_transactional_emails: values.send_seller_transactional_emails,
default_commission_tax_rate: percentToFraction(values.commission_tax_rate_percentage),
@@ -188,6 +183,9 @@ function MarketplaceSettingsPage({ store }: { store: Store }) {
const selectedProvider = payoutProviders?.data?.find(
(provider) => provider.id === form.watch('payout_provider'),
)
+ // The type list and the review rule only mean something once sellers may
+ // upload at all; shown before that they read as settings with no effect.
+ const sellerFilesEnabled = form.watch('seller_digital_assets_enabled')
return (
<FormProvider {...form}>
@@ -374,32 +372,38 @@ function MarketplaceSettingsPage({ store }: { store: Store }) {
name="seller_digital_assets_enabled"
control={form.control}
/>
- <Field>
- <FieldLabel htmlFor="marketplace-seller-content-types">
- {t('admin.fields.store.seller_digital_asset_content_types.label')}
- </FieldLabel>
- <Textarea
- id="marketplace-seller-content-types"
- rows={6}
- className="font-mono text-xs"
- placeholder={t(
- 'admin.fields.store.seller_digital_asset_content_types.placeholder',
- )}
- aria-invalid={!!errors.seller_digital_asset_content_types}
- {...form.register('seller_digital_asset_content_types')}
- />
- <FieldDescription>
- {t('admin.fields.store.seller_digital_asset_content_types.help')}
- </FieldDescription>
- <FieldError errors={[errors.seller_digital_asset_content_types]} />
- </Field>
- <SwitchField
- id="marketplace-review-seller-file-changes"
- label={t('admin.fields.store.review_seller_digital_asset_changes.label')}
- help={t('admin.fields.store.review_seller_digital_asset_changes.help')}
- name="review_seller_digital_asset_changes"
- control={form.control}
- />
+ {sellerFilesEnabled && (
+ <>
+ <Controller
+ control={form.control}
+ name="seller_digital_asset_content_types"
+ render={({ field, fieldState }) => (
+ <Field>
+ <FieldLabel htmlFor="marketplace-seller-content-types">
+ {t('admin.fields.store.seller_digital_asset_content_types.label')}
+ </FieldLabel>
+ <ContentTypeCombobox
+ id="marketplace-seller-content-types"
+ value={field.value}
+ onChange={field.onChange}
+ invalid={fieldState.invalid}
+ />
+ <FieldDescription>
+ {t('admin.fields.store.seller_digital_asset_content_types.help')}
+ </FieldDescription>
+ <FieldError errors={[fieldState.error]} />
+ </Field>
+ )}
+ />
+ <SwitchField
+ id="marketplace-review-seller-file-changes"
+ label={t('admin.fields.store.review_seller_digital_asset_changes.label')}
+ help={t('admin.fields.store.review_seller_digital_asset_changes.help')}
+ name="review_seller_digital_asset_changes"
+ control={form.control}
+ />
+ </>
+ )}
</FieldGroup>
</CardContent>
</Card>
diff --git a/packages/dashboard/src/schemas/marketplace.ts b/packages/dashboard/src/schemas/marketplace.ts
index 5ed18f5a51..be87921787 100644
--- a/packages/dashboard/src/schemas/marketplace.ts
+++ b/packages/dashboard/src/schemas/marketplace.ts
@@ -17,11 +17,11 @@ export const marketplaceSettingsFormSchema = z.object({
auto_approve_sellers: z.boolean(),
auto_approve_seller_products: z.boolean(),
seller_digital_assets_enabled: z.boolean(),
- // One content type per line in the form; sent as a list. Each line must
- // be a type/subtype, or a typo would refuse every seller upload.
+ // Each entry must be a type/subtype, or a typo would refuse every seller
+ // upload.
seller_digital_asset_content_types: z
- .string()
- .refine((value) => contentTypesFromLines(value).every((type) => MEDIA_TYPE.test(type)), {
+ .array(z.string())
+ .refine((types) => types.every((type) => isMediaType(type)), {
message: i18n.t('admin.fields.store.seller_digital_asset_content_types.invalid'),
}),
review_seller_digital_asset_changes: z.boolean(),
@@ -38,10 +38,68 @@ export type MarketplaceSettingsFormValues = z.infer<typeof marketplaceSettingsFo
const MEDIA_TYPE = /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+*-]*$/i
-/** The textarea's lines as the list the API stores, blank lines dropped. */
-export function contentTypesFromLines(value: string): string[] {
- return value
- .split(/[\n,]/)
- .map((line) => line.trim().toLowerCase())
- .filter(Boolean)
+/** Whether a typed value has the `type/subtype` shape the store accepts. */
+export function isMediaType(value: string): boolean {
+ return MEDIA_TYPE.test(value)
}
+
+export const CONTENT_TYPE_FAMILIES = ['audio', 'video', 'image', 'text'] as const
+export type ContentTypeFamily = (typeof CONTENT_TYPE_FAMILIES)[number]
+
+/**
+ * The formats digital goods usually come in, offered in the picker so an
+ * operator does not have to know the content type of a FLAC file. The format
+ * name is the label; it is the same in every language, like a currency code.
+ * Anything not listed can still be typed in.
+ */
+export const DIGITAL_FILE_CONTENT_TYPES: ReadonlyArray<{ value: string; format: string }> = [
+ { value: 'application/pdf', format: 'PDF' },
+ { value: 'application/epub+zip', format: 'EPUB' },
+ { value: 'application/zip', format: 'ZIP' },
+ { value: 'application/x-7z-compressed', format: '7Z' },
+ { value: 'application/gzip', format: 'GZIP' },
+ { value: 'application/x-tar', format: 'TAR' },
+ { value: 'application/vnd.rar', format: 'RAR' },
+ { value: 'application/json', format: 'JSON' },
+ { value: 'application/xml', format: 'XML' },
+ { value: 'text/plain', format: 'TXT' },
+ { value: 'text/csv', format: 'CSV' },
+ { value: 'text/markdown', format: 'Markdown' },
+ { value: 'application/msword', format: 'DOC' },
+ {
+ value: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+ format: 'DOCX',
+ },
+ { value: 'application/vnd.ms-excel', format: 'XLS' },
+ { value: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', format: 'XLSX' },
+ { value: 'application/vnd.ms-powerpoint', format: 'PPT' },
+ {
+ value: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
+ format: 'PPTX',
+ },
+ { value: 'audio/mpeg', format: 'MP3' },
+ { value: 'audio/mp4', format: 'M4A' },
+ { value: 'audio/aac', format: 'AAC' },
+ { value: 'audio/flac', format: 'FLAC' },
+ { value: 'audio/ogg', format: 'OGG' },
+ { value: 'audio/wav', format: 'WAV' },
+ { value: 'audio/x-wav', format: 'WAV' },
+ { value: 'audio/aiff', format: 'AIFF' },
+ { value: 'audio/midi', format: 'MIDI' },
+ { value: 'video/mp4', format: 'MP4' },
+ { value: 'video/webm', format: 'WebM' },
+ { value: 'video/quicktime', format: 'MOV' },
+ { value: 'video/x-matroska', format: 'MKV' },
+ { value: 'image/jpeg', format: 'JPEG' },
+ { value: 'image/png', format: 'PNG' },
+ { value: 'image/gif', format: 'GIF' },
+ { value: 'image/webp', format: 'WebP' },
+ { value: 'image/tiff', format: 'TIFF' },
+ { value: 'image/svg+xml', format: 'SVG' },
+ { value: 'image/vnd.adobe.photoshop', format: 'PSD' },
+ { value: 'font/ttf', format: 'TTF' },
+ { value: 'font/otf', format: 'OTF' },
+ { value: 'font/woff', format: 'WOFF' },
+ { value: 'font/woff2', format: 'WOFF2' },
+ { value: 'application/octet-stream', format: 'BIN' },
+]