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.

Give the operator the review buttons the card promised

Damian Legawiecca085ec19189
diff --git a/packages/admin-sdk/src/admin-client.ts b/packages/admin-sdk/src/admin-client.ts
index 1a41701be6..7e098a1d5c 100644
--- a/packages/admin-sdk/src/admin-client.ts
+++ b/packages/admin-sdk/src/admin-client.ts
@@ -768,6 +768,25 @@ export class AdminClient {
clone: (id: string, options?: RequestOptions): Promise<Product> =>
this.request<Product>('POST', `/products/${id}/clone`, options),
+ /**
+ * Accept a product a seller submitted, putting it on sale. Refuses
+ * anything not awaiting review — reaching `active` from elsewhere is an
+ * ordinary status write.
+ */
+ approve: (id: string, options?: RequestOptions): Promise<Product> =>
+ this.request<Product>('PATCH', `/products/${id}/approve`, options),
+
+ /**
+ * Turn a submission down. The reason is shown to the seller, so they know
+ * what to change before submitting again.
+ */
+ reject: (
+ id: string,
+ params?: { reason?: string },
+ options?: RequestOptions,
+ ): Promise<Product> =>
+ this.request<Product>('PATCH', `/products/${id}/reject`, { ...options, body: params }),
+
/**
* Bulk-set `status` on a list of products. The server validates `status`
* against the product status enum and reindexes affected products.
diff --git a/packages/dashboard-core/src/products/product-form-cards.tsx b/packages/dashboard-core/src/products/product-form-cards.tsx
index 6e46262fe9..dd6b62d02d 100644
--- a/packages/dashboard-core/src/products/product-form-cards.tsx
+++ b/packages/dashboard-core/src/products/product-form-cards.tsx
@@ -844,19 +844,33 @@ export function SEOCard({ form, product }: FormCardProps & { product?: Product }
const ASSIGNABLE_STATUSES = ['draft', 'active', 'archived']
-export function StatusCard({ form }: FormCardProps) {
+export function StatusCard({
+ form,
+ reviewActions,
+}: FormCardProps & {
+ /**
+ * Approve / Reject, supplied by the panel that can run them. Rendered only
+ * while the product is actually in review, so an ordinary product's card is
+ * unchanged.
+ */
+ reviewActions?: React.ReactNode
+}) {
const { t } = useTranslation()
const status = useWatch({ control: form.control, name: 'status' })
- // A product awaiting or refused review sits on a status nobody assigns —
- // it got there by a seller submitting or an operator deciding, and it
- // leaves through Approve/Reject. Listing it anyway is what lets the picker
- // render the product's actual state instead of a raw value with no matching
- // option; the card is read-only while it is there, because the moves out of
- // it are the review actions rather than this control
- // (docs/plans/6.0-seller-product-submission.md).
- const underReview = Boolean(status) && !ASSIGNABLE_STATUSES.includes(status as string)
- const values = underReview ? [status as string, ...ASSIGNABLE_STATUSES] : ASSIGNABLE_STATUSES
+ // A product in a review status sits on one nobody assigns — it got there by
+ // a seller submitting or an operator deciding. Listing it anyway is what
+ // lets the picker render the product's actual state instead of a raw value
+ // with no matching option (docs/plans/6.0-seller-product-submission.md).
+ //
+ // Only `proposed` locks the control. That is a decision still to be made,
+ // and it is made with Approve or Reject. `rejected` is a decision already
+ // made, so the operator can move the product on from here like any other —
+ // overriding their own refusal is not a review action, and leaving the
+ // picker disabled there was a dead end with no way out.
+ const inReview = Boolean(status) && !ASSIGNABLE_STATUSES.includes(status as string)
+ const awaitingDecision = status === 'proposed'
+ const values = inReview ? [status as string, ...ASSIGNABLE_STATUSES] : ASSIGNABLE_STATUSES
return (
<SharedStatusCard<ProductFormValues>
@@ -864,8 +878,9 @@ export function StatusCard({ form }: FormCardProps) {
name="status"
title={t('admin.fields.status.label')}
label={t('admin.fields.status.label')}
- disabled={underReview}
- description={underReview ? t('admin.pages.products.status_under_review') : undefined}
+ disabled={awaitingDecision}
+ description={awaitingDecision ? t('admin.pages.products.status_under_review') : undefined}
+ actions={inReview ? reviewActions : undefined}
options={values.map((value) => ({
value,
label: t(`admin.pages.products.status_options.${value}`),
diff --git a/packages/dashboard-ui/src/spree/products/status-card.tsx b/packages/dashboard-ui/src/spree/products/status-card.tsx
index 536e970523..4c22955cba 100644
--- a/packages/dashboard-ui/src/spree/products/status-card.tsx
+++ b/packages/dashboard-ui/src/spree/products/status-card.tsx
@@ -1,3 +1,4 @@
+import type * as React from 'react'
import type { Control, FieldValues, Path } from 'react-hook-form'
import { Controller } from 'react-hook-form'
import { Card, CardContent, CardHeader, CardTitle } from '../../ui/card'
@@ -22,6 +23,7 @@ export function StatusCard<TFieldValues extends FieldValues>({
options,
disabled,
description,
+ actions,
}: {
control: Control<TFieldValues>
name: Path<TFieldValues>
@@ -30,6 +32,12 @@ export function StatusCard<TFieldValues extends FieldValues>({
options: StatusOption[]
disabled?: boolean
description?: string
+ /**
+ * Rendered under the field. The moves out of a status this picker cannot
+ * assign live here — a review decision is a mutation, which the panel owns
+ * rather than the design system.
+ */
+ actions?: React.ReactNode
}) {
return (
<Card>
@@ -64,6 +72,7 @@ export function StatusCard<TFieldValues extends FieldValues>({
/>
{description && <p className="text-muted-foreground text-sm">{description}</p>}
</Field>
+ {actions && <div className="flex flex-wrap gap-2">{actions}</div>}
</CardContent>
</Card>
)
diff --git a/packages/dashboard/src/components/spree/products/product-review-actions.tsx b/packages/dashboard/src/components/spree/products/product-review-actions.tsx
new file mode 100644
index 0000000000..c9f9bd919b
--- /dev/null
+++ b/packages/dashboard/src/components/spree/products/product-review-actions.tsx
@@ -0,0 +1,96 @@
+import { Button, Input, toastManager, useConfirm } from '@spree/dashboard-ui'
+import { useState } from 'react'
+import { useTranslation } from 'react-i18next'
+import { useApproveProduct, useRejectProduct } from '../../../hooks/use-product'
+
+/**
+ * The operator's decision on a product a seller submitted.
+ *
+ * Lives here rather than in the shared card because approving is a mutation
+ * against the Admin API — the framework's status card knows a product is in
+ * review, but not who is allowed to end it.
+ *
+ * Approving is offered only for a product actually awaiting review.
+ * Rejecting is offered for that and for one already rejected, so an operator
+ * can correct the reason they gave.
+ */
+export function ProductReviewActions({ productId, status }: { productId: string; status: string }) {
+ const { t } = useTranslation()
+ const confirm = useConfirm()
+ const approve = useApproveProduct()
+ const reject = useRejectProduct()
+ const [reason, setReason] = useState('')
+ const [rejecting, setRejecting] = useState(false)
+
+ const awaitingReview = status === 'proposed'
+
+ async function handleApprove() {
+ const confirmed = await confirm({
+ title: t('admin.products.review.approve_confirm_title'),
+ message: t('admin.products.review.approve_confirm_message'),
+ confirmLabel: t('admin.products.review.approve'),
+ })
+ if (!confirmed) return
+
+ try {
+ await approve.mutateAsync(productId)
+ toastManager.add({ type: 'success', title: t('admin.products.review.approved') })
+ } catch (err) {
+ toastManager.add({
+ type: 'error',
+ title: err instanceof Error ? err.message : t('admin.errors.generic'),
+ })
+ }
+ }
+
+ async function handleReject() {
+ try {
+ await reject.mutateAsync({ id: productId, reason: reason.trim() || undefined })
+ toastManager.add({ type: 'success', title: t('admin.products.review.rejected') })
+ setRejecting(false)
+ setReason('')
+ } catch (err) {
+ toastManager.add({
+ type: 'error',
+ title: err instanceof Error ? err.message : t('admin.errors.generic'),
+ })
+ }
+ }
+
+ if (rejecting) {
+ return (
+ <div className="flex w-full flex-col gap-2">
+ <Input
+ value={reason}
+ autoFocus
+ placeholder={t('admin.products.review.reason_placeholder')}
+ aria-label={t('admin.products.review.reason_label')}
+ onChange={(event) => setReason(event.target.value)}
+ />
+ <div className="flex gap-2">
+ <Button type="button" size="sm" disabled={reject.isPending} onClick={handleReject}>
+ {t('admin.products.review.send_back')}
+ </Button>
+ <Button type="button" size="sm" variant="outline" onClick={() => setRejecting(false)}>
+ {t('admin.actions.cancel')}
+ </Button>
+ </div>
+ </div>
+ )
+ }
+
+ return (
+ <>
+ {awaitingReview && (
+ <Button type="button" size="sm" disabled={approve.isPending} onClick={handleApprove}>
+ {t('admin.products.review.approve')}
+ </Button>
+ )}
+ <Button type="button" size="sm" variant="outline" onClick={() => setRejecting(true)}>
+ {awaitingReview
+ ? t('admin.products.review.reject')
+ : t('admin.products.review.edit_reason')}
+ </Button>
+ </>
+ )
+}
diff --git a/packages/dashboard/src/hooks/use-product.ts b/packages/dashboard/src/hooks/use-product.ts
index 6cd9946c81..1aa0497761 100644
--- a/packages/dashboard/src/hooks/use-product.ts
+++ b/packages/dashboard/src/hooks/use-product.ts
@@ -60,6 +60,40 @@ export function useUpdateProduct() {
})
}
+/**
+ * Closing a review a seller opened. Both refresh the product itself as well
+ * as the list, since the status they write is what the list shows.
+ */
+export function useApproveProduct() {
+ const queryClient = useQueryClient()
+ const buildKey = useResourceKeyBuilder()
+
+ return useResourceMutation<Product, Error, string>({
+ mutationFn: (id) => adminClient.products.approve(id),
+ invalidate: [['products']],
+ successMessage: false,
+ errorMessage: false,
+ onSuccess: (_data, id) => {
+ queryClient.invalidateQueries({ queryKey: buildKey('products', id) })
+ },
+ })
+}
+
+export function useRejectProduct() {
+ const queryClient = useQueryClient()
+ const buildKey = useResourceKeyBuilder()
+
+ return useResourceMutation<Product, Error, { id: string; reason?: string }>({
+ mutationFn: ({ id, reason }) => adminClient.products.reject(id, { reason }),
+ invalidate: [['products']],
+ successMessage: false,
+ errorMessage: false,
+ onSuccess: (_data, variables) => {
+ queryClient.invalidateQueries({ queryKey: buildKey('products', variables.id) })
+ },
+ })
+}
+
export function useDeleteProduct() {
const queryClient = useQueryClient()
const buildKey = useResourceKeyBuilder()
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 3de64e4ca0..14ce810cd3 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -3713,6 +3713,18 @@
"product_type_adds_options_one": "يضيف هذا النوع {{options}} إلى المنتجات الجديدة.",
"product_type_adds_options_other": "يضيف هذا النوع {{options}} إلى المنتجات الجديدة.",
"product_type_placeholder": "بدون نوع منتج",
+ "review": {
+ "approve": "الموافقة",
+ "approve_confirm_message": "سيُعرض للبيع فور الموافقة عليه.",
+ "approve_confirm_title": "الموافقة على هذا المنتج؟",
+ "approved": "تمت الموافقة على المنتج",
+ "edit_reason": "تعديل السبب",
+ "reason_label": "السبب",
+ "reason_placeholder": "ما الذي ينبغي أن يغيّره البائع؟",
+ "reject": "إعادة للبائع",
+ "rejected": "أُعيد إلى البائع",
+ "send_back": "إعادة للبائع"
+ },
"save_label": "حفظ المنتج",
"seo": {
"meta_description_placeholder": "SEO description",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 9f33c8dc63..b0d638a4f0 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -3692,6 +3692,18 @@
"product_type_adds_options_one": "Dieser Typ fügt neuen Produkten {{options}} hinzu.",
"product_type_adds_options_other": "Dieser Typ fügt neuen Produkten {{options}} hinzu.",
"product_type_placeholder": "Kein Produkttyp",
+ "review": {
+ "approve": "Freigeben",
+ "approve_confirm_message": "Es geht sofort nach der Freigabe in den Verkauf.",
+ "approve_confirm_title": "Dieses Produkt freigeben?",
+ "approved": "Produkt freigegeben",
+ "edit_reason": "Grund bearbeiten",
+ "reason_label": "Grund",
+ "reason_placeholder": "Was soll der Verkäufer ändern?",
+ "reject": "Zurücksenden",
+ "rejected": "An den Verkäufer zurückgesendet",
+ "send_back": "Zurücksenden"
+ },
"save_label": "Produkt speichern",
"seo": {
"meta_description_placeholder": "SEO-Beschreibung",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 8df3a98128..2817257e1b 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -3692,6 +3692,18 @@
"product_type_adds_options_one": "This type adds {{options}} to new products.",
"product_type_adds_options_other": "This type adds {{options}} to new products.",
"product_type_placeholder": "No product type",
+ "review": {
+ "approve": "Approve",
+ "approve_confirm_message": "It goes on sale as soon as you approve it.",
+ "approve_confirm_title": "Approve this product?",
+ "approved": "Product approved",
+ "edit_reason": "Edit reason",
+ "reason_label": "Reason",
+ "reason_placeholder": "What should the seller change?",
+ "reject": "Send back",
+ "rejected": "Sent back to the seller",
+ "send_back": "Send back"
+ },
"save_label": "Save product",
"seo": {
"meta_description_placeholder": "SEO description",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 8fe2721d51..10d56a384e 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -3692,6 +3692,18 @@
"product_type_adds_options_one": "Ce type ajoute {{options}} aux nouveaux produits.",
"product_type_adds_options_other": "Ce type ajoute {{options}} aux nouveaux produits.",
"product_type_placeholder": "Aucun type de produit",
+ "review": {
+ "approve": "Approuver",
+ "approve_confirm_message": "Il sera mis en vente dès son approbation.",
+ "approve_confirm_title": "Approuver ce produit ?",
+ "approved": "Produit approuvé",
+ "edit_reason": "Modifier le motif",
+ "reason_label": "Motif",
+ "reason_placeholder": "Que doit changer le vendeur ?",
+ "reject": "Renvoyer",
+ "rejected": "Renvoyé au vendeur",
+ "send_back": "Renvoyer"
+ },
"save_label": "Enregistrer le produit",
"seo": {
"meta_description_placeholder": "Description SEO",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index e8357c2272..dca93a450c 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -3752,6 +3752,18 @@
"product_type_adds_options_one": "Ten typ dodaje {{options}} do nowych produktów.",
"product_type_adds_options_other": "Ten typ dodaje {{options}} do nowych produktów.",
"product_type_placeholder": "Brak typu produktu",
+ "review": {
+ "approve": "Zatwierdź",
+ "approve_confirm_message": "Trafi do sprzedaży zaraz po zatwierdzeniu.",
+ "approve_confirm_title": "Zatwierdzić ten produkt?",
+ "approved": "Produkt zatwierdzony",
+ "edit_reason": "Edytuj powód",
+ "reason_label": "Powód",
+ "reason_placeholder": "Co sprzedawca ma zmienić?",
+ "reject": "Odeślij",
+ "rejected": "Odesłano do sprzedawcy",
+ "send_back": "Odeślij"
+ },
"save_label": "Zapisz produkt",
"seo": {
"meta_description_placeholder": "Opis SEO",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index fafdfdc3f0..8a349068d2 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -3683,6 +3683,18 @@
"product_type_adds_options_one": "此类型会为新商品添加{{options}}。",
"product_type_adds_options_other": "此类型会为新商品添加{{options}}。",
"product_type_placeholder": "无商品类型",
+ "review": {
+ "approve": "批准",
+ "approve_confirm_message": "批准后将立即上架销售。",
+ "approve_confirm_title": "批准此商品?",
+ "approved": "商品已批准",
+ "edit_reason": "修改原因",
+ "reason_label": "原因",
+ "reason_placeholder": "卖家需要修改什么?",
+ "reject": "退回",
+ "rejected": "已退回给卖家",
+ "send_back": "退回"
+ },
"save_label": "保存产品",
"seo": {
"meta_description_placeholder": "SEO 描述",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx
index 7ee542f4fb..7c9cd382bc 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx
@@ -40,6 +40,7 @@ import { useTranslation } from 'react-i18next'
import { CustomFieldsInlineCard } from '../../../../components/spree/custom-fields/custom-fields-inline'
import { MediaRichTextEditor } from '../../../../components/spree/media-rich-text-editor'
import { ProductCustomFieldsProvider } from '../../../../components/spree/products/product-custom-fields-provider'
+import { ProductReviewActions } from '../../../../components/spree/products/product-review-actions'
import { PublishingCard } from '../../../../components/spree/products/publishing-card'
import { ResourceTranslationsCard } from '../../../../components/spree/translations/resource-translations-card'
import { useDeleteProduct, useProduct, useUpdateProduct } from '../../../../hooks/use-product'
@@ -300,7 +301,12 @@ function ProductForm({ product }: { product: Product }) {
}
sidebar={
<>
- <StatusCard form={form} />
+ <StatusCard
+ form={form}
+ reviewActions={
+ <ProductReviewActions productId={productId} status={product.status} />
+ }
+ />
<PublishingCard form={form} />
<CategorizationCard form={form} />
<TaxCard form={form} />