@medusajs/loyalty-plugin 0.0.7-preview.0 → 0.0.7-preview.3

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.
@@ -20373,7 +20373,11 @@ const GiftCardProductsSection = () => {
20373
20373
  )
20374
20374
  ] });
20375
20375
  };
20376
- const giftCardQueryKey = queryKeysFactory("gift-card");
20376
+ const _giftCardQueryKey = queryKeysFactory("gift-card");
20377
+ const giftCardQueryKey = {
20378
+ ..._giftCardQueryKey,
20379
+ orders: (id) => [..._giftCardQueryKey.detail(id), "orders"]
20380
+ };
20377
20381
  const useGiftCards = (query, options) => {
20378
20382
  const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
20379
20383
  query: query2,
@@ -20398,6 +20402,18 @@ const useGiftCard = (id, query, options) => {
20398
20402
  });
20399
20403
  return { ...data, ...rest };
20400
20404
  };
20405
+ const useGiftCardOrders = (id, options) => {
20406
+ const fetchGiftCardOrders = (id2, query, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}/orders`, {
20407
+ query,
20408
+ headers
20409
+ });
20410
+ const { data, ...rest } = reactQuery.useQuery({
20411
+ queryFn: () => fetchGiftCardOrders(id),
20412
+ queryKey: giftCardQueryKey.orders(id),
20413
+ ...options
20414
+ });
20415
+ return { ...data, ...rest };
20416
+ };
20401
20417
  const useRedeemGiftCard = (id, options) => {
20402
20418
  const queryClient = reactQuery.useQueryClient();
20403
20419
  const redeemGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}/redeem`, {
@@ -20461,6 +20477,12 @@ const columnHelper$9 = ui.createDataTableColumnHelper();
20461
20477
  const useGiftCardTableColumns = () => {
20462
20478
  return React.useMemo(() => {
20463
20479
  return [
20480
+ columnHelper$9.accessor("code", {
20481
+ header: "Code",
20482
+ cell: ({ row }) => {
20483
+ return row.original.code;
20484
+ }
20485
+ }),
20464
20486
  columnHelper$9.accessor("line_item.product.title", {
20465
20487
  header: "Product",
20466
20488
  cell: ({ row }) => {
@@ -20468,34 +20490,10 @@ const useGiftCardTableColumns = () => {
20468
20490
  return ((_b = (_a = row.original.line_item) == null ? void 0 : _a.product) == null ? void 0 : _b.title) || "Custom Gift Card";
20469
20491
  }
20470
20492
  }),
20471
- columnHelper$9.accessor("customer.first_name", {
20472
- header: "Owner",
20473
- cell: ({ row }) => {
20474
- if (!row.original.customer) {
20475
- return "N/A";
20476
- }
20477
- const fullName = [
20478
- row.original.customer.first_name,
20479
- row.original.customer.last_name
20480
- ];
20481
- if (fullName.join("").length > 0) {
20482
- return fullName.join(" ");
20483
- }
20484
- return row.original.customer.email;
20485
- }
20486
- }),
20487
20493
  columnHelper$9.accessor("created_at", {
20488
20494
  header: "Date issued",
20489
20495
  cell: ({ row }) => getRelativeDate(row.original.created_at)
20490
20496
  }),
20491
- columnHelper$9.accessor("status", {
20492
- header: "Status",
20493
- cell: ({ row }) => {
20494
- const status = getGiftCardStatus(row.original);
20495
- const color = getGiftCardStatusColor(status);
20496
- return /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color, children: status });
20497
- }
20498
- }),
20499
20497
  columnHelper$9.accessor("value", {
20500
20498
  header: "Value",
20501
20499
  cell: ({ row }) => {
@@ -20626,9 +20624,6 @@ const GiftCardCreateSchema = z.object({
20626
20624
  currency_code: z.string({
20627
20625
  required_error: "Currency is required"
20628
20626
  }),
20629
- customer_id: z.string({
20630
- required_error: "Customer is required"
20631
- }),
20632
20627
  expires_at: z.date().nullable().optional(),
20633
20628
  note: z.string().optional(),
20634
20629
  metadata: z.record(z.string(), z.string()).optional()
@@ -20644,10 +20639,9 @@ const GiftCardCreateForm = ({
20644
20639
  defaultValues: {
20645
20640
  value: void 0,
20646
20641
  currency_code: (supportedCurrencies == null ? void 0 : supportedCurrencies[0]) ?? "eur",
20647
- customer_id: "",
20648
20642
  expires_at: null,
20649
- note: "",
20650
- metadata: {}
20643
+ metadata: {},
20644
+ note: ""
20651
20645
  },
20652
20646
  resolver: t(GiftCardCreateSchema)
20653
20647
  });
@@ -20676,30 +20670,6 @@ const GiftCardCreateForm = ({
20676
20670
  (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
20677
20671
  );
20678
20672
  }, [currencySearchValue]);
20679
- const {
20680
- options: customerOptions,
20681
- fetchNextPage,
20682
- isFetchingNextPage,
20683
- searchValue,
20684
- onSearchValueChange,
20685
- isLoading
20686
- } = useComboboxData({
20687
- queryKey: customersQueryKeys.list(),
20688
- queryFn: async (params) => {
20689
- return sdk.admin.customer.list(params);
20690
- },
20691
- getOptions: (data) => {
20692
- var _a;
20693
- return ((_a = data.customers) == null ? void 0 : _a.map((customer) => {
20694
- const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
20695
- const label = fullName ? `${customer.email} (${fullName})` : customer.email;
20696
- return {
20697
- label,
20698
- value: customer.id
20699
- };
20700
- })) || [];
20701
- }
20702
- });
20703
20673
  const selectedCurrency = form.watch("currency_code");
20704
20674
  const currentCurrency = React.useMemo(() => {
20705
20675
  return currencies[selectedCurrency.toUpperCase()];
@@ -20712,7 +20682,7 @@ const GiftCardCreateForm = ({
20712
20682
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "size-full overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col items-center p-16", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8", children: [
20713
20683
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
20714
20684
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Create Gift Card" }),
20715
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new gift card for a customer" })
20685
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new gift card" })
20716
20686
  ] }),
20717
20687
  /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
20718
20688
  /* @__PURE__ */ jsxRuntime.jsxs(
@@ -20761,14 +20731,21 @@ const GiftCardCreateForm = ({
20761
20731
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
20762
20732
  ui.CurrencyInput,
20763
20733
  {
20764
- ...field,
20765
- formatValueOnBlur: true,
20766
- symbol: currentCurrency.symbol_native,
20734
+ value: field.value,
20767
20735
  code: currentCurrency.code,
20736
+ symbol: currentCurrency.symbol_native,
20768
20737
  decimalScale: currentCurrency.decimal_digits,
20769
20738
  decimalsLimit: currentCurrency.decimal_digits,
20739
+ allowDecimals: true,
20740
+ formatValueOnBlur: true,
20741
+ allowNegativeValue: false,
20770
20742
  autoComplete: "off",
20771
- tabIndex: -1
20743
+ tabIndex: -1,
20744
+ onValueChange: (_value, _name, values) => {
20745
+ field.onChange(
20746
+ (values == null ? void 0 : values.value) ? values == null ? void 0 : values.value : ""
20747
+ );
20748
+ }
20772
20749
  }
20773
20750
  ) }),
20774
20751
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
@@ -20780,22 +20757,17 @@ const GiftCardCreateForm = ({
20780
20757
  Form$2.Field,
20781
20758
  {
20782
20759
  control: form.control,
20783
- name: "customer_id",
20760
+ name: "expires_at",
20784
20761
  render: ({ field }) => {
20785
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "w-full", children: [
20786
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { className: "font-normal", children: "Customer" }),
20762
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
20763
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Expires at" }),
20787
20764
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
20788
- Combobox,
20765
+ ui.DatePicker,
20789
20766
  {
20790
- value: field.value,
20791
- onChange: field.onChange,
20792
- searchValue,
20793
- onSearchValueChange,
20794
- options: customerOptions,
20795
- placeholder: "Search for a customer...",
20796
- fetchNextPage,
20797
- isFetchingNextPage,
20798
- noResultsPlaceholder: isLoading ? "Loading customers..." : "No customers found"
20767
+ hourCycle: 24,
20768
+ granularity: "minute",
20769
+ shouldCloseOnSelect: false,
20770
+ ...field
20799
20771
  }
20800
20772
  ) }),
20801
20773
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
@@ -23739,8 +23711,7 @@ const GiftCardGeneralSection = ({ giftCard }) => {
23739
23711
  onError: (error) => ui.toast.error(error.message)
23740
23712
  });
23741
23713
  };
23742
- const status = getGiftCardStatus(giftCard);
23743
- const statusColor = getGiftCardStatusColor(status);
23714
+ getGiftCardStatus(giftCard);
23744
23715
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
23745
23716
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
23746
23717
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
@@ -23756,43 +23727,40 @@ const GiftCardGeneralSection = ({ giftCard }) => {
23756
23727
  includeTime: true
23757
23728
  }) })
23758
23729
  ] }),
23759
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-4", children: [
23760
- /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: statusColor, children: status }),
23761
- /* @__PURE__ */ jsxRuntime.jsx(
23762
- ActionMenu,
23763
- {
23764
- groups: [
23765
- {
23766
- actions: [
23767
- // TODO: revisit this - now GC doesn't have owner so redeeming would result in an anonymous account
23768
- // {
23769
- // icon: <Gift />,
23770
- // label: "Redeem gift card",
23771
- // onClick: () => handleRedeem(),
23772
- // disabled: isPending || giftCard.status === "redeemed",
23773
- // },
23774
- {
23775
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Calendar, {}),
23776
- label: "Edit expiration date",
23777
- to: "expiration",
23778
- disabled: isPending
23779
- }
23780
- ]
23781
- },
23782
- {
23783
- actions: [
23784
- {
23785
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
23786
- label: "Delete",
23787
- onClick: handleDelete,
23788
- disabled: isDeleting || true
23789
- }
23790
- ]
23791
- }
23792
- ]
23793
- }
23794
- )
23795
- ] })
23730
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-x-4", children: /* @__PURE__ */ jsxRuntime.jsx(
23731
+ ActionMenu,
23732
+ {
23733
+ groups: [
23734
+ {
23735
+ actions: [
23736
+ // TODO: revisit this - now GC doesn't have owner so redeeming would result in an anonymous account
23737
+ // {
23738
+ // icon: <Gift />,
23739
+ // label: "Redeem gift card",
23740
+ // onClick: () => handleRedeem(),
23741
+ // disabled: isPending || giftCard.status === "redeemed",
23742
+ // },
23743
+ {
23744
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Calendar, {}),
23745
+ label: "Edit expiration date",
23746
+ to: "expiration",
23747
+ disabled: isPending
23748
+ }
23749
+ ]
23750
+ },
23751
+ {
23752
+ actions: [
23753
+ {
23754
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
23755
+ label: "Delete",
23756
+ onClick: handleDelete,
23757
+ disabled: isDeleting || true
23758
+ }
23759
+ ]
23760
+ }
23761
+ ]
23762
+ }
23763
+ ) })
23796
23764
  ] }),
