@mercurjs/vendor 2.3.8-canary.2 → 2.3.8-canary.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,8 +59,10 @@ import { useForm } from "react-hook-form";
59
59
  import { useTranslation } from "react-i18next";
60
60
  import { useParams } from "react-router-dom";
61
61
  import { isForbidden, SectionNoAccess, useCan } from "@mercurjs/dashboard-shared";
62
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
63
- var numericOrZero = (v) => v === "" || v === null || v === void 0 ? 0 : castNumber(v) || 0;
62
+
63
+ // src/pages/offers/[id]/edit-price/utils.ts
64
+ var isEmpty = (v) => v === "" || v === null || v === void 0;
65
+ var numericOrZero = (v) => castNumber(v) || 0;
64
66
  var buildRows = (product, currencies, regions) => (product.variants ?? []).flatMap(
65
67
  (variant) => (variant.offers ?? []).map((offer) => {
66
68
  const offerPrices = offer.prices ?? [];
@@ -85,6 +87,27 @@ var buildRows = (product, currencies, regions) => (product.variants ?? []).flatM
85
87
  };
86
88
  })
87
89
  );
90
+ var buildPricePayload = (row, currencies, regions) => {
91
+ const prices = [];
92
+ for (const code of currencies) {
93
+ const value = row.prices?.[code];
94
+ if (isEmpty(value)) continue;
95
+ prices.push({ amount: numericOrZero(value), currency_code: code });
96
+ }
97
+ for (const region of regions) {
98
+ const value = row.region_prices?.[region.id];
99
+ if (isEmpty(value)) continue;
100
+ prices.push({
101
+ amount: numericOrZero(value),
102
+ currency_code: region.currency_code,
103
+ rules: { region_id: region.id }
104
+ });
105
+ }
106
+ return prices;
107
+ };
108
+
109
+ // src/pages/offers/[id]/edit-price/index.tsx
110
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
88
111
  var columnHelper = createDataGridHelper();
