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.

feat(vendor,admin): add a per-card widget zone to the locations list (#1620)

Viktor Holik765309f61583
diff --git a/apps/docs/references/panel-extensions/widgets.mdx b/apps/docs/references/panel-extensions/widgets.mdx
index 5369942de..b91f5cbf7 100644
--- a/apps/docs/references/panel-extensions/widgets.mdx
+++ b/apps/docs/references/panel-extensions/widgets.mdx
@@ -128,6 +128,55 @@ works as on any other widget and hides the tab from actors who lack it.
| ----- | ------------------- | ------------------------------------------------------- |
| Admin | `stores.detail.tabs` | Store detail, next to Orders, Offers, Users and Time off. |
+## List item rows
+
+The locations list renders one card per stock location. The `locations.list.item`
+zone sits inside each card, so a widget there adds a row to the card instead of a
+separate block above or below the list. `locations.list.item.before` renders
+between the card header and the built-in rows, and `locations.list.item.after`
+renders after them. `data` is the stock location of that card.
+
+```tsx apps/vendor/src/widgets/location-local-delivery-row.tsx
+import { defineWidgetConfig } from "@mercurjs/dashboard-sdk"
+import { StatusBadge, Text } from "@medusajs/ui"
+import type { HttpTypes } from "@mercurjs/types"
+
+type StockLocation = HttpTypes.VendorStockLocationResponse["stock_location"]
+
+const LocationLocalDeliveryRow = ({ data }: { data?: StockLocation }) => {
+ const enabled = data?.fulfillment_sets?.some(
+ (set) => set.type === "local_delivery"
+ )
+
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ <Text size="small" weight="plus" className="text-ui-fg-subtle flex-1">
+ Local delivery
+ </Text>
+ <div className="flex-1">
+ <StatusBadge color={enabled ? "green" : "grey"}>
+ {enabled ? "Enabled" : "Disabled"}
+ </StatusBadge>
+ </div>
+ </div>
+ )
+}
+
+export const config = defineWidgetConfig({
+ zone: "locations.list.item.after",
+})
+
+export default LocationLocalDeliveryRow
+```
+
+Return a single row element, without a `Container` of its own. The card draws the
+divider between rows.
+
+| Panel | Zone | Page |
+| ------ | --------------------- | -------------------------------------- |
+| Vendor | `locations.list.item` | Settings → Locations, each location card. |
+| Admin | `locations.list.item` | Settings → Locations, each location card. |
+
## Zone ids
A zone id reads `<domain>.<view>.<placement>`.
@@ -155,7 +204,7 @@ expands to a `.before` and an `.after` zone.
| `customer-groups` | ✓ | ✓ | | |
| `customers` | ✓ | ✓ | ✓ | |
| `inventory` | ✓ | ✓ | ✓ | |
-| `locations` | ✓ | ✓ | ✓ | |
+| `locations` | ✓ | ✓ | ✓ | `list.item` |
| `offer-variants` | | ✓ | ✓ | |
| `offers` | ✓ | ✓ | ✓ | |
| `orders` | ✓ | ✓ | ✓ | `detail.summary` |
@@ -202,7 +251,7 @@ cell expands to a `.before` and an `.after` zone.
| `customer-groups` | ✓ | ✓ | | |
| `customers` | ✓ | ✓ | ✓ | |
| `inventory` | ✓ | ✓ | ✓ | |
-| `locations` | ✓ | ✓ | ✓ | |
+| `locations` | ✓ | ✓ | ✓ | `list.item` |
| `marketplace` | | ✓ | | |
| `offer-variants` | | ✓ | ✓ | |
| `offers` | ✓ | ✓ | ✓ | |
diff --git a/packages/admin/src/__tests__/extension-targets.spec.ts b/packages/admin/src/__tests__/extension-targets.spec.ts
index f4ddaa01e..a341e5e33 100644
--- a/packages/admin/src/__tests__/extension-targets.spec.ts
+++ b/packages/admin/src/__tests__/extension-targets.spec.ts
@@ -13,6 +13,8 @@ describe("extension targets", () => {
"topbar.after",
"stores.detail.tabs.before",
"stores.detail.tabs.after",
+ "locations.list.item.before",
+ "locations.list.item.after",
])(
"registers the %s widget zone",
(zone) => {
diff --git a/packages/admin/src/extension-targets.d.ts b/packages/admin/src/extension-targets.d.ts
index d79b91b8d..da1638579 100644
--- a/packages/admin/src/extension-targets.d.ts
+++ b/packages/admin/src/extension-targets.d.ts
@@ -54,6 +54,8 @@ declare module "@mercurjs/dashboard-sdk" {
"locations.detail.side.before": true
"locations.list.after": true
"locations.list.before": true
+ "locations.list.item.after": true
+ "locations.list.item.before": true
"marketplace.detail.main.after": true
"marketplace.detail.main.before": true
"offer-variants.detail.main.after": true
diff --git a/packages/admin/src/pages/locations/location-list/components/location-list-item/location-list-item.tsx b/packages/admin/src/pages/locations/location-list/components/location-list-item/location-list-item.tsx
index 293b3165a..4691d272d 100644
--- a/packages/admin/src/pages/locations/location-list/components/location-list-item/location-list-item.tsx
+++ b/packages/admin/src/pages/locations/location-list/components/location-list-item/location-list-item.tsx
@@ -1,6 +1,7 @@
import { Buildings, PencilSquare, Trash } from "@medusajs/icons"
import type { HttpTypes } from "@medusajs/types"
import { Container, StatusBadge, Text, toast, usePrompt } from "@medusajs/ui"
+import { WidgetZone } from "@mercurjs/dashboard-shared"
import { useTranslation } from "react-i18next"
import { ActionMenu } from "../../../../../components/common/action-menu"
@@ -168,20 +169,22 @@ function LocationListItem(props: LocationProps) {
</div>
</div>
- <SalesChannels salesChannels={location.sales_channels} />
-
- <FulfillmentSet
- type={FulfillmentSetType.Pickup}
- fulfillmentSet={location.fulfillment_sets?.find(
- (f) => f.type === FulfillmentSetType.Pickup
- )}
- />
- <FulfillmentSet
- type={FulfillmentSetType.Shipping}
- fulfillmentSet={location.fulfillment_sets?.find(
- (f) => f.type === FulfillmentSetType.Shipping
- )}
- />
+ <WidgetZone id="locations.list.item" data={location}>
+ <SalesChannels salesChannels={location.sales_channels} />
+
+ <FulfillmentSet
+ type={FulfillmentSetType.Pickup}
+ fulfillmentSet={location.fulfillment_sets?.find(
+ (f) => f.type === FulfillmentSetType.Pickup
+ )}
+ />
+ <FulfillmentSet
+ type={FulfillmentSetType.Shipping}
+ fulfillmentSet={location.fulfillment_sets?.find(
+ (f) => f.type === FulfillmentSetType.Shipping
+ )}
+ />
+ </WidgetZone>
</Container>
)
}
diff --git a/packages/vendor/src/__tests__/extension-targets.spec.ts b/packages/vendor/src/__tests__/extension-targets.spec.ts
index 62f737e42..f3f3bc411 100644
--- a/packages/vendor/src/__tests__/extension-targets.spec.ts
+++ b/packages/vendor/src/__tests__/extension-targets.spec.ts
@@ -8,7 +8,12 @@ const targets = fs.readFileSync(
)
describe("extension targets", () => {
- test.each(["topbar.before", "topbar.after"])(
+ test.each([
+ "topbar.before",
+ "topbar.after",
+ "locations.list.item.before",
+ "locations.list.item.after",
+ ])(
"registers the %s widget zone",
(zone) => {
expect(targets).toContain(`"${zone}": true`)
diff --git a/packages/vendor/src/extension-targets.d.ts b/packages/vendor/src/extension-targets.d.ts
index 94b64f254..2bd59b6cc 100644
--- a/packages/vendor/src/extension-targets.d.ts
+++ b/packages/vendor/src/extension-targets.d.ts
@@ -42,6 +42,8 @@ declare module "@mercurjs/dashboard-sdk" {
"locations.detail.side.before": true
"locations.list.after": true
"locations.list.before": true
+ "locations.list.item.after": true
+ "locations.list.item.before": true
"login.after.after": true
"login.after.before": true
"login.before.after": true
diff --git a/packages/vendor/src/pages/settings/locations/_components/location-list-item.tsx b/packages/vendor/src/pages/settings/locations/_components/location-list-item.tsx
index 14462b74a..e09bc87b6 100644
--- a/packages/vendor/src/pages/settings/locations/_components/location-list-item.tsx
+++ b/packages/vendor/src/pages/settings/locations/_components/location-list-item.tsx
@@ -7,6 +7,7 @@ import { ActionMenu } from "@components/common/action-menu";
import { LinkButton } from "@components/common/link-button";
import { useDeleteStockLocation } from "@hooks/api/stock-locations";
import { getFormattedAddress } from "@lib/addresses";
+import { WidgetZone } from "@mercurjs/dashboard-shared";
import { FulfillmentSetType } from "@pages/settings/locations/_common/constants";
import { HttpTypes } from "@mercurjs/types";
@@ -179,18 +180,20 @@ function LocationListItem(props: LocationProps) {
{/* <SalesChannels salesChannels={location.sales_channels} /> */}
- <FulfillmentSet
- type={FulfillmentSetType.Pickup}
- fulfillmentSet={location.fulfillment_sets?.find(
- (f) => f.type === FulfillmentSetType.Pickup,
- )}
- />
- <FulfillmentSet
- type={FulfillmentSetType.Shipping}
- fulfillmentSet={location.fulfillment_sets?.find(
- (f) => f.type === FulfillmentSetType.Shipping,
- )}
- />
+ <WidgetZone id="locations.list.item" data={location}>
+ <FulfillmentSet
+ type={FulfillmentSetType.Pickup}
+ fulfillmentSet={location.fulfillment_sets?.find(
+ (f) => f.type === FulfillmentSetType.Pickup,
+ )}
+ />
+ <FulfillmentSet
+ type={FulfillmentSetType.Shipping}
+ fulfillmentSet={location.fulfillment_sets?.find(
+ (f) => f.type === FulfillmentSetType.Shipping,
+ )}
+ />
+ </WidgetZone>
</Container>
);
}