23797
23765
  ((_a = giftCard.line_item) == null ? void 0 : _a.product) && /* @__PURE__ */ jsxRuntime.jsx(
23798
23766
  SectionRow,
@@ -23875,19 +23843,21 @@ const GiftCardNoteSection = ({ giftCard }) => {
23875
23843
  ] });
23876
23844
  };
23877
23845
  const GiftCardOrderSection = ({ giftCard }) => {
23878
- if (!giftCard || giftCard.reference !== "order") {
23879
- return;
23880
- }
23881
- const { order, isLoading, isError, error } = useOrder(giftCard.reference_id);
23846
+ const { orders, isLoading, isError, error } = useGiftCardOrders(
23847
+ giftCard == null ? void 0 : giftCard.id
23848
+ );
23882
23849
  if (isError) {
23883
23850
  throw error;
23884
23851
  }
23885
- if (isLoading) {
23852
+ if (isLoading || !orders) {
23853
+ return null;
23854
+ }
23855
+ if (orders && orders.length === 0) {
23886
23856
  return null;
23887
23857
  }
23888
23858
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
23889
23859
  /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Order" }),
23890
- /* @__PURE__ */ jsxRuntime.jsx(
23860
+ orders.map((order) => /* @__PURE__ */ jsxRuntime.jsx(
23891
23861
  SidebarLink,
23892
23862
  {
23893
23863
  to: `/orders/${order.id}`,
@@ -23895,7 +23865,7 @@ const GiftCardOrderSection = ({ giftCard }) => {
23895
23865
  icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ShoppingCart, {}),
23896
23866
  descriptionKey: `Order #${order.display_id}`
23897
23867
  }
23898
- )
23868
+ ))
23899
23869
  ] });