89
112
  var useColumns = ({
90
113
  currencies,
@@ -127,11 +150,12 @@ var useColumns = ({
127
150
  };
128
151
  var EditPriceGrid = ({
129
152
  product,
130
- productId
153
+ productId,
154
+ currencies,
155
+ regions
131
156
  }) => {
132
157
  const { t } = useTranslation();
133
158
  const { handleSuccess, setCloseOnEscape } = useRouteModal();
134
- const { currencies, regions } = useSellerCurrencies();
135
159
  const canViewPricePreferences = useCan("price_preferences");
136
160
  const { price_preferences: pricePreferences } = usePricePreferences(
137
161
  {},
@@ -146,24 +170,12 @@ var EditPriceGrid = ({
146
170
  const handleSubmit = form.handleSubmit(async (values) => {
147
171
  try {
148
172
  await Promise.all(
149
- values.rows.map((row) => {
150
- const prices = [];
151
- for (const code of currencies) {
152
- const value = row.prices?.[code];
153
- if (value === "" || value === null || value === void 0) continue;
154
- prices.push({ amount: numericOrZero(value), currency_code: code });
155
- }
156
- for (const region of regions) {
157
- const value = row.region_prices?.[region.id];
158
- if (value === "" || value === null || value === void 0) continue;
159
- prices.push({
160
- amount: numericOrZero(value),
161
- currency_code: region.currency_code,
162
- rules: { region_id: region.id }
163
- });
164
- }
165
- return sdk.vendor.offers.$id.mutate({ $id: row.offer_id, prices });
166
- })
173
+ values.rows.map(
174
+ (row) => sdk.vendor.offers.$id.mutate({
175
+ $id: row.offer_id,
176
+ prices: buildPricePayload(row, currencies, regions)
177
+ })
178
+ )
167
179
  );
168
180
  await queryClient.invalidateQueries({ queryKey: offerQueryKeys.lists() });
169
181
  await queryClient.invalidateQueries({
@@ -214,15 +226,32 @@ var OfferEditPricePage = () => {
214
226
  const { product, isPending, isError, error } = useProduct(id, {
215
227
  fields: OFFER_PRODUCT_DETAIL_FIELDS
216
228
  });
229
+ const {
230
+ currencies,
231
+ regions,
232
+ isPending: isRegionsPending,
233
+ isError: isRegionsError,
234
+ error: regionsError
235
+ } = useSellerCurrencies();
217
236
  const forbidden = isError && isForbidden(error);
218
237
  if (isError && !forbidden) throw error;
238
+ if (isRegionsError) throw regionsError;
239
+ const ready = !isPending && !!product && !isRegionsPending;
219
240
  return /* @__PURE__ */ jsxs(RouteFocusModal, { children: [
220
241
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: t("offers.pricing.header") }) }),
221
242
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: t("offers.pricing.description") }) }),
222
243
  forbidden ? /* @__PURE__ */ jsxs(Fragment, { children: [
223
244
  /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
224
245
  /* @__PURE__ */ jsx(RouteFocusModal.Body, { children: /* @__PURE__ */ jsx(SectionNoAccess, {}) })
225
- ] }) : !isPending && product && /* @__PURE__ */ jsx(EditPriceGrid, { product, productId: id })
246
+ ] }) : ready && /* @__PURE__ */ jsx(
247
+ EditPriceGrid,
248
+ {
249
+ product,
250
+ productId: id,
251
+ currencies,
252
+ regions
253
+ }
254
+ )
226
255
  ] });
227
256
  };
228
257
  var Component = OfferEditPricePage;
@@ -54,8 +54,11 @@ declare module "@mercurjs/dashboard-sdk" {
54
54
  "offer-variants.detail.main.before": true
55
55
  "offer-variants.detail.side.after": true
56
56
  "offer-variants.detail.side.before": true
57
+ "offers.detail": true
58
+ "offers.detail.main": true
57
59
  "offers.detail.main.after": true
58
60
  "offers.detail.main.before": true
61
+ "offers.detail.side": true
59
62
  "offers.detail.side.after": true
60
63
  "offers.detail.side.before": true
61
64
  "offers.list.after": true
@@ -134,6 +137,13 @@ declare module "@mercurjs/dashboard-sdk" {
134
137
  "topbar.before": true
135
138
  }
136
139
 
140
+ interface LayoutEntryRegistry {
141
+ "core:OfferAssociatedProductSection": true
142
+ "core:OfferDetailGeneralSection": true
143
+ "core:OfferVariantsSection": true
144
+ "core:ProductMediaSection": true
145
+ }
146
+
137
147
  interface NavItemRegistry {
138
148
  "campaigns": true
139
149
  "categories": true
package/dist/index.js CHANGED
@@ -68,9 +68,11 @@ import { customRoutes } from "virtual:mercur/routes";
68
68
  import widgets from "virtual:mercur/widgets";
69
69
  import navigation from "virtual:mercur/navigation";
70
70
  import customFields from "virtual:mercur/custom-fields";
71
+ import layouts from "virtual:mercur/layouts";
72
+ import preferences from "virtual:mercur/preferences";
71
73
  import { HelmetProvider } from "react-helmet-async";
72
74
  import { QueryClientProvider } from "@tanstack/react-query";
73
- import { ExtensionProvider } from "@mercurjs/dashboard-shared";
75
+ import { ExtensionProvider, resolveRouteOverrides } from "@mercurjs/dashboard-shared";
74
76
  import { I18nProvider, Toaster, TooltipProvider } from "@medusajs/ui";
75
77
  import { createBrowserRouter, RouterProvider } from "react-router-dom";
76
78
 
@@ -130,10 +132,15 @@ function mergeRoutes(baseRoutes, customRoutes2) {
130
132
  );
131
133
  if (existingIndex !== -1) {
132
134
  const { children: customChildren, ...customRest } = customRoute;
135
+ const baseHandle = result[existingIndex].handle;
136
+ const customHandle = customRest.handle;
133
137
  result[existingIndex] = {
134
138
  ...result[existingIndex],
135
139
  ...customRest,
136
140
  path: result[existingIndex].path,
141
+ // Merge rather than replace, so a custom route declaring only
142
+ // `permissions` doesn't drop the base route's `breadcrumb`.
143
+ handle: baseHandle || customHandle ? { ...baseHandle, ...customHandle } : void 0,
137
144
  children: customChildren ? mergeRoutes(result[existingIndex].children ?? [], customChildren) : result[existingIndex].children
138
145
  };
139
146
  } else {
@@ -703,14 +710,14 @@ function getRouteMap({
703
710
  {
704
711
  path: "",
705
712
  lazy: async () => {
706
- const { OfferDetailPage } = await import("./offer-detail-page-ATLR3KNB.js");
713
+ const { OfferDetailPage } = await import("./offer-detail-page-KDVITBTP.js");
707
714
  return { Component: OfferDetailPage };
708
715
  },
709
716
  children: [
710
717
  {
711
718
  path: "edit-price",
712
719
  handle: { permissions: ["offers:edit", "products:view"] },
713
- lazy: () => import("./edit-price-2FAMT7BH.js")
720
+ lazy: () => import("./edit-price-QKTDC4OC.js")
714
721
  },
715
722
  {
716
723
  path: "edit-stock",
@@ -1621,10 +1628,11 @@ import { useMemo } from "react";
1621
1628
  import { jsx as jsx4, jsxs } from "react/jsx-runtime";
1622
1629
  function App() {
1623
1630
  const routes = useMemo(() => {
1631
+ const resolved = resolveRouteOverrides(customRoutes);
1624
1632
  return {
1625
- settingsRoutes: createRouteMap(getRoutesByType(customRoutes, "settings")),
1626
- mainRoutes: createRouteMap(getRoutesByType(customRoutes, "main")),
1627
- publicRoutes: createRouteMap(getRoutesByType(customRoutes, "public"))
1633
+ settingsRoutes: createRouteMap(getRoutesByType(resolved, "settings")),
1634
+ mainRoutes: createRouteMap(getRoutesByType(resolved, "main")),
1635
+ publicRoutes: createRouteMap(getRoutesByType(resolved, "public"))
1628
1636
  };
1629
1637
  }, []);
1630
1638
  return /* @__PURE__ */ jsx4(TooltipProvider, { children: /* @__PURE__ */ jsx4(HelmetProvider, { children: /* @__PURE__ */ jsx4(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx4(ThemeProvider, { children: /* @__PURE__ */ jsxs(
@@ -1633,6 +1641,8 @@ function App() {
1633
1641
  widgets,
1634
1642
  navigation,
1635
1643
  customFields,
1644
+ layouts,
1645
+ preferences,
1636
1646
  children: [
1637
1647
  /* @__PURE__ */ jsx4(I18n, {}),
1638
1648
  /* @__PURE__ */ jsx4(I18nProvider, { children: /* @__PURE__ */ jsx4(
@@ -15,9 +15,6 @@ import {
15
15
  SidebarLink
16
16
  } from "./chunk-UST2RGWB.js";
17
17
  import "./chunk-U2EI2ZLM.js";
18
- import {
19
- TwoColumnPage
20
- } from "./chunk-YV6MK4PZ.js";
21
18
  import "./chunk-FQERBIVS.js";
22
19
  import {
23
20
  _DataTable,
@@ -52,14 +49,21 @@ import "./chunk-UKLW4VDE.js";
52
49
  import "./chunk-NBMM2TZK.js";
53
50
 
54
51
  // src/pages/offers/[id]/offer-detail-page.tsx
55
- import { Children } from "react";
56
52
  import { useLoaderData, useParams } from "react-router-dom";
57
53
  import { Container as Container4 } from "@medusajs/ui";
54
+
55
+ // ../dashboard-sdk/dist/index.js
56
+ var CORE_LAYOUT_IDS = {
57
+ SINGLE_COLUMN: "core:single-column",
58
+ TWO_COLUMN: "core:two-column"
59
+ };
60
+
61
+ // src/pages/offers/[id]/offer-detail-page.tsx
58
62
  import {
59
63
  isForbidden,
64
+ LayoutComposer,
60
65
  SectionNoAccess,
61
- useLinkQuery,
62
- WidgetZone
66
+ useLinkQuery
63
67
  } from "@mercurjs/dashboard-shared";
64
68
 
65
69
  // src/pages/offers/[id]/_components/offer-detail-general-section.tsx
@@ -608,7 +612,7 @@ var OfferAssociatedProductSection = ({
608
612
 
609
613
  // src/pages/offers/[id]/offer-detail-page.tsx
610
614
  import { Fragment, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
611
- var Root = ({ children }) => {
615
+ var OfferDetailPage = () => {
612
616
  const { id } = useParams();
613
617
  const initialData = useLoaderData();
614
618
  const query = useLinkQuery("offer", OFFER_PRODUCT_DETAIL_FIELDS);
@@ -625,30 +629,30 @@ var Root = ({ children }) => {
625
629
  return /* @__PURE__ */ jsx4(TwoColumnPageSkeleton, { mainSections: 3, sidebarSections: 1 });
626
630
  }
627
631
  const typed = product;
628
- return /* @__PURE__ */ jsx4(Fragment, { children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs4(TwoColumnPage, { data: typed, hasOutlet: true, children: [
629
- /* @__PURE__ */ jsx4(TwoColumnPage.Main, { children: /* @__PURE__ */ jsxs4(WidgetZone, { id: "offers.detail.main", data: typed, children: [
630
- /* @__PURE__ */ jsx4(OfferDetailGeneralSection, { product: typed }),
631
- /* @__PURE__ */ jsx4(ProductMediaSection, { product: typed, readOnly: true }),
632
- /* @__PURE__ */ jsx4(
633
- OfferVariantsSection,
634
- {
635
- variants: typed.variants,
636
- thumbnail: typed.thumbnail
637
- }
638
- )
639
- ] }) }),
640
- /* @__PURE__ */ jsx4(TwoColumnPage.Sidebar, { children: /* @__PURE__ */ jsx4(WidgetZone, { id: "offers.detail.side", data: typed, children: /* @__PURE__ */ jsx4(OfferAssociatedProductSection, { product: typed }) }) })
641
- ] }) });
632
+ return /* @__PURE__ */ jsx4(
633
+ LayoutComposer,
634
+ {
635
+ widgetsZonePrefix: "offers.detail",
636
+ preferredLayoutId: CORE_LAYOUT_IDS.TWO_COLUMN,
637
+ data: typed,
638
+ sections: {
639
+ main: /* @__PURE__ */ jsxs4(Fragment, { children: [
640
+ /* @__PURE__ */ jsx4(LayoutComposer.Entry, { id: "OfferDetailGeneralSection", children: /* @__PURE__ */ jsx4(OfferDetailGeneralSection, { product: typed }) }),
641
+ /* @__PURE__ */ jsx4(LayoutComposer.Entry, { id: "ProductMediaSection", children: /* @__PURE__ */ jsx4(ProductMediaSection, { product: typed, readOnly: true }) }),
642
+ /* @__PURE__ */ jsx4(LayoutComposer.Entry, { id: "OfferVariantsSection", children: /* @__PURE__ */ jsx4(
643
+ OfferVariantsSection,
644
+ {
645
+ variants: typed.variants,
646
+ thumbnail: typed.thumbnail
647
+ }
648
+ ) })
649
+ ] }),
650
+ side: /* @__PURE__ */ jsx4(LayoutComposer.Entry, { id: "OfferAssociatedProductSection", children: /* @__PURE__ */ jsx4(OfferAssociatedProductSection, { product: typed }) })
651
+ }
652
+ }
653
+ );
642
654
  };
643
- var OfferDetailPage = Object.assign(Root, {
644
- Main: TwoColumnPage.Main,
645
- Sidebar: TwoColumnPage.Sidebar,
646
- General: OfferDetailGeneralSection,
647
- Media: ProductMediaSection,
648
- Variants: OfferVariantsSection,
649
- AssociatedProduct: OfferAssociatedProductSection
650
- });
651
- var Component2 = Root;
655
+ var Component2 = OfferDetailPage;
652
656
  export {
653
657
  Component2 as Component,
654
658
  OfferDetailPage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercurjs/vendor",
3
- "version": "2.3.8-canary.2",
3
+ "version": "2.3.8-canary.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/mercurjs/mercur",
@@ -37,8 +37,8 @@
37
37
  "lint": "oxlint --max-warnings 0"
38
38
  },
39
39
  "dependencies": {
40
- "@mercurjs/dashboard-shared": "2.3.8-canary.2",
41
- "@mercurjs/client": "2.3.8-canary.2",
40
+ "@mercurjs/dashboard-shared": "2.3.8-canary.4",
41
+ "@mercurjs/client": "2.3.8-canary.4",
42
42
  "@ariakit/react": "^0.4.15",
43
43
  "@babel/runtime": "^8.0.0",
44
44
  "@dnd-kit/core": "^6.1.0",
@@ -91,9 +91,9 @@
91
91
  "tsup": "^8.0.2",
92
92
  "typescript": "5.9.3",
93
93
  "@medusajs/types": "2.21.2",
94
- "@mercurjs/core": "2.3.8-canary.2",
95
- "@mercurjs/dashboard-sdk": "2.3.8-canary.2",
96
- "@mercurjs/types": "2.3.8-canary.2",
94
+ "@mercurjs/core": "2.3.8-canary.4",
95
+ "@mercurjs/dashboard-sdk": "2.3.8-canary.4",
96
+ "@mercurjs/types": "2.3.8-canary.4",
97
97
  "react-router-dom": "7.18.1"
98
98
  }
99
99
  }