Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

refactor(vendor): deliver order outstanding-payment link as a widget (#1199)

Viktor Holikd5f883209a76
diff --git a/apps/docs/docs.json b/apps/docs/docs.json
index eb17b088b..8804d6c2c 100644
--- a/apps/docs/docs.json
+++ b/apps/docs/docs.json
@@ -75,6 +75,7 @@
"pages": [
"rc/resources/tutorials/custom-panel-page",
"rc/resources/tutorials/add-a-widget",
+ "rc/resources/tutorials/add-order-detail-button",
"rc/resources/tutorials/extend-forms-and-tables",
"rc/resources/tutorials/extend-onboarding",
"rc/resources/tutorials/store-setup-checklist",
diff --git a/apps/docs/rc/resources/tutorials/add-order-detail-button.mdx b/apps/docs/rc/resources/tutorials/add-order-detail-button.mdx
new file mode 100644
index 000000000..d5dbe88b8
--- /dev/null
+++ b/apps/docs/rc/resources/tutorials/add-order-detail-button.mdx
@@ -0,0 +1,113 @@
+---
+title: "Add a button to order details"
+description: "Drop a 'Copy link' button onto the vendor order detail page with a widget — no forking, no page override."
+---
+
+The order detail page is a built-in panel screen you don't own. To add a small piece of UI to it — a button, a badge, a note — you don't copy the page. You drop a **widget** at one of its zones, and the SDK renders your component there while the rest of the page keeps working exactly as shipped.
+
+This tutorial adds a **"Copy link"** button to the order summary section that copies a link to the order.
+
+<Info>
+ **Additive, not a replacement.** A widget layers your component onto a built-in page at a documented zone. Reach for it first whenever you just want to *add* something to an existing screen.
+</Info>
+
+## Add the button
+
+<Steps>
+ <Step title="Create the widget file">
+ Drop a file under `src/widgets/`. Export the component as the **default** and a `config` built with `defineWidgetConfig`. Target `orders.detail.summary.after` — your component renders in the order summary section footer and receives the loaded order as `data`.
+
+ ```tsx apps/vendor/src/widgets/order-copy-link.tsx
+ import { defineWidgetConfig } from "@mercurjs/dashboard-sdk"
+ import type { HttpTypes } from "@medusajs/types"
+ import { Button, Container, toast } from "@medusajs/ui"
+
+ export const config = defineWidgetConfig({
+ zone: "orders.detail.summary.after",
+ })
+
+ const OrderCopyLink = ({ data: order }: { data?: HttpTypes.AdminOrder }) => {
+ if (!order) return null
+
+ const orderLink = `${window.location.origin}/orders/${order.id}`
+
+ const handleCopy = async () => {
+ try {
+ await navigator.clipboard.writeText(orderLink)
+ toast.success("Link copied")
+ } catch {
+ toast.error("Couldn't copy the link")
+ }
+ }
+
+ return (
+ <Container className="flex items-center justify-end p-3">
+ <Button size="small" variant="secondary" onClick={handleCopy}>
+ Copy link
+ </Button>
+ </Container>
+ )
+ }
+
+ export default OrderCopyLink
+ ```
+ </Step>
+ <Step title="Understand the zone id">
+ A zone id is `<domain>.<view>.<slot>.<placement>`. The last segment is the placement:
+
+ | Placement | Effect |
+ |-----------|--------|
+ | `before` | Renders before the built-in content of the zone |
+ | `after` | Renders after the built-in content |
+
+ Multiple `before` / `after` widgets on the same zone stack in registration order.
+ </Step>
+ <Step title="Reload the panel">
+ Start the project (`bun run dev`) and open any order in the vendor portal. Widget files hot-reload — the "Copy link" button appears in the summary section footer, and the rest of the page is untouched.
+ </Step>
+</Steps>
+
+## Order detail zones
+
+Zones mounted on the vendor order detail page:
+
+| Zone | Where it renders |
+|------|------------------|
+| `orders.detail.summary.before` / `.after` | Inside the order summary section (around its footer) |
+| `orders.detail.main.before` / `.after` | Around the main column (summary, payment, fulfillment) |
+| `orders.detail.side.before` / `.after` | Around the sidebar (customer, activity) |
+
+Each is passed the loaded `order` as `data`. The full, valid set is typed as `WidgetZoneId` and generated from the panel's own zone hosts — let your editor autocomplete `zone:` to see every option. A zone no page renders can't be targeted and won't type-check.
+
+## Verify
+
+1. Open an order — the "Copy link" button renders in the summary section footer.
+2. Click it — the link is copied and a toast appears.
+3. Change the zone to `orders.detail.side.before` and reload — the button moves to the top of the sidebar.
+4. Set `zone: "not.a.zone"` — `tsc` (`bun run lint`) fails with a "not assignable to `WidgetZoneId`" error.
+5. Delete the file — the button disappears; nothing else changed.
+
+## FAQ
+
+<AccordionGroup>
+ <Accordion title="What can I read from the order?">
+ The zone passes the loaded order as `data` (`HttpTypes.AdminOrder`) — id, display id, totals, items, `payment_collections`, customer, and more. Build the link (or any UI) from it.
+ </Accordion>
+ <Accordion title="Can a block ship this instead of the host app?">
+ Yes. Put the same file in a [block](/rc/learn/blocks)'s `vendor_ui` entry under `src/widgets/`; installing the block adds the button with no wiring.
+ </Accordion>
+ <Accordion title="Can I render more than a button?">
+ The zone renders any React component — a badge, an action menu, a whole section. You have the full order in `data`.
+ </Accordion>
+</AccordionGroup>
+
+## Next steps
+
+<CardGroup cols={2}>
+ <Card title="Add a widget" href="/rc/resources/tutorials/add-a-widget">
+ The general widget model and the full list of zones.
+ </Card>
+ <Card title="Extend forms and tables" href="/rc/resources/tutorials/extend-forms-and-tables">
+ Add validated fields and columns with defineCustomFieldsConfig.
+ </Card>
+</CardGroup>
diff --git a/apps/vendor/src/widgets/order-outstanding-payment.tsx b/apps/vendor/src/widgets/order-outstanding-payment.tsx
new file mode 100644
index 000000000..3246362cb
--- /dev/null
+++ b/apps/vendor/src/widgets/order-outstanding-payment.tsx
@@ -0,0 +1,97 @@
+import { defineWidgetConfig } from "@mercurjs/dashboard-sdk"
+import type { HttpTypes } from "@medusajs/types"
+import { Button, toast } from "@medusajs/ui"
+import { useTranslation } from "react-i18next"
+
+export const config = defineWidgetConfig({
+ zone: "orders.detail.summary.after",
+})
+
+type PaymentSession = NonNullable<
+ HttpTypes.AdminPaymentCollection["payment_sessions"]
+>[number]
+
+/**
+ * Turning an unpaid payment session into a copyable link is provider-specific:
+ * the panel stays provider-agnostic and never assumes a shape for `session.data`.
+ * Branch on `provider_id` for the providers your marketplace actually uses.
+ */
+const resolvePaymentLink = (session?: PaymentSession): string | null => {
+ if (!session) {
+ return null
+ }
+
+ const data = session.data as { url?: string } | undefined
+
+ switch (session.provider_id) {
+ case "pp_stripe_stripe":
+ return data?.url ?? null
+ default:
+ return data?.url ?? null
+ }
+}
+
+const formatAmount = (amount: number, currencyCode: string) =>
+ new Intl.NumberFormat([], {
+ style: "currency",
+ currencyDisplay: "narrowSymbol",
+ currency: currencyCode,
+ }).format(amount)
+
+const OrderOutstandingPayment = ({
+ data: order,
+}: {
+ data?: HttpTypes.AdminOrder
+}) => {
+ const { t } = useTranslation()
+
+ if (!order) {
+ return null
+ }
+
+ const unpaidCollection = order.payment_collections?.find(
+ (pc) => pc.status !== "captured" && pc.status !== "canceled"
+ )
+
+ const pendingDifference = order.summary?.pending_difference ?? 0
+ const isOutstanding =
+ pendingDifference > 0.005 &&
+ order.status !== "canceled" &&
+ !!unpaidCollection
+
+ if (!isOutstanding || !unpaidCollection) {
+ return null
+ }
+
+ const paymentLink = resolvePaymentLink(unpaidCollection.payment_sessions?.[0])
+
+ if (!paymentLink) {
+ return null
+ }
+
+ const handleCopyLink = async () => {
+ try {
+ await navigator.clipboard.writeText(paymentLink)
+ toast.success(t("orders.payment.copyLinkSuccess"))
+ } catch {
+ toast.error(t("orders.payment.copyLinkError"))
+ }
+ }
+
+ return (
+ <div className="bg-ui-bg-subtle flex items-center justify-end gap-x-2 rounded-b-xl px-4 py-4">
+ <Button
+ size="small"
+ variant="secondary"
+ onClick={handleCopyLink}
+ data-testid="order-outstanding-copy-payment-link"
+ >
+ {t("orders.payment.copyPaymentLink", {
+ amount: formatAmount(pendingDifference, order.currency_code),
+ })}
+ </Button>
+ </div>
+ )
+}
+
+export default OrderOutstandingPayment
diff --git a/packages/vendor/src/extension-targets.d.ts b/packages/vendor/src/extension-targets.d.ts
index 84a4d989a..478ca4192 100644
--- a/packages/vendor/src/extension-targets.d.ts
+++ b/packages/vendor/src/extension-targets.d.ts
@@ -62,6 +62,8 @@ declare module "@mercurjs/dashboard-sdk" {
"orders.detail.main.before": true
"orders.detail.side.after": true
"orders.detail.side.before": true
+ "orders.detail.summary.after": true
+ "orders.detail.summary.before": true
"orders.list.after": true
"orders.list.before": true
"payouts.detail.main.after": true
diff --git a/packages/vendor/src/pages/orders/[id]/_components/order-summary-section/order-summary-section.tsx b/packages/vendor/src/pages/orders/[id]/_components/order-summary-section/order-summary-section.tsx
index 418beeff3..68311714c 100644
--- a/packages/vendor/src/pages/orders/[id]/_components/order-summary-section/order-summary-section.tsx
+++ b/packages/vendor/src/pages/orders/[id]/_components/order-summary-section/order-summary-section.tsx
@@ -32,10 +32,9 @@ import {
StatusBadge,
Text,
Tooltip,
- toast,
} from "@medusajs/ui"
-import { DisplayExtensionZone } from "@mercurjs/dashboard-shared"
+import { DisplayExtensionZone, WidgetZone } from "@mercurjs/dashboard-shared"
import { ActionMenu } from "@components/common/action-menu"
import {
useOrderCommissionLines,
@@ -223,7 +222,7 @@ export const OrderSummarySection = ({
</div>
)}
- <OutstandingActions order={order} />
+ <WidgetZone id="orders.detail.summary" data={order} />
<DisplayExtensionZone model="order" zone="summary" data={order} />
</Container>
)
@@ -996,50 +995,3 @@ const Total = ({ order }: { order: AdminOrder }) => {
)
}
-const OutstandingActions = ({ order }: { order: HttpTypes.AdminOrder }) => {
- const { t } = useTranslation()
-
- const unpaidCollection = order.payment_collections?.find(
- (pc) => pc.status !== "captured" && pc.status !== "canceled"
- )
-
- const pendingDifference = order.summary?.pending_difference || 0
- const isOutstanding =
- pendingDifference > 0.005 &&
- order.status !== "canceled" &&
- !!unpaidCollection
-
- if (!isOutstanding || !unpaidCollection) {
- return null
- }
-
- const paymentLink =
- (
- unpaidCollection.payment_sessions?.[0]?.data as
- | { url?: string }
- | undefined
- )?.url ?? null
-
- if (!paymentLink) {
- return null
- }
-
- const handleCopyLink = async () => {
- try {
- await navigator.clipboard.writeText(paymentLink)
- toast.success(t("orders.payment.copyLinkSuccess"))
- } catch {
- toast.error(t("orders.payment.copyLinkError"))
- }
- }
-
- return (
- <div className="bg-ui-bg-subtle flex items-center justify-end gap-x-2 rounded-b-xl px-4 py-4">
- <Button size="small" variant="secondary" onClick={handleCopyLink}>
- {t("orders.payment.copyPaymentLink", {
- amount: getStylizedAmount(pendingDifference, order.currency_code),
- })}
- </Button>
- </div>
- )
-}