23900
23870
  };
23901
23871
  const GiftCardTransactionsSection = ({
@@ -23972,73 +23942,6 @@ const KeyboundForm = React__namespace.default.forwardRef(({ onSubmit, onKeyDown,
23972
23942
  );
23973
23943
  });
23974
23944
  KeyboundForm.displayName = "KeyboundForm";
23975
- const Note = () => {
23976
- const { id } = reactRouterDom.useParams();
23977
- const {
23978
- gift_card: giftCard,
23979
- isPending,
23980
- isError,
23981
- error
23982
- } = useGiftCard(id, {});
23983
- if (isError) {
23984
- throw error;
23985
- }
23986
- const isReady = !isPending && !!giftCard;
23987
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
23988
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
23989
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit note" }) }),
23990
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the note for the gift card" }) })
23991
- ] }),
23992
- isReady && /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteForm, { giftCard })
23993
- ] });
23994
- };
23995
- const GiftCardNoteForm = ({ giftCard }) => {
23996
- const form = useForm({
23997
- defaultValues: {
23998
- note: giftCard.note ?? ""
23999
- },
24000
- resolver: t(schema$1)
24001
- });
24002
- const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
24003
- const { handleSuccess } = useRouteModal();
24004
- const onSubmit = form.handleSubmit(async (data) => {
24005
- await mutateAsync(
24006
- { note: data.note },
24007
- {
24008
- onSuccess: () => handleSuccess(),
24009
- onError: (error) => ui.toast.error(error.message)
24010
- }
24011
- );
24012
- });
24013
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
24014
- KeyboundForm,
24015
- {
24016
- className: "flex flex-1 flex-col overflow-hidden",
24017
- onSubmit,
24018
- children: [
24019
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
24020
- Form$2.Field,
24021
- {
24022
- control: form.control,
24023
- name: "note",
24024
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
24025
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
24026
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
24027
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
24028
- ] })
24029
- }
24030
- ) }),
24031
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
24032
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
24033
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
24034
- ] }) })
24035
- ]
24036
- }
24037
- ) });
24038
- };
24039
- const schema$1 = z.object({
24040
- note: z.string().optional()
24041
- });
24042
23945
  const GiftCardExpiration = () => {
24043
23946
  const { id } = reactRouterDom.useParams();
24044
23947
  const {
@@ -24064,7 +23967,7 @@ const GiftCardExpirationForm = ({ giftCard }) => {
24064
23967
  defaultValues: {
24065
23968
  expires_at: giftCard.expires_at ? new Date(giftCard.expires_at) : null
24066
23969
  },
24067
- resolver: t(schema)
23970
+ resolver: t(schema$1)
24068
23971
  });
24069
23972
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
24070
23973
  const { handleSuccess } = useRouteModal();
@@ -24153,9 +24056,76 @@ const GiftCardExpirationForm = ({ giftCard }) => {
24153
24056
  }
24154
24057
  ) });
24155
24058
  };
