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
Fixed review findings on the Replace file action
Damian Legawiec3655505130ff
diff --git a/packages/dashboard-core/src/locales/ar.json b/packages/dashboard-core/src/locales/ar.jsonindex 443e528891..12e41757c3 100644--- a/packages/dashboard-core/src/locales/ar.json+++ b/packages/dashboard-core/src/locales/ar.json@@ -2087,7 +2087,9 @@"upload_failed": "فشل رفع {{name}}: {{message}}","uploading": "جارٍ رفع {{name}}…","uploading_short": "جارٍ الرفع…",- "replace": "استبدال الملف"+ "replace": "استبدال الملف",+ "replace_description": "سيُحذف \"{{name}}\" وسيحمّل كل من اشتراه الملف الجديد من روابطه الحالية. يسري فورًا.",+ "replace_title": "استبدال هذا الملف؟"}}}diff --git a/packages/dashboard-core/src/locales/de.json b/packages/dashboard-core/src/locales/de.jsonindex 2144256f75..1fbf871397 100644--- a/packages/dashboard-core/src/locales/de.json+++ b/packages/dashboard-core/src/locales/de.json@@ -2082,7 +2082,9 @@"upload_failed": "Hochladen von {{name}} fehlgeschlagen: {{message}}","uploading": "{{name}} wird hochgeladen…","uploading_short": "Wird hochgeladen…",- "replace": "Datei ersetzen"+ "replace": "Datei ersetzen",+ "replace_description": "„{{name}}“ wird entfernt, und alle Käufer laden über ihre bestehenden Links die neue Datei herunter. Dies gilt sofort.",+ "replace_title": "Diese Datei ersetzen?"}}}diff --git a/packages/dashboard-core/src/locales/en.json b/packages/dashboard-core/src/locales/en.jsonindex 04cb0ba342..f2f76b4a00 100644--- a/packages/dashboard-core/src/locales/en.json+++ b/packages/dashboard-core/src/locales/en.json@@ -2084,7 +2084,9 @@"upload_failed": "Failed to upload {{name}}: {{message}}","uploading": "Uploading {{name}}…","uploading_short": "Uploading…",- "replace": "Replace file"+ "replace": "Replace file",+ "replace_description": "\"{{name}}\" is removed and everyone who bought it downloads the new file from their existing links. This takes effect immediately.",+ "replace_title": "Replace this file?"}}}diff --git a/packages/dashboard-core/src/locales/es.json b/packages/dashboard-core/src/locales/es.jsonindex 59680e657a..9695f5fc4c 100644--- a/packages/dashboard-core/src/locales/es.json+++ b/packages/dashboard-core/src/locales/es.json@@ -2084,7 +2084,9 @@"upload_failed": "No se pudo subir {{name}}: {{message}}","uploading": "Subiendo {{name}}…","uploading_short": "Subiendo…",- "replace": "Reemplazar archivo"+ "replace": "Reemplazar archivo",+ "replace_description": "\"{{name}}\" se elimina y todos los compradores descargan el archivo nuevo desde sus enlaces existentes. Tiene efecto inmediato.",+ "replace_title": "¿Reemplazar este archivo?"}}}diff --git a/packages/dashboard-core/src/locales/fr.json b/packages/dashboard-core/src/locales/fr.jsonindex 080ee1e03e..1b16d7f83c 100644--- a/packages/dashboard-core/src/locales/fr.json+++ b/packages/dashboard-core/src/locales/fr.json@@ -2082,7 +2082,9 @@"upload_failed": "Échec du téléversement de {{name}} : {{message}}","uploading": "Téléversement de {{name}}…","uploading_short": "Téléversement…",- "replace": "Remplacer le fichier"+ "replace": "Remplacer le fichier",+ "replace_description": "« {{name}} » est supprimé et tous les acheteurs téléchargent le nouveau fichier depuis leurs liens existants. Effet immédiat.",+ "replace_title": "Remplacer ce fichier ?"}}}diff --git a/packages/dashboard-core/src/locales/pl.json b/packages/dashboard-core/src/locales/pl.jsonindex cfa1086ff4..fe6719b844 100644--- a/packages/dashboard-core/src/locales/pl.json+++ b/packages/dashboard-core/src/locales/pl.json@@ -2111,7 +2111,9 @@"upload_failed": "Nie udało się przesłać {{name}}: {{message}}","uploading": "Przesyłanie {{name}}…","uploading_short": "Przesyłanie…",- "replace": "Zastąp plik"+ "replace": "Zastąp plik",+ "replace_description": "„{{name}}” zostanie usunięty, a wszyscy kupujący pobiorą nowy plik ze swoich dotychczasowych linków. Obowiązuje natychmiast.",+ "replace_title": "Zastąpić ten plik?"}}}diff --git a/packages/dashboard-core/src/locales/zh-CN.json b/packages/dashboard-core/src/locales/zh-CN.jsonindex abd72c76b0..7856007299 100644--- a/packages/dashboard-core/src/locales/zh-CN.json+++ b/packages/dashboard-core/src/locales/zh-CN.json@@ -2081,7 +2081,9 @@"upload_failed": "上传 {{name}} 失败:{{message}}","uploading": "正在上传 {{name}}…","uploading_short": "上传中…",- "replace": "替换文件"+ "replace": "替换文件",+ "replace_description": "“{{name}}”将被移除,所有买家将通过现有链接下载新文件。立即生效。",+ "replace_title": "替换此文件?"}}}diff --git a/packages/dashboard-core/src/products/digital-assets-card.tsx b/packages/dashboard-core/src/products/digital-assets-card.tsxindex 33a1404d10..fcbbef6ba6 100644--- a/packages/dashboard-core/src/products/digital-assets-card.tsx+++ b/packages/dashboard-core/src/products/digital-assets-card.tsx@@ -90,9 +90,11 @@ export function DigitalAssetsCard({const fileUpload = useFileUpload({ visibility: 'private' })const { data, isLoading } = useDigitalAssets(productId ?? '', page, Boolean(productId))const { data: providersData } = useDigitalAssetProviders(productId ?? '', Boolean(productId))- const createAsset = useCreateDigitalAsset(productId ?? '')+ // The card toasts upload failures itself, naming the file, so the+ // mutations stay quiet about theirs.+ const createAsset = useCreateDigitalAsset(productId ?? '', { errorMessage: false })const deleteAsset = useDeleteDigitalAsset(productId ?? '')- const updateAsset = useUpdateDigitalAsset(productId ?? '')+ const updateAsset = useUpdateDigitalAsset(productId ?? '', { errorMessage: false })const assets: PanelDigitalAsset[] = data?.data ?? []const meta = data?.meta@@ -105,6 +107,25 @@ export function DigitalAssetsCard({// keeps its today behaviour — a single "Add file" button.const sourceProviders = providers.filter((p) => !p.requires_attachment)+ // One path for a new file and a replacement: upload to private storage,+ // hand the signed id on, and name the file when either step fails — a+ // refused upload must never be silent.+ async function uploadThen(file: File, persist: (signedId: string) => Promise<unknown>) {+ try {+ const { signedId, previewUrl } = await fileUpload.mutateAsync(file)+ // The preview is for image cards; a download has nothing to show, and+ // an unreleased object URL pins the whole file in memory.+ URL.revokeObjectURL(previewUrl)+ await persist(signedId)+ } catch (err) {+ const message = err instanceof Error ? err.message : t('admin.errors.unexpected')+ toastManager.add({+ type: 'error',+ title: t('admin.digital_assets.upload_failed', { name: file.name, message }),+ })+ }+ }+async function handleFiles(files: FileList | File[]) {const list = Array.from(files)if (list.length === 0 || !productId) return@@ -112,19 +133,7 @@ export function DigitalAssetsCard({setUploading(true)try {for (const file of list) {- try {- const { signedId } = await fileUpload.mutateAsync(file)- await createAsset.mutateAsync({ signed_id: signedId })- } catch (err) {- // The create mutation suppresses its own toast for validation- // errors, so surface the failure here — otherwise a rejected upload- // is silent.- const message = err instanceof Error ? err.message : t('admin.errors.unexpected')- toastManager.add({- type: 'error',- title: t('admin.digital_assets.upload_failed', { name: file.name, message }),- })- }+ await uploadThen(file, (signedId) => createAsset.mutateAsync({ signed_id: signedId }))}setPage(1)} finally {@@ -141,7 +150,17 @@ export function DigitalAssetsCard({if (files.length > 0) void handleFiles(files)}- function openReplace(asset: PanelDigitalAsset) {+ // Replacing removes the current file for everyone who bought it, so it is+ // confirmed before the picker opens, like deleting.+ async function openReplace(asset: PanelDigitalAsset) {+ const confirmed = await confirm({+ title: t('admin.digital_assets.replace_title'),+ message: t('admin.digital_assets.replace_description', {+ name: asset.filename ?? t('admin.digital_assets.untitled'),+ }),+ variant: 'destructive',+ })+ if (!confirmed) returnreplacingRef.current = assetreplaceInputRef.current?.click()}@@ -157,14 +176,9 @@ export function DigitalAssetsCard({setUploading(true)try {- const { signedId } = await fileUpload.mutateAsync(file)- await updateAsset.mutateAsync({ id: asset.id, signed_id: signedId })- } catch (err) {- const message = err instanceof Error ? err.message : t('admin.errors.unexpected')- toastManager.add({- type: 'error',- title: t('admin.digital_assets.upload_failed', { name: file.name, message }),- })+ await uploadThen(file, (signedId) =>+ updateAsset.mutateAsync({ id: asset.id, signed_id: signedId }),+ )} finally {setUploading(false)}@@ -383,8 +397,10 @@ export function DigitalAssetsCard({key: 'replace',label: t('admin.digital_assets.replace'),icon: <UploadIcon className="size-4" />,- // A provider delivers its own deliverable; there is no file to swap.- visible: canWrite && !asset.provider_type,+ // Only a stored file can be swapped; a provider's+ // own deliverable has none to download.+ visible: canWrite && Boolean(asset.download_url),+ disabled: uploading,onSelect: () => openReplace(asset),},{ key: 'edit', visible: canWrite, onSelect: () => setEditing(asset) },diff --git a/packages/dashboard-core/src/products/use-digital-assets.ts b/packages/dashboard-core/src/products/use-digital-assets.tsindex 84c64348c4..0bc0275b43 100644--- a/packages/dashboard-core/src/products/use-digital-assets.ts+++ b/packages/dashboard-core/src/products/use-digital-assets.ts@@ -33,21 +33,27 @@ export function useDigitalAssetProviders(productId: string, enabled = true) {})}-export function useCreateDigitalAsset(productId: string) {+/**+ * `errorMessage: false` hands every failure to the caller — the card names+ * the file in its own toast, and two toasts for one refusal is noise.+ */+export function useCreateDigitalAsset(productId: string, options: { errorMessage?: false } = {}) {return useResourceMutation({mutationFn: (params: PanelDigitalAssetParams) =>digitalAssetsClient().create(productId, params),invalidate: [digitalAssetsKey(productId)],successMessage: i18n.t('admin.messages.digital_asset_saved'),+ ...options,})}-export function useUpdateDigitalAsset(productId: string) {+export function useUpdateDigitalAsset(productId: string, options: { errorMessage?: false } = {}) {return useResourceMutation({mutationFn: ({ id, ...params }: PanelDigitalAssetParams & { id: string }) =>digitalAssetsClient().update(productId, id, params),invalidate: [digitalAssetsKey(productId)],successMessage: i18n.t('admin.messages.digital_asset_saved'),+ ...options,})}diff --git a/packages/dashboard/e2e/digital-assets.spec.ts b/packages/dashboard/e2e/digital-assets.spec.tsindex 94654c7051..5eef869d0b 100644--- a/packages/dashboard/e2e/digital-assets.spec.ts+++ b/packages/dashboard/e2e/digital-assets.spec.ts@@ -51,9 +51,29 @@ test.describe('product digital files', () => {})await expect(fileRow.getByRole('cell', { name: '7', exact: true })).toBeVisible()+ // Replacing is confirmed first, then picks the file; the row keeps its+ // limits and only the name changes.+ const replacementName = 'manual-v2.txt'+ await openRowMenu(page, fileName)+ await page.getByRole('menuitem', { name: /replace file/i }).click()+ await expect(page.getByRole('heading', { name: /replace this file\?/i })).toBeVisible()+ const replaceChooser = page.waitForEvent('filechooser')+ await page+ .getByRole('dialog')+ .getByRole('button', { name: /^confirm$/i })+ .click()+ await (await replaceChooser).setFiles({+ name: replacementName,+ mimeType: 'text/plain',+ buffer: Buffer.from('second edition'),+ })+ const replacedRow = digitalCard.locator('tr').filter({ hasText: replacementName })+ await expect(replacedRow).toBeVisible({ timeout: 30_000 })+ await expect(replacedRow.getByRole('cell', { name: '5', exact: true })).toBeVisible()+// Remove it — the row-menu delete goes through a destructive confirm whose// action button is the default "Confirm" (the card passes no confirmLabel).- await openRowMenu(page, fileName)+ await openRowMenu(page, replacementName)await page.getByRole('menuitem', { name: /^delete$/i }).click()await expect(page.getByRole('heading', { name: /delete this file\?/i })).toBeVisible()await page@@ -62,7 +82,7 @@ test.describe('product digital files', () => {.click()// The row is gone and the card falls back to its empty dropzone.- await expect(fileRow).toBeHidden({ timeout: 15_000 })+ await expect(replacedRow).toBeHidden({ timeout: 15_000 })await expect(page.getByText(/drag & drop files here/i)).toBeVisible()})})diff --git a/packages/dashboard/e2e/seller-panel-products.spec.ts b/packages/dashboard/e2e/seller-panel-products.spec.tsindex b21e439dd3..d969749576 100644--- a/packages/dashboard/e2e/seller-panel-products.spec.ts+++ b/packages/dashboard/e2e/seller-panel-products.spec.ts@@ -141,9 +141,13 @@ test.describe('seller panel — products', () => {// Replacing keeps the row and its limits; only the file changes.const replacementName = 'clean-tube-amp.nam'- const replaceChooser = page.waitForEvent('filechooser')await openRowMenu(page, fileName)await page.getByRole('menuitem', { name: /replace file/i }).click()+ const replaceChooser = page.waitForEvent('filechooser')+ await page+ .getByRole('dialog')+ .getByRole('button', { name: /^confirm$/i })+ .click()await (await replaceChooser).setFiles({name: replacementName,mimeType: 'application/octet-stream',