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.

Share the cancel and label-upload dialogs between both panels

Damian Legawiecd131b5427da7
diff --git a/packages/dashboard-core/src/index.ts b/packages/dashboard-core/src/index.ts
index d5a773742c..923e666120 100644
--- a/packages/dashboard-core/src/index.ts
+++ b/packages/dashboard-core/src/index.ts
@@ -66,6 +66,7 @@ export * from './hooks/use-resource-mutation'
export * from './hooks/use-stock-locations'
export * from './hooks/use-switch-admin-locale'
export * from './hooks/use-visual-viewport-offset'
+export * from './lib/cancel-order-form'
export * from './lib/create-action-registry'
// ---------------------------------------------------------------------------
// Registries — pluggable extension points (nav, route, slot, table,
@@ -90,6 +91,7 @@ export * from './lib/fulfillment-items'
// `i18n.addResourceBundle`) get it via the named re-export.
export * from './lib/i18n'
export * from './lib/import-types'
+export * from './lib/label-upload-form'
export * from './lib/nav-registry'
export * from './lib/permissions'
export * from './lib/progress'
diff --git a/packages/dashboard-core/src/lib/cancel-order-form.ts b/packages/dashboard-core/src/lib/cancel-order-form.ts
new file mode 100644
index 0000000000..8eb457f875
--- /dev/null
+++ b/packages/dashboard-core/src/lib/cancel-order-form.ts
@@ -0,0 +1,27 @@
+import { z } from 'zod'
+
+/**
+ * Why an order is being cancelled, and what happens to the money and the
+ * customer.
+ *
+ * Both toggles are always present in the form; which of them a surface
+ * actually renders is its own business — the seller branch accepts no refund
+ * argument at all, so it never shows that one.
+ */
+export const cancelOrderFormSchema = z.object({
+ cancel_reason_id: z.string(),
+ cancel_note: z.string(),
+ refund_payments: z.boolean(),
+ notify_customer: z.boolean(),
+})
+
+export type CancelOrderFormValues = z.infer<typeof cancelOrderFormSchema>
+
+export const CANCEL_ORDER_DEFAULTS: CancelOrderFormValues = {
+ cancel_reason_id: '',
+ cancel_note: '',
+ // Off by default, like the API: releasing the gateway's hold is automatic,
+ // but handing back money already taken is the merchant's call.
+ refund_payments: false,
+ notify_customer: false,
+}
diff --git a/packages/dashboard-core/src/lib/label-upload-form.ts b/packages/dashboard-core/src/lib/label-upload-form.ts
new file mode 100644
index 0000000000..c037e868da
--- /dev/null
+++ b/packages/dashboard-core/src/lib/label-upload-form.ts
@@ -0,0 +1,19 @@
+import { z } from 'zod'
+
+/**
+ * What a label bought outside Spree needs recording against a parcel.
+ *
+ * The carrier is free text: a forwarder's own name is as real a carrier as a
+ * registered one, and an empty value asks the server to detect one from the
+ * number.
+ */
+export const labelUploadFormSchema = z.object({
+ tracking_number: z.string().min(1),
+ carrier: z.string(),
+ cost: z.string(),
+})
+
+export type LabelUploadFormValues = z.infer<typeof labelUploadFormSchema>
+
+/** What a carrier label plausibly arrives as — mirrors the server allowlist. */
+export const LABEL_ACCEPT = 'application/pdf,image/png,text/plain'
diff --git a/packages/dashboard-ui/src/index.ts b/packages/dashboard-ui/src/index.ts
index 8e42889adb..73d5e92c86 100644
--- a/packages/dashboard-ui/src/index.ts
+++ b/packages/dashboard-ui/src/index.ts
@@ -46,6 +46,8 @@ export * from './spree/fulfill-items-form'
export * from './spree/fulfillment-edit-dialog'
export * from './spree/fulfillment-item-list'
export * from './spree/fulfillment-panel'
+export * from './spree/label-upload-dialog'
+export * from './spree/order-cancel-dialog'
export * from './spree/post-sale-create-dialogs'
export * from './spree/post-sale-fields'
export * from './spree/return-dialogs'
diff --git a/packages/dashboard-ui/src/spree/label-upload-dialog.tsx b/packages/dashboard-ui/src/spree/label-upload-dialog.tsx
new file mode 100644
index 0000000000..4146f231fd
--- /dev/null
+++ b/packages/dashboard-ui/src/spree/label-upload-dialog.tsx
@@ -0,0 +1,195 @@
+import type { ReactNode } from 'react'
+import { Controller, type UseFormReturn } from 'react-hook-form'
+import { useTranslation } from 'react-i18next'
+import { Button } from '../ui/button'
+import {
+ Combobox,
+ ComboboxButtonTrigger,
+ ComboboxContent,
+ ComboboxEmpty,
+ ComboboxItem,
+ ComboboxList,
+ ComboboxSearch,
+ ComboboxTriggerPlaceholder,
+ ComboboxValue,
+} from '../ui/combobox'
+import {
+ Dialog,
+ DialogBody,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from '../ui/dialog'
+import { Field, FieldError, FieldLabel } from '../ui/field'
+import { Input } from '../ui/input'
+import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from '../ui/input-group'
+
+/** The form shape both panels bind for a label bought elsewhere. */
+export type LabelUploadFields = {
+ tracking_number: string
+ carrier: string
+ cost: string
+}
+
+/**
+ * Records a label the merchant bought elsewhere — postage from a carrier's
+ * own site, a 3PL's PDF — so the parcel still has its file, its tracking
+ * number and what it cost, with no carrier account connected.
+ *
+ * Shared by the operator's order page and the seller's; on the seller branch
+ * it is the only way a label arrives, since buying one runs through the
+ * marketplace's carrier account.
+ *
+ * The file field comes in as a slot: uploading needs an API client, which is
+ * each panel's own.
+ */
+export function LabelUploadDialog({
+ form,
+ open,
+ onOpenChange,
+ fileField,
+ carrierKeys,
+ carrierLabel,
+ currency,
+ onSubmit,
+ pending = false,
+}: {
+ form: UseFormReturn<LabelUploadFields>
+ open: boolean
+ onOpenChange: (open: boolean) => void
+ fileField: ReactNode
+ carrierKeys: string[]
+ carrierLabel: (key: string) => string
+ /** Shown beside the cost, when the caller knows which currency it is in. */
+ currency?: string
+ onSubmit: (values: LabelUploadFields) => void | Promise<void>
+ pending?: boolean
+}) {
+ const { t } = useTranslation()
+ const { errors } = form.formState
+
+ return (
+ <Dialog open={open} onOpenChange={onOpenChange}>
+ <DialogContent>
+ <form
+ onSubmit={(event) => {
+ // The order page renders its cards inside their own forms — without
+ // stopping the bubble the browser submits the outer one.
+ form.handleSubmit(onSubmit)(event)
+ event.stopPropagation()
+ }}
+ >
+ <DialogHeader>
+ <DialogTitle>{t('admin.orders.detail.fulfillments.upload_label_title')}</DialogTitle>
+ <DialogDescription>
+ {t('admin.orders.detail.fulfillments.upload_label_description')}
+ </DialogDescription>
+ </DialogHeader>
+
+ <DialogBody className="flex flex-col gap-4">
+ {errors.root?.message && (
+ <p className="text-destructive text-sm" role="alert">
+ {errors.root.message}
+ </p>
+ )}
+
+ <Field>
+ <FieldLabel>{t('admin.orders.detail.fulfillments.upload_label_file')}</FieldLabel>
+ {fileField}
+ </Field>
+
+ <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
+ <Field>
+ <FieldLabel htmlFor="label-tracking-number">
+ {t('admin.orders.fulfill.tracking_label')}
+ </FieldLabel>
+ <Input
+ id="label-tracking-number"
+ placeholder={t('admin.orders.fulfill.tracking_placeholder')}
+ aria-invalid={!!errors.tracking_number}
+ {...form.register('tracking_number')}
+ />
+ <FieldError errors={[errors.tracking_number]} />
+ </Field>
+
+ <Field>
+ <FieldLabel htmlFor="label-cost">
+ {t('admin.orders.detail.fulfillments.upload_label_cost')}
+ </FieldLabel>
+ <InputGroup>
+ {currency && (
+ <InputGroupAddon>
+ <InputGroupText>{currency}</InputGroupText>
+ </InputGroupAddon>
+ )}
+ <InputGroupInput
+ id="label-cost"
+ type="number"
+ step="0.01"
+ min="0"
+ {...form.register('cost')}
+ />
+ </InputGroup>
+ <FieldError errors={[errors.cost]} />
+ </Field>
+ </div>
+
+ <Field>
+ <FieldLabel htmlFor="label-carrier">
+ {t('admin.orders.detail.fulfillments.carrier_label')}
+ </FieldLabel>
+ <Controller
+ control={form.control}
+ name="carrier"
+ render={({ field }) => (
+ <Combobox
+ items={carrierKeys}
+ value={field.value}
+ onValueChange={(value: string | null) => field.onChange(value ?? '')}
+ itemToStringLabel={carrierLabel}
+ >
+ <ComboboxButtonTrigger id="label-carrier" onBlur={field.onBlur}>
+ {field.value ? (
+ <ComboboxValue />
+ ) : (
+ <ComboboxTriggerPlaceholder>
+ {t('admin.orders.detail.fulfillments.carrier_auto')}
+ </ComboboxTriggerPlaceholder>
+ )}
+ </ComboboxButtonTrigger>
+ <ComboboxContent>
+ <ComboboxSearch
+ placeholder={t('admin.orders.detail.fulfillments.carrier_search')}
+ />
+ <ComboboxEmpty>{t('admin.common.no_results')}</ComboboxEmpty>
+ <ComboboxList>
+ {(value: string) => (
+ <ComboboxItem key={value} value={value}>
+ {carrierLabel(value)}
+ </ComboboxItem>
+ )}
+ </ComboboxList>
+ </ComboboxContent>
+ </Combobox>
+ )}
+ />
+ </Field>
+ </DialogBody>
+
+ <DialogFooter>
+ <Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
+ {t('admin.actions.cancel')}
+ </Button>
+ <Button type="submit" disabled={pending}>
+ {pending
+ ? t('admin.actions.saving')
+ : t('admin.orders.detail.fulfillments.upload_label')}
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+ )
+}
diff --git a/packages/dashboard-ui/src/spree/order-cancel-dialog.tsx b/packages/dashboard-ui/src/spree/order-cancel-dialog.tsx
new file mode 100644
index 0000000000..6fe540a930
--- /dev/null
+++ b/packages/dashboard-ui/src/spree/order-cancel-dialog.tsx
@@ -0,0 +1,149 @@
+import type { ReactNode } from 'react'
+import { Controller, type UseFormReturn } from 'react-hook-form'
+import { useTranslation } from 'react-i18next'
+import { Button } from '../ui/button'
+import { Checkbox } from '../ui/checkbox'
+import {
+ Dialog,
+ DialogBody,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from '../ui/dialog'
+import { Field, FieldLabel } from '../ui/field'
+import { Textarea } from '../ui/textarea'
+
+/** The form shape both panels bind for a cancellation. */
+export type CancelOrderFields = {
+ cancel_reason_id: string
+ cancel_note: string
+ refund_payments: boolean
+ notify_customer: boolean
+}
+
+/**
+ * Cancels an order, asking why first.
+ *
+ * A dialog rather than a bare confirm, because a cancellation carries a
+ * reason the merchant wants recorded — this doubles as the confirmation, so
+ * there is no second dialog in front of it.
+ *
+ * `showRefund` is off by default: releasing an unclaimed authorization happens
+ * either way, but handing back money already taken is not every surface's
+ * decision. On the seller branch the endpoint accepts no refund argument at
+ * all, so showing the switch would offer something that would be refused.
+ */
+export function OrderCancelDialog({
+ form,
+ reasonField,
+ showRefund = false,
+ showNotify = true,
+ onSubmit,
+ onClose,
+ pending = false,
+}: {
+ form: UseFormReturn<CancelOrderFields>
+ /** The reason picker, wired to whichever vocabulary the caller reads. */
+ reasonField?: ReactNode
+ showRefund?: boolean
+ showNotify?: boolean
+ onSubmit: (values: CancelOrderFields) => void | Promise<void>
+ onClose: () => void
+ pending?: boolean
+}) {
+ const { t } = useTranslation()
+ const { errors } = form.formState
+
+ return (
+ <Dialog open onOpenChange={(next) => !next && onClose()}>
+ <DialogContent>
+ <form onSubmit={form.handleSubmit(onSubmit)}>
+ <DialogHeader>
+ <DialogTitle>{t('admin.pages.orders.detail.dialogs.cancel_title')}</DialogTitle>
+ <DialogDescription>{t('admin.orders.detail.cancel.description')}</DialogDescription>
+ </DialogHeader>
+
+ <DialogBody>
+ {errors.root?.message && (
+ <p className="text-destructive text-sm" role="alert">
+ {errors.root.message}
+ </p>
+ )}
+
+ <div className="flex flex-col gap-4">
+ {reasonField}
+
+ <Field>
+ <FieldLabel htmlFor="order-cancel-note">
+ {t('admin.orders.detail.cancel.note_label')}
+ </FieldLabel>
+ <Textarea
+ id="order-cancel-note"
+ rows={3}
+ placeholder={t('admin.orders.detail.cancel.note_placeholder')}
+ {...form.register('cancel_note')}
+ />
+ </Field>
+
+ {showRefund && (
+ <Controller
+ control={form.control}
+ name="refund_payments"
+ render={({ field }) => (
+ <label
+ htmlFor="order-cancel-refund"
+ className="flex cursor-pointer items-start gap-2 text-sm"
+ >
+ <Checkbox
+ id="order-cancel-refund"
+ checked={field.value}
+ onCheckedChange={(checked) => field.onChange(checked === true)}
+ />
+ <span>
+ {t('admin.orders.detail.cancel.refund_payments')}
+ <span className="block text-muted-foreground">
+ {t('admin.orders.detail.cancel.refund_payments_help')}
+ </span>
+ </span>
+ </label>
+ )}
+ />
+ )}
+
+ {showNotify && (
+ <Controller
+ control={form.control}
+ name="notify_customer"
+ render={({ field }) => (
+ <label
+ htmlFor="order-cancel-notify"
+ className="flex cursor-pointer items-center gap-2 text-sm"
+ >
+ <Checkbox
+ id="order-cancel-notify"
+ checked={field.value}
+ onCheckedChange={(checked) => field.onChange(checked === true)}
+ />
+ {t('admin.orders.detail.cancel.notify_customer')}
+ </label>
+ )}
+ />
+ )}
+ </div>
+ </DialogBody>
+
+ <DialogFooter>
+ <Button type="button" variant="outline" onClick={onClose} disabled={pending}>
+ {t('admin.orders.detail.cancel.keep_order')}
+ </Button>
+ <Button type="submit" variant="destructive" disabled={pending}>
+ {t('admin.pages.orders.detail.actions.cancel')}
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+ )
+}
diff --git a/packages/dashboard/src/components/spree/orders/fulfillment-label-upload-dialog.tsx b/packages/dashboard/src/components/spree/orders/fulfillment-label-upload-dialog.tsx
index 58bb65f201..feb258f430 100644
--- a/packages/dashboard/src/components/spree/orders/fulfillment-label-upload-dialog.tsx
+++ b/packages/dashboard/src/components/spree/orders/fulfillment-label-upload-dialog.tsx
@@ -3,58 +3,19 @@ import {
EMPTY_FILE_UPLOAD_VALUE,
FileUploadField,
type FileUploadValue,
+ LABEL_ACCEPT,
+ type LabelUploadFormValues,
+ labelUploadFormSchema,
mapSpreeErrorsToForm,
} from '@spree/dashboard-core'
-import {
- Button,
- Combobox,
- ComboboxButtonTrigger,
- ComboboxContent,
- ComboboxEmpty,
- ComboboxItem,
- ComboboxList,
- ComboboxSearch,
- ComboboxTriggerPlaceholder,
- ComboboxValue,
- Dialog,
- DialogBody,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- Field,
- FieldError,
- FieldLabel,
- Input,
- InputGroup,
- InputGroupAddon,
- InputGroupInput,
- InputGroupText,
-} from '@spree/dashboard-ui'
+import { LabelUploadDialog } from '@spree/dashboard-ui'
import { useState } from 'react'
-import { Controller, useForm } from 'react-hook-form'
+import { useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
-import { z } from 'zod'
import { useFulfillmentActions } from '../../../hooks/use-fulfillments'
import { useTrackingCarriers } from '../../../hooks/use-tracking-carriers'
-/** What a carrier label plausibly arrives as — mirrors the server allowlist. */
-const LABEL_ACCEPT = 'application/pdf,image/png,text/plain'
-
-const uploadSchema = z.object({
- tracking_number: z.string().min(1),
- carrier: z.string(),
- cost: z.string(),
-})
-
-type UploadFormValues = z.infer<typeof uploadSchema>
-
-/**
- * Records a label the merchant bought elsewhere — postage from a carrier site,
- * a 3PL's PDF — so the parcel still has its file, its tracking number and what
- * it cost, with no carrier account connected.
- */
+/** Records a label the operator bought outside Spree. */
export function FulfillmentLabelUploadDialog({
orderId,
fulfillmentId,
@@ -72,28 +33,24 @@ export function FulfillmentLabelUploadDialog({
const { buyLabel } = useFulfillmentActions(orderId)
const { data: carriersData } = useTrackingCarriers(open)
- // The registry's carriers, stored by key and shown by name. Anything it
- // does not know is still typeable — a forwarder's own name is a legal
- // carrier, and an empty value asks the server to detect one.
- const carrierOptions = (carriersData?.data ?? []).map((carrier) => ({
- value: carrier.id,
- label: carrier.name,
- }))
-
+ const carriers = carriersData?.data ?? []
+ const carrierKeys = carriers.map((carrier) => carrier.id)
const carrierLabel = (value: string) =>
- carrierOptions.find((option) => option.value === value)?.label ?? value
+ carriers.find((carrier) => carrier.id === value)?.name ?? value
const [file, setFile] = useState<FileUploadValue>(EMPTY_FILE_UPLOAD_VALUE)
// The signed id does not exist until the upload resolves, so saving during
// one would silently drop the file.
const [uploading, setUploading] = useState(false)
- const form = useForm<UploadFormValues>({
- resolver: zodResolver(uploadSchema),
+ const form = useForm<LabelUploadFormValues>({
+ resolver: zodResolver(labelUploadFormSchema),
defaultValues: { tracking_number: '', carrier: '', cost: '' },
})
- async function onSubmit(values: UploadFormValues) {
+ async function onSubmit(values: LabelUploadFormValues) {
+ // Guarded here as well as on the server: submitting without one would
+ // record a label with no file behind it.
if (!file.signedId) {
form.setError('root', { message: t('admin.orders.detail.fulfillments.upload_label_file') })
return
@@ -115,129 +72,24 @@ export function FulfillmentLabelUploadDialog({
}
return (
- <Dialog open={open} onOpenChange={onOpenChange}>
- <DialogContent>
- <form
- onSubmit={(event) => {
- // The order page renders its cards inside their own forms — without
- // stopping the bubble the browser submits the outer one.
- form.handleSubmit(onSubmit)(event)
- event.stopPropagation()
- }}
- >
- <DialogHeader>
- <DialogTitle>{t('admin.orders.detail.fulfillments.upload_label_title')}</DialogTitle>
- <DialogDescription>
- {t('admin.orders.detail.fulfillments.upload_label_description')}
- </DialogDescription>
- </DialogHeader>
-
- <DialogBody className="flex flex-col gap-4">
- {form.formState.errors.root?.message && (
- <p className="text-sm text-destructive" role="alert">
- {form.formState.errors.root.message}
- </p>
- )}
-
- <Field>
- <FieldLabel>{t('admin.orders.detail.fulfillments.upload_label_file')}</FieldLabel>
- <FileUploadField
- accept={LABEL_ACCEPT}
- value={file}
- onChange={setFile}
- onUploadingChange={setUploading}
- private
- />
- </Field>
-
- <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
- <Field>
- <FieldLabel htmlFor="label-tracking-number">
- {t('admin.orders.fulfill.tracking_label')}
- </FieldLabel>
- <Input
- id="label-tracking-number"
- placeholder={t('admin.orders.fulfill.tracking_placeholder')}
- aria-invalid={!!form.formState.errors.tracking_number}
- {...form.register('tracking_number')}
- />
- <FieldError errors={[form.formState.errors.tracking_number]} />
- </Field>
-
- <Field>
- <FieldLabel htmlFor="label-cost">
- {t('admin.orders.detail.fulfillments.upload_label_cost')}
- </FieldLabel>
- <InputGroup>
- {currency && (
- <InputGroupAddon>
- <InputGroupText>{currency}</InputGroupText>
- </InputGroupAddon>
- )}
- <InputGroupInput
- id="label-cost"
- type="number"
- step="0.01"
- min="0"
- {...form.register('cost')}
- />
- </InputGroup>
- <FieldError errors={[form.formState.errors.cost]} />
- </Field>
- </div>
-
- <Field>
- <FieldLabel htmlFor="label-carrier">
- {t('admin.orders.detail.fulfillments.carrier_label')}
- </FieldLabel>
- <Controller
- control={form.control}
- name="carrier"
- render={({ field }) => (
- <Combobox
- items={carrierOptions.map((option) => option.value)}
- value={field.value}
- onValueChange={(value: string | null) => field.onChange(value ?? '')}
- itemToStringLabel={carrierLabel}
- >
- <ComboboxButtonTrigger id="label-carrier" onBlur={field.onBlur}>
- {field.value ? (
- <ComboboxValue />
- ) : (
- <ComboboxTriggerPlaceholder>
- {t('admin.orders.detail.fulfillments.carrier_auto')}
- </ComboboxTriggerPlaceholder>
- )}
- </ComboboxButtonTrigger>
- <ComboboxContent>
- <ComboboxSearch
- placeholder={t('admin.orders.detail.fulfillments.carrier_search')}
- />
- <ComboboxEmpty>{t('admin.common.no_results')}</ComboboxEmpty>
- <ComboboxList>
- {(value: string) => (
- <ComboboxItem key={value} value={value}>
- {carrierLabel(value)}
- </ComboboxItem>
- )}
- </ComboboxList>
- </ComboboxContent>
- </Combobox>
- )}
- />
- </Field>
- </DialogBody>
-
- <DialogFooter>
- <Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
- {t('admin.actions.cancel')}
- </Button>
- <Button type="submit" disabled={buyLabel.isPending || uploading}>
- {buyLabel.isPending ? t('admin.actions.saving') : t('admin.actions.save')}
- </Button>
- </DialogFooter>
- </form>
- </DialogContent>
- </Dialog>
+ <LabelUploadDialog
+ form={form}
+ open={open}
+ onOpenChange={onOpenChange}
+ fileField={
+ <FileUploadField
+ accept={LABEL_ACCEPT}
+ value={file}
+ onChange={setFile}
+ onUploadingChange={setUploading}
+ private
+ />
+ }
+ carrierKeys={carrierKeys}
+ carrierLabel={carrierLabel}
+ currency={currency}
+ onSubmit={onSubmit}
+ pending={buyLabel.isPending || uploading}
+ />
)
}
diff --git a/packages/dashboard/src/components/spree/orders/order-cancel-dialog.tsx b/packages/dashboard/src/components/spree/orders/order-cancel-dialog.tsx
index 7ed72ae6f6..08373c3f45 100644
--- a/packages/dashboard/src/components/spree/orders/order-cancel-dialog.tsx
+++ b/packages/dashboard/src/components/spree/orders/order-cancel-dialog.tsx
@@ -1,34 +1,21 @@
import { zodResolver } from '@hookform/resolvers/zod'
-import { adminClient, mapSpreeErrorsToForm, useResourceMutation } from '@spree/dashboard-core'
-import {
- Button,
- Checkbox,
- Dialog,
- DialogBody,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- Field,
- FieldLabel,
- Textarea,
-} from '@spree/dashboard-ui'
-import { Controller, useForm } from 'react-hook-form'
-import { useTranslation } from 'react-i18next'
-import { orderQueryKey } from '../../../hooks/use-order'
import {
+ adminClient,
CANCEL_ORDER_DEFAULTS,
type CancelOrderFormValues,
cancelOrderFormSchema,
-} from '../../../schemas/order'
+ mapSpreeErrorsToForm,
+ useResourceMutation,
+} from '@spree/dashboard-core'
+import { OrderCancelDialog as SharedOrderCancelDialog } from '@spree/dashboard-ui'
+import { Controller, useForm } from 'react-hook-form'
+import { useTranslation } from 'react-i18next'
+import { orderQueryKey } from '../../../hooks/use-order'
import { ReasonField } from '../reason-field'
/**
- * Cancels an order, asking why first. The reason comes from the store's own
- * cancellation vocabulary and is stamped on the order along with the note, so
- * this doubles as the confirmation step — there is no separate confirm dialog
- * in front of it.
+ * What the operator records when cancelling an order, and what they choose to
+ * do with money already taken.
*/
export function OrderCancelDialog({ orderId, onClose }: { orderId: string; onClose: () => void }) {
const { t } = useTranslation()
@@ -39,6 +26,7 @@ export function OrderCancelDialog({ orderId, onClose }: { orderId: string; onClo
cancel_reason_id: values.cancel_reason_id || undefined,
cancel_note: values.cancel_note.trim() || undefined,
refund_payments: values.refund_payments,
+ notify_customer: values.notify_customer,
}),
invalidate: [orderQueryKey(orderId)],
successMessage: t('admin.orders.detail.messages.canceled'),
@@ -60,88 +48,29 @@ export function OrderCancelDialog({ orderId, onClose }: { orderId: string; onClo
}
return (
- <Dialog open onOpenChange={(next) => !next && onClose()}>
- <DialogContent>
- <form onSubmit={form.handleSubmit(onSubmit)}>
- <DialogHeader>
- <DialogTitle>{t('admin.pages.orders.detail.dialogs.cancel_title')}</DialogTitle>
- <DialogDescription>{t('admin.orders.detail.cancel.description')}</DialogDescription>
- </DialogHeader>
-
- <DialogBody>
- {form.formState.errors.root?.message && (
- <p className="text-sm text-destructive" role="alert">
- {form.formState.errors.root.message}
- </p>
- )}
-
- <div className="flex flex-col gap-4">
- {/* A merchant who has not curated the vocabulary can still
- cancel, so the empty choice stays available rather than
- forcing a reason. */}
- <Controller
- control={form.control}
- name="cancel_reason_id"
- render={({ field }) => (
- <ReasonField
- kind="order-cancellation-reasons"
- value={field.value}
- onChange={field.onChange}
- label={t('admin.orders.detail.cancel.reason_label')}
- emptyOptionLabel={t('admin.orders.detail.cancel.no_reason')}
- />
- )}
- />
-
- <Field>
- <FieldLabel htmlFor="order-cancel-note">
- {t('admin.orders.detail.cancel.note_label')}
- </FieldLabel>
- <Textarea
- id="order-cancel-note"
- rows={3}
- placeholder={t('admin.orders.detail.cancel.note_placeholder')}
- {...form.register('cancel_note')}
- />
- </Field>
-
- {/* An unclaimed authorization is released either way, so this
- only decides what happens to money actually taken. */}
- <Controller
- control={form.control}
- name="refund_payments"
- render={({ field }) => (
- <label
- htmlFor="order-cancel-refund"
- className="flex cursor-pointer items-start gap-2 text-sm"
- >
- <Checkbox
- id="order-cancel-refund"
- checked={field.value}
- onCheckedChange={(checked) => field.onChange(checked === true)}
- />
- <span>
- {t('admin.orders.detail.cancel.refund_payments')}
- <span className="block text-muted-foreground">
- {t('admin.orders.detail.cancel.refund_payments_help')}
- </span>
- </span>
- </label>
- )}
- />
- </div>
- </DialogBody>
-
- <DialogFooter>
- <Button type="button" variant="outline" onClick={onClose}>
- {t('admin.orders.detail.cancel.keep_order')}
- </Button>
- <Button type="submit" variant="destructive" disabled={cancelMutation.isPending}>
- {t('admin.pages.orders.detail.actions.cancel')}
- </Button>
- </DialogFooter>
- </form>
- </DialogContent>
- </Dialog>
+ <SharedOrderCancelDialog
+ form={form}
+ showRefund
+ reasonField={
+ /* A merchant who has not curated the vocabulary can still cancel, so
+ the empty choice stays available rather than forcing a reason. */
+ <Controller
+ control={form.control}
+ name="cancel_reason_id"
+ render={({ field }) => (
+ <ReasonField
+ kind="order-cancellation-reasons"
+ value={field.value}
+ onChange={field.onChange}
+ label={t('admin.orders.detail.cancel.reason_label')}
+ emptyOptionLabel={t('admin.orders.detail.cancel.no_reason')}
+ />
+ )}
+ />
+ }
+ onSubmit={onSubmit}
+ onClose={onClose}
+ pending={cancelMutation.isPending}
+ />
)
}
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 56ffb659ef..5c0833e79e 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -2661,6 +2661,7 @@
"no_reason": "لم يُذكر سبب",
"note_label": "ملاحظة",
"note_placeholder": "يرى هذه الملاحظة الموظفون فقط",
+ "notify_customer": "إرسال بريد إلكتروني إلى العميل",
"reason_label": "السبب",
"refund_payments": "رد المبلغ إلى العميل",
"refund_payments_help": "تُعاد الأموال التي جرى تحصيلها. أما التفويض غير المُحصَّل فيُحرَّر في كل الأحوال."
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 826ce06c98..f419dfabef 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -2643,6 +2643,7 @@
"no_reason": "Kein Grund angegeben",
"note_label": "Notiz",
"note_placeholder": "Diese Notiz sehen nur Mitarbeiter",
+ "notify_customer": "Kundin oder Kunden per E-Mail benachrichtigen",
"reason_label": "Grund",
"refund_payments": "Kundin oder Kunden erstatten",
"refund_payments_help": "Bereits eingezogenes Geld wird zurückgezahlt. Eine nicht eingelöste Autorisierung wird ohnehin freigegeben."
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 648d743c03..6535c620db 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -2643,6 +2643,7 @@
"no_reason": "No reason given",
"note_label": "Note",
"note_placeholder": "Only staff see this note",
+ "notify_customer": "Email the customer",
"reason_label": "Reason",
"refund_payments": "Refund the customer",
"refund_payments_help": "Money already taken is returned. An unclaimed authorization is released either way."
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 929993a6f8..b8aeff75ff 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -2643,6 +2643,7 @@
"no_reason": "Aucun motif indiqué",
"note_label": "Note",
"note_placeholder": "Cette note n'est visible que par le personnel",
+ "notify_customer": "Envoyer un e-mail au client",
"reason_label": "Motif",
"refund_payments": "Rembourser le client",
"refund_payments_help": "L'argent déjà encaissé est restitué. Une autorisation non utilisée est libérée dans tous les cas."
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 929cf01245..f9c65a8db7 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -2663,6 +2663,7 @@
"no_reason": "Nie podano powodu",
"note_label": "Notatka",
"note_placeholder": "Notatkę widzi tylko personel",
+ "notify_customer": "Wyślij klientowi wiadomość e-mail",
"reason_label": "Powód",
"refund_payments": "Zwróć pieniądze klientowi",
"refund_payments_help": "Pobrane środki zostaną zwrócone. Niewykorzystana autoryzacja i tak zostanie zwolniona."
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index a1fa921650..c32f94959d 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -2636,6 +2636,7 @@
"no_reason": "未填写原因",
"note_label": "备注",
"note_placeholder": "此备注仅员工可见",
+ "notify_customer": "通过电子邮件通知客户",
"reason_label": "原因",
"refund_payments": "向客户退款",
"refund_payments_help": "已扣取的款项将退回。未使用的授权无论如何都会释放。"
diff --git a/packages/dashboard/src/schemas/order.ts b/packages/dashboard/src/schemas/order.ts
index fbad757c7e..625f21f942 100644
--- a/packages/dashboard/src/schemas/order.ts
+++ b/packages/dashboard/src/schemas/order.ts
@@ -34,22 +34,6 @@ export type NewOrderFormValues = z.infer<typeof newOrderFormSchema>
* Cancelling an order. The reason is an id from the store's own cancellation
* vocabulary, and an empty string means the merchant gave none.
*/
-export const cancelOrderFormSchema = z.object({
- cancel_reason_id: z.string(),
- cancel_note: z.string(),
- refund_payments: z.boolean(),
-})
-
-export type CancelOrderFormValues = z.infer<typeof cancelOrderFormSchema>
-
-export const CANCEL_ORDER_DEFAULTS: CancelOrderFormValues = {
- cancel_reason_id: '',
- cancel_note: '',
- // Off by default, like the API: releasing the gateway's hold is automatic,
- // but handing back money already taken is the merchant's call.
- refund_payments: false,
-}
-
export const NEW_ORDER_DEFAULTS: NewOrderFormValues = {
email: '',
customer_note: '',
diff --git a/packages/seller-dashboard/src/components/orders/fulfillment-label-upload-dialog.tsx b/packages/seller-dashboard/src/components/orders/fulfillment-label-upload-dialog.tsx
index f37f804380..cadbb67e6b 100644
--- a/packages/seller-dashboard/src/components/orders/fulfillment-label-upload-dialog.tsx
+++ b/packages/seller-dashboard/src/components/orders/fulfillment-label-upload-dialog.tsx
@@ -3,61 +3,19 @@ import {
EMPTY_FILE_UPLOAD_VALUE,
FileUploadField,
type FileUploadValue,
+ LABEL_ACCEPT,
+ type LabelUploadFormValues,
+ labelUploadFormSchema,
mapSpreeErrorsToForm,
} from '@spree/dashboard-core'
-import {
- Button,
- Combobox,
- ComboboxButtonTrigger,
- ComboboxContent,
- ComboboxEmpty,
- ComboboxItem,
- ComboboxList,
- ComboboxSearch,
- ComboboxTriggerPlaceholder,
- ComboboxValue,
- Dialog,
- DialogBody,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- Field,
- FieldError,
- FieldLabel,
- Input,
- InputGroup,
- InputGroupAddon,
- InputGroupInput,
- InputGroupText,
-} from '@spree/dashboard-ui'
+import { LabelUploadDialog } from '@spree/dashboard-ui'
import { useState } from 'react'
-import { Controller, useForm } from 'react-hook-form'
+import { useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
-import { z } from 'zod/v4'
import { useFulfillmentActions } from '../../hooks/use-fulfillments'
import { useTrackingCarriers } from '../../hooks/use-reasons'
-/** What a carrier label plausibly arrives as — mirrors the server allowlist. */
-const LABEL_ACCEPT = 'application/pdf,image/png,text/plain'
-
-const uploadSchema = z.object({
- tracking_number: z.string().min(1),
- carrier: z.string(),
- cost: z.string(),
-})
-
-type UploadFormValues = z.infer<typeof uploadSchema>
-
-/**
- * Records postage the seller bought elsewhere — from a carrier's own site, or
- * a 3PL's PDF — so the parcel still has its file, its tracking number and what
- * it cost, with no carrier account connected.
- *
- * Buying and refunding are not here: both run through the marketplace's
- * carrier account, and the endpoint refuses them.
- */
+/** Records postage the seller bought elsewhere. Buying and refunding are not here: both run through the marketplace's carrier account, and the endpoint refuses them. */
export function FulfillmentLabelUploadDialog({
orderId,
fulfillmentId,
@@ -75,29 +33,26 @@ export function FulfillmentLabelUploadDialog({
const { uploadLabel } = useFulfillmentActions(orderId)
const { data: carriersData } = useTrackingCarriers(open)
- // The registry's carriers, stored by key and shown by name. Anything it does
- // not know is kept as typed — a forwarder is as real a carrier — and an
- // empty value asks the server to detect one.
- const carrierOptions = (carriersData?.data ?? []).map((carrier) => ({
- value: carrier.id,
- label: carrier.name,
- }))
-
+ const carriers = carriersData?.data ?? []
+ const carrierKeys = carriers.map((carrier) => carrier.id)
const carrierLabel = (value: string) =>
- carrierOptions.find((option) => option.value === value)?.label ?? value
+ carriers.find((carrier) => carrier.id === value)?.name ?? value
const [file, setFile] = useState<FileUploadValue>(EMPTY_FILE_UPLOAD_VALUE)
+ // The signed id does not exist until the upload resolves, so saving during
+ // one would silently drop the file.
+ const [uploading, setUploading] = useState(false)
- const form = useForm<UploadFormValues>({
- resolver: zodResolver(uploadSchema),
+ const form = useForm<LabelUploadFormValues>({
+ resolver: zodResolver(labelUploadFormSchema),
defaultValues: { tracking_number: '', carrier: '', cost: '' },
})
- async function onSubmit(values: UploadFormValues) {
+ async function onSubmit(values: LabelUploadFormValues) {
// Guarded here as well as on the server: submitting without one would
- // silently record a label with no file behind it.
+ // record a label with no file behind it.
if (!file.signedId) {
- form.setError('root', { message: t('orders.fulfillments.upload_label_file') })
+ form.setError('root', { message: t('admin.orders.detail.fulfillments.upload_label_file') })
return
}
@@ -117,118 +72,24 @@ export function FulfillmentLabelUploadDialog({
}
return (
- <Dialog open={open} onOpenChange={onOpenChange}>
- <DialogContent>
- <form
- onSubmit={(event) => {
- // The order page renders its cards inside their own forms — without
- // stopping the bubble the browser submits the outer one.
- form.handleSubmit(onSubmit)(event)
- event.stopPropagation()
- }}
- >
- <DialogHeader>
- <DialogTitle>{t('orders.fulfillments.upload_label_title')}</DialogTitle>
- <DialogDescription>
- {t('orders.fulfillments.upload_label_description')}
- </DialogDescription>
- </DialogHeader>
-
- <DialogBody className="flex flex-col gap-4">
- {form.formState.errors.root?.message && (
- <p className="text-sm text-destructive" role="alert">
- {form.formState.errors.root.message}
- </p>
- )}
-
- <Field>
- <FieldLabel>{t('orders.fulfillments.upload_label_file')}</FieldLabel>
- <FileUploadField accept={LABEL_ACCEPT} value={file} onChange={setFile} />
- </Field>
-
- <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
- <Field>
- <FieldLabel htmlFor="label-tracking-number">
- {t('orders.tracking_label')}
- </FieldLabel>
- <Input
- id="label-tracking-number"
- placeholder={t('orders.tracking_placeholder')}
- aria-invalid={!!form.formState.errors.tracking_number}
- {...form.register('tracking_number')}
- />
- <FieldError errors={[form.formState.errors.tracking_number]} />
- </Field>
-
- <Field>
- <FieldLabel htmlFor="label-carrier">
- {t('orders.fulfillments.carrier_label')}
- </FieldLabel>
- <Controller
- control={form.control}
- name="carrier"
- render={({ field }) => (
- <Combobox
- items={carrierOptions.map((option) => option.value)}
- value={field.value}
- onValueChange={(value: string | null) => field.onChange(value ?? '')}
- itemToStringLabel={carrierLabel}
- >
- <ComboboxButtonTrigger id="label-carrier" onBlur={field.onBlur}>
- {field.value ? (
- <ComboboxValue />
- ) : (
- <ComboboxTriggerPlaceholder>
- {t('orders.fulfillments.carrier_auto')}
- </ComboboxTriggerPlaceholder>
- )}
- </ComboboxButtonTrigger>
- <ComboboxContent>
- <ComboboxSearch placeholder={t('orders.fulfillments.carrier_search')} />
- <ComboboxEmpty>{t('common.no_results')}</ComboboxEmpty>
- <ComboboxList>
- {(value: string) => (
- <ComboboxItem key={value} value={value}>
- {carrierLabel(value)}
- </ComboboxItem>
- )}
- </ComboboxList>
- </ComboboxContent>
- </Combobox>
- )}
- />
- </Field>
- </div>
-
- <Field>
- <FieldLabel htmlFor="label-cost">
- {t('orders.fulfillments.label_cost_label')}
- </FieldLabel>
- <InputGroup>
- <InputGroupAddon>
- <InputGroupText>{currency}</InputGroupText>
- </InputGroupAddon>
- <InputGroupInput
- id="label-cost"
- type="number"
- step="0.01"
- min={0}
- {...form.register('cost')}
- />
- </InputGroup>
- </Field>
- </DialogBody>
-
- <DialogFooter>
- <Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
- {t('common.cancel')}
- </Button>
- <Button type="submit" disabled={uploadLabel.isPending}>
- {uploadLabel.isPending ? t('common.saving') : t('common.save')}
- </Button>
- </DialogFooter>
- </form>
- </DialogContent>
- </Dialog>
+ <LabelUploadDialog
+ form={form}
+ open={open}
+ onOpenChange={onOpenChange}
+ fileField={
+ <FileUploadField
+ accept={LABEL_ACCEPT}
+ value={file}
+ onChange={setFile}
+ onUploadingChange={setUploading}
+ private
+ />
+ }
+ carrierKeys={carrierKeys}
+ carrierLabel={carrierLabel}
+ currency={currency}
+ onSubmit={onSubmit}
+ pending={uploadLabel.isPending || uploading}
+ />
)
}
diff --git a/packages/seller-dashboard/src/components/orders/order-cancel-dialog.tsx b/packages/seller-dashboard/src/components/orders/order-cancel-dialog.tsx
index 8bf6d9f46c..d9e796ad6c 100644
--- a/packages/seller-dashboard/src/components/orders/order-cancel-dialog.tsx
+++ b/packages/seller-dashboard/src/components/orders/order-cancel-dialog.tsx
@@ -1,64 +1,36 @@
-import { mapSpreeErrorsToForm } from '@spree/dashboard-core'
+import { zodResolver } from '@hookform/resolvers/zod'
import {
- Button,
- Checkbox,
- Dialog,
- DialogBody,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- Field,
- FieldLabel,
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
- Textarea,
-} from '@spree/dashboard-ui'
+ CANCEL_ORDER_DEFAULTS,
+ type CancelOrderFormValues,
+ cancelOrderFormSchema,
+ mapSpreeErrorsToForm,
+} from '@spree/dashboard-core'
+import { ReasonField, OrderCancelDialog as SharedOrderCancelDialog } from '@spree/dashboard-ui'
import { Controller, useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { useCancelOrder } from '../../hooks/use-order'
import { useReasons } from '../../hooks/use-reasons'
-type CancelFormValues = {
- cancel_reason_id: string
- cancel_note: string
- notify_customer: boolean
-}
-
/**
* Withdrawing from an order this seller cannot fulfil.
*
- * A dialog rather than a bare confirm, because a cancellation carries a
- * reason the marketplace wants recorded — without one, operator reporting has
- * nothing to say about why a seller pulled out.
- *
- * Deliberately offers no refund control. The goods return to the shelf and
- * the authorization is released either way; giving back money already taken
- * is the operator's decision, and the endpoint accepts no refund arguments at
- * all rather than showing a seller a switch that would be refused.
+ * Deliberately offers no refund control: the goods return to the shelf and
+ * the authorization is released either way, but giving back money already
+ * taken is the operator's decision, and the endpoint accepts no refund
+ * argument at all rather than showing a seller a switch that would be
+ * refused.
*/
export function OrderCancelDialog({ orderId, onClose }: { orderId: string; onClose: () => void }) {
const { t } = useTranslation()
const cancel = useCancelOrder(orderId)
const { data: reasonsData } = useReasons('order-cancellation-reasons')
- const reasons = (reasonsData?.data ?? []).filter((reason) => reason.active)
- const reasonOptions = [
- // A marketplace that has not curated the vocabulary can still be pulled
- // out of, so the empty choice stays rather than forcing a reason.
- { value: '', label: t('orders.cancel_dialog.no_reason') },
- ...reasons.map((reason) => ({ value: reason.id, label: reason.name })),
- ]
-
- const form = useForm<CancelFormValues>({
- defaultValues: { cancel_reason_id: '', cancel_note: '', notify_customer: false },
+ const form = useForm<CancelOrderFormValues>({
+ resolver: zodResolver(cancelOrderFormSchema),
+ defaultValues: CANCEL_ORDER_DEFAULTS,
})
- async function onSubmit(values: CancelFormValues) {
+ async function onSubmit(values: CancelOrderFormValues) {
try {
await cancel.mutateAsync({
cancel_reason_id: values.cancel_reason_id || undefined,
@@ -72,86 +44,30 @@ export function OrderCancelDialog({ orderId, onClose }: { orderId: string; onClo
}
return (
- <Dialog open onOpenChange={(next) => !next && onClose()}>
- <DialogContent>
- <form onSubmit={form.handleSubmit(onSubmit)}>
- <DialogHeader>
- <DialogTitle>{t('orders.cancel_confirm.title')}</DialogTitle>
- <DialogDescription>{t('orders.cancel_dialog.description')}</DialogDescription>
- </DialogHeader>
-
- <DialogBody>
- {form.formState.errors.root?.message && (
- <p className="text-sm text-destructive" role="alert">
- {form.formState.errors.root.message}
- </p>
- )}
-
- <div className="flex flex-col gap-4">
- {reasons.length > 0 && (
- <Field>
- <FieldLabel htmlFor="cancel-reason">
- {t('orders.cancel_dialog.reason_label')}
- </FieldLabel>
- <Controller
- control={form.control}
- name="cancel_reason_id"
- render={({ field }) => (
- <Select
- items={reasonOptions}
- value={field.value}
- onValueChange={(value) => field.onChange(value ?? '')}
- >
- <SelectTrigger id="cancel-reason">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- {reasonOptions.map((option) => (
- <SelectItem key={option.value} value={option.value}>
- {option.label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- )}
- />
- </Field>
- )}
-
- <Field>
- <FieldLabel htmlFor="cancel-note">
- {t('orders.cancel_dialog.note_label')}
- </FieldLabel>
- <Textarea id="cancel-note" {...form.register('cancel_note')} />
- </Field>
-
- <label className="flex items-center gap-2 text-sm" htmlFor="cancel-notify">
- <Controller
- control={form.control}
- name="notify_customer"
- render={({ field }) => (
- <Checkbox
- id="cancel-notify"
- checked={field.value}
- onCheckedChange={(checked) => field.onChange(!!checked)}
- />
- )}
- />
- {t('orders.cancel_dialog.notify_customer')}
- </label>
- </div>
- </DialogBody>
-
- <DialogFooter>
- <Button type="button" variant="outline" onClick={onClose}>
- {t('common.cancel')}
- </Button>
- <Button type="submit" variant="destructive" disabled={cancel.isPending}>
- {t('orders.cancel')}
- </Button>
- </DialogFooter>
- </form>
- </DialogContent>
- </Dialog>
+ <SharedOrderCancelDialog
+ form={form}
+ reasonField={
+ /* The reasons are the marketplace's — the operator decides what they
+ are. A marketplace that has not curated them can still be pulled
+ out of, so the empty choice stays rather than forcing one. */
+ <Controller
+ control={form.control}
+ name="cancel_reason_id"
+ render={({ field }) => (
+ <ReasonField
+ id="order-cancellation"
+ reasons={(reasonsData?.data ?? []).filter((reason) => reason.active)}
+ value={field.value}
+ onChange={field.onChange}
+ label={t('admin.orders.detail.cancel.reason_label')}
+ emptyOptionLabel={t('admin.orders.detail.cancel.no_reason')}
+ />
+ )}
+ />
+ }
+ onSubmit={onSubmit}
+ onClose={onClose}
+ pending={cancel.isPending}
+ />
)
}
diff --git a/packages/seller-dashboard/src/locales/en.json b/packages/seller-dashboard/src/locales/en.json
index c1ab619370..91d518b2cd 100644
--- a/packages/seller-dashboard/src/locales/en.json
+++ b/packages/seller-dashboard/src/locales/en.json
@@ -48,6 +48,15 @@
},
"orders": {
"detail": {
+ "cancel": {
+ "description": "The goods go back on the shelf and the customer is no longer charged for them. Any money already taken is returned by the marketplace, not here.",
+ "note_label": "Note",
+ "note_placeholder": "Only staff see this note",
+ "notify_customer": "Email the customer",
+ "keep_order": "Keep order",
+ "reason_label": "Reason",
+ "no_reason": "No reason given"
+ },
"fulfillments": {
"add_tracking_title": "Add tracking",
"carrier_auto": "Detect automatically",
@@ -61,8 +70,14 @@
"no_rates": "No delivery methods are quoted for this fulfillment.",
"rates_pending_origin": "Save the new origin to see the delivery methods it offers.",
"ships_from": "Ships from",
- "tracking_description": "The carrier tracking number, or a full tracking link."
- }
+ "tracking_description": "The carrier tracking number, or a full tracking link.",
+ "upload_label_cost": "Postage cost",
+ "upload_label_description": "Record a label you bought elsewhere, so the parcel has its file, its tracking number and what it cost.",
+ "upload_label_file": "Label file",
+ "upload_label_title": "Upload label"
+ },
+ "section_customer_note": "Special Instructions",
+ "section_internal_note": "Internal Note"
},
"fulfill": {
"include_item": "Ship {{name}}",
@@ -155,6 +170,12 @@
"create": "New claim"
},
"create_title": "New claim"
+ },
+ "dialogs": {
+ "cancel_title": "Cancel order?"
+ },
+ "actions": {
+ "cancel": "Cancel order"
}
}
}
@@ -322,18 +343,6 @@
},
"billing_address": "Billing address",
"cancel": "Cancel order",
- "cancel_confirm": {
- "message": "The customer is refunded and any stock goes back on the shelf. This cannot be undone.",
- "title": "Cancel this order?"
- },
- "cancel_dialog": {
- "description": "The goods go back on the shelf and the customer is no longer charged for them. Any money already taken is returned by the marketplace, not here.",
- "reason_label": "Reason",
- "no_reason": "No reason given",
- "note_label": "Note",
- "notify_customer": "Email the customer"
- },
- "canceled": "Order canceled",
"columns": {
"fulfillment": "Fulfillment",
"number": "Order",
@@ -362,9 +371,6 @@
"cancel": "Cancel parcel",
"cancel_message": "The goods go back on the shelf and the carrier is stood down.",
"cancel_title": "Cancel this parcel?",
- "carrier_auto": "Detect from number",
- "carrier_label": "Carrier",
- "carrier_search": "Search carriers…",
"carrier_status_available_for_pickup": "Available for pickup",
"carrier_status_delivered": "Delivered",
"carrier_status_failure": "Delivery failed",
@@ -381,7 +387,6 @@
"empty": "Nothing to send on this order.",
"free": "Free",
"label_cost": "Cost {{amount}}",
- "label_cost_label": "What it cost",
"label_title": "Shipping label",
"label_uploaded": "Uploaded",
"packing_slip_title": "Packing slip — order {{number}}",
@@ -397,10 +402,7 @@
"split_would_empty": "Moving everything would leave this parcel empty.",
"splitting": "Splitting…",
"title": "Fulfillments",
- "upload_label": "Upload label",
- "upload_label_description": "Record a label you bought elsewhere, so the parcel carries its file and tracking number.",
- "upload_label_file": "Label file",
- "upload_label_title": "Upload postage"
+ "upload_label": "Upload label"
},
"items": "Items",
"not_found": "That order could not be found.",
@@ -415,26 +417,32 @@
"voided": "Voided"
},
"post_sale": {
- "reason": "Reason",
- "memo": "Note",
"approve": "Approve",
"cancel": "Cancel",
- "statuses": {
- "requested": "Requested",
- "approved": "Approved",
- "received": "Received",
- "refunded": "Refunded",
- "fulfilled": "Fulfilled",
- "open": "Open",
- "resolved": "Resolved",
- "denied": "Denied",
- "canceled": "Canceled"
+ "claims": {
+ "cancel_message": "The customer is told it will not go ahead.",
+ "cancel_title": "Cancel this claim?",
+ "create": "New claim",
+ "deny": "Deny",
+ "deny_message": "The customer is told the claim was not upheld.",
+ "deny_title": "Deny this claim?",
+ "empty": "Nothing has been reported on this order.",
+ "resolve": "Resolve",
+ "title": "Claims"
},
+ "exchanges": {
+ "title": "Exchanges",
+ "receive": "Receive",
+ "fulfill": "Send replacement",
+ "price_difference": "Price difference: {{amount}}",
+ "cancel_title": "Cancel this exchange?",
+ "cancel_message": "The customer is told it will not go ahead."
+ },
+ "reason": "Reason",
"returns": {
"cancel_message": "The customer is told it will not go ahead.",
"cancel_title": "Cancel this return?",
"create": "New return",
- "create_title": "Take goods back",
"empty": "Nothing has come back from this order.",
"not_resellable": "Not resellable",
"partially_received": "{{received}} of {{quantity}} received",
@@ -443,26 +451,16 @@
"refund_total": "Refund total: {{amount}}",
"title": "Returns"
},
- "exchanges": {
- "title": "Exchanges",
- "receive": "Receive",
- "fulfill": "Send replacement",
- "price_difference": "Price difference: {{amount}}",
- "cancel_title": "Cancel this exchange?",
- "cancel_message": "The customer is told it will not go ahead."
- },
- "claims": {
- "cancel_message": "The customer is told it will not go ahead.",
- "cancel_title": "Cancel this claim?",
- "create": "New claim",
- "create_title": "Report a problem",
- "deny": "Deny",
- "deny_message": "The customer is told the claim was not upheld.",
- "deny_title": "Deny this claim?",
- "description": "What went wrong",
- "empty": "Nothing has been reported on this order.",
- "resolve": "Resolve",
- "title": "Claims"
+ "statuses": {
+ "requested": "Requested",
+ "approved": "Approved",
+ "received": "Received",
+ "refunded": "Refunded",
+ "fulfilled": "Fulfilled",
+ "open": "Open",
+ "resolved": "Resolved",
+ "denied": "Denied",
+ "canceled": "Canceled"
}
},
"search_placeholder": "Search by order number…",
@@ -489,9 +487,7 @@
"total": "Total"
},
"title": "Orders",
- "tracking": "Tracking {{number}}",
- "tracking_label": "Tracking number",
- "tracking_placeholder": "Optional"
+ "tracking_label": "Tracking number"
},
"policies": {
"add": "Add policy",