24156
- const schema = z.object({
24059
+ const schema$1 = z.object({
24157
24060
  expires_at: z.date().nullish()
24158
24061
  });
24062
+ const Note = () => {
24063
+ const { id } = reactRouterDom.useParams();
24064
+ const {
24065
+ gift_card: giftCard,
24066
+ isPending,
24067
+ isError,
24068
+ error
24069
+ } = useGiftCard(id, {});
24070
+ if (isError) {
24071
+ throw error;
24072
+ }
24073
+ const isReady = !isPending && !!giftCard;
24074
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
24075
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
24076
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit note" }) }),
24077
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the note for the gift card" }) })
24078
+ ] }),
24079
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteForm, { giftCard })
24080
+ ] });
24081
+ };
24082
+ const GiftCardNoteForm = ({ giftCard }) => {
24083
+ const form = useForm({
24084
+ defaultValues: {
24085
+ note: giftCard.note ?? ""
24086
+ },
24087
+ resolver: t(schema)
24088
+ });
24089
+ const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
24090
+ const { handleSuccess } = useRouteModal();
24091
+ const onSubmit = form.handleSubmit(async (data) => {
24092
+ await mutateAsync(
24093
+ { note: data.note },
24094
+ {
24095
+ onSuccess: () => handleSuccess(),
24096
+ onError: (error) => ui.toast.error(error.message)
24097
+ }
24098
+ );
24099
+ });
24100
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
24101
+ KeyboundForm,
24102
+ {
24103
+ className: "flex flex-1 flex-col overflow-hidden",
24104
+ onSubmit,
24105
+ children: [
24106
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
24107
+ Form$2.Field,
24108
+ {
24109
+ control: form.control,
24110
+ name: "note",
24111
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
24112
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
24113
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
24114
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
24115
+ ] })
24116
+ }
24117
+ ) }),
24118
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
24119
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
24120
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
24121
+ ] }) })
24122
+ ]
24123
+ }
24124
+ ) });
24125
+ };
24126
+ const schema = z.object({
24127
+ note: z.string().optional()
24128
+ });
24159
24129
  const columnHelper$7 = createColumnHelper();
24160
24130
  const useGiftCardProductsTableColumns = () => {
24161
24131
  return React.useMemo(
@@ -37438,25 +37408,172 @@ const ProductDetail = () => {
37438
37408
  ] });
37439
37409
  };
37440
37410
  const EditProductSchema$1 = z.object({
37441
- status: z.enum(["draft", "published", "proposed", "rejected"]),
37442
- title: z.string().min(1),
37443
- subtitle: z.string().optional(),
37444
- handle: z.string().min(1),
37445
- description: z.string().optional()
37411
+ denominations: z.array(
37412
+ z.object({
37413
+ id: z.string().optional(),
37414
+ value: z.string().min(1),
37415
+ prices: z.record(z.string(), optionalFloat).optional()
37416
+ })
37417
+ ).min(1)
37446
37418
  });
37447
- const GiftCardProductEditForm = ({
37419
+ const GiftCardProductEditDenominationsForm = ({
37448
37420
  product
37449
37421
  }) => {
37422
+ var _a;
37450
37423
  const { handleSuccess } = useRouteModal();
37451
37424
  const form = useForm({
37452
37425
  defaultValues: {
37453
- status: product.status,
37454
- title: product.title,
37455
- subtitle: product.subtitle || "",
37426
+ denominations: (_a = product.variants) == null ? void 0 : _a.map((variant) => ({
37427
+ id: variant.id,
37428
+ value: variant.title
37429
+ }))
37430
+ },
37431
+ resolver: t(EditProductSchema$1)
37432
+ });
37433
+ const { mutateAsync, isPending } = useUpdateProduct(product.id);
37434
+ const handleSubmit = form.handleSubmit(async (data) => {
37435
+ const optionValues = data.denominations.map(
37436
+ (denomination) => denomination.value
37437
+ );
37438
+ const options = [
37439
+ {
37440
+ title: "denomination",
37441
+ values: optionValues
37442
+ }
37443
+ ];
37444
+ await mutateAsync(
37445
+ {
37446
+ options,
37447
+ variants: data.denominations.map((denomination) => ({
37448
+ id: denomination.id,
37449
+ title: denomination.value,
37450
+ manage_inventory: false,
37451
+ options: {
37452
+ denomination: denomination.value
37453
+ }
37454
+ }))
37455
+ },
37456
+ {
37457
+ onSuccess: () => {
37458
+ ui.toast.success(`Denominations updated successfully`);
37459
+ handleSuccess();
37460
+ },
37461
+ onError: (e2) => {
37462
+ ui.toast.error(e2.message);
37463
+ }
37464
+ }
37465
+ );
37466
+ });
37467
+ const {
37468
+ fields: denominationsFields,
37469
+ append: addDenomination,
37470
+ remove: removeDenomination
37471
+ } = useFieldArray({
37472
+ name: "denominations",
37473
+ control: form.control
37474
+ });
37475
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
37476
+ KeyboundForm,
37477
+ {
37478
+ onSubmit: handleSubmit,
37479
+ className: "flex flex-1 flex-col overflow-hidden",
37480
+ children: [
37481
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
37482
+ denominationsFields.map((denominationField, index) => {
37483
+ return /* @__PURE__ */ jsxRuntime.jsxs(
37484
+ "div",
37485
+ {
37486
+ className: "flex items-center justify-between shadow-elevation-card-rest bg-ui-bg-component transition-fg rounded-md px-4 py-2",
37487
+ children: [
37488
+ /* @__PURE__ */ jsxRuntime.jsx(
37489
+ Form$2.Field,
37490
+ {
37491
+ control: form.control,
37492
+ name: `denominations.${index}.value`,
37493
+ render: ({ field }) => {
37494
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "w-full", children: [
37495
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, placeholder: "100" }) }),
37496
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
37497
+ ] });
37498
+ }
37499
+ },
37500
+ denominationField.id
37501
+ ),
37502
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center rounded-xl", children: /* @__PURE__ */ jsxRuntime.jsx(
37503
+ ui.Button,
37504
+ {
37505
+ size: "small",
37506
+ variant: "secondary",
37507
+ type: "button",
37508
+ className: "rounded-full p-0 ml-4",
37509
+ onClick: () => {
37510
+ removeDenomination(index);
37511
+ },
37512
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XCircleSolid, { className: "rounded-full" })
37513
+ }
37514
+ ) })
37515
+ ]
37516
+ },
37517
+ denominationField.id
37518
+ );
37519
+ }),
37520
+ /* @__PURE__ */ jsxRuntime.jsx(
37521
+ ui.Button,
37522
+ {
37523
+ size: "small",
37524
+ variant: "secondary",
37525
+ type: "button",
37526
+ className: "w-full",
37527
+ onClick: () => {
37528
+ addDenomination({ value: "", prices: {} });
37529
+ },
37530
+ children: "Add denomination"
37531
+ }
37532
+ ),
37533
+ form.formState.errors.denominations && /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", children: "Please add at least one denomination." })
37534
+ ] }) }) }) }),
37535
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
37536
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
37537
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
37538
+ ] }) })
37539
+ ]
37540
+ }
37541
+ ) });
37542
+ };
37543
+ const GiftCardProductEdit$1 = () => {
37544
+ const { id } = reactRouterDom.useParams();
37545
+ const { product, isLoading, isError, error } = useProduct(id, {});
37546
+ if (isError) {
37547
+ throw error;
37548
+ }
37549
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
37550
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
37551
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit gift cards denominations" }) }),
37552
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card denominations" })
37553
+ ] }),
37554
+ !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditDenominationsForm, { product })
37555
+ ] });
37556
+ };
37557
+ const EditProductSchema = z.object({
37558
+ status: z.enum(["draft", "published", "proposed", "rejected"]),
37559
+ title: z.string().min(1),
37560
+ subtitle: z.string().optional(),
37561
+ handle: z.string().min(1),
37562
+ description: z.string().optional()
37563
+ });
37564
+ const GiftCardProductEditForm = ({
37565
+ product
37566
+ }) => {
37567
+ const { handleSuccess } = useRouteModal();
37568
+ const form = useForm({
37569
+ defaultValues: {
37570
+ status: product.status,
37571
+ title: product.title,
37572
+ subtitle: product.subtitle || "",
37456
37573
  handle: product.handle || "",
37457
37574
  description: product.description || ""
37458
37575
  },
37459
- resolver: t(EditProductSchema$1)
37576
+ resolver: t(EditProductSchema)
37460
37577
  });
37461
37578
  const { mutateAsync, isPending } = useUpdateProduct(product.id);
37462
37579
  const handleSubmit = form.handleSubmit(async (data) => {
@@ -37567,174 +37684,28 @@ const GiftCardProductEditForm = ({
37567
37684
  children: "/"
37568
37685
  }
37569
37686
  ) }),
37570
- /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, className: "pl-10" })
37571
- ] }) }),
37572
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
37573
- ] });
37574
- }
37575
- }
37576
- ),
37577
- /* @__PURE__ */ jsxRuntime.jsx(
37578
- Form$2.Field,
37579
- {
37580
- control: form.control,
37581
- name: "description",
37582
- render: ({ field }) => {
37583
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
37584
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Description" }),
37585
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
37586
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
37587
- ] });
37588
- }
37589
- }
37590
- )
37591
- ] }) }) }),
37592
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
37593
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
37594
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
37595
- ] }) })
37596
- ]
37597
- }
37598
- ) });
37599
- };
37600
- const GiftCardProductEdit$1 = () => {
37601
- const { id } = reactRouterDom.useParams();
37602
- const { product, isLoading, isError, error } = useProduct(id, {});
37603
- if (isError) {
37604
- throw error;
37605
- }
37606
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
37607
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
37608
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit gift card product" }) }),
37609
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card product" })
37610
- ] }),
37611
- !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditForm, { product })
37612
- ] });
37613
- };
37614
- const EditProductSchema = z.object({
37615
- denominations: z.array(
37616
- z.object({
37617
- id: z.string().optional(),
37618
- value: z.string().min(1),
37619
- prices: z.record(z.string(), optionalFloat).optional()
37620
- })
37621
- ).min(1)
37622
- });
37623
- const GiftCardProductEditDenominationsForm = ({
37624
- product
37625
- }) => {
37626
- var _a;
37627
- const { handleSuccess } = useRouteModal();
37628
- const form = useForm({
37629
- defaultValues: {
37630
- denominations: (_a = product.variants) == null ? void 0 : _a.map((variant) => ({
37631
- id: variant.id,
37632
- value: variant.title
37633
- }))
37634
- },
37635
- resolver: t(EditProductSchema)
37636
- });
37637
- const { mutateAsync, isPending } = useUpdateProduct(product.id);
37638
- const handleSubmit = form.handleSubmit(async (data) => {
37639
- const optionValues = data.denominations.map(
37640
- (denomination) => denomination.value
37641
- );
37642
- const options = [
37643
- {
37644
- title: "denomination",
37645
- values: optionValues
37646
- }
37647
- ];
37648
- await mutateAsync(
37649
- {
37650
- options,
37651
- variants: data.denominations.map((denomination) => ({
37652
- id: denomination.id,
37653
- title: denomination.value,
37654
- options: {
37655
- denomination: denomination.value
37656
- }
37657
- }))
37658
- },
37659
- {
37660
- onSuccess: () => {
37661
- ui.toast.success(`Denominations updated successfully`);
37662
- handleSuccess();
37663
- },
37664
- onError: (e2) => {
37665
- ui.toast.error(e2.message);
37666
- }
37667
- }
37668
- );
37669
- });
37670
- const {
37671
- fields: denominationsFields,
37672
- append: addDenomination,
37673
- remove: removeDenomination
37674
- } = useFieldArray({
37675
- name: "denominations",
37676
- control: form.control
37677
- });
37678
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
37679
- KeyboundForm,
37680
- {
37681
- onSubmit: handleSubmit,
37682
- className: "flex flex-1 flex-col overflow-hidden",
37683
- children: [
37684
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
37685
- denominationsFields.map((denominationField, index) => {
37686
- return /* @__PURE__ */ jsxRuntime.jsxs(
37687
- "div",
37688
- {
37689
- className: "flex items-center justify-between shadow-elevation-card-rest bg-ui-bg-component transition-fg rounded-md px-4 py-2",
37690
- children: [
37691
- /* @__PURE__ */ jsxRuntime.jsx(
37692
- Form$2.Field,
37693
- {
37694
- control: form.control,
37695
- name: `denominations.${index}.value`,
37696
- render: ({ field }) => {
37697
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "w-full", children: [
37698
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, placeholder: "100" }) }),
37699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
37700
- ] });
37701
- }
37702
- },
37703
- denominationField.id
37704
- ),
37705
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center rounded-xl", children: /* @__PURE__ */ jsxRuntime.jsx(
37706
- ui.Button,
37707
- {
37708
- size: "small",
37709
- variant: "secondary",
37710
- type: "button",
37711
- className: "rounded-full p-0 ml-4",
37712
- onClick: () => {
37713
- removeDenomination(index);
37714
- },
37715
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XCircleSolid, { className: "rounded-full" })
37716
- }
37717
- ) })
37718
- ]
37719
- },
37720
- denominationField.id
37721
- );
37722
- }),
37723
- /* @__PURE__ */ jsxRuntime.jsx(
37724
- ui.Button,
37725
- {
37726
- size: "small",
37727
- variant: "secondary",
37728
- type: "button",
37729
- className: "w-full",
37730
- onClick: () => {
37731
- addDenomination({ value: "", prices: {} });
37732
- },
37733
- children: "Add denomination"
37687
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, className: "pl-10" })
37688
+ ] }) }),
37689
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
37690
+ ] });
37691
+ }
37734
37692
  }
37735
37693
  ),
37736
- form.formState.errors.denominations && /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", children: "Please add at least one denomination." })
37737
- ] }) }) }) }),
37694
+ /* @__PURE__ */ jsxRuntime.jsx(
37695
+ Form$2.Field,
37696
+ {
37697
+ control: form.control,
37698
+ name: "description",
37699
+ render: ({ field }) => {
37700
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
37701
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Description" }),
37702
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
37703
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
37704
+ ] });
37705
+ }
37706
+ }
37707
+ )
37708
+ ] }) }) }),
37738
37709
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
37739
37710
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
37740
37711
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -37751,10 +37722,10 @@ const GiftCardProductEdit = () => {
37751
37722
  }
37752
37723
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
37753
37724
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
37754
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit gift cards denominations" }) }),
37755
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card denominations" })
37725
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit gift card product" }) }),
37726
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card product" })
37756
37727
  ] }),
37757
- !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditDenominationsForm, { product })
37728
+ !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditForm, { product })
37758
37729
  ] });
37759
37730
  };
37760
37731
  const EditProductMediaForm = ({ product }) => {
@@ -38370,6 +38341,112 @@ const ProductMedia = () => {
38370
38341
  ready && /* @__PURE__ */ jsxRuntime.jsx(ProductMediaView, { product })
38371
38342
  ] });
38372
38343
  };
38344
+ const EditSalesChannelsSchema = objectType({
38345
+ sales_channels: arrayType(stringType()).optional()
38346
+ });
38347
+ const PAGE_SIZE = 50;
38348
+ const PREFIX = "sc";
38349
+ const EditSalesChannelsForm = ({
38350
+ product
38351
+ }) => {
38352
+ var _a, _b;
38353
+ const { handleSuccess } = useRouteModal();
38354
+ const form = useForm({
38355
+ defaultValues: {
38356
+ sales_channels: ((_a = product.sales_channels) == null ? void 0 : _a.map((sc) => sc.id)) ?? []
38357
+ },
38358
+ resolver: t(EditSalesChannelsSchema)
38359
+ });
38360
+ const { setValue: setValue2 } = form;
38361
+ const initialState2 = ((_b = product.sales_channels) == null ? void 0 : _b.reduce((acc, curr) => {
38362
+ acc[curr.id] = true;
38363
+ return acc;
38364
+ }, {})) ?? {};
38365
+ const [rowSelection, setRowSelection] = React.useState(initialState2);
38366
+ React.useEffect(() => {
38367
+ const ids2 = Object.keys(rowSelection);
38368
+ setValue2("sales_channels", ids2, {
38369
+ shouldDirty: true,
38370
+ shouldTouch: true
38371
+ });
38372
+ }, [rowSelection, setValue2]);
38373
+ const searchParams = useSalesChannelTableQuery({
38374
+ pageSize: PAGE_SIZE,
38375
+ prefix: PREFIX
38376
+ });
38377
+ const { sales_channels, count: count2, isLoading, isError, error } = useSalesChannels(
38378
+ {
38379
+ ...searchParams
38380
+ },
38381
+ {
38382
+ placeholderData: reactQuery.keepPreviousData
38383
+ }
38384
+ );
38385
+ const filters = useSalesChannelTableFilters();
38386
+ const emptyState = useSalesChannelTableEmptyState();
38387
+ const columns = useColumns();
38388
+ const { mutateAsync, isPending: isMutating } = useUpdateProduct(product.id);
38389
+ const handleSubmit = form.handleSubmit(async (data) => {
38390
+ const arr = data.sales_channels ?? [];
38391
+ const sales_channels2 = arr.map((id) => {
38392
+ return {
38393
+ id
38394
+ };
38395
+ });
38396
+ await mutateAsync(
38397
+ {
38398
+ sales_channels: sales_channels2
38399
+ },
38400
+ {
38401
+ onSuccess: () => {
38402
+ handleSuccess();
38403
+ }
38404
+ }
38405
+ );
38406
+ });
38407
+ if (isError) {
38408
+ throw error;
38409
+ }
38410
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
38411
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
38412
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
38413
+ DataTable,
38414
+ {
38415
+ data: sales_channels,
38416
+ columns,
38417
+ getRowId: (row) => row.id,
38418
+ rowCount: count2,
38419
+ isLoading,
38420
+ filters,
38421
+ rowSelection: {
38422
+ state: rowSelection,
38423
+ onRowSelectionChange: setRowSelection
38424
+ },
38425
+ autoFocusSearch: true,
38426
+ layout: "fill",
38427
+ emptyState,
38428
+ prefix: PREFIX
38429
+ }
38430
+ ) }),
38431
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
38432
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
38433
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", isLoading: isMutating, onClick: handleSubmit, children: "Save" })
38434
+ ] }) })
38435
+ ] }) });
38436
+ };
38437
+ const columnHelper$1 = ui.createDataTableColumnHelper();
38438
+ const useColumns = () => {
38439
+ const columns = useSalesChannelTableColumns();
38440
+ return React.useMemo(() => [columnHelper$1.select(), ...columns], [columns]);
38441
+ };
38442
+ const ProductSalesChannels = () => {
38443
+ const { id } = reactRouterDom.useParams();
38444
+ const { product, isLoading, isError, error } = useProduct(id);
38445
+ if (isError) {
38446
+ throw error;
38447
+ }
38448
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { children: !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(EditSalesChannelsForm, { product }) });
38449
+ };
38373
38450
  const VariantPricingForm = ({ form }) => {
38374
38451
  const { store } = useStore$1();
38375
38452
  const { regions } = useRegions({ limit: 9999 });
@@ -38394,7 +38471,7 @@ const VariantPricingForm = ({ form }) => {
38394
38471
  }
38395
38472
  );
38396
38473
  };
38397
- const columnHelper$1 = createDataGridHelper();
38474
+ const columnHelper = createDataGridHelper();
38398
38475
  const useVariantPriceGridColumns = ({
38399
38476
  currencies: currencies2 = [],
38400
38477
  regions = [],
@@ -38402,7 +38479,7 @@ const useVariantPriceGridColumns = ({
38402
38479
  }) => {
38403
38480
  return React.useMemo(() => {
38404
38481
  return [
38405
- columnHelper$1.column({
38482
+ columnHelper.column({
38406
38483
  id: "Title",
38407
38484
  header: "Title",
38408
38485
  cell: (context) => {
@@ -38528,112 +38605,6 @@ const ProductPrices = () => {
38528
38605
  }
38529
38606
  return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { children: !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(PricingEdit, { product, variantId: variant_id }) });
38530
38607
  };
38531
- const EditSalesChannelsSchema = objectType({
38532
- sales_channels: arrayType(stringType()).optional()
38533
- });
38534
- const PAGE_SIZE = 50;
38535
- const PREFIX = "sc";
38536
- const EditSalesChannelsForm = ({
38537
- product
38538
- }) => {
38539
- var _a, _b;
38540
- const { handleSuccess } = useRouteModal();
38541
- const form = useForm({
38542
- defaultValues: {
38543
- sales_channels: ((_a = product.sales_channels) == null ? void 0 : _a.map((sc) => sc.id)) ?? []
38544
- },
38545
- resolver: t(EditSalesChannelsSchema)
38546
- });
38547
- const { setValue: setValue2 } = form;
38548
- const initialState2 = ((_b = product.sales_channels) == null ? void 0 : _b.reduce((acc, curr) => {
38549
- acc[curr.id] = true;
38550
- return acc;
38551
- }, {})) ?? {};
38552
- const [rowSelection, setRowSelection] = React.useState(initialState2);
38553
- React.useEffect(() => {
38554
- const ids2 = Object.keys(rowSelection);
38555
- setValue2("sales_channels", ids2, {
38556
- shouldDirty: true,
38557
- shouldTouch: true
38558
- });
38559
- }, [rowSelection, setValue2]);
38560
- const searchParams = useSalesChannelTableQuery({
38561
- pageSize: PAGE_SIZE,
38562
- prefix: PREFIX
38563
- });
38564
- const { sales_channels, count: count2, isLoading, isError, error } = useSalesChannels(
38565
- {
38566
- ...searchParams
38567
- },
38568
- {
38569
- placeholderData: reactQuery.keepPreviousData
38570
- }
38571
- );
38572
- const filters = useSalesChannelTableFilters();
38573
- const emptyState = useSalesChannelTableEmptyState();
38574
- const columns = useColumns();
38575
- const { mutateAsync, isPending: isMutating } = useUpdateProduct(product.id);
38576
- const handleSubmit = form.handleSubmit(async (data) => {
38577
- const arr = data.sales_channels ?? [];
38578
- const sales_channels2 = arr.map((id) => {
38579
- return {
38580
- id
38581
- };
38582
- });
38583
- await mutateAsync(
38584
- {
38585
- sales_channels: sales_channels2
38586
- },
38587
- {
38588
- onSuccess: () => {
38589
- handleSuccess();
38590
- }
38591
- }
38592
- );
38593
- });
38594
- if (isError) {
38595
- throw error;
38596
- }
38597
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
38598
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
38599
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
38600
- DataTable,
38601
- {
38602
- data: sales_channels,
38603
- columns,
38604
- getRowId: (row) => row.id,
38605
- rowCount: count2,
38606
- isLoading,
38607
- filters,
38608
- rowSelection: {
38609
- state: rowSelection,
38610
- onRowSelectionChange: setRowSelection
38611
- },
38612
- autoFocusSearch: true,
38613
- layout: "fill",
38614
- emptyState,
38615
- prefix: PREFIX
38616
- }
38617
- ) }),
38618
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
38619
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
38620
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", isLoading: isMutating, onClick: handleSubmit, children: "Save" })
38621
- ] }) })
38622
- ] }) });
38623
- };
38624
- const columnHelper = ui.createDataTableColumnHelper();
38625
- const useColumns = () => {
38626
- const columns = useSalesChannelTableColumns();
38627
- return React.useMemo(() => [columnHelper.select(), ...columns], [columns]);
38628
- };
38629
- const ProductSalesChannels = () => {
38630
- const { id } = reactRouterDom.useParams();
38631
- const { product, isLoading, isError, error } = useProduct(id);
38632
- if (isError) {
38633
- throw error;
38634
- }
38635
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { children: !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(EditSalesChannelsForm, { product }) });
38636
- };
38637
38608
  const widgetModule = { widgets: [
38638
38609
  {
38639
38610
  Component: CustomerStoreCreditWidget,
@@ -38678,13 +38649,13 @@ const routeModule = {
38678
38649
  Component: GiftCardDetailsPage,
38679
38650
  path: "/gift-cards/:id",
38680
38651
  children: [
38681
- {
38682
- Component: Note,
38683
- path: "/gift-cards/:id/note"
38684
- },
38685
38652
  {
38686
38653
  Component: GiftCardExpiration,
38687
38654
  path: "/gift-cards/:id/expiration"
38655
+ },
38656
+ {
38657
+ Component: Note,
38658
+ path: "/gift-cards/:id/note"
38688
38659
  }
38689
38660
  ]
38690
38661
  },
@@ -38704,11 +38675,11 @@ const routeModule = {
38704
38675
  children: [
38705
38676
  {
38706
38677
  Component: GiftCardProductEdit$1,
38707
- path: "/gift-cards/gift-card-products/:id/edit"
38678
+ path: "/gift-cards/gift-card-products/:id/denominations"
38708
38679
  },
38709
38680
  {
38710
38681
  Component: GiftCardProductEdit,
38711
- path: "/gift-cards/gift-card-products/:id/denominations"
38682
+ path: "/gift-cards/gift-card-products/:id/edit"
38712
38683
  }
38713
38684
  ]
38714
38685
  },
@@ -38716,13 +38687,13 @@ const routeModule = {
38716
38687
  Component: ProductMedia,
38717
38688
  path: "/gift-cards/gift-card-products/:id/media"
38718
38689
  },
38719
- {
38720
- Component: ProductPrices,
38721
- path: "/gift-cards/gift-card-products/:id/prices"
38722
- },
38723
38690
  {
38724
38691
  Component: ProductSalesChannels,
38725
38692
  path: "/gift-cards/gift-card-products/:id/sales-channels"
38693
+ },
38694
+ {
38695
+ Component: ProductPrices,
38696
+ path: "/gift-cards/gift-card-products/:id/prices"
38726
38697
  }
38727
38698
  ]
38728
38699
  };