@medusajs/loyalty-plugin 2.22.3-snapshot-20261030141225 → 2.22.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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  const jsxRuntime = require("react/jsx-runtime");
3
3
  const adminSdk = require("@medusajs/admin-sdk");
4
+ const hooks = require("@medusajs/dashboard/hooks");
4
5
  const ui = require("@medusajs/ui");
5
6
  const reactRouterDom = require("react-router-dom");
6
7
  const React = require("react");
@@ -8,8 +9,8 @@ const icons = require("@medusajs/icons");
8
9
  const reactQuery = require("@tanstack/react-query");
9
10
  const Medusa = require("@medusajs/js-sdk");
10
11
  const components = require("@medusajs/dashboard/components");
11
- const ReactDOM = require("react-dom");
12
12
  const zod = require("@medusajs/framework/zod");
13
+ const ReactDOM = require("react-dom");
13
14
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
14
15
  function _interopNamespace(e) {
15
16
  if (e && e.__esModule) return e;
@@ -428,10 +429,16 @@ const formatAmount = (amount, currency_code) => {
428
429
  };
429
430
  const CustomerStoreCreditWidget = () => {
430
431
  const params = reactRouterDom.useParams();
431
- const { store_credit_accounts: storeCreditAccounts, isPending } = useStoreCreditAccounts({
432
- customer_id: params.id
433
- });
434
- if (isPending) {
432
+ const { hasPermission } = hooks.usePermissions();
433
+ const canRead = hasPermission("store_credit_account:read");
434
+ const canCreate = hasPermission("store_credit_account:create");
435
+ const { store_credit_accounts: storeCreditAccounts, isPending } = useStoreCreditAccounts(
436
+ {
437
+ customer_id: params.id
438
+ },
439
+ { enabled: canRead }
440
+ );
441
+ if (!canRead || isPending) {
435
442
  return null;
436
443
  }
437
444
  const createHref = `/store-credit-accounts/create?prefill_customer_id=${params.id}`;
@@ -440,12 +447,12 @@ const CustomerStoreCreditWidget = () => {
440
447
  Header$5,
441
448
  {
442
449
  title: "Store Credit Accounts",
443
- actions: [
450
+ actions: canCreate ? [
444
451
  {
445
452
  type: "custom",
446
453
  children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: createHref, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Create" }) })
447
454
  }
448
- ]
455
+ ] : []
449
456
  }
450
457
  ),
451
458
  !storeCreditAccounts?.length && /* @__PURE__ */ jsxRuntime.jsx(
@@ -453,7 +460,7 @@ const CustomerStoreCreditWidget = () => {
453
460
  {
454
461
  className: "border-t",
455
462
  title: "No store credit accounts",
456
- message: "Create an account to credit this customer",
463
+ message: canCreate ? "Create an account to credit this customer" : "This customer has no store credit accounts",
457
464
  icon: null
458
465
  }
459
466
  ),
@@ -488,10 +495,16 @@ const useOrder = (id, query, options) => {
488
495
  };
489
496
  const OrderGiftCardsWidget = () => {
490
497
  const params = reactRouterDom.useParams();
491
- const { order } = useOrder(params.id, {
492
- fields: "+*gift_cards"
493
- });
494
- if (!order?.gift_cards?.length) {
498
+ const { hasPermission } = hooks.usePermissions();
499
+ const canRead = hasPermission("gift_card:read");
500
+ const { order } = useOrder(
501
+ params.id,
502
+ {
503
+ fields: "+gift_cards"
504
+ },
505
+ { enabled: canRead }
506
+ );
507
+ if (!canRead || !order?.gift_cards?.length) {
495
508
  return;
496
509
  }
497
510
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
@@ -5576,6 +5589,14 @@ const useGiftCardProductsTableQuery$1 = ({
5576
5589
  };
5577
5590
  };
5578
5591
  const PAGE_SIZE$7 = 10;
5592
+ const MANAGE_CHANNEL_PRODUCTS_PERMISSIONS = [
5593
+ "sales_channel:update",
5594
+ "product:update"
5595
+ ];
5596
+ const useCanManageChannelProducts = () => {
5597
+ const { hasAllPermissions } = hooks.usePermissions();
5598
+ return hasAllPermissions([...MANAGE_CHANNEL_PRODUCTS_PERMISSIONS]);
5599
+ };
5579
5600
  const SalesChannelGiftCardsSection = ({
5580
5601
  salesChannel
5581
5602
  }) => {
@@ -5594,7 +5615,8 @@ const SalesChannelGiftCardsSection = ({
5594
5615
  sales_channel_id: [salesChannel.id],
5595
5616
  is_giftcard: true
5596
5617
  });
5597
- const columns = useColumns$4({ salesChannel });
5618
+ const canManageProducts = useCanManageChannelProducts();
5619
+ const columns = useColumns$4({ salesChannel, canManageProducts });
5598
5620
  const filters = useGiftCardProductsFilters$1();
5599
5621
  const { mutateAsync } = useSalesChannelRemoveProducts(salesChannel.id);
5600
5622
  const prompt = ui.usePrompt();
@@ -5630,13 +5652,13 @@ const SalesChannelGiftCardsSection = ({
5630
5652
  data: products ?? [],
5631
5653
  columns,
5632
5654
  pageSize: PAGE_SIZE$7,
5633
- commands: [
5655
+ commands: canManageProducts ? [
5634
5656
  {
5635
5657
  action: handleRemove,
5636
5658
  label: "Remove",
5637
5659
  shortcut: "r"
5638
5660
  }
5639
- ],
5661
+ ] : [],
5640
5662
  rowCount: count2,
5641
5663
  pagination: true,
5642
5664
  search: true,
@@ -5652,46 +5674,24 @@ const SalesChannelGiftCardsSection = ({
5652
5674
  ],
5653
5675
  queryObject: raw,
5654
5676
  emptyState,
5655
- actions: [
5677
+ actions: canManageProducts ? [
5656
5678
  {
5657
5679
  label: "Add",
5658
5680
  to: `/gift-cards/gift-card-products/${salesChannel.id}/add-gift-card-products`
5659
5681
  }
5660
- ]
5682
+ ] : []
5661
5683
  }
5662
5684
  ) });
5663
5685
  };
5664
5686
  const columnHelper$b = createColumnHelper();
5665
- const useColumns$4 = ({ salesChannel }) => {
5687
+ const useColumns$4 = ({
5688
+ salesChannel,
5689
+ canManageProducts
5690
+ }) => {
5666
5691
  const base = useProductTableColumns();
5667
5692
  return React.useMemo(
5668
5693
  () => [
5669
- columnHelper$b.display({
5670
- id: "select",
5671
- header: ({ table }) => {
5672
- return /* @__PURE__ */ jsxRuntime.jsx(
5673
- ui.Checkbox,
5674
- {
5675
- checked: table.getIsSomePageRowsSelected() ? "indeterminate" : table.getIsAllPageRowsSelected(),
5676
- onCheckedChange: (value) => table.getRowModel().rows.forEach((row) => {
5677
- row.toggleSelected(!!value);
5678
- })
5679
- }
5680
- );
5681
- },
5682
- cell: ({ row }) => {
5683
- return /* @__PURE__ */ jsxRuntime.jsx(
5684
- ui.Checkbox,
5685
- {
5686
- checked: row.getIsSelected(),
5687
- onCheckedChange: (value) => row.toggleSelected(!!value),
5688
- onClick: (e) => {
5689
- e.stopPropagation();
5690
- }
5691
- }
5692
- );
5693
- }
5694
- }),
5694
+ ...canManageProducts ? [selectColumn] : [],
5695
5695
  ...base,
5696
5696
  columnHelper$b.display({
5697
5697
  id: "actions",
@@ -5700,18 +5700,46 @@ const useColumns$4 = ({ salesChannel }) => {
5700
5700
  ProductListCellActions,
5701
5701
  {
5702
5702
  productId: row.original.id,
5703
- salesChannelId: salesChannel.id
5703
+ salesChannelId: salesChannel.id,
5704
+ canManageProducts
5704
5705
  }
5705
5706
  ) });
5706
5707
  }
5707
5708
  })
5708
5709
  ],
5709
- [base]
5710
+ [base, canManageProducts]
5710
5711
  );
5711
5712
  };
5713
+ const selectColumn = columnHelper$b.display({
5714
+ id: "select",
5715
+ header: ({ table }) => {
5716
+ return /* @__PURE__ */ jsxRuntime.jsx(
5717
+ ui.Checkbox,
5718
+ {
5719
+ checked: table.getIsSomePageRowsSelected() ? "indeterminate" : table.getIsAllPageRowsSelected(),
5720
+ onCheckedChange: (value) => table.getRowModel().rows.forEach((row) => {
5721
+ row.toggleSelected(!!value);
5722
+ })
5723
+ }
5724
+ );
5725
+ },
5726
+ cell: ({ row }) => {
5727
+ return /* @__PURE__ */ jsxRuntime.jsx(
5728
+ ui.Checkbox,
5729
+ {
5730
+ checked: row.getIsSelected(),
5731
+ onCheckedChange: (value) => row.toggleSelected(!!value),
5732
+ onClick: (e) => {
5733
+ e.stopPropagation();
5734
+ }
5735
+ }
5736
+ );
5737
+ }
5738
+ });
5712
5739
  const ProductListCellActions = ({
5713
5740
  salesChannelId,
5714
- productId
5741
+ productId,
5742
+ canManageProducts
5715
5743
  }) => {
5716
5744
  const { mutateAsync } = useSalesChannelRemoveProducts(salesChannelId);
5717
5745
  const onRemove = async () => {
@@ -5738,13 +5766,13 @@ const ProductListCellActions = ({
5738
5766
  ]
5739
5767
  },
5740
5768
  {
5741
- actions: [
5769
+ actions: canManageProducts ? [
5742
5770
  {
5743
5771
  icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
5744
5772
  label: "Remove",
5745
5773
  onClick: onRemove
5746
5774
  }
5747
- ]
5775
+ ] : []
5748
5776
  }
5749
5777
  ]
5750
5778
  }
@@ -5752,10 +5780,12 @@ const ProductListCellActions = ({
5752
5780
  };
5753
5781
  const SalesChannelGiftCardsWidget = () => {
5754
5782
  const params = reactRouterDom.useParams();
5783
+ const { hasPermission } = hooks.usePermissions();
5784
+ const canReadProducts = hasPermission("product:read");
5755
5785
  const { sales_channel: salesChannel } = useSalesChannel(params.id, {
5756
- enabled: !!params.id
5786
+ enabled: !!params.id && canReadProducts
5757
5787
  });
5758
- if (!salesChannel) {
5788
+ if (!canReadProducts || !salesChannel) {
5759
5789
  return null;
5760
5790
  }
5761
5791
  return /* @__PURE__ */ jsxRuntime.jsx(SalesChannelGiftCardsSection, { salesChannel });
@@ -5764,7 +5794,7 @@ adminSdk.defineWidgetConfig({
5764
5794
  zone: "sales_channel.details.after",
5765
5795
  id: "medusa:sales-channel-gift-cards-widget"
5766
5796
  });
5767
- const GiftCardIcon = (props) => {
5797
+ const StoreCreditIcon = (props) => {
5768
5798
  return /* @__PURE__ */ jsxRuntime.jsxs(
5769
5799
  "svg",
5770
5800
  {
@@ -5775,197 +5805,49 @@ const GiftCardIcon = (props) => {
5775
5805
  xmlns: "http://www.w3.org/2000/svg",
5776
5806
  ...props,
5777
5807
  children: [
5778
- /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "15", height: "15", fill: "#F97316" }),
5808
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "15", height: "15", fill: "#8B5CF6" }),
5779
5809
  /* @__PURE__ */ jsxRuntime.jsx(
5780
5810
  "rect",
5781
5811
  {
5782
5812
  width: "15",
5783
5813
  height: "15",
5784
- fill: "url(#paint0_linear_28788_25808)",
5814
+ fill: "url(#paint0_linear_29181_44790)",
5785
5815
  fillOpacity: "0.2"
5786
5816
  }
5787
5817
  ),
5788
- /* @__PURE__ */ jsxRuntime.jsxs("g", { clipPath: "url(#clip0_28788_25808)", children: [
5789
- /* @__PURE__ */ jsxRuntime.jsx(
5790
- "path",
5791
- {
5792
- d: "M7.5 6.375H5.375C4.479 6.375 3.75 5.618 3.75 4.688C3.75 3.757 4.479 3 5.375 3C7.365 3 8.019 5.569 8.047 5.678C8.088 5.846 8.05 6.023 7.943 6.16C7.836 6.296 7.673 6.375 7.5 6.375ZM5.375 4.125C5.099 4.125 4.875 4.377 4.875 4.688C4.875 4.998 5.099 5.25 5.375 5.25H6.688C6.439 4.736 6.011 4.125 5.375 4.125Z",
5793
- fill: "white"
5794
- }
5795
- ),
5796
- /* @__PURE__ */ jsxRuntime.jsx(
5797
- "path",
5798
- {
5799
- d: "M9.625 6.375H7.5C7.328 6.375 7.164 6.296 7.058 6.16C6.95 6.023 6.913 5.846 6.953 5.678C6.98 5.569 7.634 3 9.625 3C10.521 3 11.25 3.757 11.25 4.688C11.25 5.618 10.521 6.375 9.625 6.375ZM8.312 5.25H9.625C9.901 5.25 10.125 4.998 10.125 4.688C10.125 4.377 9.901 4.125 9.625 4.125C8.99 4.125 8.561 4.736 8.312 5.25Z",
5800
- fill: "white"
5801
- }
5802
- ),
5803
- /* @__PURE__ */ jsxRuntime.jsx(
5804
- "path",
5805
- {
5806
- d: "M11.438 6.375H3.562C3.252 6.375 3 6.123 3 5.813C3 5.502 3.252 5.25 3.562 5.25H11.438C11.748 5.25 12 5.502 12 5.813C12 6.123 11.748 6.375 11.438 6.375Z",
5807
- fill: "white"
5808
- }
5809
- ),
5810
- /* @__PURE__ */ jsxRuntime.jsx(
5811
- "path",
5812
- {
5813
- d: "M6.938 7.5H3.75V9.563C3.75 10.7 4.675 11.625 5.813 11.625H6.938V7.5Z",
5814
- fill: "white"
5815
- }
5816
- ),
5817
- /* @__PURE__ */ jsxRuntime.jsx(
5818
- "path",
5819
- {
5820
- d: "M8.063 7.5V11.625H9.188C10.325 11.625 11.25 10.7 11.25 9.563V7.5H8.063Z",
5821
- fill: "white"
5822
- }
5823
- )
5824
- ] }),
5825
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
5826
- /* @__PURE__ */ jsxRuntime.jsxs(
5827
- "linearGradient",
5828
- {
5829
- id: "paint0_linear_28788_25808",
5830
- x1: "7.5",
5831
- y1: "0",
5832
- x2: "7.5",
5833
- y2: "15",
5834
- gradientUnits: "userSpaceOnUse",
5835
- children: [
5836
- /* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "white" }),
5837
- /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
5838
- ]
5839
- }
5840
- ),
5841
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_28788_25808", children: /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "9", height: "9", fill: "white", transform: "translate(3 3)" }) })
5842
- ] })
5818
+ /* @__PURE__ */ jsxRuntime.jsx(
5819
+ "path",
5820
+ {
5821
+ d: "M12 6V5.813C12 4.675 11.075 3.75 9.938 3.75H5.063C3.925 3.75 3 4.675 3 5.813V6H12Z",
5822
+ fill: "white"
5823
+ }
5824
+ ),
5825
+ /* @__PURE__ */ jsxRuntime.jsx(
5826
+ "path",
5827
+ {
5828
+ d: "M3 7.125V9.188C3 10.325 3.925 11.25 5.063 11.25H9.938C11.075 11.25 12 10.325 12 9.188V7.125H3ZM9.938 9.75H8.438C8.127 9.75 7.875 9.498 7.875 9.188C7.875 8.877 8.127 8.625 8.438 8.625H9.938C10.248 8.625 10.5 8.877 10.5 9.188C10.5 9.498 10.248 9.75 9.938 9.75Z",
5829
+ fill: "white"
5830
+ }
5831
+ ),
5832
+ /* @__PURE__ */ jsxRuntime.jsx("defs", { children: /* @__PURE__ */ jsxRuntime.jsxs(
5833
+ "linearGradient",
5834
+ {
5835
+ id: "paint0_linear_29181_44790",
5836
+ x1: "7.5",
5837
+ y1: "0",
5838
+ x2: "7.5",
5839
+ y2: "15",
5840
+ gradientUnits: "userSpaceOnUse",
5841
+ children: [
5842
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "white" }),
5843
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
5844
+ ]
5845
+ }
5846
+ ) })
5843
5847
  ]
5844
5848
  }
5845
5849
  );
5846
5850
  };
5847
- const GiftCardProductsSection = () => {
5848
- const { products: giftCardProducts, count: count2 = 0 } = useProducts({
5849
- is_giftcard: true
5850
- });
5851
- const slicedProducts = giftCardProducts?.slice(0, 3) ?? [];
5852
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
5853
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
5854
- /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Gift Card Products" }),
5855
- /* @__PURE__ */ jsxRuntime.jsx(
5856
- reactRouterDom.Link,
5857
- {
5858
- to: `/gift-cards/gift-card-products/create`,
5859
- className: "text-ui-fg-muted text-sm px-6",
5860
- children: "Create"
5861
- }
5862
- )
5863
- ] }),
5864
- giftCardProducts?.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(
5865
- NoRecords,
5866
- {
5867
- className: "px-10 py-4 h-[200px]",
5868
- title: "No gift card products",
5869
- message: "There are no gift card products to show. Create one to get started.",
5870
- action: {
5871
- to: "/gift-cards/gift-card-products/create",
5872
- label: "Create gift card product"
5873
- }
5874
- }
5875
- ),
5876
- slicedProducts.map((giftCardProduct) => /* @__PURE__ */ jsxRuntime.jsx(
5877
- SidebarLink,
5878
- {
5879
- to: `/gift-cards/gift-card-products/${giftCardProduct.id}`,
5880
- labelKey: giftCardProduct.title,
5881
- descriptionKey: giftCardProduct.title,
5882
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Tag, {})
5883
- }
5884
- )),
5885
- count2 > 3 && /* @__PURE__ */ jsxRuntime.jsx(
5886
- reactRouterDom.Link,
5887
- {
5888
- to: "/gift-cards/gift-card-products",
5889
- className: "text-ui-fg-muted text-sm px-6 py-4 flex items-center justify-center",
5890
- children: "View more"
5891
- }
5892
- )
5893
- ] });
5894
- };
5895
- const _giftCardQueryKey = queryKeysFactory("gift-card");
5896
- const giftCardQueryKey = {
5897
- ..._giftCardQueryKey,
5898
- orders: (id) => [..._giftCardQueryKey.detail(id), "orders"]
5899
- };
5900
- const useGiftCards = (query, options) => {
5901
- const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
5902
- query: query2,
5903
- headers
5904
- });
5905
- const { data, ...rest } = reactQuery.useQuery({
5906
- ...options,
5907
- queryFn: () => fetchGiftCards(query),
5908
- queryKey: giftCardQueryKey.list(query)
5909
- });
5910
- return { ...data, ...rest };
5911
- };
5912
- const useGiftCard = (id, query, options) => {
5913
- const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
5914
- query: query2,
5915
- headers
5916
- });
5917
- const { data, ...rest } = reactQuery.useQuery({
5918
- queryFn: () => fetchGiftCard(id, query),
5919
- queryKey: giftCardQueryKey.detail(id, query),
5920
- ...options
5921
- });
5922
- return { ...data, ...rest };
5923
- };
5924
- const useGiftCardOrders = (id, options) => {
5925
- const fetchGiftCardOrders = (id2, query, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}/orders`, {
5926
- query,
5927
- headers
5928
- });
5929
- const { data, ...rest } = reactQuery.useQuery({
5930
- queryFn: () => fetchGiftCardOrders(id),
5931
- queryKey: giftCardQueryKey.orders(id),
5932
- ...options
5933
- });
5934
- return { ...data, ...rest };
5935
- };
5936
- const useUpdateGiftCard = (id, options) => {
5937
- const queryClient = reactQuery.useQueryClient();
5938
- const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
5939
- body,
5940
- method: "POST"
5941
- });
5942
- return reactQuery.useMutation({
5943
- mutationFn: async (payload) => updateGiftCard(id, payload),
5944
- onSuccess: (data, variables, context) => {
5945
- queryClient.invalidateQueries({
5946
- queryKey: giftCardQueryKey.detail(id)
5947
- });
5948
- queryClient.invalidateQueries({
5949
- queryKey: giftCardQueryKey.lists()
5950
- });
5951
- },
5952
- ...options
5953
- });
5954
- };
5955
- const useCreateGiftCard = (options) => {
5956
- const queryClient = reactQuery.useQueryClient();
5957
- const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
5958
- body,
5959
- method: "POST"
5960
- });
5961
- return reactQuery.useMutation({
5962
- mutationFn: (body) => createGiftCard(body),
5963
- onSuccess: (data, variables, context) => {
5964
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
5965
- },
5966
- ...options
5967
- });
5968
- };
5969
5851
  function getRelativeDate(date2) {
5970
5852
  const now = /* @__PURE__ */ new Date();
5971
5853
  return formatDistance(sub(new Date(date2), { minutes: 0 }), now, {
@@ -5983,30 +5865,51 @@ function formatDate(date2, withTime = true) {
5983
5865
  return format(new Date(date2), "dd MMM, yyyy");
5984
5866
  }
5985
5867
  const columnHelper$a = ui.createDataTableColumnHelper();
5986
- const useGiftCardTableColumns = () => {
5868
+ const useStoreCreditAccountTableColumns = () => {
5987
5869
  return React.useMemo(() => {
5988
5870
  return [
5989
- columnHelper$a.accessor("code", {
5990
- header: "Code",
5871
+ columnHelper$a.accessor("currency_code", {
5872
+ header: "Currency",
5991
5873
  cell: ({ row }) => {
5992
- return row.original.code;
5874
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", children: row.original.currency_code.toUpperCase() });
5993
5875
  }
5994
5876
  }),
5995
- columnHelper$a.accessor("line_item.product.title", {
5996
- header: "Product",
5877
+ columnHelper$a.accessor("customer.email", {
5878
+ header: "Customer",
5997
5879
  cell: ({ row }) => {
5998
- return row.original.line_item?.product?.title || "Custom Gift Card";
5880
+ return row.original.customer?.email ?? "N/A";
5999
5881
  }
6000
5882
  }),
6001
- columnHelper$a.accessor("created_at", {
6002
- header: "Date issued",
6003
- cell: ({ row }) => getRelativeDate(row.original.created_at)
5883
+ columnHelper$a.accessor("balance", {
5884
+ header: "Balance",
5885
+ cell: ({ row }) => {
5886
+ return formatAmount(
5887
+ row.original.balance,
5888
+ row.original.currency_code
5889
+ );
5890
+ }
6004
5891
  }),
6005
- columnHelper$a.accessor("value", {
6006
- header: "Value",
5892
+ columnHelper$a.accessor("credits", {
5893
+ header: "Credits",
6007
5894
  cell: ({ row }) => {
6008
- return formatAmount(row.original.value, row.original.currency_code);
5895
+ return formatAmount(
5896
+ row.original.credits,
5897
+ row.original.currency_code
5898
+ );
5899
+ }
5900
+ }),
5901
+ columnHelper$a.accessor("debits", {
5902
+ header: "Debits",
5903
+ cell: ({ row }) => {
5904
+ return formatAmount(
5905
+ row.original.debits,
5906
+ row.original.currency_code
5907
+ );
6009
5908
  }
5909
+ }),
5910
+ columnHelper$a.accessor("created_at", {
5911
+ header: "Created at",
5912
+ cell: ({ row }) => getRelativeDate(row.original.created_at)
6010
5913
  })
6011
5914
  ];
6012
5915
  }, []);
@@ -6030,8 +5933,8 @@ const useCustomers = (query, options) => {
6030
5933
  return { ...data, ...rest };
6031
5934
  };
6032
5935
  const filterHelper$2 = ui.createDataTableFilterHelper();
6033
- const useCustomerFilterOptions = () => {
6034
- const { customers } = useCustomers({ limit: 1e3 });
5936
+ const useCustomerFilterOptions = (enabled) => {
5937
+ const { customers } = useCustomers({ limit: 1e3 }, { enabled });
6035
5938
  return React.useMemo(() => {
6036
5939
  return customers?.map((customer) => {
6037
5940
  return {
@@ -6042,8 +5945,13 @@ const useCustomerFilterOptions = () => {
6042
5945
  }, [customers]);
6043
5946
  };
6044
5947
  const useCustomerFilters = () => {
6045
- const customerFilterOptions = useCustomerFilterOptions();
5948
+ const { hasPermission } = hooks.usePermissions();
5949
+ const canReadCustomers = hasPermission("customer:read");
5950
+ const customerFilterOptions = useCustomerFilterOptions(canReadCustomers);
6046
5951
  return React.useMemo(() => {
5952
+ if (!canReadCustomers) {
5953
+ return [];
5954
+ }
6047
5955
  return [
6048
5956
  filterHelper$2.accessor("customer_id", {
6049
5957
  type: "select",
@@ -6051,94 +5959,103 @@ const useCustomerFilters = () => {
6051
5959
  options: customerFilterOptions ?? []
6052
5960
  })
6053
5961
  ];
6054
- }, [customerFilterOptions]);
5962
+ }, [canReadCustomers, customerFilterOptions]);
6055
5963
  };
6056
- const useGiftCardFilters = () => {
5964
+ const useStoreCreditAccountFilters = () => {
6057
5965
  const dateFilterOptions = useDataTableDateFilters$1();
6058
5966
  const customerFilterOptions = useCustomerFilters();
6059
5967
  return React.useMemo(() => {
6060
5968
  return [...dateFilterOptions, ...customerFilterOptions];
6061
5969
  }, [dateFilterOptions, customerFilterOptions]);
6062
5970
  };
6063
- const useGiftCardTableQuery = ({
5971
+ const useStoreCreditAccountsTableQuery = ({
6064
5972
  prefix,
6065
5973
  pageSize = 20
6066
5974
  }) => {
6067
5975
  const queryObject = useQueryParams(
6068
- ["q", "offset", "customer_id", "created_at", "updated_at"],
5976
+ ["offset", "customer_id", "currency_code", "created_at", "updated_at"],
6069
5977
  prefix
6070
5978
  );
6071
- const { offset: offset2, created_at, updated_at, customer_id, ...rest } = queryObject;
5979
+ const {
5980
+ offset: offset2,
5981
+ created_at,
5982
+ updated_at,
5983
+ customer_id,
5984
+ currency_code,
5985
+ ...rest
5986
+ } = queryObject;
6072
5987
  const searchParams = {
6073
5988
  limit: pageSize,
6074
5989
  offset: offset2 ? Number(offset2) : 0,
6075
5990
  created_at: created_at ? JSON.parse(created_at) : void 0,
6076
5991
  updated_at: updated_at ? JSON.parse(updated_at) : void 0,
6077
5992
  customer_id: customer_id ? JSON.parse(customer_id) : void 0,
5993
+ currency_code: currency_code ? JSON.parse(currency_code) : void 0,
6078
5994
  ...rest
6079
5995
  };
6080
5996
  return searchParams;
6081
5997
  };
6082
5998
  const PAGE_SIZE$6 = 10;
6083
- function GiftCardsTable() {
6084
- const queryParams = useGiftCardTableQuery({
5999
+ function StoreCreditAccountsTable() {
6000
+ const queryParams = useStoreCreditAccountsTableQuery({
6085
6001
  pageSize: PAGE_SIZE$6
6086
6002
  });
6087
6003
  const {
6088
- gift_cards: giftCards,
6004
+ store_credit_accounts: storeCreditAccounts,
6089
6005
  isPending,
6090
6006
  count: count2
6091
- } = useGiftCards({
6007
+ } = useStoreCreditAccounts({
6092
6008
  ...queryParams,
6093
- order: queryParams.order ?? "-created_at",
6094
- fields: "+line_item.product.title"
6009
+ order: queryParams.order ?? "-created_at"
6095
6010
  });
6096
- const columns = useGiftCardTableColumns();
6097
- const filters = useGiftCardFilters();
6011
+ const columns = useStoreCreditAccountTableColumns();
6012
+ const filters = useStoreCreditAccountFilters();
6013
+ const { hasPermission } = hooks.usePermissions();
6014
+ const canCreate = hasPermission("store_credit_account:create");
6098
6015
  return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
6099
6016
  /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
6100
6017
  DataTable,
6101
6018
  {
6102
- data: giftCards,
6019
+ data: storeCreditAccounts ?? [],
6103
6020
  getRowId: (row) => row.id,
6104
6021
  columns,
6105
6022
  filters,
6106
6023
  isLoading: isPending,
6107
6024
  pageSize: PAGE_SIZE$6,
6108
6025
  rowCount: count2,
6109
- heading: "Gift Cards",
6026
+ enableSearch: false,
6027
+ heading: "Store Credit Accounts",
6110
6028
  rowHref: (row) => `${row.id}`,
6111
6029
  emptyState: {
6112
6030
  empty: {
6113
- heading: "No gift cards found",
6114
- description: "Create a gift card to get started."
6031
+ heading: "No store credit accounts found",
6032
+ description: "Create a new store credit account to get started."
6115
6033
  },
6116
6034
  filtered: {
6117
6035
  heading: "No results found",
6118
- description: "No gift cards match your filter criteria."
6036
+ description: "No store credit accounts match your filter criteria."
6119
6037
  }
6120
6038
  },
6121
- actions: [
6039
+ actions: canCreate ? [
6122
6040
  {
6123
6041
  label: "Create",
6124
- to: "create"
6042
+ to: "/store-credit-accounts/create"
6125
6043
  }
6126
- ]
6044
+ ] : []
6127
6045
  }
6128
6046
  ) }),
6129
6047
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
6130
6048
  ] });
6131
6049
  }
6132
- const GiftCardsPage = () => {
6050
+ const StoreCreditAccountsPage = () => {
6133
6051
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6134
6052
  /* @__PURE__ */ jsxRuntime.jsx(
6135
6053
  components.LayoutComposer,
6136
6054
  {
6137
- widgetsZonePrefix: "gift_card.list",
6138
- preferredLayoutId: "core:two-column",
6055
+ widgetsZonePrefix: "store_credit_account.list",
6056
+ preferredLayoutId: "core:single-column",
6139
6057
  sections: {
6140
- main: /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "GiftCardsTable", children: /* @__PURE__ */ jsxRuntime.jsx(GiftCardsTable, {}) }),
6141
- side: /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "GiftCardProductsSection", children: /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductsSection, {}) })
6058
+ main: /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountsTable", children: /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountsTable, {}) })
6142
6059
  }
6143
6060
  }
6144
6061
  ),
@@ -6146,8 +6063,9 @@ const GiftCardsPage = () => {
6146
6063
  ] });
6147
6064
  };
6148
6065
  const config$3 = adminSdk.defineRouteConfig({
6149
- label: "Gift Cards",
6150
- icon: GiftCardIcon
6066
+ label: "Store Credits",
6067
+ icon: StoreCreditIcon,
6068
+ permissions: ["store_credit_account:read"]
6151
6069
  });
6152
6070
  function setRef$2(ref, value) {
6153
6071
  if (typeof ref === "function") {
@@ -10842,27 +10760,6 @@ const StackedFocusModal = Object.assign(Root, {
10842
10760
  Description,
10843
10761
  Title
10844
10762
  });
10845
- const STORE_QUERY_KEY = "store";
10846
- const storeQueryKeys = queryKeysFactory(STORE_QUERY_KEY);
10847
- async function retrieveActiveStore(query) {
10848
- const response = await sdk.admin.store.list(query);
10849
- const activeStore = response.stores?.[0];
10850
- if (!activeStore) {
10851
- throw new Medusa.FetchError("No active store found", "Not Found", 404);
10852
- }
10853
- return { store: activeStore };
10854
- }
10855
- const useStore$2 = (query, options) => {
10856
- const { data, ...rest } = reactQuery.useQuery({
10857
- queryFn: () => retrieveActiveStore(query),
10858
- queryKey: storeQueryKeys.details(),
10859
- ...options
10860
- });
10861
- return {
10862
- ...data,
10863
- ...rest
10864
- };
10865
- };
10866
10763
  const t$1 = (r, t2, s2) => {
10867
10764
  if (r && "reportValidity" in r) {
10868
10765
  const o2 = get$2(s2, t2);
@@ -13908,7 +13805,7 @@ function useStoreProps(store, props, key2, setKey) {
13908
13805
  });
13909
13806
  });
13910
13807
  }
13911
- function useStore$1(createStore2, props) {
13808
+ function useStore$2(createStore2, props) {
13912
13809
  const [store, setStore] = React__namespace.useState(() => createStore2(props));
13913
13810
  useSafeLayoutEffect(() => init(store), [store]);
13914
13811
  const useState = React__namespace.useCallback((keyOrSelector) => useStoreState(store, keyOrSelector), [store]);
@@ -14865,7 +14762,7 @@ function useDisclosureStoreProps(store, update, props) {
14865
14762
  return Object.assign(store, { disclosure: props.disclosure });
14866
14763
  }
14867
14764
  function useDisclosureStore(props = {}) {
14868
- const [store, update] = useStore$1(createDisclosureStore, props);
14765
+ const [store, update] = useStore$2(createDisclosureStore, props);
14869
14766
  return useDisclosureStoreProps(store, update, props);
14870
14767
  }
14871
14768
  const ctx$2 = createStoreContext([DialogContextProvider], [DialogScopedContextProvider]);
@@ -15674,7 +15571,7 @@ function useDialogStoreProps(store, update, props) {
15674
15571
  return useDisclosureStoreProps(store, update, props);
15675
15572
  }
15676
15573
  function useDialogStore(props = {}) {
15677
- const [store, update] = useStore$1(createDialogStore, props);
15574
+ const [store, update] = useStore$2(createDialogStore, props);
15678
15575
  return useDialogStoreProps(store, update, props);
15679
15576
  }
15680
15577
  function isHiddenDismiss(element, ...ids2) {
@@ -18990,7 +18887,7 @@ function useComboboxStoreProps(store, update, props) {
18990
18887
  }
18991
18888
  function useComboboxStore(props = {}) {
18992
18889
  props = useComboboxStoreOptions(props);
18993
- const [store, update] = useStore$1(createComboboxStore, props);
18890
+ const [store, update] = useStore$2(createComboboxStore, props);
18994
18891
  return useComboboxStoreProps(store, update, props);
18995
18892
  }
18996
18893
  function ComboboxProvider(props = {}) {
@@ -20109,6 +20006,371 @@ const ComboboxImpl = ({
20109
20006
  );
20110
20007
  };
20111
20008
  const Combobox2 = genericForwardRef(ComboboxImpl);
20009
+ var isObject_1;
20010
+ var hasRequiredIsObject;
20011
+ function requireIsObject() {
20012
+ if (hasRequiredIsObject) return isObject_1;
20013
+ hasRequiredIsObject = 1;
20014
+ function isObject2(value) {
20015
+ var type = typeof value;
20016
+ return value != null && (type == "object" || type == "function");
20017
+ }
20018
+ isObject_1 = isObject2;
20019
+ return isObject_1;
20020
+ }
20021
+ var _freeGlobal;
20022
+ var hasRequired_freeGlobal;
20023
+ function require_freeGlobal() {
20024
+ if (hasRequired_freeGlobal) return _freeGlobal;
20025
+ hasRequired_freeGlobal = 1;
20026
+ var freeGlobal = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
20027
+ _freeGlobal = freeGlobal;
20028
+ return _freeGlobal;
20029
+ }
20030
+ var _root;
20031
+ var hasRequired_root;
20032
+ function require_root() {
20033
+ if (hasRequired_root) return _root;
20034
+ hasRequired_root = 1;
20035
+ var freeGlobal = require_freeGlobal();
20036
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
20037
+ var root = freeGlobal || freeSelf || Function("return this")();
20038
+ _root = root;
20039
+ return _root;
20040
+ }
20041
+ var now_1;
20042
+ var hasRequiredNow;
20043
+ function requireNow() {
20044
+ if (hasRequiredNow) return now_1;
20045
+ hasRequiredNow = 1;
20046
+ var root = require_root();
20047
+ var now = function() {
20048
+ return root.Date.now();
20049
+ };
20050
+ now_1 = now;
20051
+ return now_1;
20052
+ }
20053
+ var _trimmedEndIndex;
20054
+ var hasRequired_trimmedEndIndex;
20055
+ function require_trimmedEndIndex() {
20056
+ if (hasRequired_trimmedEndIndex) return _trimmedEndIndex;
20057
+ hasRequired_trimmedEndIndex = 1;
20058
+ var reWhitespace = /\s/;
20059
+ function trimmedEndIndex(string2) {
20060
+ var index = string2.length;
20061
+ while (index-- && reWhitespace.test(string2.charAt(index))) {
20062
+ }
20063
+ return index;
20064
+ }
20065
+ _trimmedEndIndex = trimmedEndIndex;
20066
+ return _trimmedEndIndex;
20067
+ }
20068
+ var _baseTrim;
20069
+ var hasRequired_baseTrim;
20070
+ function require_baseTrim() {
20071
+ if (hasRequired_baseTrim) return _baseTrim;
20072
+ hasRequired_baseTrim = 1;
20073
+ var trimmedEndIndex = require_trimmedEndIndex();
20074
+ var reTrimStart = /^\s+/;
20075
+ function baseTrim(string2) {
20076
+ return string2 ? string2.slice(0, trimmedEndIndex(string2) + 1).replace(reTrimStart, "") : string2;
20077
+ }
20078
+ _baseTrim = baseTrim;
20079
+ return _baseTrim;
20080
+ }
20081
+ var _Symbol;
20082
+ var hasRequired_Symbol;
20083
+ function require_Symbol() {
20084
+ if (hasRequired_Symbol) return _Symbol;
20085
+ hasRequired_Symbol = 1;
20086
+ var root = require_root();
20087
+ var Symbol2 = root.Symbol;
20088
+ _Symbol = Symbol2;
20089
+ return _Symbol;
20090
+ }
20091
+ var _getRawTag;
20092
+ var hasRequired_getRawTag;
20093
+ function require_getRawTag() {
20094
+ if (hasRequired_getRawTag) return _getRawTag;
20095
+ hasRequired_getRawTag = 1;
20096
+ var Symbol2 = require_Symbol();
20097
+ var objectProto = Object.prototype;
20098
+ var hasOwnProperty2 = objectProto.hasOwnProperty;
20099
+ var nativeObjectToString = objectProto.toString;
20100
+ var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
20101
+ function getRawTag(value) {
20102
+ var isOwn = hasOwnProperty2.call(value, symToStringTag), tag = value[symToStringTag];
20103
+ try {
20104
+ value[symToStringTag] = void 0;
20105
+ var unmasked = true;
20106
+ } catch (e) {
20107
+ }
20108
+ var result = nativeObjectToString.call(value);
20109
+ if (unmasked) {
20110
+ if (isOwn) {
20111
+ value[symToStringTag] = tag;
20112
+ } else {
20113
+ delete value[symToStringTag];
20114
+ }
20115
+ }
20116
+ return result;
20117
+ }
20118
+ _getRawTag = getRawTag;
20119
+ return _getRawTag;
20120
+ }
20121
+ var _objectToString;
20122
+ var hasRequired_objectToString;
20123
+ function require_objectToString() {
20124
+ if (hasRequired_objectToString) return _objectToString;
20125
+ hasRequired_objectToString = 1;
20126
+ var objectProto = Object.prototype;
20127
+ var nativeObjectToString = objectProto.toString;
20128
+ function objectToString(value) {
20129
+ return nativeObjectToString.call(value);
20130
+ }
20131
+ _objectToString = objectToString;
20132
+ return _objectToString;
20133
+ }
20134
+ var _baseGetTag;
20135
+ var hasRequired_baseGetTag;
20136
+ function require_baseGetTag() {
20137
+ if (hasRequired_baseGetTag) return _baseGetTag;
20138
+ hasRequired_baseGetTag = 1;
20139
+ var Symbol2 = require_Symbol(), getRawTag = require_getRawTag(), objectToString = require_objectToString();
20140
+ var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
20141
+ var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
20142
+ function baseGetTag(value) {
20143
+ if (value == null) {
20144
+ return value === void 0 ? undefinedTag : nullTag;
20145
+ }
20146
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
20147
+ }
20148
+ _baseGetTag = baseGetTag;
20149
+ return _baseGetTag;
20150
+ }
20151
+ var isObjectLike_1;
20152
+ var hasRequiredIsObjectLike;
20153
+ function requireIsObjectLike() {
20154
+ if (hasRequiredIsObjectLike) return isObjectLike_1;
20155
+ hasRequiredIsObjectLike = 1;
20156
+ function isObjectLike(value) {
20157
+ return value != null && typeof value == "object";
20158
+ }
20159
+ isObjectLike_1 = isObjectLike;
20160
+ return isObjectLike_1;
20161
+ }
20162
+ var isSymbol_1;
20163
+ var hasRequiredIsSymbol;
20164
+ function requireIsSymbol() {
20165
+ if (hasRequiredIsSymbol) return isSymbol_1;
20166
+ hasRequiredIsSymbol = 1;
20167
+ var baseGetTag = require_baseGetTag(), isObjectLike = requireIsObjectLike();
20168
+ var symbolTag = "[object Symbol]";
20169
+ function isSymbol(value) {
20170
+ return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
20171
+ }
20172
+ isSymbol_1 = isSymbol;
20173
+ return isSymbol_1;
20174
+ }
20175
+ var toNumber_1;
20176
+ var hasRequiredToNumber;
20177
+ function requireToNumber() {
20178
+ if (hasRequiredToNumber) return toNumber_1;
20179
+ hasRequiredToNumber = 1;
20180
+ var baseTrim = require_baseTrim(), isObject2 = requireIsObject(), isSymbol = requireIsSymbol();
20181
+ var NAN = 0 / 0;
20182
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
20183
+ var reIsBinary = /^0b[01]+$/i;
20184
+ var reIsOctal = /^0o[0-7]+$/i;
20185
+ var freeParseInt = parseInt;
20186
+ function toNumber(value) {
20187
+ if (typeof value == "number") {
20188
+ return value;
20189
+ }
20190
+ if (isSymbol(value)) {
20191
+ return NAN;
20192
+ }
20193
+ if (isObject2(value)) {
20194
+ var other = typeof value.valueOf == "function" ? value.valueOf() : value;
20195
+ value = isObject2(other) ? other + "" : other;
20196
+ }
20197
+ if (typeof value != "string") {
20198
+ return value === 0 ? value : +value;
20199
+ }
20200
+ value = baseTrim(value);
20201
+ var isBinary = reIsBinary.test(value);
20202
+ return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
20203
+ }
20204
+ toNumber_1 = toNumber;
20205
+ return toNumber_1;
20206
+ }
20207
+ var debounce_1;
20208
+ var hasRequiredDebounce;
20209
+ function requireDebounce() {
20210
+ if (hasRequiredDebounce) return debounce_1;
20211
+ hasRequiredDebounce = 1;
20212
+ var isObject2 = requireIsObject(), now = requireNow(), toNumber = requireToNumber();
20213
+ var FUNC_ERROR_TEXT = "Expected a function";
20214
+ var nativeMax = Math.max, nativeMin = Math.min;
20215
+ function debounce2(func, wait, options) {
20216
+ var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
20217
+ if (typeof func != "function") {
20218
+ throw new TypeError(FUNC_ERROR_TEXT);
20219
+ }
20220
+ wait = toNumber(wait) || 0;
20221
+ if (isObject2(options)) {
20222
+ leading = !!options.leading;
20223
+ maxing = "maxWait" in options;
20224
+ maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
20225
+ trailing = "trailing" in options ? !!options.trailing : trailing;
20226
+ }
20227
+ function invokeFunc(time2) {
20228
+ var args = lastArgs, thisArg = lastThis;
20229
+ lastArgs = lastThis = void 0;
20230
+ lastInvokeTime = time2;
20231
+ result = func.apply(thisArg, args);
20232
+ return result;
20233
+ }
20234
+ function leadingEdge(time2) {
20235
+ lastInvokeTime = time2;
20236
+ timerId = setTimeout(timerExpired, wait);
20237
+ return leading ? invokeFunc(time2) : result;
20238
+ }
20239
+ function remainingWait(time2) {
20240
+ var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
20241
+ return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
20242
+ }
20243
+ function shouldInvoke(time2) {
20244
+ var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime;
20245
+ return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
20246
+ }
20247
+ function timerExpired() {
20248
+ var time2 = now();
20249
+ if (shouldInvoke(time2)) {
20250
+ return trailingEdge(time2);
20251
+ }
20252
+ timerId = setTimeout(timerExpired, remainingWait(time2));
20253
+ }
20254
+ function trailingEdge(time2) {
20255
+ timerId = void 0;
20256
+ if (trailing && lastArgs) {
20257
+ return invokeFunc(time2);
20258
+ }
20259
+ lastArgs = lastThis = void 0;
20260
+ return result;
20261
+ }
20262
+ function cancel() {
20263
+ if (timerId !== void 0) {
20264
+ clearTimeout(timerId);
20265
+ }
20266
+ lastInvokeTime = 0;
20267
+ lastArgs = lastCallTime = lastThis = timerId = void 0;
20268
+ }
20269
+ function flush() {
20270
+ return timerId === void 0 ? result : trailingEdge(now());
20271
+ }
20272
+ function debounced() {
20273
+ var time2 = now(), isInvoking = shouldInvoke(time2);
20274
+ lastArgs = arguments;
20275
+ lastThis = this;
20276
+ lastCallTime = time2;
20277
+ if (isInvoking) {
20278
+ if (timerId === void 0) {
20279
+ return leadingEdge(lastCallTime);
20280
+ }
20281
+ if (maxing) {
20282
+ clearTimeout(timerId);
20283
+ timerId = setTimeout(timerExpired, wait);
20284
+ return invokeFunc(lastCallTime);
20285
+ }
20286
+ }
20287
+ if (timerId === void 0) {
20288
+ timerId = setTimeout(timerExpired, wait);
20289
+ }
20290
+ return result;
20291
+ }
20292
+ debounced.cancel = cancel;
20293
+ debounced.flush = flush;
20294
+ return debounced;
20295
+ }
20296
+ debounce_1 = debounce2;
20297
+ return debounce_1;
20298
+ }
20299
+ var debounceExports = requireDebounce();
20300
+ const debounce$1 = /* @__PURE__ */ getDefaultExportFromCjs(debounceExports);
20301
+ const useDebouncedSearch = () => {
20302
+ const [searchValue, onSearchValueChange] = React.useState("");
20303
+ const [debouncedQuery, setDebouncedQuery] = React.useState("");
20304
+ const debouncedUpdate = React.useCallback(
20305
+ debounce$1((query) => setDebouncedQuery(query), 300),
20306
+ []
20307
+ );
20308
+ React.useEffect(() => {
20309
+ debouncedUpdate(searchValue);
20310
+ return () => debouncedUpdate.cancel();
20311
+ }, [searchValue, debouncedUpdate]);
20312
+ return {
20313
+ searchValue,
20314
+ onSearchValueChange,
20315
+ query: debouncedQuery || void 0
20316
+ };
20317
+ };
20318
+ const useComboboxData = ({
20319
+ queryKey,
20320
+ queryFn,
20321
+ getOptions,
20322
+ defaultValue: defaultValue2,
20323
+ defaultValueKey,
20324
+ pageSize = 10,
20325
+ enabled = true
20326
+ }) => {
20327
+ const { searchValue, onSearchValueChange, query } = useDebouncedSearch();
20328
+ const queryInitialDataBy = defaultValueKey || "id";
20329
+ const { data: initialData } = reactQuery.useQuery({
20330
+ queryKey,
20331
+ queryFn: async () => {
20332
+ return queryFn({
20333
+ [queryInitialDataBy]: defaultValue2,
20334
+ limit: Array.isArray(defaultValue2) ? defaultValue2.length : 1
20335
+ });
20336
+ },
20337
+ enabled: enabled && !!defaultValue2
20338
+ });
20339
+ const { data, ...rest } = reactQuery.useInfiniteQuery({
20340
+ queryKey: [...queryKey, query],
20341
+ queryFn: async ({ pageParam = 0 }) => {
20342
+ return await queryFn({
20343
+ q: query,
20344
+ limit: pageSize,
20345
+ offset: pageParam
20346
+ });
20347
+ },
20348
+ initialPageParam: 0,
20349
+ getNextPageParam: (lastPage) => {
20350
+ const moreItemsExist = lastPage.count > lastPage.offset + lastPage.limit;
20351
+ return moreItemsExist ? lastPage.offset + lastPage.limit : void 0;
20352
+ },
20353
+ placeholderData: reactQuery.keepPreviousData,
20354
+ enabled
20355
+ });
20356
+ const options = data?.pages.flatMap((page) => getOptions(page)) ?? [];
20357
+ const defaultOptions2 = initialData ? getOptions(initialData) : [];
20358
+ const disabled = !rest.isPending && !options.length && !searchValue;
20359
+ if (defaultValue2 && defaultOptions2.length && !searchValue) {
20360
+ defaultOptions2.forEach((option) => {
20361
+ if (!options.find((o2) => o2.value === option.value)) {
20362
+ options.unshift(option);
20363
+ }
20364
+ });
20365
+ }
20366
+ return {
20367
+ options,
20368
+ searchValue,
20369
+ onSearchValueChange,
20370
+ disabled,
20371
+ ...rest
20372
+ };
20373
+ };
20112
20374
  const currencies = {
20113
20375
  USD: {
20114
20376
  code: "USD",
@@ -20170,6 +20432,12 @@ const currencies = {
20170
20432
  symbol_native: "$",
20171
20433
  decimal_digits: 2
20172
20434
  },
20435
+ AWG: {
20436
+ code: "AWG",
20437
+ name: "Aruban Florin",
20438
+ symbol_native: "Afl.",
20439
+ decimal_digits: 2
20440
+ },
20173
20441
  AZN: {
20174
20442
  code: "AZN",
20175
20443
  name: "Azerbaijani Manat",
@@ -20855,6 +21123,515 @@ const currencies = {
20855
21123
  decimal_digits: 0
20856
21124
  }
20857
21125
  };
21126
+ const formSchema = zod.z.object({
21127
+ currency_code: zod.z.string().min(1, "Please select a currency"),
21128
+ customer_id: zod.z.string().optional()
21129
+ });
21130
+ const StoreCreditAccountCreateForm = () => {
21131
+ const { handleSuccess } = useRouteModal();
21132
+ const [searchParams] = reactRouterDom.useSearchParams();
21133
+ const prefilledCustomerId = searchParams.get("prefill_customer_id") ?? "";
21134
+ const { hasPermission } = hooks.usePermissions();
21135
+ const canReadCustomers = hasPermission("customer:read");
21136
+ const form = useForm({
21137
+ defaultValues: {
21138
+ currency_code: "",
21139
+ customer_id: prefilledCustomerId
21140
+ },
21141
+ resolver: u(formSchema)
21142
+ });
21143
+ const { mutateAsync: createStoreCreditAccount, isPending } = useCreateStoreCreditAccount();
21144
+ const handleSubmit = form.handleSubmit(async (data) => {
21145
+ if (!data.customer_id) {
21146
+ delete data.customer_id;
21147
+ }
21148
+ await createStoreCreditAccount(data, {
21149
+ onSuccess: (data2) => {
21150
+ ui.toast.success(`Store credit account was successfully created.`);
21151
+ handleSuccess(`../${data2.store_credit_account.id}`);
21152
+ },
21153
+ onError: (error2) => {
21154
+ ui.toast.error(error2.message);
21155
+ }
21156
+ });
21157
+ });
21158
+ const [currencySearchValue, setCurrencySearchValue] = React.useState("");
21159
+ const currencyOptions = React.useMemo(() => {
21160
+ const options = Object.values(currencies).map((currency) => ({
21161
+ label: `${currency.code} - ${currency.name} (${currency.symbol_native})`,
21162
+ value: currency.code.toLowerCase()
21163
+ }));
21164
+ if (!currencySearchValue) {
21165
+ return options;
21166
+ }
21167
+ return options.filter(
21168
+ (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
21169
+ );
21170
+ }, [currencySearchValue]);
21171
+ const {
21172
+ options: customerOptions,
21173
+ fetchNextPage,
21174
+ isFetchingNextPage,
21175
+ searchValue,
21176
+ onSearchValueChange,
21177
+ isLoading
21178
+ } = useComboboxData({
21179
+ queryKey: customersQueryKeys.list(),
21180
+ defaultValue: prefilledCustomerId || void 0,
21181
+ enabled: canReadCustomers,
21182
+ queryFn: async (params) => {
21183
+ return sdk.admin.customer.list(params);
21184
+ },
21185
+ getOptions: (data) => {
21186
+ return data.customers?.map((customer) => {
21187
+ const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
21188
+ const label = fullName ? `${customer.email} (${fullName})` : customer.email;
21189
+ return {
21190
+ label,
21191
+ value: customer.id
21192
+ };
21193
+ }) || [];
21194
+ }
21195
+ });
21196
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Form, { form, children: [
21197
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "-my-2 w-full border-l" }) }),
21198
+ /* @__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: [
21199
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
21200
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Create Store Credit Account" }),
21201
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new store credit account for a customer" })
21202
+ ] }),
21203
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-x-4", children: [
21204
+ /* @__PURE__ */ jsxRuntime.jsx(
21205
+ Form$2.Field,
21206
+ {
21207
+ control: form.control,
21208
+ name: "currency_code",
21209
+ render: ({ field }) => {
21210
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "w-full", children: [
21211
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { className: "font-normal", children: "Currency" }),
21212
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
21213
+ Combobox2,
21214
+ {
21215
+ value: field.value,
21216
+ onChange: field.onChange,
21217
+ searchValue: currencySearchValue,
21218
+ onSearchValueChange: setCurrencySearchValue,
21219
+ options: currencyOptions,
21220
+ placeholder: "Search for a currency..."
21221
+ }
21222
+ ) }),
21223
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
21224
+ ] });
21225
+ }
21226
+ }
21227
+ ),
21228
+ canReadCustomers && /* @__PURE__ */ jsxRuntime.jsx(
21229
+ Form$2.Field,
21230
+ {
21231
+ control: form.control,
21232
+ name: "customer_id",
21233
+ render: ({ field }) => {
21234
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "w-full", children: [
21235
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { className: "font-normal", children: "Customer" }),
21236
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
21237
+ Combobox2,
21238
+ {
21239
+ value: field.value,
21240
+ onChange: field.onChange,
21241
+ searchValue,
21242
+ onSearchValueChange,
21243
+ options: customerOptions,
21244
+ placeholder: "Search for a customer...",
21245
+ fetchNextPage,
21246
+ isFetchingNextPage,
21247
+ noResultsPlaceholder: isLoading ? "Loading customers..." : "No customers found"
21248
+ }
21249
+ ) }),
21250
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
21251
+ ] });
21252
+ }
21253
+ }
21254
+ )
21255
+ ] })
21256
+ ] }) }) }),
21257
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Footer, { children: [
21258
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, disabled: isPending, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", disabled: isPending, children: "Cancel" }) }),
21259
+ /* @__PURE__ */ jsxRuntime.jsx(
21260
+ ui.Button,
21261
+ {
21262
+ variant: "primary",
21263
+ size: "small",
21264
+ onClick: handleSubmit,
21265
+ disabled: isPending,
21266
+ children: "Create"
21267
+ }
21268
+ )
21269
+ ] })
21270
+ ] });
21271
+ };
21272
+ const StoreCreditAccountCreate = () => {
21273
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal, { children: [
21274
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Create Store Credit Account" }) }),
21275
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Create a new store credit account" }) }),
21276
+ /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountCreateForm, {})
21277
+ ] });
21278
+ };
21279
+ const handle$e = {
21280
+ permissions: ["store_credit_account:create"]
21281
+ };
21282
+ const GiftCardIcon = (props) => {
21283
+ return /* @__PURE__ */ jsxRuntime.jsxs(
21284
+ "svg",
21285
+ {
21286
+ width: "15",
21287
+ height: "15",
21288
+ viewBox: "0 0 15 15",
21289
+ fill: "none",
21290
+ xmlns: "http://www.w3.org/2000/svg",
21291
+ ...props,
21292
+ children: [
21293
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "15", height: "15", fill: "#F97316" }),
21294
+ /* @__PURE__ */ jsxRuntime.jsx(
21295
+ "rect",
21296
+ {
21297
+ width: "15",
21298
+ height: "15",
21299
+ fill: "url(#paint0_linear_28788_25808)",
21300
+ fillOpacity: "0.2"
21301
+ }
21302
+ ),
21303
+ /* @__PURE__ */ jsxRuntime.jsxs("g", { clipPath: "url(#clip0_28788_25808)", children: [
21304
+ /* @__PURE__ */ jsxRuntime.jsx(
21305
+ "path",
21306
+ {
21307
+ d: "M7.5 6.375H5.375C4.479 6.375 3.75 5.618 3.75 4.688C3.75 3.757 4.479 3 5.375 3C7.365 3 8.019 5.569 8.047 5.678C8.088 5.846 8.05 6.023 7.943 6.16C7.836 6.296 7.673 6.375 7.5 6.375ZM5.375 4.125C5.099 4.125 4.875 4.377 4.875 4.688C4.875 4.998 5.099 5.25 5.375 5.25H6.688C6.439 4.736 6.011 4.125 5.375 4.125Z",
21308
+ fill: "white"
21309
+ }
21310
+ ),
21311
+ /* @__PURE__ */ jsxRuntime.jsx(
21312
+ "path",
21313
+ {
21314
+ d: "M9.625 6.375H7.5C7.328 6.375 7.164 6.296 7.058 6.16C6.95 6.023 6.913 5.846 6.953 5.678C6.98 5.569 7.634 3 9.625 3C10.521 3 11.25 3.757 11.25 4.688C11.25 5.618 10.521 6.375 9.625 6.375ZM8.312 5.25H9.625C9.901 5.25 10.125 4.998 10.125 4.688C10.125 4.377 9.901 4.125 9.625 4.125C8.99 4.125 8.561 4.736 8.312 5.25Z",
21315
+ fill: "white"
21316
+ }
21317
+ ),
21318
+ /* @__PURE__ */ jsxRuntime.jsx(
21319
+ "path",
21320
+ {
21321
+ d: "M11.438 6.375H3.562C3.252 6.375 3 6.123 3 5.813C3 5.502 3.252 5.25 3.562 5.25H11.438C11.748 5.25 12 5.502 12 5.813C12 6.123 11.748 6.375 11.438 6.375Z",
21322
+ fill: "white"
21323
+ }
21324
+ ),
21325
+ /* @__PURE__ */ jsxRuntime.jsx(
21326
+ "path",
21327
+ {
21328
+ d: "M6.938 7.5H3.75V9.563C3.75 10.7 4.675 11.625 5.813 11.625H6.938V7.5Z",
21329
+ fill: "white"
21330
+ }
21331
+ ),
21332
+ /* @__PURE__ */ jsxRuntime.jsx(
21333
+ "path",
21334
+ {
21335
+ d: "M8.063 7.5V11.625H9.188C10.325 11.625 11.25 10.7 11.25 9.563V7.5H8.063Z",
21336
+ fill: "white"
21337
+ }
21338
+ )
21339
+ ] }),
21340
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
21341
+ /* @__PURE__ */ jsxRuntime.jsxs(
21342
+ "linearGradient",
21343
+ {
21344
+ id: "paint0_linear_28788_25808",
21345
+ x1: "7.5",
21346
+ y1: "0",
21347
+ x2: "7.5",
21348
+ y2: "15",
21349
+ gradientUnits: "userSpaceOnUse",
21350
+ children: [
21351
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "white" }),
21352
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
21353
+ ]
21354
+ }
21355
+ ),
21356
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_28788_25808", children: /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "9", height: "9", fill: "white", transform: "translate(3 3)" }) })
21357
+ ] })
21358
+ ]
21359
+ }
21360
+ );
21361
+ };
21362
+ const GiftCardProductsSection = () => {
21363
+ const { hasPermission } = hooks.usePermissions();
21364
+ const canCreateProduct = hasPermission("product:create");
21365
+ const { products: giftCardProducts, count: count2 = 0 } = useProducts({
21366
+ is_giftcard: true
21367
+ });
21368
+ const slicedProducts = giftCardProducts?.slice(0, 3) ?? [];
21369
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
21370
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
21371
+ /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Gift Card Products" }),
21372
+ canCreateProduct && /* @__PURE__ */ jsxRuntime.jsx(
21373
+ reactRouterDom.Link,
21374
+ {
21375
+ to: `/gift-cards/gift-card-products/create`,
21376
+ className: "text-ui-fg-muted text-sm px-6",
21377
+ children: "Create"
21378
+ }
21379
+ )
21380
+ ] }),
21381
+ giftCardProducts?.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(
21382
+ NoRecords,
21383
+ {
21384
+ className: "px-10 py-4 h-[200px]",
21385
+ title: "No gift card products",
21386
+ message: "There are no gift card products to show. Create one to get started.",
21387
+ action: canCreateProduct ? {
21388
+ to: "/gift-cards/gift-card-products/create",
21389
+ label: "Create gift card product"
21390
+ } : void 0
21391
+ }
21392
+ ),
21393
+ slicedProducts.map((giftCardProduct) => /* @__PURE__ */ jsxRuntime.jsx(
21394
+ SidebarLink,
21395
+ {
21396
+ to: `/gift-cards/gift-card-products/${giftCardProduct.id}`,
21397
+ labelKey: giftCardProduct.title,
21398
+ descriptionKey: giftCardProduct.title,
21399
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Tag, {})
21400
+ }
21401
+ )),
21402
+ count2 > 3 && /* @__PURE__ */ jsxRuntime.jsx(
21403
+ reactRouterDom.Link,
21404
+ {
21405
+ to: "/gift-cards/gift-card-products",
21406
+ className: "text-ui-fg-muted text-sm px-6 py-4 flex items-center justify-center",
21407
+ children: "View more"
21408
+ }
21409
+ )
21410
+ ] });
21411
+ };
21412
+ const _giftCardQueryKey = queryKeysFactory("gift-card");
21413
+ const giftCardQueryKey = {
21414
+ ..._giftCardQueryKey,
21415
+ orders: (id) => [..._giftCardQueryKey.detail(id), "orders"]
21416
+ };
21417
+ const useGiftCards = (query, options) => {
21418
+ const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
21419
+ query: query2,
21420
+ headers
21421
+ });
21422
+ const { data, ...rest } = reactQuery.useQuery({
21423
+ ...options,
21424
+ queryFn: () => fetchGiftCards(query),
21425
+ queryKey: giftCardQueryKey.list(query)
21426
+ });
21427
+ return { ...data, ...rest };
21428
+ };
21429
+ const useGiftCard = (id, query, options) => {
21430
+ const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
21431
+ query: query2,
21432
+ headers
21433
+ });
21434
+ const { data, ...rest } = reactQuery.useQuery({
21435
+ queryFn: () => fetchGiftCard(id, query),
21436
+ queryKey: giftCardQueryKey.detail(id, query),
21437
+ ...options
21438
+ });
21439
+ return { ...data, ...rest };
21440
+ };
21441
+ const useGiftCardOrders = (id, options) => {
21442
+ const fetchGiftCardOrders = (id2, query, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}/orders`, {
21443
+ query,
21444
+ headers
21445
+ });
21446
+ const { data, ...rest } = reactQuery.useQuery({
21447
+ queryFn: () => fetchGiftCardOrders(id),
21448
+ queryKey: giftCardQueryKey.orders(id),
21449
+ ...options
21450
+ });
21451
+ return { ...data, ...rest };
21452
+ };
21453
+ const useUpdateGiftCard = (id, options) => {
21454
+ const queryClient = reactQuery.useQueryClient();
21455
+ const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
21456
+ body,
21457
+ method: "POST"
21458
+ });
21459
+ return reactQuery.useMutation({
21460
+ mutationFn: async (payload) => updateGiftCard(id, payload),
21461
+ onSuccess: (data, variables, context) => {
21462
+ queryClient.invalidateQueries({
21463
+ queryKey: giftCardQueryKey.detail(id)
21464
+ });
21465
+ queryClient.invalidateQueries({
21466
+ queryKey: giftCardQueryKey.lists()
21467
+ });
21468
+ },
21469
+ ...options
21470
+ });
21471
+ };
21472
+ const useCreateGiftCard = (options) => {
21473
+ const queryClient = reactQuery.useQueryClient();
21474
+ const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
21475
+ body,
21476
+ method: "POST"
21477
+ });
21478
+ return reactQuery.useMutation({
21479
+ mutationFn: (body) => createGiftCard(body),
21480
+ onSuccess: (data, variables, context) => {
21481
+ queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
21482
+ },
21483
+ ...options
21484
+ });
21485
+ };
21486
+ const columnHelper$9 = ui.createDataTableColumnHelper();
21487
+ const useGiftCardTableColumns = () => {
21488
+ return React.useMemo(() => {
21489
+ return [
21490
+ columnHelper$9.accessor("code", {
21491
+ header: "Code",
21492
+ cell: ({ row }) => {
21493
+ return row.original.code;
21494
+ }
21495
+ }),
21496
+ columnHelper$9.accessor("line_item.product.title", {
21497
+ header: "Product",
21498
+ cell: ({ row }) => {
21499
+ return row.original.line_item?.product?.title || "Custom Gift Card";
21500
+ }
21501
+ }),
21502
+ columnHelper$9.accessor("created_at", {
21503
+ header: "Date issued",
21504
+ cell: ({ row }) => getRelativeDate(row.original.created_at)
21505
+ }),
21506
+ columnHelper$9.accessor("value", {
21507
+ header: "Value",
21508
+ cell: ({ row }) => {
21509
+ return formatAmount(row.original.value, row.original.currency_code);
21510
+ }
21511
+ })
21512
+ ];
21513
+ }, []);
21514
+ };
21515
+ const useGiftCardFilters = () => {
21516
+ const dateFilterOptions = useDataTableDateFilters$1();
21517
+ const customerFilterOptions = useCustomerFilters();
21518
+ return React.useMemo(() => {
21519
+ return [...dateFilterOptions, ...customerFilterOptions];
21520
+ }, [dateFilterOptions, customerFilterOptions]);
21521
+ };
21522
+ const useGiftCardTableQuery = ({
21523
+ prefix,
21524
+ pageSize = 20
21525
+ }) => {
21526
+ const queryObject = useQueryParams(
21527
+ ["q", "offset", "customer_id", "created_at", "updated_at"],
21528
+ prefix
21529
+ );
21530
+ const { offset: offset2, created_at, updated_at, customer_id, ...rest } = queryObject;
21531
+ const searchParams = {
21532
+ limit: pageSize,
21533
+ offset: offset2 ? Number(offset2) : 0,
21534
+ created_at: created_at ? JSON.parse(created_at) : void 0,
21535
+ updated_at: updated_at ? JSON.parse(updated_at) : void 0,
21536
+ customer_id: customer_id ? JSON.parse(customer_id) : void 0,
21537
+ ...rest
21538
+ };
21539
+ return searchParams;
21540
+ };
21541
+ const PAGE_SIZE$5 = 10;
21542
+ function GiftCardsTable() {
21543
+ const queryParams = useGiftCardTableQuery({
21544
+ pageSize: PAGE_SIZE$5
21545
+ });
21546
+ const {
21547
+ gift_cards: giftCards,
21548
+ isPending,
21549
+ count: count2
21550
+ } = useGiftCards({
21551
+ ...queryParams,
21552
+ order: queryParams.order ?? "-created_at",
21553
+ fields: "+line_item.product.title"
21554
+ });
21555
+ const columns = useGiftCardTableColumns();
21556
+ const filters = useGiftCardFilters();
21557
+ const { hasPermission } = hooks.usePermissions();
21558
+ const canCreate = hasPermission("gift_card:create");
21559
+ return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
21560
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
21561
+ DataTable,
21562
+ {
21563
+ data: giftCards,
21564
+ getRowId: (row) => row.id,
21565
+ columns,
21566
+ filters,
21567
+ isLoading: isPending,
21568
+ pageSize: PAGE_SIZE$5,
21569
+ rowCount: count2,
21570
+ heading: "Gift Cards",
21571
+ rowHref: (row) => `${row.id}`,
21572
+ emptyState: {
21573
+ empty: {
21574
+ heading: "No gift cards found",
21575
+ description: "Create a gift card to get started."
21576
+ },
21577
+ filtered: {
21578
+ heading: "No results found",
21579
+ description: "No gift cards match your filter criteria."
21580
+ }
21581
+ },
21582
+ actions: canCreate ? [
21583
+ {
21584
+ label: "Create",
21585
+ to: "create"
21586
+ }
21587
+ ] : []
21588
+ }
21589
+ ) }),
21590
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
21591
+ ] });
21592
+ }
21593
+ const GiftCardsPage = () => {
21594
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
21595
+ /* @__PURE__ */ jsxRuntime.jsx(
21596
+ components.LayoutComposer,
21597
+ {
21598
+ widgetsZonePrefix: "gift_card.list",
21599
+ preferredLayoutId: "core:two-column",
21600
+ sections: {
21601
+ main: /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "GiftCardsTable", children: /* @__PURE__ */ jsxRuntime.jsx(GiftCardsTable, {}) }),
21602
+ side: /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "GiftCardProductsSection", children: /* @__PURE__ */ jsxRuntime.jsx(hooks.PermissionGuard, { permission: "product:read", children: /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductsSection, {}) }) })
21603
+ }
21604
+ }
21605
+ ),
21606
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Toaster, {})
21607
+ ] });
21608
+ };
21609
+ const config$2 = adminSdk.defineRouteConfig({
21610
+ label: "Gift Cards",
21611
+ icon: GiftCardIcon,
21612
+ permissions: ["gift_card:read"]
21613
+ });
21614
+ const STORE_QUERY_KEY = "store";
21615
+ const storeQueryKeys = queryKeysFactory(STORE_QUERY_KEY);
21616
+ async function retrieveActiveStore(query) {
21617
+ const response = await sdk.admin.store.list(query);
21618
+ const activeStore = response.stores?.[0];
21619
+ if (!activeStore) {
21620
+ throw new Medusa.FetchError("No active store found", "Not Found", 404);
21621
+ }
21622
+ return { store: activeStore };
21623
+ }
21624
+ const useStore$1 = (query, options) => {
21625
+ const { data, ...rest } = reactQuery.useQuery({
21626
+ queryFn: () => retrieveActiveStore(query),
21627
+ queryKey: storeQueryKeys.details(),
21628
+ ...options
21629
+ });
21630
+ return {
21631
+ ...data,
21632
+ ...rest
21633
+ };
21634
+ };
20858
21635
  function getEnumValues(entries) {
20859
21636
  const numericValues = Object.values(entries).filter((v) => typeof v === "number");
20860
21637
  const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
@@ -21521,7 +22298,7 @@ class $ZodEncodeError extends Error {
21521
22298
  }
21522
22299
  (_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__zod_globalConfig = {});
21523
22300
  const globalConfig = globalThis.__zod_globalConfig;
21524
- function config$2(newConfig) {
22301
+ function config$1(newConfig) {
21525
22302
  if (newConfig)
21526
22303
  Object.assign(globalConfig, newConfig);
21527
22304
  return globalConfig;
@@ -21647,7 +22424,7 @@ const _parse = (_Err) => {
21647
22424
  throw new $ZodAsyncError();
21648
22425
  }
21649
22426
  if (result.issues.length) {
21650
- const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
22427
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
21651
22428
  captureStackTrace(e, _params?.callee ?? fn);
21652
22429
  throw e;
21653
22430
  }
@@ -21662,7 +22439,7 @@ const _parseAsync = (_Err) => {
21662
22439
  if (result instanceof Promise)
21663
22440
  result = await result;
21664
22441
  if (result.issues.length) {
21665
- const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
22442
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
21666
22443
  captureStackTrace(e, params?.callee ?? fn);
21667
22444
  throw e;
21668
22445
  }
@@ -21684,7 +22461,7 @@ function failure(Err, issues, ctx2) {
21684
22461
  success: false,
21685
22462
  get error() {
21686
22463
  if (!error2) {
21687
- error2 = new Err(issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
22464
+ error2 = new Err(issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
21688
22465
  issues = void 0;
21689
22466
  ctx2 = void 0;
21690
22467
  }
@@ -22309,7 +23086,7 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
22309
23086
  own(this, "~standard", value);
22310
23087
  }
22311
23088
  });
22312
- const toStandardResult = (r, ctx2) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())) } : { value: r.value };
23089
+ const toStandardResult = (r, ctx2) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())) } : { value: r.value };
22313
23090
  async function validateAsync(inst, value) {
22314
23091
  const ctx2 = { async: true };
22315
23092
  return toStandardResult(await inst._zod.run({ value, issues: [] }, ctx2), ctx2);
@@ -23171,7 +23948,7 @@ function handleUnionResults(results, final, inst, ctx2) {
23171
23948
  code: "invalid_union",
23172
23949
  input: final.value,
23173
23950
  inst,
23174
- errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())))
23951
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())))
23175
23952
  });
23176
23953
  return final;
23177
23954
  }
@@ -23367,7 +24144,7 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
23367
24144
  payload.issues.push({
23368
24145
  code: "invalid_key",
23369
24146
  origin: "record",
23370
- issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())),
24147
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())),
23371
24148
  input: key2,
23372
24149
  path: [key2],
23373
24150
  inst
@@ -23447,7 +24224,7 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
23447
24224
  payload.issues.push({
23448
24225
  code: "invalid_key",
23449
24226
  origin: "record",
23450
- issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())),
24227
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())),
23451
24228
  input: key2,
23452
24229
  path: [key2],
23453
24230
  inst
@@ -23663,7 +24440,7 @@ function handleCatchResult(payload, result, def, ctx2) {
23663
24440
  ...result,
23664
24441
  value: payload.value,
23665
24442
  error: {
23666
- issues: result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2()))
24443
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1()))
23667
24444
  },
23668
24445
  input: payload.value
23669
24446
  });
@@ -25807,11 +26584,11 @@ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
25807
26584
  const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
25808
26585
  function _ensureDefaultLocale() {
25809
26586
  if (!globalConfig.localeError)
25810
- config$2(en());
26587
+ config$1(en());
25811
26588
  }
25812
26589
  function _ensureDefaultMemoizer() {
25813
26590
  if (!globalConfig.memoizer)
25814
- config$2({ memoizer: memoizer() });
26591
+ config$1({ memoizer: memoizer() });
25815
26592
  }
25816
26593
  const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
25817
26594
  _ensureDefaultLocale();
@@ -26915,732 +27692,742 @@ const GiftCardCreateForm = ({
26915
27692
  ] });
26916
27693
  };
26917
27694
  const GiftCardCreate = () => {
26918
- const { store, isLoading } = useStore$2({});
27695
+ const { store, isLoading } = useStore$1({});
26919
27696
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal, { children: [
26920
27697
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Create Gift Card" }) }),
26921
27698
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Create a new gift card" }) }),
26922
27699
  !isLoading && /* @__PURE__ */ jsxRuntime.jsx(GiftCardCreateForm, { store })
26923
27700
  ] });
26924
27701
  };
26925
- const StoreCreditIcon = (props) => {
26926
- return /* @__PURE__ */ jsxRuntime.jsxs(
26927
- "svg",
26928
- {
26929
- width: "15",
26930
- height: "15",
26931
- viewBox: "0 0 15 15",
26932
- fill: "none",
26933
- xmlns: "http://www.w3.org/2000/svg",
26934
- ...props,
26935
- children: [
26936
- /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "15", height: "15", fill: "#8B5CF6" }),
26937
- /* @__PURE__ */ jsxRuntime.jsx(
26938
- "rect",
26939
- {
26940
- width: "15",
26941
- height: "15",
26942
- fill: "url(#paint0_linear_29181_44790)",
26943
- fillOpacity: "0.2"
26944
- }
26945
- ),
26946
- /* @__PURE__ */ jsxRuntime.jsx(
26947
- "path",
26948
- {
26949
- d: "M12 6V5.813C12 4.675 11.075 3.75 9.938 3.75H5.063C3.925 3.75 3 4.675 3 5.813V6H12Z",
26950
- fill: "white"
26951
- }
26952
- ),
26953
- /* @__PURE__ */ jsxRuntime.jsx(
26954
- "path",
26955
- {
26956
- d: "M3 7.125V9.188C3 10.325 3.925 11.25 5.063 11.25H9.938C11.075 11.25 12 10.325 12 9.188V7.125H3ZM9.938 9.75H8.438C8.127 9.75 7.875 9.498 7.875 9.188C7.875 8.877 8.127 8.625 8.438 8.625H9.938C10.248 8.625 10.5 8.877 10.5 9.188C10.5 9.498 10.248 9.75 9.938 9.75Z",
26957
- fill: "white"
26958
- }
26959
- ),
26960
- /* @__PURE__ */ jsxRuntime.jsx("defs", { children: /* @__PURE__ */ jsxRuntime.jsxs(
26961
- "linearGradient",
27702
+ const handle$d = {
27703
+ permissions: ["gift_card:create", "store:read"]
27704
+ };
27705
+ const StoreCreditAccountBalanceSection = ({
27706
+ storeCreditAccount
27707
+ }) => {
27708
+ if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
27709
+ return;
27710
+ }
27711
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "grid grid-cols-2 gap-x-2 px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-x-3", children: [
27712
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-tag-green-icon h-8 w-1 rounded-full" }),
27713
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
27714
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", size: "small", className: "text-ui-fg-subtle", children: "Current Balance" }),
27715
+ /* @__PURE__ */ jsxRuntime.jsx(
27716
+ ui.Text,
27717
+ {
27718
+ weight: "plus",
27719
+ size: "xlarge",
27720
+ className: "tabular-nums text-ui-fg-base",
27721
+ children: formatAmount(
27722
+ storeCreditAccount.balance,
27723
+ storeCreditAccount.currency_code
27724
+ )
27725
+ }
27726
+ )
27727
+ ] })
27728
+ ] }) });
27729
+ };
27730
+ var __create = Object.create;
27731
+ var __defProp = Object.defineProperty;
27732
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
27733
+ var __getOwnPropNames = Object.getOwnPropertyNames;
27734
+ var __getProtoOf = Object.getPrototypeOf;
27735
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
27736
+ var __commonJS = (cb, mod) => function __require() {
27737
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
27738
+ };
27739
+ var __copyProps = (to, from, except, desc) => {
27740
+ if (from && typeof from === "object" || typeof from === "function") {
27741
+ for (let key2 of __getOwnPropNames(from))
27742
+ if (!__hasOwnProp.call(to, key2) && key2 !== except)
27743
+ __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
27744
+ }
27745
+ return to;
27746
+ };
27747
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27748
+ // If the importer is in node compatibility mode or this is not an ESM
27749
+ // file that has been converted to a CommonJS file using a Babel-
27750
+ // compatible transform (i.e. "__esModule" has not been set), then set
27751
+ // "default" to the CommonJS "module.exports" for node compatibility.
27752
+ __defProp(target, "default", { value: mod, enumerable: true }),
27753
+ mod
27754
+ ));
27755
+ var require_toggle_selection = __commonJS({
27756
+ "node_modules/toggle-selection/index.js"(exports2, module2) {
27757
+ module2.exports = function() {
27758
+ var selection = document.getSelection();
27759
+ if (!selection.rangeCount) {
27760
+ return function() {
27761
+ };
27762
+ }
27763
+ var active = document.activeElement;
27764
+ var ranges = [];
27765
+ for (var i2 = 0; i2 < selection.rangeCount; i2++) {
27766
+ ranges.push(selection.getRangeAt(i2));
27767
+ }
27768
+ switch (active.tagName.toUpperCase()) {
27769
+ // .toUpperCase handles XHTML
27770
+ case "INPUT":
27771
+ case "TEXTAREA":
27772
+ active.blur();
27773
+ break;
27774
+ default:
27775
+ active = null;
27776
+ break;
27777
+ }
27778
+ selection.removeAllRanges();
27779
+ return function() {
27780
+ selection.type === "Caret" && selection.removeAllRanges();
27781
+ if (!selection.rangeCount) {
27782
+ ranges.forEach(function(range) {
27783
+ selection.addRange(range);
27784
+ });
27785
+ }
27786
+ active && active.focus();
27787
+ };
27788
+ };
27789
+ }
27790
+ });
27791
+ var import_index = __toESM(require_toggle_selection());
27792
+ var toggle_selection_default = import_index.default;
27793
+ var defaultMessage = "Copy to clipboard: #{key}, Enter";
27794
+ function formatPromptMessage(message2) {
27795
+ var isMac2 = navigator.userAgentData ? /mac/i.test(navigator.userAgentData.platform) : /mac os x/i.test(navigator.userAgent);
27796
+ var copyKey = (isMac2 ? "⌘" : "Ctrl") + "+C";
27797
+ return message2.replace(/#{\s*key\s*}/g, copyKey);
27798
+ }
27799
+ function buildClipboardItem(text2, format2) {
27800
+ var items = {};
27801
+ items["text/plain"] = new Blob([text2], { type: "text/plain" });
27802
+ if (format2 && format2 !== "text/plain") {
27803
+ items[format2] = new Blob([text2], { type: format2 });
27804
+ }
27805
+ return new ClipboardItem(items);
27806
+ }
27807
+ async function copyViaClipboardAPI(text2, options) {
27808
+ if (!options.format && !options.onCopy) {
27809
+ await navigator.clipboard.writeText(text2);
27810
+ return true;
27811
+ }
27812
+ var item = buildClipboardItem(text2, options.format);
27813
+ if (options.onCopy) {
27814
+ item = options.onCopy(item) || item;
27815
+ }
27816
+ await navigator.clipboard.write([item]);
27817
+ return true;
27818
+ }
27819
+ function createHiddenSpan(text2, options) {
27820
+ var mark = document.createElement("span");
27821
+ mark.textContent = text2;
27822
+ mark.ariaHidden = "true";
27823
+ mark.style.all = "unset";
27824
+ mark.style.position = "fixed";
27825
+ mark.style.top = "0";
27826
+ mark.style.clip = "rect(0, 0, 0, 0)";
27827
+ mark.style.whiteSpace = "pre";
27828
+ mark.style.webkitUserSelect = "text";
27829
+ mark.style.MozUserSelect = "text";
27830
+ mark.style.msUserSelect = "text";
27831
+ mark.style.userSelect = "text";
27832
+ mark.addEventListener("copy", function(e) {
27833
+ e.stopPropagation();
27834
+ if (options.format) {
27835
+ e.preventDefault();
27836
+ if (e.clipboardData) {
27837
+ e.clipboardData.setData(options.format, text2);
27838
+ }
27839
+ }
27840
+ if (options.onCopy && e.clipboardData) {
27841
+ options.onCopy(e.clipboardData);
27842
+ }
27843
+ });
27844
+ return mark;
27845
+ }
27846
+ function findOpenedModalDialog() {
27847
+ let element = document.activeElement;
27848
+ while (element) {
27849
+ if (element.tagName === "DIALOG" && element.open) {
27850
+ return element;
27851
+ }
27852
+ element = element.parentElement;
27853
+ }
27854
+ return null;
27855
+ }
27856
+ function copyViaExecCommand(text2, options) {
27857
+ var reselectPrevious = toggle_selection_default();
27858
+ var range = document.createRange();
27859
+ var selection = document.getSelection();
27860
+ var mark = createHiddenSpan(text2, options);
27861
+ var root = findOpenedModalDialog() || document.fullscreenElement || document.body;
27862
+ var success = false;
27863
+ try {
27864
+ root.appendChild(mark);
27865
+ range.selectNodeContents(mark);
27866
+ selection.removeAllRanges();
27867
+ selection.addRange(range);
27868
+ var successful = document.execCommand("copy");
27869
+ if (!successful) {
27870
+ throw new Error("copy command was unsuccessful");
27871
+ }
27872
+ success = true;
27873
+ } finally {
27874
+ if (typeof selection.removeRange == "function") {
27875
+ selection.removeRange(range);
27876
+ } else {
27877
+ selection.removeAllRanges();
27878
+ }
27879
+ root.removeChild(mark);
27880
+ reselectPrevious();
27881
+ }
27882
+ return success;
27883
+ }
27884
+ async function copy$1(text2, options = {}) {
27885
+ var debug2 = options.debug || false;
27886
+ if (window.isSecureContext && navigator.clipboard) {
27887
+ try {
27888
+ return await copyViaClipboardAPI(text2, options);
27889
+ } catch (err) {
27890
+ debug2 && console.error("unable to copy using navigator.clipboard: ", err);
27891
+ debug2 && console.warn("falling back to execCommand");
27892
+ }
27893
+ } else {
27894
+ debug2 && !window.isSecureContext && console.warn("copy-to-clipboard: navigator.clipboard requires a secure context (HTTPS/localhost). Falling back to execCommand.");
27895
+ }
27896
+ try {
27897
+ return copyViaExecCommand(text2, options);
27898
+ } catch (err) {
27899
+ debug2 && console.error("unable to copy using execCommand: ", err);
27900
+ debug2 && console.error("falling back to prompt");
27901
+ if (options.fallbackToPrompt) {
27902
+ var message2 = formatPromptMessage("message" in options ? options.message : defaultMessage);
27903
+ window.prompt(message2, text2);
27904
+ }
27905
+ }
27906
+ return false;
27907
+ }
27908
+ var index_default = copy$1;
27909
+ function DisplayId({ id, className }) {
27910
+ const [open2, setOpen] = React.useState(false);
27911
+ const onClick = () => {
27912
+ index_default(id);
27913
+ ui.toast.success("Copied to clipboard");
27914
+ };
27915
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { maxWidth: 260, content: id, open: open2, onOpenChange: setOpen, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { onClick, className: ui.clx("cursor-pointer", className), children: [
27916
+ "#",
27917
+ id.slice(-7)
27918
+ ] }) });
27919
+ }
27920
+ const StoreCreditAccountDetailsSection = ({
27921
+ storeCreditAccount
27922
+ }) => {
27923
+ const { hasPermission } = hooks.usePermissions();
27924
+ const canUpdate = hasPermission("store_credit_account:update");
27925
+ if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
27926
+ return;
27927
+ }
27928
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "flex justify-between gap-x-2 px-6 py-6", children: [
27929
+ /* @__PURE__ */ jsxRuntime.jsxs(
27930
+ ui.Text,
27931
+ {
27932
+ weight: "plus",
27933
+ size: "xlarge",
27934
+ className: "text-ui-fg-base flex gap-x-4",
27935
+ children: [
27936
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
27937
+ /* @__PURE__ */ jsxRuntime.jsx(CreditCardIcon, { className: "inline" }),
27938
+ " "
27939
+ ] }),
27940
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
27941
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle", children: [
27942
+ storeCreditAccount.currency_code.toUpperCase(),
27943
+ " Account"
27944
+ ] }),
27945
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx(
27946
+ ui.Text,
27947
+ {
27948
+ weight: "regular",
27949
+ size: "small",
27950
+ className: "text-ui-fg-base flex gap-x-4",
27951
+ children: /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: storeCreditAccount.id })
27952
+ }
27953
+ ) })
27954
+ ] })
27955
+ ]
27956
+ }
27957
+ ),
27958
+ canUpdate && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-x-4", children: /* @__PURE__ */ jsxRuntime.jsx(
27959
+ ActionMenu,
27960
+ {
27961
+ groups: [
26962
27962
  {
26963
- id: "paint0_linear_29181_44790",
26964
- x1: "7.5",
26965
- y1: "0",
26966
- x2: "7.5",
26967
- y2: "15",
26968
- gradientUnits: "userSpaceOnUse",
26969
- children: [
26970
- /* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "white" }),
26971
- /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
27963
+ actions: [
27964
+ {
27965
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CreditCard, {}),
27966
+ label: "Credit the account",
27967
+ to: "credit"
27968
+ },
27969
+ {
27970
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.MinusMini, {}),
27971
+ label: "Debit the account",
27972
+ to: "debit",
27973
+ disabled: !Number(storeCreditAccount.balance)
27974
+ }
26972
27975
  ]
26973
27976
  }
26974
- ) })
26975
- ]
26976
- }
26977
- );
27977
+ ]
27978
+ }
27979
+ ) })
27980
+ ] });
26978
27981
  };
26979
- const columnHelper$9 = ui.createDataTableColumnHelper();
26980
- const useStoreCreditAccountTableColumns = () => {
27982
+ function StoreCreditAccountCustomerSection({
27983
+ customerId
27984
+ }) {
27985
+ const { hasPermission } = hooks.usePermissions();
27986
+ const canReadCustomer = hasPermission("customer:read");
27987
+ const { customer, isPending } = useCustomer(customerId, void 0, {
27988
+ enabled: !!customerId && canReadCustomer
27989
+ });
27990
+ if (!canReadCustomer || isPending || !customer) {
27991
+ return null;
27992
+ }
27993
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
27994
+ /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Customer" }),
27995
+ /* @__PURE__ */ jsxRuntime.jsx(
27996
+ SidebarLink,
27997
+ {
27998
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.User, {}),
27999
+ labelKey: customer.email || "N/A",
28000
+ descriptionKey: !customer.first_name && !customer.last_name ? "N/A" : `${customer.first_name} ${customer.last_name}`,
28001
+ to: `/customers/${customer.id}`
28002
+ },
28003
+ customer.id
28004
+ )
28005
+ ] });
28006
+ }
28007
+ const columnHelper$8 = ui.createDataTableColumnHelper();
28008
+ const useTransactionsTableColumns = () => {
26981
28009
  return React.useMemo(() => {
26982
28010
  return [
26983
- columnHelper$9.accessor("currency_code", {
26984
- header: "Currency",
28011
+ columnHelper$8.accessor("id", {
28012
+ header: "ID",
26985
28013
  cell: ({ row }) => {
26986
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", children: row.original.currency_code.toUpperCase() });
28014
+ return /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: row.original.id });
26987
28015
  }
26988
28016
  }),
26989
- columnHelper$9.accessor("customer.email", {
26990
- header: "Customer",
26991
- cell: ({ row }) => {
26992
- return row.original.customer?.email ?? "N/A";
26993
- }
28017
+ columnHelper$8.accessor("created_at", {
28018
+ header: "Created At",
28019
+ cell: ({ row }) => formatDate(row.original.created_at, false)
26994
28020
  }),
26995
- columnHelper$9.accessor("balance", {
26996
- header: "Balance",
26997
- cell: ({ row }) => {
26998
- return formatAmount(
26999
- row.original.balance,
27000
- row.original.currency_code
27001
- );
27002
- }
28021
+ columnHelper$8.accessor("note", {
28022
+ header: "Description",
28023
+ cell: ({ row }) => row.original.note
27003
28024
  }),
27004
- columnHelper$9.accessor("credits", {
27005
- header: "Credits",
28025
+ columnHelper$8.accessor("note", {
28026
+ header: "Note",
27006
28027
  cell: ({ row }) => {
27007
- return formatAmount(
27008
- row.original.credits,
27009
- row.original.currency_code
27010
- );
28028
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { title: row.original.note, className: "max-w-[300px] truncate", children: row.original.note || "-" });
27011
28029
  }
27012
28030
  }),
27013
- columnHelper$9.accessor("debits", {
27014
- header: "Debits",
28031
+ columnHelper$8.accessor("amount", {
28032
+ header: "Amount",
27015
28033
  cell: ({ row }) => {
27016
- return formatAmount(
27017
- row.original.debits,
27018
- row.original.currency_code
28034
+ const isDebit = row.original.type === "debit";
28035
+ return row.original.account.currency_code && formatAmount(
28036
+ row.original.amount * (isDebit ? -1 : 1),
28037
+ row.original.account.currency_code
27019
28038
  );
27020
28039
  }
27021
- }),
27022
- columnHelper$9.accessor("created_at", {
27023
- header: "Created at",
27024
- cell: ({ row }) => getRelativeDate(row.original.created_at)
27025
28040
  })
27026
28041
  ];
27027
28042
  }, []);
27028
28043
  };
27029
- const useStoreCreditAccountFilters = () => {
28044
+ const useTransactionsTableFilters = ({}) => {
27030
28045
  const dateFilterOptions = useDataTableDateFilters$1();
27031
- const customerFilterOptions = useCustomerFilters();
27032
28046
  return React.useMemo(() => {
27033
- return [...dateFilterOptions, ...customerFilterOptions];
27034
- }, [dateFilterOptions, customerFilterOptions]);
28047
+ return [...dateFilterOptions];
28048
+ }, [dateFilterOptions]);
27035
28049
  };
27036
- const useStoreCreditAccountsTableQuery = ({
28050
+ const useTransactionsTableQuery = ({
27037
28051
  prefix,
27038
28052
  pageSize = 20
27039
28053
  }) => {
27040
28054
  const queryObject = useQueryParams(
27041
- ["offset", "customer_id", "currency_code", "created_at", "updated_at"],
28055
+ ["offset", "limit", "currency_code", "created_at", "updated_at"],
27042
28056
  prefix
27043
28057
  );
27044
- const {
27045
- offset: offset2,
27046
- created_at,
27047
- updated_at,
27048
- customer_id,
27049
- currency_code,
27050
- ...rest
27051
- } = queryObject;
28058
+ const { offset: offset2, limit, created_at, updated_at, ...rest } = queryObject;
27052
28059
  const searchParams = {
27053
- limit: pageSize,
28060
+ limit: limit ? Number(limit) : pageSize,
27054
28061
  offset: offset2 ? Number(offset2) : 0,
27055
28062
  created_at: created_at ? JSON.parse(created_at) : void 0,
27056
28063
  updated_at: updated_at ? JSON.parse(updated_at) : void 0,
27057
- customer_id: customer_id ? JSON.parse(customer_id) : void 0,
27058
- currency_code: currency_code ? JSON.parse(currency_code) : void 0,
27059
28064
  ...rest
27060
28065
  };
27061
28066
  return searchParams;
27062
28067
  };
27063
- const PAGE_SIZE$5 = 10;
27064
- function StoreCreditAccountsTable() {
27065
- const queryParams = useStoreCreditAccountsTableQuery({
27066
- pageSize: PAGE_SIZE$5
27067
- });
27068
- const {
27069
- store_credit_accounts: storeCreditAccounts,
27070
- isPending,
27071
- count: count2
27072
- } = useStoreCreditAccounts({
27073
- ...queryParams,
27074
- order: queryParams.order ?? "-created_at"
28068
+ const PAGE_SIZE$4 = 10;
28069
+ function TransactionsTable({ id }) {
28070
+ const queryParams = useTransactionsTableQuery({
28071
+ pageSize: PAGE_SIZE$4
27075
28072
  });
27076
- const columns = useStoreCreditAccountTableColumns();
27077
- const filters = useStoreCreditAccountFilters();
28073
+ const { transactions, isLoading, count: count2 } = useStoreCreditAccountTransactions(
28074
+ id,
28075
+ {
28076
+ ...queryParams,
28077
+ order: queryParams.order ?? "-created_at",
28078
+ fields: "*account"
28079
+ }
28080
+ );
28081
+ const columns = useTransactionsTableColumns();
28082
+ const filters = useTransactionsTableFilters({});
27078
28083
  return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
27079
28084
  /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
27080
28085
  DataTable,
27081
28086
  {
27082
- data: storeCreditAccounts ?? [],
28087
+ data: transactions ?? [],
27083
28088
  getRowId: (row) => row.id,
27084
28089
  columns,
27085
28090
  filters,
27086
- isLoading: isPending,
27087
- pageSize: PAGE_SIZE$5,
28091
+ isLoading,
28092
+ pageSize: PAGE_SIZE$4,
27088
28093
  rowCount: count2,
27089
28094
  enableSearch: false,
27090
- heading: "Store Credit Accounts",
27091
- rowHref: (row) => `${row.id}`,
28095
+ heading: "Transactions",
27092
28096
  emptyState: {
27093
28097
  empty: {
27094
- heading: "No store credit accounts found",
27095
- description: "Create a new store credit account to get started."
28098
+ heading: "No transactions found"
27096
28099
  },
27097
28100
  filtered: {
27098
28101
  heading: "No results found",
27099
- description: "No store credit accounts match your filter criteria."
27100
- }
27101
- },
27102
- actions: [
27103
- {
27104
- label: "Create",
27105
- to: "/store-credit-accounts/create"
28102
+ description: "No transactions match your filter criteria."
27106
28103
  }
27107
- ]
28104
+ }
27108
28105
  }
27109
28106
  ) }),
27110
28107
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
27111
28108
  ] });
27112
28109
  }
27113
- const StoreCreditAccountsPage = () => {
27114
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
27115
- /* @__PURE__ */ jsxRuntime.jsx(
27116
- components.LayoutComposer,
27117
- {
27118
- widgetsZonePrefix: "store_credit_account.list",
27119
- preferredLayoutId: "core:single-column",
27120
- sections: {
27121
- main: /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountsTable", children: /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountsTable, {}) })
27122
- }
27123
- }
27124
- ),
27125
- /* @__PURE__ */ jsxRuntime.jsx(ui.Toaster, {})
27126
- ] });
27127
- };
27128
- const config$1 = adminSdk.defineRouteConfig({
27129
- label: "Store Credits",
27130
- icon: StoreCreditIcon
27131
- });
27132
- var isObject_1;
27133
- var hasRequiredIsObject;
27134
- function requireIsObject() {
27135
- if (hasRequiredIsObject) return isObject_1;
27136
- hasRequiredIsObject = 1;
27137
- function isObject2(value) {
27138
- var type = typeof value;
27139
- return value != null && (type == "object" || type == "function");
28110
+ function StoreCreditAccountCodeSection({ code }) {
28111
+ if (!code) {
28112
+ return null;
27140
28113
  }
27141
- isObject_1 = isObject2;
27142
- return isObject_1;
27143
- }
27144
- var _freeGlobal;
27145
- var hasRequired_freeGlobal;
27146
- function require_freeGlobal() {
27147
- if (hasRequired_freeGlobal) return _freeGlobal;
27148
- hasRequired_freeGlobal = 1;
27149
- var freeGlobal = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
27150
- _freeGlobal = freeGlobal;
27151
- return _freeGlobal;
28114
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
28115
+ /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Account Code" }),
28116
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-4 px-6 mb-2", children: [
28117
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Share, { className: "inline" }),
28118
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle text-sm", children: code })
28119
+ ] })
28120
+ ] });
27152
28121
  }
27153
- var _root;
27154
- var hasRequired_root;
27155
- function require_root() {
27156
- if (hasRequired_root) return _root;
27157
- hasRequired_root = 1;
27158
- var freeGlobal = require_freeGlobal();
27159
- var freeSelf = typeof self == "object" && self && self.Object === Object && self;
27160
- var root = freeGlobal || freeSelf || Function("return this")();
27161
- _root = root;
27162
- return _root;
27163
- }
27164
- var now_1;
27165
- var hasRequiredNow;
27166
- function requireNow() {
27167
- if (hasRequiredNow) return now_1;
27168
- hasRequiredNow = 1;
27169
- var root = require_root();
27170
- var now = function() {
27171
- return root.Date.now();
27172
- };
27173
- now_1 = now;
27174
- return now_1;
27175
- }
27176
- var _trimmedEndIndex;
27177
- var hasRequired_trimmedEndIndex;
27178
- function require_trimmedEndIndex() {
27179
- if (hasRequired_trimmedEndIndex) return _trimmedEndIndex;
27180
- hasRequired_trimmedEndIndex = 1;
27181
- var reWhitespace = /\s/;
27182
- function trimmedEndIndex(string2) {
27183
- var index = string2.length;
27184
- while (index-- && reWhitespace.test(string2.charAt(index))) {
27185
- }
27186
- return index;
27187
- }
27188
- _trimmedEndIndex = trimmedEndIndex;
27189
- return _trimmedEndIndex;
27190
- }
27191
- var _baseTrim;
27192
- var hasRequired_baseTrim;
27193
- function require_baseTrim() {
27194
- if (hasRequired_baseTrim) return _baseTrim;
27195
- hasRequired_baseTrim = 1;
27196
- var trimmedEndIndex = require_trimmedEndIndex();
27197
- var reTrimStart = /^\s+/;
27198
- function baseTrim(string2) {
27199
- return string2 ? string2.slice(0, trimmedEndIndex(string2) + 1).replace(reTrimStart, "") : string2;
27200
- }
27201
- _baseTrim = baseTrim;
27202
- return _baseTrim;
27203
- }
27204
- var _Symbol;
27205
- var hasRequired_Symbol;
27206
- function require_Symbol() {
27207
- if (hasRequired_Symbol) return _Symbol;
27208
- hasRequired_Symbol = 1;
27209
- var root = require_root();
27210
- var Symbol2 = root.Symbol;
27211
- _Symbol = Symbol2;
27212
- return _Symbol;
27213
- }
27214
- var _getRawTag;
27215
- var hasRequired_getRawTag;
27216
- function require_getRawTag() {
27217
- if (hasRequired_getRawTag) return _getRawTag;
27218
- hasRequired_getRawTag = 1;
27219
- var Symbol2 = require_Symbol();
27220
- var objectProto = Object.prototype;
27221
- var hasOwnProperty2 = objectProto.hasOwnProperty;
27222
- var nativeObjectToString = objectProto.toString;
27223
- var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
27224
- function getRawTag(value) {
27225
- var isOwn = hasOwnProperty2.call(value, symToStringTag), tag = value[symToStringTag];
27226
- try {
27227
- value[symToStringTag] = void 0;
27228
- var unmasked = true;
27229
- } catch (e) {
27230
- }
27231
- var result = nativeObjectToString.call(value);
27232
- if (unmasked) {
27233
- if (isOwn) {
27234
- value[symToStringTag] = tag;
27235
- } else {
27236
- delete value[symToStringTag];
27237
- }
27238
- }
27239
- return result;
27240
- }
27241
- _getRawTag = getRawTag;
27242
- return _getRawTag;
27243
- }
27244
- var _objectToString;
27245
- var hasRequired_objectToString;
27246
- function require_objectToString() {
27247
- if (hasRequired_objectToString) return _objectToString;
27248
- hasRequired_objectToString = 1;
27249
- var objectProto = Object.prototype;
27250
- var nativeObjectToString = objectProto.toString;
27251
- function objectToString(value) {
27252
- return nativeObjectToString.call(value);
27253
- }
27254
- _objectToString = objectToString;
27255
- return _objectToString;
27256
- }
27257
- var _baseGetTag;
27258
- var hasRequired_baseGetTag;
27259
- function require_baseGetTag() {
27260
- if (hasRequired_baseGetTag) return _baseGetTag;
27261
- hasRequired_baseGetTag = 1;
27262
- var Symbol2 = require_Symbol(), getRawTag = require_getRawTag(), objectToString = require_objectToString();
27263
- var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
27264
- var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
27265
- function baseGetTag(value) {
27266
- if (value == null) {
27267
- return value === void 0 ? undefinedTag : nullTag;
27268
- }
27269
- return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
27270
- }
27271
- _baseGetTag = baseGetTag;
27272
- return _baseGetTag;
27273
- }
27274
- var isObjectLike_1;
27275
- var hasRequiredIsObjectLike;
27276
- function requireIsObjectLike() {
27277
- if (hasRequiredIsObjectLike) return isObjectLike_1;
27278
- hasRequiredIsObjectLike = 1;
27279
- function isObjectLike(value) {
27280
- return value != null && typeof value == "object";
27281
- }
27282
- isObjectLike_1 = isObjectLike;
27283
- return isObjectLike_1;
27284
- }
27285
- var isSymbol_1;
27286
- var hasRequiredIsSymbol;
27287
- function requireIsSymbol() {
27288
- if (hasRequiredIsSymbol) return isSymbol_1;
27289
- hasRequiredIsSymbol = 1;
27290
- var baseGetTag = require_baseGetTag(), isObjectLike = requireIsObjectLike();
27291
- var symbolTag = "[object Symbol]";
27292
- function isSymbol(value) {
27293
- return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
27294
- }
27295
- isSymbol_1 = isSymbol;
27296
- return isSymbol_1;
27297
- }
27298
- var toNumber_1;
27299
- var hasRequiredToNumber;
27300
- function requireToNumber() {
27301
- if (hasRequiredToNumber) return toNumber_1;
27302
- hasRequiredToNumber = 1;
27303
- var baseTrim = require_baseTrim(), isObject2 = requireIsObject(), isSymbol = requireIsSymbol();
27304
- var NAN = 0 / 0;
27305
- var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
27306
- var reIsBinary = /^0b[01]+$/i;
27307
- var reIsOctal = /^0o[0-7]+$/i;
27308
- var freeParseInt = parseInt;
27309
- function toNumber(value) {
27310
- if (typeof value == "number") {
27311
- return value;
27312
- }
27313
- if (isSymbol(value)) {
27314
- return NAN;
27315
- }
27316
- if (isObject2(value)) {
27317
- var other = typeof value.valueOf == "function" ? value.valueOf() : value;
27318
- value = isObject2(other) ? other + "" : other;
27319
- }
27320
- if (typeof value != "string") {
27321
- return value === 0 ? value : +value;
27322
- }
27323
- value = baseTrim(value);
27324
- var isBinary = reIsBinary.test(value);
27325
- return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
28122
+ const StoreCreditAccountPage = () => {
28123
+ const { id } = reactRouterDom.useParams();
28124
+ const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
28125
+ id
28126
+ );
28127
+ if (!storeCreditAccount) {
28128
+ return;
27326
28129
  }
27327
- toNumber_1 = toNumber;
27328
- return toNumber_1;
27329
- }
27330
- var debounce_1;
27331
- var hasRequiredDebounce;
27332
- function requireDebounce() {
27333
- if (hasRequiredDebounce) return debounce_1;
27334
- hasRequiredDebounce = 1;
27335
- var isObject2 = requireIsObject(), now = requireNow(), toNumber = requireToNumber();
27336
- var FUNC_ERROR_TEXT = "Expected a function";
27337
- var nativeMax = Math.max, nativeMin = Math.min;
27338
- function debounce2(func, wait, options) {
27339
- var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
27340
- if (typeof func != "function") {
27341
- throw new TypeError(FUNC_ERROR_TEXT);
27342
- }
27343
- wait = toNumber(wait) || 0;
27344
- if (isObject2(options)) {
27345
- leading = !!options.leading;
27346
- maxing = "maxWait" in options;
27347
- maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
27348
- trailing = "trailing" in options ? !!options.trailing : trailing;
27349
- }
27350
- function invokeFunc(time2) {
27351
- var args = lastArgs, thisArg = lastThis;
27352
- lastArgs = lastThis = void 0;
27353
- lastInvokeTime = time2;
27354
- result = func.apply(thisArg, args);
27355
- return result;
27356
- }
27357
- function leadingEdge(time2) {
27358
- lastInvokeTime = time2;
27359
- timerId = setTimeout(timerExpired, wait);
27360
- return leading ? invokeFunc(time2) : result;
27361
- }
27362
- function remainingWait(time2) {
27363
- var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
27364
- return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
27365
- }
27366
- function shouldInvoke(time2) {
27367
- var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime;
27368
- return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
27369
- }
27370
- function timerExpired() {
27371
- var time2 = now();
27372
- if (shouldInvoke(time2)) {
27373
- return trailingEdge(time2);
28130
+ return /* @__PURE__ */ jsxRuntime.jsx(
28131
+ components.LayoutComposer,
28132
+ {
28133
+ widgetsZonePrefix: "store_credit_account.details",
28134
+ preferredLayoutId: "core:two-column",
28135
+ data: storeCreditAccount,
28136
+ sections: {
28137
+ main: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
28138
+ /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountDetailsSection", children: /* @__PURE__ */ jsxRuntime.jsx(
28139
+ StoreCreditAccountDetailsSection,
28140
+ {
28141
+ storeCreditAccount
28142
+ }
28143
+ ) }),
28144
+ /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "TransactionsTable", children: /* @__PURE__ */ jsxRuntime.jsx(TransactionsTable, { id: storeCreditAccount.id }) })
28145
+ ] }),
28146
+ side: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
28147
+ /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountBalanceSection", children: /* @__PURE__ */ jsxRuntime.jsx(
28148
+ StoreCreditAccountBalanceSection,
28149
+ {
28150
+ storeCreditAccount
28151
+ }
28152
+ ) }),
28153
+ /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountCodeSection", children: /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountCodeSection, { code: storeCreditAccount.code }) }),
28154
+ /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountCustomerSection", children: /* @__PURE__ */ jsxRuntime.jsx(
28155
+ StoreCreditAccountCustomerSection,
28156
+ {
28157
+ customerId: storeCreditAccount.customer_id
28158
+ }
28159
+ ) })
28160
+ ] })
27374
28161
  }
27375
- timerId = setTimeout(timerExpired, remainingWait(time2));
27376
28162
  }
27377
- function trailingEdge(time2) {
27378
- timerId = void 0;
27379
- if (trailing && lastArgs) {
27380
- return invokeFunc(time2);
28163
+ );
28164
+ };
28165
+ const handle$c = {
28166
+ permissions: ["store_credit_account:read"]
28167
+ };
28168
+ const KeyboundForm = React__namespace.default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
28169
+ const handleSubmit = (event) => {
28170
+ event.preventDefault();
28171
+ onSubmit?.(event);
28172
+ };
28173
+ const handleKeyDown = (event) => {
28174
+ if (event.key === "Enter") {
28175
+ if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
28176
+ return;
27381
28177
  }
27382
- lastArgs = lastThis = void 0;
27383
- return result;
27384
- }
27385
- function cancel() {
27386
- if (timerId !== void 0) {
27387
- clearTimeout(timerId);
28178
+ event.preventDefault();
28179
+ if (event.metaKey || event.ctrlKey) {
28180
+ handleSubmit(event);
27388
28181
  }
27389
- lastInvokeTime = 0;
27390
- lastArgs = lastCallTime = lastThis = timerId = void 0;
27391
28182
  }
27392
- function flush() {
27393
- return timerId === void 0 ? result : trailingEdge(now());
27394
- }
27395
- function debounced() {
27396
- var time2 = now(), isInvoking = shouldInvoke(time2);
27397
- lastArgs = arguments;
27398
- lastThis = this;
27399
- lastCallTime = time2;
27400
- if (isInvoking) {
27401
- if (timerId === void 0) {
27402
- return leadingEdge(lastCallTime);
27403
- }
27404
- if (maxing) {
27405
- clearTimeout(timerId);
27406
- timerId = setTimeout(timerExpired, wait);
27407
- return invokeFunc(lastCallTime);
27408
- }
27409
- }
27410
- if (timerId === void 0) {
27411
- timerId = setTimeout(timerExpired, wait);
27412
- }
27413
- return result;
28183
+ };
28184
+ return /* @__PURE__ */ jsxRuntime.jsx(
28185
+ "form",
28186
+ {
28187
+ ...rest,
28188
+ onSubmit: handleSubmit,
28189
+ onKeyDown: onKeyDown ?? handleKeyDown,
28190
+ ref
27414
28191
  }
27415
- debounced.cancel = cancel;
27416
- debounced.flush = flush;
27417
- return debounced;
27418
- }
27419
- debounce_1 = debounce2;
27420
- return debounce_1;
27421
- }
27422
- var debounceExports = requireDebounce();
27423
- const debounce$1 = /* @__PURE__ */ getDefaultExportFromCjs(debounceExports);
27424
- const useDebouncedSearch = () => {
27425
- const [searchValue, onSearchValueChange] = React.useState("");
27426
- const [debouncedQuery, setDebouncedQuery] = React.useState("");
27427
- const debouncedUpdate = React.useCallback(
27428
- debounce$1((query) => setDebouncedQuery(query), 300),
27429
- []
27430
28192
  );
27431
- React.useEffect(() => {
27432
- debouncedUpdate(searchValue);
27433
- return () => debouncedUpdate.cancel();
27434
- }, [searchValue, debouncedUpdate]);
27435
- return {
27436
- searchValue,
27437
- onSearchValueChange,
27438
- query: debouncedQuery || void 0
27439
- };
28193
+ });
28194
+ KeyboundForm.displayName = "KeyboundForm";
28195
+ const Note$1 = () => {
28196
+ const { id } = reactRouterDom.useParams();
28197
+ const {
28198
+ store_credit_account: storeCreditAccount,
28199
+ isPending,
28200
+ isError,
28201
+ error: error2
28202
+ } = useStoreCreditAccount(id, {});
28203
+ if (isError) {
28204
+ throw error2;
28205
+ }
28206
+ const isReady = !isPending && !!storeCreditAccount;
28207
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
28208
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
28209
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Credit store credit account" }) }),
28210
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Credit the store credit account" }) })
28211
+ ] }),
28212
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountCreditForm, { storeCreditAccount })
28213
+ ] });
27440
28214
  };
27441
- const useComboboxData = ({
27442
- queryKey,
27443
- queryFn,
27444
- getOptions,
27445
- defaultValue: defaultValue2,
27446
- defaultValueKey,
27447
- pageSize = 10
28215
+ const StoreCreditAccountCreditForm = ({
28216
+ storeCreditAccount
27448
28217
  }) => {
27449
- const { searchValue, onSearchValueChange, query } = useDebouncedSearch();
27450
- const queryInitialDataBy = defaultValueKey || "id";
27451
- const { data: initialData } = reactQuery.useQuery({
27452
- queryKey,
27453
- queryFn: async () => {
27454
- return queryFn({
27455
- [queryInitialDataBy]: defaultValue2,
27456
- limit: Array.isArray(defaultValue2) ? defaultValue2.length : 1
27457
- });
27458
- },
27459
- enabled: !!defaultValue2
27460
- });
27461
- const { data, ...rest } = reactQuery.useInfiniteQuery({
27462
- queryKey: [...queryKey, query],
27463
- queryFn: async ({ pageParam = 0 }) => {
27464
- return await queryFn({
27465
- q: query,
27466
- limit: pageSize,
27467
- offset: pageParam
27468
- });
27469
- },
27470
- initialPageParam: 0,
27471
- getNextPageParam: (lastPage) => {
27472
- const moreItemsExist = lastPage.count > lastPage.offset + lastPage.limit;
27473
- return moreItemsExist ? lastPage.offset + lastPage.limit : void 0;
28218
+ const form = useForm({
28219
+ defaultValues: {
28220
+ amount: {
28221
+ float: 0,
28222
+ value: ""
28223
+ },
28224
+ note: ""
27474
28225
  },
27475
- placeholderData: reactQuery.keepPreviousData
28226
+ resolver: u(schema$3)
27476
28227
  });
27477
- const options = data?.pages.flatMap((page) => getOptions(page)) ?? [];
27478
- const defaultOptions2 = initialData ? getOptions(initialData) : [];
27479
- const disabled = !rest.isPending && !options.length && !searchValue;
27480
- if (defaultValue2 && defaultOptions2.length && !searchValue) {
27481
- defaultOptions2.forEach((option) => {
27482
- if (!options.find((o2) => o2.value === option.value)) {
27483
- options.unshift(option);
28228
+ const { mutateAsync, isPending } = useCreditStoreCreditAccount(
28229
+ storeCreditAccount.id
28230
+ );
28231
+ const { handleSuccess } = useRouteModal();
28232
+ const onSubmit = form.handleSubmit(async (data) => {
28233
+ if (data.amount.float <= 0) {
28234
+ form.setError("amount", { message: "Amount must be greater than 0" });
28235
+ return;
28236
+ }
28237
+ await mutateAsync(
28238
+ { amount: data.amount.float, note: data.note },
28239
+ {
28240
+ onSuccess: () => handleSuccess(),
28241
+ onError: (error2) => ui.toast.error(error2.message)
27484
28242
  }
27485
- });
27486
- }
27487
- return {
27488
- options,
27489
- searchValue,
27490
- onSearchValueChange,
27491
- disabled,
27492
- ...rest
27493
- };
28243
+ );
28244
+ });
28245
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
28246
+ KeyboundForm,
28247
+ {
28248
+ className: "flex flex-1 flex-col overflow-hidden",
28249
+ onSubmit,
28250
+ children: [
28251
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
28252
+ /* @__PURE__ */ jsxRuntime.jsx(
28253
+ Form$2.Field,
28254
+ {
28255
+ control: form.control,
28256
+ name: "amount",
28257
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
28258
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Amount" }),
28259
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
28260
+ ui.CurrencyInput,
28261
+ {
28262
+ min: 0,
28263
+ placeholder: "0",
28264
+ value: field.value.value,
28265
+ onValueChange: (_value, _name, values) => {
28266
+ field.onChange({
28267
+ value: values?.value,
28268
+ float: values?.float || null
28269
+ });
28270
+ },
28271
+ symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
28272
+ code: storeCreditAccount.currency_code.toUpperCase()
28273
+ }
28274
+ ) }),
28275
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
28276
+ ] })
28277
+ }
28278
+ ),
28279
+ /* @__PURE__ */ jsxRuntime.jsx(
28280
+ Form$2.Field,
28281
+ {
28282
+ control: form.control,
28283
+ name: "note",
28284
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
28285
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
28286
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
28287
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
28288
+ ] })
28289
+ }
28290
+ )
28291
+ ] }),
28292
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
28293
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
28294
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
28295
+ ] }) })
28296
+ ]
28297
+ }
28298
+ ) });
27494
28299
  };
27495
- const formSchema = zod.z.object({
27496
- currency_code: zod.z.string().min(1, "Please select a currency"),
27497
- customer_id: zod.z.string().optional()
28300
+ const schema$3 = zod.z.object({
28301
+ note: zod.z.string(),
28302
+ amount: zod.z.object({
28303
+ float: zod.z.number(),
28304
+ value: zod.z.string()
28305
+ })
27498
28306
  });
27499
- const StoreCreditAccountCreateForm = () => {
27500
- const { handleSuccess } = useRouteModal();
27501
- const [searchParams] = reactRouterDom.useSearchParams();
27502
- const prefilledCustomerId = searchParams.get("prefill_customer_id") ?? "";
28307
+ const handle$b = {
28308
+ permissions: ["store_credit_account:read", "store_credit_account:update"]
28309
+ };
28310
+ const Debit = () => {
28311
+ const { id } = reactRouterDom.useParams();
28312
+ const {
28313
+ store_credit_account: storeCreditAccount,
28314
+ isPending,
28315
+ isError,
28316
+ error: error2
28317
+ } = useStoreCreditAccount(id, {});
28318
+ if (isError) {
28319
+ throw error2;
28320
+ }
28321
+ const isReady = !isPending && !!storeCreditAccount;
28322
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
28323
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
28324
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Debit store credit account" }) }),
28325
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Debit the store credit account" }) })
28326
+ ] }),
28327
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountDebitForm, { storeCreditAccount })
28328
+ ] });
28329
+ };
28330
+ const StoreCreditAccountDebitForm = ({
28331
+ storeCreditAccount
28332
+ }) => {
27503
28333
  const form = useForm({
27504
28334
  defaultValues: {
27505
- currency_code: "",
27506
- customer_id: prefilledCustomerId
28335
+ amount: {
28336
+ float: 0,
28337
+ value: ""
28338
+ },
28339
+ note: ""
27507
28340
  },
27508
- resolver: u(formSchema)
28341
+ resolver: u(schema$2)
27509
28342
  });
27510
- const { mutateAsync: createStoreCreditAccount, isPending } = useCreateStoreCreditAccount();
27511
- const handleSubmit = form.handleSubmit(async (data) => {
27512
- if (!data.customer_id) {
27513
- delete data.customer_id;
28343
+ const { mutateAsync, isPending } = useDebitStoreCreditAccount(
28344
+ storeCreditAccount.id
28345
+ );
28346
+ const { handleSuccess } = useRouteModal();
28347
+ const balance = storeCreditAccount.balance ?? 0;
28348
+ const onSubmit = form.handleSubmit(async (data) => {
28349
+ if (data.amount.float <= 0) {
28350
+ form.setError("amount", { message: "Amount must be greater than 0" });
28351
+ return;
27514
28352
  }
27515
- await createStoreCreditAccount(data, {
27516
- onSuccess: (data2) => {
27517
- ui.toast.success(`Store credit account was successfully created.`);
27518
- handleSuccess(`../${data2.store_credit_account.id}`);
27519
- },
27520
- onError: (error2) => {
27521
- ui.toast.error(error2.message);
27522
- }
27523
- });
27524
- });
27525
- const [currencySearchValue, setCurrencySearchValue] = React.useState("");
27526
- const currencyOptions = React.useMemo(() => {
27527
- const options = Object.values(currencies).map((currency) => ({
27528
- label: `${currency.code} - ${currency.name} (${currency.symbol_native})`,
27529
- value: currency.code.toLowerCase()
27530
- }));
27531
- if (!currencySearchValue) {
27532
- return options;
28353
+ if (data.amount.float > balance) {
28354
+ form.setError("amount", {
28355
+ message: "Amount can't be greater than the current balance"
28356
+ });
28357
+ return;
27533
28358
  }
27534
- return options.filter(
27535
- (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
28359
+ await mutateAsync(
28360
+ { amount: data.amount.float, note: data.note },
28361
+ {
28362
+ onSuccess: () => handleSuccess(),
28363
+ onError: (error2) => ui.toast.error(error2.message)
28364
+ }
27536
28365
  );
27537
- }, [currencySearchValue]);
27538
- const {
27539
- options: customerOptions,
27540
- fetchNextPage,
27541
- isFetchingNextPage,
27542
- searchValue,
27543
- onSearchValueChange,
27544
- isLoading
27545
- } = useComboboxData({
27546
- queryKey: customersQueryKeys.list(),
27547
- defaultValue: prefilledCustomerId || void 0,
27548
- queryFn: async (params) => {
27549
- return sdk.admin.customer.list(params);
27550
- },
27551
- getOptions: (data) => {
27552
- return data.customers?.map((customer) => {
27553
- const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
27554
- const label = fullName ? `${customer.email} (${fullName})` : customer.email;
27555
- return {
27556
- label,
27557
- value: customer.id
27558
- };
27559
- }) || [];
27560
- }
27561
28366
  });
27562
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Form, { form, children: [
27563
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "-my-2 w-full border-l" }) }),
27564
- /* @__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: [
27565
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
27566
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Create Store Credit Account" }),
27567
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new store credit account for a customer" })
27568
- ] }),
27569
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-x-4", children: [
27570
- /* @__PURE__ */ jsxRuntime.jsx(
27571
- Form$2.Field,
27572
- {
27573
- control: form.control,
27574
- name: "currency_code",
27575
- render: ({ field }) => {
27576
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "w-full", children: [
27577
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { className: "font-normal", children: "Currency" }),
28367
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
28368
+ KeyboundForm,
28369
+ {
28370
+ className: "flex flex-1 flex-col overflow-hidden",
28371
+ onSubmit,
28372
+ children: [
28373
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
28374
+ /* @__PURE__ */ jsxRuntime.jsx(
28375
+ Form$2.Field,
28376
+ {
28377
+ control: form.control,
28378
+ name: "amount",
28379
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
28380
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Amount" }),
27578
28381
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
27579
- Combobox2,
28382
+ ui.CurrencyInput,
27580
28383
  {
27581
- value: field.value,
27582
- onChange: field.onChange,
27583
- searchValue: currencySearchValue,
27584
- onSearchValueChange: setCurrencySearchValue,
27585
- options: currencyOptions,
27586
- placeholder: "Search for a currency..."
28384
+ min: 0,
28385
+ placeholder: "0",
28386
+ value: field.value.value,
28387
+ onValueChange: (_value, _name, values) => {
28388
+ field.onChange({
28389
+ value: values?.value,
28390
+ float: values?.float || null
28391
+ });
28392
+ },
28393
+ symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
28394
+ code: storeCreditAccount.currency_code.toUpperCase()
27587
28395
  }
27588
28396
  ) }),
27589
28397
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
27590
- ] });
28398
+ ] })
27591
28399
  }
27592
- }
27593
- ),
27594
- /* @__PURE__ */ jsxRuntime.jsx(
27595
- Form$2.Field,
27596
- {
27597
- control: form.control,
27598
- name: "customer_id",
27599
- render: ({ field }) => {
27600
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "w-full", children: [
27601
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { className: "font-normal", children: "Customer" }),
27602
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
27603
- Combobox2,
27604
- {
27605
- value: field.value,
27606
- onChange: field.onChange,
27607
- searchValue,
27608
- onSearchValueChange,
27609
- options: customerOptions,
27610
- placeholder: "Search for a customer...",
27611
- fetchNextPage,
27612
- isFetchingNextPage,
27613
- noResultsPlaceholder: isLoading ? "Loading customers..." : "No customers found"
27614
- }
27615
- ) }),
28400
+ ),
28401
+ /* @__PURE__ */ jsxRuntime.jsx(
28402
+ Form$2.Field,
28403
+ {
28404
+ control: form.control,
28405
+ name: "note",
28406
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
28407
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
28408
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
27616
28409
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
27617
- ] });
28410
+ ] })
27618
28411
  }
27619
- }
27620
- )
27621
- ] })
27622
- ] }) }) }),
27623
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Footer, { children: [
27624
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, disabled: isPending, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", disabled: isPending, children: "Cancel" }) }),
27625
- /* @__PURE__ */ jsxRuntime.jsx(
27626
- ui.Button,
27627
- {
27628
- variant: "primary",
27629
- size: "small",
27630
- onClick: handleSubmit,
27631
- disabled: isPending,
27632
- children: "Create"
27633
- }
27634
- )
27635
- ] })
27636
- ] });
28412
+ )
28413
+ ] }),
28414
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
28415
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
28416
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
28417
+ ] }) })
28418
+ ]
28419
+ }
28420
+ ) });
27637
28421
  };
27638
- const StoreCreditAccountCreate = () => {
27639
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal, { children: [
27640
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Create Store Credit Account" }) }),
27641
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Create a new store credit account" }) }),
27642
- /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountCreateForm, {})
27643
- ] });
28422
+ const schema$2 = zod.z.object({
28423
+ note: zod.z.string(),
28424
+ amount: zod.z.object({
28425
+ float: zod.z.number(),
28426
+ value: zod.z.string()
28427
+ })
28428
+ });
28429
+ const handle$a = {
28430
+ permissions: ["store_credit_account:read", "store_credit_account:update"]
27644
28431
  };
27645
28432
  function _extends() {
27646
28433
  return _extends = Object.assign ? Object.assign.bind() : function(n2) {
@@ -30177,6 +30964,8 @@ const SectionRow = ({ title, value, actions }) => {
30177
30964
  );
30178
30965
  };
30179
30966
  const GiftCardGeneralSection = ({ giftCard }) => {
30967
+ const { hasPermission } = hooks.usePermissions();
30968
+ const canUpdate = hasPermission("gift_card:update");
30180
30969
  const hasGiftCardExpired = React.useMemo(() => {
30181
30970
  return giftCard.expires_at && new Date(giftCard.expires_at) < /* @__PURE__ */ new Date();
30182
30971
  }, [giftCard.expires_at]);
@@ -30197,7 +30986,7 @@ const GiftCardGeneralSection = ({ giftCard }) => {
30197
30986
  ] }),
30198
30987
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-4", children: [
30199
30988
  hasGiftCardExpired && /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: "orange", children: "Expired" }),
30200
- /* @__PURE__ */ jsxRuntime.jsx(
30989
+ canUpdate && /* @__PURE__ */ jsxRuntime.jsx(
30201
30990
  ActionMenu,
30202
30991
  {
30203
30992
  groups: [
@@ -30276,13 +31065,15 @@ const GiftCardGeneralSection = ({ giftCard }) => {
30276
31065
  ] });
30277
31066
  };
30278
31067
  const GiftCardNoteSection = ({ giftCard }) => {
31068
+ const { hasPermission } = hooks.usePermissions();
31069
+ const canUpdate = hasPermission("gift_card:update");
30279
31070
  if (!giftCard) {
30280
31071
  return;
30281
31072
  }
30282
31073
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
30283
31074
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
30284
31075
  /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Note" }),
30285
- /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: "note", className: "text-ui-fg-muted text-sm px-6", children: "Edit note" })
31076
+ canUpdate && /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: "note", className: "text-ui-fg-muted text-sm px-6", children: "Edit note" })
30286
31077
  ] }),
30287
31078
  giftCard.note && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2 px-2 pb-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shadow-elevation-card-rest bg-ui-bg-component transition-fg hover:bg-ui-bg-component-hover active:bg-ui-bg-component-pressed group-focus-visible:shadow-borders-interactive-with-active rounded-md px-4 py-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col", children: /* @__PURE__ */ jsxRuntime.jsx(
30288
31079
  ui.Text,
@@ -30321,299 +31112,6 @@ const GiftCardOrderSection = ({ giftCard }) => {
30321
31112
  ))
30322
31113
  ] });
30323
31114
  };
30324
- var __create = Object.create;
30325
- var __defProp = Object.defineProperty;
30326
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
30327
- var __getOwnPropNames = Object.getOwnPropertyNames;
30328
- var __getProtoOf = Object.getPrototypeOf;
30329
- var __hasOwnProp = Object.prototype.hasOwnProperty;
30330
- var __commonJS = (cb, mod) => function __require() {
30331
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
30332
- };
30333
- var __copyProps = (to, from, except, desc) => {
30334
- if (from && typeof from === "object" || typeof from === "function") {
30335
- for (let key2 of __getOwnPropNames(from))
30336
- if (!__hasOwnProp.call(to, key2) && key2 !== except)
30337
- __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
30338
- }
30339
- return to;
30340
- };
30341
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30342
- // If the importer is in node compatibility mode or this is not an ESM
30343
- // file that has been converted to a CommonJS file using a Babel-
30344
- // compatible transform (i.e. "__esModule" has not been set), then set
30345
- // "default" to the CommonJS "module.exports" for node compatibility.
30346
- __defProp(target, "default", { value: mod, enumerable: true }),
30347
- mod
30348
- ));
30349
- var require_toggle_selection = __commonJS({
30350
- "node_modules/toggle-selection/index.js"(exports2, module2) {
30351
- module2.exports = function() {
30352
- var selection = document.getSelection();
30353
- if (!selection.rangeCount) {
30354
- return function() {
30355
- };
30356
- }
30357
- var active = document.activeElement;
30358
- var ranges = [];
30359
- for (var i2 = 0; i2 < selection.rangeCount; i2++) {
30360
- ranges.push(selection.getRangeAt(i2));
30361
- }
30362
- switch (active.tagName.toUpperCase()) {
30363
- // .toUpperCase handles XHTML
30364
- case "INPUT":
30365
- case "TEXTAREA":
30366
- active.blur();
30367
- break;
30368
- default:
30369
- active = null;
30370
- break;
30371
- }
30372
- selection.removeAllRanges();
30373
- return function() {
30374
- selection.type === "Caret" && selection.removeAllRanges();
30375
- if (!selection.rangeCount) {
30376
- ranges.forEach(function(range) {
30377
- selection.addRange(range);
30378
- });
30379
- }
30380
- active && active.focus();
30381
- };
30382
- };
30383
- }
30384
- });
30385
- var import_index = __toESM(require_toggle_selection());
30386
- var toggle_selection_default = import_index.default;
30387
- var defaultMessage = "Copy to clipboard: #{key}, Enter";
30388
- function formatPromptMessage(message2) {
30389
- var isMac2 = navigator.userAgentData ? /mac/i.test(navigator.userAgentData.platform) : /mac os x/i.test(navigator.userAgent);
30390
- var copyKey = (isMac2 ? "⌘" : "Ctrl") + "+C";
30391
- return message2.replace(/#{\s*key\s*}/g, copyKey);
30392
- }
30393
- function buildClipboardItem(text2, format2) {
30394
- var items = {};
30395
- items["text/plain"] = new Blob([text2], { type: "text/plain" });
30396
- if (format2 && format2 !== "text/plain") {
30397
- items[format2] = new Blob([text2], { type: format2 });
30398
- }
30399
- return new ClipboardItem(items);
30400
- }
30401
- async function copyViaClipboardAPI(text2, options) {
30402
- if (!options.format && !options.onCopy) {
30403
- await navigator.clipboard.writeText(text2);
30404
- return true;
30405
- }
30406
- var item = buildClipboardItem(text2, options.format);
30407
- if (options.onCopy) {
30408
- item = options.onCopy(item) || item;
30409
- }
30410
- await navigator.clipboard.write([item]);
30411
- return true;
30412
- }
30413
- function createHiddenSpan(text2, options) {
30414
- var mark = document.createElement("span");
30415
- mark.textContent = text2;
30416
- mark.ariaHidden = "true";
30417
- mark.style.all = "unset";
30418
- mark.style.position = "fixed";
30419
- mark.style.top = "0";
30420
- mark.style.clip = "rect(0, 0, 0, 0)";
30421
- mark.style.whiteSpace = "pre";
30422
- mark.style.webkitUserSelect = "text";
30423
- mark.style.MozUserSelect = "text";
30424
- mark.style.msUserSelect = "text";
30425
- mark.style.userSelect = "text";
30426
- mark.addEventListener("copy", function(e) {
30427
- e.stopPropagation();
30428
- if (options.format) {
30429
- e.preventDefault();
30430
- if (e.clipboardData) {
30431
- e.clipboardData.setData(options.format, text2);
30432
- }
30433
- }
30434
- if (options.onCopy && e.clipboardData) {
30435
- options.onCopy(e.clipboardData);
30436
- }
30437
- });
30438
- return mark;
30439
- }
30440
- function findOpenedModalDialog() {
30441
- let element = document.activeElement;
30442
- while (element) {
30443
- if (element.tagName === "DIALOG" && element.open) {
30444
- return element;
30445
- }
30446
- element = element.parentElement;
30447
- }
30448
- return null;
30449
- }
30450
- function copyViaExecCommand(text2, options) {
30451
- var reselectPrevious = toggle_selection_default();
30452
- var range = document.createRange();
30453
- var selection = document.getSelection();
30454
- var mark = createHiddenSpan(text2, options);
30455
- var root = findOpenedModalDialog() || document.fullscreenElement || document.body;
30456
- var success = false;
30457
- try {
30458
- root.appendChild(mark);
30459
- range.selectNodeContents(mark);
30460
- selection.removeAllRanges();
30461
- selection.addRange(range);
30462
- var successful = document.execCommand("copy");
30463
- if (!successful) {
30464
- throw new Error("copy command was unsuccessful");
30465
- }
30466
- success = true;
30467
- } finally {
30468
- if (typeof selection.removeRange == "function") {
30469
- selection.removeRange(range);
30470
- } else {
30471
- selection.removeAllRanges();
30472
- }
30473
- root.removeChild(mark);
30474
- reselectPrevious();
30475
- }
30476
- return success;
30477
- }
30478
- async function copy$1(text2, options = {}) {
30479
- var debug2 = options.debug || false;
30480
- if (window.isSecureContext && navigator.clipboard) {
30481
- try {
30482
- return await copyViaClipboardAPI(text2, options);
30483
- } catch (err) {
30484
- debug2 && console.error("unable to copy using navigator.clipboard: ", err);
30485
- debug2 && console.warn("falling back to execCommand");
30486
- }
30487
- } else {
30488
- debug2 && !window.isSecureContext && console.warn("copy-to-clipboard: navigator.clipboard requires a secure context (HTTPS/localhost). Falling back to execCommand.");
30489
- }
30490
- try {
30491
- return copyViaExecCommand(text2, options);
30492
- } catch (err) {
30493
- debug2 && console.error("unable to copy using execCommand: ", err);
30494
- debug2 && console.error("falling back to prompt");
30495
- if (options.fallbackToPrompt) {
30496
- var message2 = formatPromptMessage("message" in options ? options.message : defaultMessage);
30497
- window.prompt(message2, text2);
30498
- }
30499
- }
30500
- return false;
30501
- }
30502
- var index_default = copy$1;
30503
- function DisplayId({ id, className }) {
30504
- const [open2, setOpen] = React.useState(false);
30505
- const onClick = () => {
30506
- index_default(id);
30507
- ui.toast.success("Copied to clipboard");
30508
- };
30509
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { maxWidth: 260, content: id, open: open2, onOpenChange: setOpen, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { onClick, className: ui.clx("cursor-pointer", className), children: [
30510
- "#",
30511
- id.slice(-7)
30512
- ] }) });
30513
- }
30514
- const columnHelper$8 = ui.createDataTableColumnHelper();
30515
- const useTransactionsTableColumns = () => {
30516
- return React.useMemo(() => {
30517
- return [
30518
- columnHelper$8.accessor("id", {
30519
- header: "ID",
30520
- cell: ({ row }) => {
30521
- return /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: row.original.id });
30522
- }
30523
- }),
30524
- columnHelper$8.accessor("created_at", {
30525
- header: "Created At",
30526
- cell: ({ row }) => formatDate(row.original.created_at, false)
30527
- }),
30528
- columnHelper$8.accessor("note", {
30529
- header: "Description",
30530
- cell: ({ row }) => row.original.note
30531
- }),
30532
- columnHelper$8.accessor("note", {
30533
- header: "Note",
30534
- cell: ({ row }) => {
30535
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { title: row.original.note, className: "max-w-[300px] truncate", children: row.original.note || "-" });
30536
- }
30537
- }),
30538
- columnHelper$8.accessor("amount", {
30539
- header: "Amount",
30540
- cell: ({ row }) => {
30541
- const isDebit = row.original.type === "debit";
30542
- return row.original.account.currency_code && formatAmount(
30543
- row.original.amount * (isDebit ? -1 : 1),
30544
- row.original.account.currency_code
30545
- );
30546
- }
30547
- })
30548
- ];
30549
- }, []);
30550
- };
30551
- const useTransactionsTableFilters = ({}) => {
30552
- const dateFilterOptions = useDataTableDateFilters$1();
30553
- return React.useMemo(() => {
30554
- return [...dateFilterOptions];
30555
- }, [dateFilterOptions]);
30556
- };
30557
- const useTransactionsTableQuery = ({
30558
- prefix,
30559
- pageSize = 20
30560
- }) => {
30561
- const queryObject = useQueryParams(
30562
- ["offset", "limit", "currency_code", "created_at", "updated_at"],
30563
- prefix
30564
- );
30565
- const { offset: offset2, limit, created_at, updated_at, ...rest } = queryObject;
30566
- const searchParams = {
30567
- limit: limit ? Number(limit) : pageSize,
30568
- offset: offset2 ? Number(offset2) : 0,
30569
- created_at: created_at ? JSON.parse(created_at) : void 0,
30570
- updated_at: updated_at ? JSON.parse(updated_at) : void 0,
30571
- ...rest
30572
- };
30573
- return searchParams;
30574
- };
30575
- const PAGE_SIZE$4 = 10;
30576
- function TransactionsTable({ id }) {
30577
- const queryParams = useTransactionsTableQuery({
30578
- pageSize: PAGE_SIZE$4
30579
- });
30580
- const { transactions, isLoading, count: count2 } = useStoreCreditAccountTransactions(
30581
- id,
30582
- {
30583
- ...queryParams,
30584
- order: queryParams.order ?? "-created_at",
30585
- fields: "*account"
30586
- }
30587
- );
30588
- const columns = useTransactionsTableColumns();
30589
- const filters = useTransactionsTableFilters({});
30590
- return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
30591
- /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
30592
- DataTable,
30593
- {
30594
- data: transactions ?? [],
30595
- getRowId: (row) => row.id,
30596
- columns,
30597
- filters,
30598
- isLoading,
30599
- pageSize: PAGE_SIZE$4,
30600
- rowCount: count2,
30601
- enableSearch: false,
30602
- heading: "Transactions",
30603
- emptyState: {
30604
- empty: {
30605
- heading: "No transactions found"
30606
- },
30607
- filtered: {
30608
- heading: "No results found",
30609
- description: "No transactions match your filter criteria."
30610
- }
30611
- }
30612
- }
30613
- ) }),
30614
- /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
30615
- ] });
30616
- }
30617
31115
  const GiftCardTransactionsSection = ({
30618
31116
  storeCreditAccount
30619
31117
  }) => {
@@ -30621,6 +31119,8 @@ const GiftCardTransactionsSection = ({
30621
31119
  };
30622
31120
  const GiftCardDetailsPage = () => {
30623
31121
  const { id } = reactRouterDom.useParams();
31122
+ const { hasPermission } = hooks.usePermissions();
31123
+ const canReadStoreCreditAccount = hasPermission("store_credit_account:read");
30624
31124
  const { gift_card: giftCard, isLoading } = useGiftCard(id, {
30625
31125
  fields: "*line_item.product,*store_credit_account"
30626
31126
  });
@@ -30630,7 +31130,7 @@ const GiftCardDetailsPage = () => {
30630
31130
  if (!isLoading && !giftCard) {
30631
31131
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Gift card not found" });
30632
31132
  }
30633
- const storeCreditAccount = giftCard?.store_credit_account;
31133
+ const storeCreditAccount = canReadStoreCreditAccount ? giftCard?.store_credit_account : void 0;
30634
31134
  return /* @__PURE__ */ jsxRuntime.jsx(
30635
31135
  components.LayoutComposer,
30636
31136
  {
@@ -30657,39 +31157,15 @@ const GiftCardDetailsPage = () => {
30657
31157
  }
30658
31158
  ) }),
30659
31159
  /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "GiftCardNoteSection", children: /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteSection, { giftCard }) }),
30660
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "GiftCardOrderSection", children: /* @__PURE__ */ jsxRuntime.jsx(GiftCardOrderSection, { giftCard }) })
31160
+ /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "GiftCardOrderSection", children: /* @__PURE__ */ jsxRuntime.jsx(hooks.PermissionGuard, { permission: "order:read", children: /* @__PURE__ */ jsxRuntime.jsx(GiftCardOrderSection, { giftCard }) }) })
30661
31161
  ] })
30662
31162
  }
30663
31163
  }
30664
31164
  );
30665
31165
  };
30666
- const KeyboundForm = React__namespace.default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
30667
- const handleSubmit = (event) => {
30668
- event.preventDefault();
30669
- onSubmit?.(event);
30670
- };
30671
- const handleKeyDown = (event) => {
30672
- if (event.key === "Enter") {
30673
- if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
30674
- return;
30675
- }
30676
- event.preventDefault();
30677
- if (event.metaKey || event.ctrlKey) {
30678
- handleSubmit(event);
30679
- }
30680
- }
30681
- };
30682
- return /* @__PURE__ */ jsxRuntime.jsx(
30683
- "form",
30684
- {
30685
- ...rest,
30686
- onSubmit: handleSubmit,
30687
- onKeyDown: onKeyDown ?? handleKeyDown,
30688
- ref
30689
- }
30690
- );
30691
- });
30692
- KeyboundForm.displayName = "KeyboundForm";
31166
+ const handle$9 = {
31167
+ permissions: ["gift_card:read"]
31168
+ };
30693
31169
  const GiftCardExpiration = () => {
30694
31170
  const { id } = reactRouterDom.useParams();
30695
31171
  const { gift_card: giftCard, isPending, isError, error: error2 } = useGiftCard(id);
@@ -30710,7 +31186,7 @@ const GiftCardExpirationForm = ({ giftCard }) => {
30710
31186
  defaultValues: {
30711
31187
  expires_at: giftCard.expires_at ? new Date(giftCard.expires_at) : null
30712
31188
  },
30713
- resolver: u(schema$3)
31189
+ resolver: u(schema$1)
30714
31190
  });
30715
31191
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
30716
31192
  const { handleSuccess } = useRouteModal();
@@ -30805,10 +31281,13 @@ const GiftCardExpirationForm = ({ giftCard }) => {
30805
31281
  }
30806
31282
  ) });
30807
31283
  };
30808
- const schema$3 = zod.z.object({
31284
+ const schema$1 = zod.z.object({
30809
31285
  expires_at: zod.z.date().nullish()
30810
31286
  });
30811
- const Note$1 = () => {
31287
+ const handle$8 = {
31288
+ permissions: ["gift_card:read", "gift_card:update"]
31289
+ };
31290
+ const Note = () => {
30812
31291
  const { id } = reactRouterDom.useParams();
30813
31292
  const {
30814
31293
  gift_card: giftCard,
@@ -30833,7 +31312,7 @@ const GiftCardNoteForm = ({ giftCard }) => {
30833
31312
  defaultValues: {
30834
31313
  note: giftCard.note ?? ""
30835
31314
  },
30836
- resolver: u(schema$2)
31315
+ resolver: u(schema)
30837
31316
  });
30838
31317
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
30839
31318
  const { handleSuccess } = useRouteModal();
@@ -30872,9 +31351,12 @@ const GiftCardNoteForm = ({ giftCard }) => {
30872
31351
  }
30873
31352
  ) });
30874
31353
  };
30875
- const schema$2 = zod.z.object({
31354
+ const schema = zod.z.object({
30876
31355
  note: zod.z.string().optional()
30877
31356
  });
31357
+ const handle$7 = {
31358
+ permissions: ["gift_card:read", "gift_card:update"]
31359
+ };
30878
31360
  const columnHelper$7 = createColumnHelper();
30879
31361
  const useGiftCardProductsTableColumns = () => {
30880
31362
  return React.useMemo(
@@ -30941,6 +31423,8 @@ function GiftCardProductsTable() {
30941
31423
  });
30942
31424
  const columns = useGiftCardProductsTableColumns();
30943
31425
  const filters = useGiftCardProductsFilters();
31426
+ const { hasPermission } = hooks.usePermissions();
31427
+ const canCreate = hasPermission("product:create");
30944
31428
  return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
30945
31429
  /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
30946
31430
  DataTable,
@@ -30954,12 +31438,12 @@ function GiftCardProductsTable() {
30954
31438
  rowCount: count2,
30955
31439
  enableSearch: false,
30956
31440
  heading: "Gift Card Products",
30957
- actions: [
31441
+ actions: canCreate ? [
30958
31442
  {
30959
31443
  label: "Create",
30960
31444
  to: "create"
30961
31445
  }
30962
- ],
31446
+ ] : [],
30963
31447
  rowHref: (row) => `${row.id}`,
30964
31448
  emptyState: {
30965
31449
  empty: {
@@ -30992,7 +31476,8 @@ const GiftCardProductsPage = () => {
30992
31476
  ] });
30993
31477
  };
30994
31478
  const config = adminSdk.defineRouteConfig({
30995
- label: "Gift Card Products"
31479
+ label: "Gift Card Products",
31480
+ permissions: ["product:read"]
30996
31481
  });
30997
31482
  const PRICE_PREFERENCES_QUERY_KEY = "price-preferences";
30998
31483
  const pricePreferencesQueryKeys = queryKeysFactory(
@@ -32776,7 +33261,7 @@ function get$1() {
32776
33261
  parseMissingKeyHandler: false,
32777
33262
  appendNamespaceToMissingKey: false,
32778
33263
  appendNamespaceToCIMode: false,
32779
- overloadTranslationOptionHandler: function handle(args) {
33264
+ overloadTranslationOptionHandler: function handle2(args) {
32780
33265
  let ret = {};
32781
33266
  if (typeof args[1] === "object") ret = args[1];
32782
33267
  if (typeof args[1] === "string") ret.defaultValue = args[1];
@@ -44265,7 +44750,7 @@ const GiftCardProductCreateFormMedia = ({
44265
44750
  };
44266
44751
  };
44267
44752
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
44268
- /* @__PURE__ */ jsxRuntime.jsx(UploadMediaFormItem, { form, append, showHint: false }),
44753
+ /* @__PURE__ */ jsxRuntime.jsx(hooks.PermissionGuard, { permission: "file:create", children: /* @__PURE__ */ jsxRuntime.jsx(UploadMediaFormItem, { form, append, showHint: false }) }),
44269
44754
  /* @__PURE__ */ jsxRuntime.jsxs(
44270
44755
  DndContext,
44271
44756
  {
@@ -45363,7 +45848,7 @@ const GiftCardProductCreate = () => {
45363
45848
  isPending: isStorePending,
45364
45849
  isError: isStoreError,
45365
45850
  error: storeError
45366
- } = useStore$2({
45851
+ } = useStore$1({
45367
45852
  fields: "+default_sales_channel"
45368
45853
  });
45369
45854
  const {
@@ -45415,400 +45900,15 @@ const GiftCardProductCreate = () => {
45415
45900
  )
45416
45901
  ] });
45417
45902
  };
45418
- const StoreCreditAccountBalanceSection = ({
45419
- storeCreditAccount
45420
- }) => {
45421
- if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
45422
- return;
45423
- }
45424
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "grid grid-cols-2 gap-x-2 px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-x-3", children: [
45425
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-tag-green-icon h-8 w-1 rounded-full" }),
45426
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
45427
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", size: "small", className: "text-ui-fg-subtle", children: "Current Balance" }),
45428
- /* @__PURE__ */ jsxRuntime.jsx(
45429
- ui.Text,
45430
- {
45431
- weight: "plus",
45432
- size: "xlarge",
45433
- className: "tabular-nums text-ui-fg-base",
45434
- children: formatAmount(
45435
- storeCreditAccount.balance,
45436
- storeCreditAccount.currency_code
45437
- )
45438
- }
45439
- )
45440
- ] })
45441
- ] }) });
45442
- };
45443
- const StoreCreditAccountDetailsSection = ({
45444
- storeCreditAccount
45445
- }) => {
45446
- if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
45447
- return;
45448
- }
45449
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "flex justify-between gap-x-2 px-6 py-6", children: [
45450
- /* @__PURE__ */ jsxRuntime.jsxs(
45451
- ui.Text,
45452
- {
45453
- weight: "plus",
45454
- size: "xlarge",
45455
- className: "text-ui-fg-base flex gap-x-4",
45456
- children: [
45457
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
45458
- /* @__PURE__ */ jsxRuntime.jsx(CreditCardIcon, { className: "inline" }),
45459
- " "
45460
- ] }),
45461
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
45462
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle", children: [
45463
- storeCreditAccount.currency_code.toUpperCase(),
45464
- " Account"
45465
- ] }),
45466
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx(
45467
- ui.Text,
45468
- {
45469
- weight: "regular",
45470
- size: "small",
45471
- className: "text-ui-fg-base flex gap-x-4",
45472
- children: /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: storeCreditAccount.id })
45473
- }
45474
- ) })
45475
- ] })
45476
- ]
45477
- }
45478
- ),
45479
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-x-4", children: /* @__PURE__ */ jsxRuntime.jsx(
45480
- ActionMenu,
45481
- {
45482
- groups: [
45483
- {
45484
- actions: [
45485
- {
45486
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CreditCard, {}),
45487
- label: "Credit the account",
45488
- to: "credit"
45489
- },
45490
- {
45491
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.MinusMini, {}),
45492
- label: "Debit the account",
45493
- to: "debit",
45494
- disabled: !Number(storeCreditAccount.balance)
45495
- }
45496
- ]
45497
- }
45498
- ]
45499
- }
45500
- ) })
45501
- ] });
45502
- };
45503
- function StoreCreditAccountCustomerSection({
45504
- customerId
45505
- }) {
45506
- const { customer, isPending } = useCustomer(customerId, void 0, {
45507
- enabled: !!customerId
45508
- });
45509
- if (isPending || !customer) {
45510
- return null;
45511
- }
45512
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
45513
- /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Customer" }),
45514
- /* @__PURE__ */ jsxRuntime.jsx(
45515
- SidebarLink,
45516
- {
45517
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.User, {}),
45518
- labelKey: customer.email || "N/A",
45519
- descriptionKey: !customer.first_name && !customer.last_name ? "N/A" : `${customer.first_name} ${customer.last_name}`,
45520
- to: `/customers/${customer.id}`
45521
- },
45522
- customer.id
45523
- )
45524
- ] });
45525
- }
45526
- function StoreCreditAccountCodeSection({ code }) {
45527
- if (!code) {
45528
- return null;
45529
- }
45530
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
45531
- /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Account Code" }),
45532
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-4 px-6 mb-2", children: [
45533
- /* @__PURE__ */ jsxRuntime.jsx(icons.Share, { className: "inline" }),
45534
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle text-sm", children: code })
45535
- ] })
45536
- ] });
45537
- }
45538
- const StoreCreditAccountPage = () => {
45539
- const { id } = reactRouterDom.useParams();
45540
- const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
45541
- id
45542
- );
45543
- if (!storeCreditAccount) {
45544
- return;
45545
- }
45546
- return /* @__PURE__ */ jsxRuntime.jsx(
45547
- components.LayoutComposer,
45548
- {
45549
- widgetsZonePrefix: "store_credit_account.details",
45550
- preferredLayoutId: "core:two-column",
45551
- data: storeCreditAccount,
45552
- sections: {
45553
- main: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
45554
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountDetailsSection", children: /* @__PURE__ */ jsxRuntime.jsx(
45555
- StoreCreditAccountDetailsSection,
45556
- {
45557
- storeCreditAccount
45558
- }
45559
- ) }),
45560
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "TransactionsTable", children: /* @__PURE__ */ jsxRuntime.jsx(TransactionsTable, { id: storeCreditAccount.id }) })
45561
- ] }),
45562
- side: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
45563
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountBalanceSection", children: /* @__PURE__ */ jsxRuntime.jsx(
45564
- StoreCreditAccountBalanceSection,
45565
- {
45566
- storeCreditAccount
45567
- }
45568
- ) }),
45569
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountCodeSection", children: /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountCodeSection, { code: storeCreditAccount.code }) }),
45570
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountCustomerSection", children: /* @__PURE__ */ jsxRuntime.jsx(
45571
- StoreCreditAccountCustomerSection,
45572
- {
45573
- customerId: storeCreditAccount.customer_id
45574
- }
45575
- ) })
45576
- ] })
45577
- }
45578
- }
45579
- );
45580
- };
45581
- const Note = () => {
45582
- const { id } = reactRouterDom.useParams();
45583
- const {
45584
- store_credit_account: storeCreditAccount,
45585
- isPending,
45586
- isError,
45587
- error: error2
45588
- } = useStoreCreditAccount(id, {});
45589
- if (isError) {
45590
- throw error2;
45591
- }
45592
- const isReady = !isPending && !!storeCreditAccount;
45593
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
45594
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
45595
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Credit store credit account" }) }),
45596
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Credit the store credit account" }) })
45597
- ] }),
45598
- isReady && /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountCreditForm, { storeCreditAccount })
45599
- ] });
45600
- };
45601
- const StoreCreditAccountCreditForm = ({
45602
- storeCreditAccount
45603
- }) => {
45604
- const form = useForm({
45605
- defaultValues: {
45606
- amount: {
45607
- float: 0,
45608
- value: ""
45609
- },
45610
- note: ""
45611
- },
45612
- resolver: u(schema$1)
45613
- });
45614
- const { mutateAsync, isPending } = useCreditStoreCreditAccount(
45615
- storeCreditAccount.id
45616
- );
45617
- const { handleSuccess } = useRouteModal();
45618
- const onSubmit = form.handleSubmit(async (data) => {
45619
- if (data.amount.float <= 0) {
45620
- form.setError("amount", { message: "Amount must be greater than 0" });
45621
- return;
45622
- }
45623
- await mutateAsync(
45624
- { amount: data.amount.float, note: data.note },
45625
- {
45626
- onSuccess: () => handleSuccess(),
45627
- onError: (error2) => ui.toast.error(error2.message)
45628
- }
45629
- );
45630
- });
45631
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
45632
- KeyboundForm,
45633
- {
45634
- className: "flex flex-1 flex-col overflow-hidden",
45635
- onSubmit,
45636
- children: [
45637
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
45638
- /* @__PURE__ */ jsxRuntime.jsx(
45639
- Form$2.Field,
45640
- {
45641
- control: form.control,
45642
- name: "amount",
45643
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
45644
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Amount" }),
45645
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
45646
- ui.CurrencyInput,
45647
- {
45648
- min: 0,
45649
- placeholder: "0",
45650
- value: field.value.value,
45651
- onValueChange: (_value, _name, values) => {
45652
- field.onChange({
45653
- value: values?.value,
45654
- float: values?.float || null
45655
- });
45656
- },
45657
- symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
45658
- code: storeCreditAccount.currency_code.toUpperCase()
45659
- }
45660
- ) }),
45661
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
45662
- ] })
45663
- }
45664
- ),
45665
- /* @__PURE__ */ jsxRuntime.jsx(
45666
- Form$2.Field,
45667
- {
45668
- control: form.control,
45669
- name: "note",
45670
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
45671
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
45672
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
45673
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
45674
- ] })
45675
- }
45676
- )
45677
- ] }),
45678
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
45679
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
45680
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
45681
- ] }) })
45682
- ]
45683
- }
45684
- ) });
45685
- };
45686
- const schema$1 = zod.z.object({
45687
- note: zod.z.string(),
45688
- amount: zod.z.object({
45689
- float: zod.z.number(),
45690
- value: zod.z.string()
45691
- })
45692
- });
45693
- const Debit = () => {
45694
- const { id } = reactRouterDom.useParams();
45695
- const {
45696
- store_credit_account: storeCreditAccount,
45697
- isPending,
45698
- isError,
45699
- error: error2
45700
- } = useStoreCreditAccount(id, {});
45701
- if (isError) {
45702
- throw error2;
45703
- }
45704
- const isReady = !isPending && !!storeCreditAccount;
45705
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
45706
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
45707
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Debit store credit account" }) }),
45708
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Debit the store credit account" }) })
45709
- ] }),
45710
- isReady && /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountDebitForm, { storeCreditAccount })
45711
- ] });
45712
- };
45713
- const StoreCreditAccountDebitForm = ({
45714
- storeCreditAccount
45715
- }) => {
45716
- const form = useForm({
45717
- defaultValues: {
45718
- amount: {
45719
- float: 0,
45720
- value: ""
45721
- },
45722
- note: ""
45723
- },
45724
- resolver: u(schema)
45725
- });
45726
- const { mutateAsync, isPending } = useDebitStoreCreditAccount(
45727
- storeCreditAccount.id
45728
- );
45729
- const { handleSuccess } = useRouteModal();
45730
- const balance = storeCreditAccount.balance ?? 0;
45731
- const onSubmit = form.handleSubmit(async (data) => {
45732
- if (data.amount.float <= 0) {
45733
- form.setError("amount", { message: "Amount must be greater than 0" });
45734
- return;
45735
- }
45736
- if (data.amount.float > balance) {
45737
- form.setError("amount", {
45738
- message: "Amount can't be greater than the current balance"
45739
- });
45740
- return;
45741
- }
45742
- await mutateAsync(
45743
- { amount: data.amount.float, note: data.note },
45744
- {
45745
- onSuccess: () => handleSuccess(),
45746
- onError: (error2) => ui.toast.error(error2.message)
45747
- }
45748
- );
45749
- });
45750
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
45751
- KeyboundForm,
45752
- {
45753
- className: "flex flex-1 flex-col overflow-hidden",
45754
- onSubmit,
45755
- children: [
45756
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
45757
- /* @__PURE__ */ jsxRuntime.jsx(
45758
- Form$2.Field,
45759
- {
45760
- control: form.control,
45761
- name: "amount",
45762
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
45763
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Amount" }),
45764
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
45765
- ui.CurrencyInput,
45766
- {
45767
- min: 0,
45768
- placeholder: "0",
45769
- value: field.value.value,
45770
- onValueChange: (_value, _name, values) => {
45771
- field.onChange({
45772
- value: values?.value,
45773
- float: values?.float || null
45774
- });
45775
- },
45776
- symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
45777
- code: storeCreditAccount.currency_code.toUpperCase()
45778
- }
45779
- ) }),
45780
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
45781
- ] })
45782
- }
45783
- ),
45784
- /* @__PURE__ */ jsxRuntime.jsx(
45785
- Form$2.Field,
45786
- {
45787
- control: form.control,
45788
- name: "note",
45789
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
45790
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
45791
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
45792
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
45793
- ] })
45794
- }
45795
- )
45796
- ] }),
45797
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
45798
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
45799
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
45800
- ] }) })
45801
- ]
45802
- }
45803
- ) });
45903
+ const handle$6 = {
45904
+ permissions: [
45905
+ "product:create",
45906
+ "store:read",
45907
+ "sales_channel:read",
45908
+ "region:read",
45909
+ "price_preference:read"
45910
+ ]
45804
45911
  };
45805
- const schema = zod.z.object({
45806
- note: zod.z.string(),
45807
- amount: zod.z.object({
45808
- float: zod.z.number(),
45809
- value: zod.z.string()
45810
- })
45811
- });
45812
45912
  const productStatusColor = (status) => {
45813
45913
  switch (status) {
45814
45914
  case "draft":
@@ -45828,6 +45928,9 @@ const ProductGeneralSection = ({
45828
45928
  }) => {
45829
45929
  const prompt = ui.usePrompt();
45830
45930
  const navigate = reactRouterDom.useNavigate();
45931
+ const { hasPermission } = hooks.usePermissions();
45932
+ const canUpdate = hasPermission("product:update");
45933
+ const canDelete = hasPermission("product:delete");
45831
45934
  const { mutateAsync } = useDeleteProduct(product.id);
45832
45935
  const handleDelete = async () => {
45833
45936
  const res = await prompt({
@@ -45857,27 +45960,27 @@ const ProductGeneralSection = ({
45857
45960
  children: product.status
45858
45961
  }
45859
45962
  ),
45860
- /* @__PURE__ */ jsxRuntime.jsx(
45963
+ (canUpdate || canDelete) && /* @__PURE__ */ jsxRuntime.jsx(
45861
45964
  ActionMenu,
45862
45965
  {
45863
45966
  groups: [
45864
45967
  {
45865
- actions: [
45968
+ actions: canUpdate ? [
45866
45969
  {
45867
45970
  label: "Edit",
45868
45971
  to: "edit",
45869
45972
  icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
45870
45973
  }
45871
- ]
45974
+ ] : []
45872
45975
  },
45873
45976
  {
45874
- actions: [
45977
+ actions: canDelete ? [
45875
45978
  {
45876
45979
  label: "Delete",
45877
45980
  onClick: handleDelete,
45878
45981
  icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {})
45879
45982
  }
45880
- ]
45983
+ ] : []
45881
45984
  }
45882
45985
  ]
45883
45986
  }
@@ -45892,6 +45995,8 @@ const ProductGeneralSection = ({
45892
45995
  const ProductMediaSection = ({ product }) => {
45893
45996
  const prompt = ui.usePrompt();
45894
45997
  const [selection, setSelection] = React.useState({});
45998
+ const { hasPermission } = hooks.usePermissions();
45999
+ const canUpdate = hasPermission("product:update");
45895
46000
  const media = getMedia$1(product);
45896
46001
  const handleCheckedChange = (id) => {
45897
46002
  setSelection((prev) => {
@@ -45934,7 +46039,7 @@ const ProductMediaSection = ({ product }) => {
45934
46039
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
45935
46040
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
45936
46041
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Media" }),
45937
- media.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
46042
+ canUpdate && media.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
45938
46043
  reactRouterDom.Link,
45939
46044
  {
45940
46045
  to: `media?view=edit`,
@@ -45950,7 +46055,7 @@ const ProductMediaSection = ({ product }) => {
45950
46055
  {
45951
46056
  className: "shadow-elevation-card-rest hover:shadow-elevation-card-hover transition-fg group relative aspect-square size-full cursor-pointer overflow-hidden rounded-[8px]",
45952
46057
  children: [
45953
- /* @__PURE__ */ jsxRuntime.jsx(
46058
+ canUpdate && /* @__PURE__ */ jsxRuntime.jsx(
45954
46059
  "div",
45955
46060
  {
45956
46061
  className: ui.clx(
@@ -45995,9 +46100,9 @@ const ProductMediaSection = ({ product }) => {
45995
46100
  ),
45996
46101
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Add images to your product" })
45997
46102
  ] }),
45998
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: "media?view=edit", children: "Add images" }) })
46103
+ canUpdate && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: "media?view=edit", children: "Add images" }) })
45999
46104
  ] }),
46000
- /* @__PURE__ */ jsxRuntime.jsx(ui.CommandBar, { open: !!Object.keys(selection).length, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.CommandBar.Bar, { children: [
46105
+ /* @__PURE__ */ jsxRuntime.jsx(ui.CommandBar, { open: canUpdate && !!Object.keys(selection).length, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.CommandBar.Bar, { children: [
46001
46106
  /* @__PURE__ */ jsxRuntime.jsxs(ui.CommandBar.Value, { children: [
46002
46107
  Object.keys(selection).length,
46003
46108
  " selected"
@@ -46034,6 +46139,8 @@ const ProductSalesChannelSection = ({
46034
46139
  product
46035
46140
  }) => {
46036
46141
  const { count: count2 } = useSalesChannels();
46142
+ const { hasPermission } = hooks.usePermissions();
46143
+ const canUpdate = hasPermission("product:update");
46037
46144
  const availableInSalesChannels = product.sales_channels?.map((sc) => ({
46038
46145
  id: sc.id,
46039
46146
  name: sc.name
@@ -46041,7 +46148,7 @@ const ProductSalesChannelSection = ({
46041
46148
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "flex flex-col p-2", children: [
46042
46149
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-3 py-3", children: [
46043
46150
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Sales Channels" }),
46044
- /* @__PURE__ */ jsxRuntime.jsx(
46151
+ canUpdate && /* @__PURE__ */ jsxRuntime.jsx(
46045
46152
  reactRouterDom.Link,
46046
46153
  {
46047
46154
  to: `sales-channels`,
@@ -46067,6 +46174,29 @@ const ProductSalesChannelSection = ({
46067
46174
  )
46068
46175
  ] });
46069
46176
  };
46177
+ const EDIT_GIFT_CARD_DENOMINATIONS_PERMISSIONS = [
46178
+ "product:read",
46179
+ "product_variant:read",
46180
+ "product_option:read",
46181
+ "product:update",
46182
+ "product_option:create",
46183
+ "product_option:update",
46184
+ "product_option:delete"
46185
+ ];
46186
+ const EDIT_GIFT_CARD_PRICES_PERMISSIONS = [
46187
+ "product:read",
46188
+ "product_variant:read",
46189
+ "price:read",
46190
+ "store:read",
46191
+ "product:update",
46192
+ "product_variant:create",
46193
+ "product_variant:update",
46194
+ "product_variant:delete"
46195
+ ];
46196
+ const DELETE_GIFT_CARD_DENOMINATION_PERMISSIONS = [
46197
+ "product:update",
46198
+ "product_variant:delete"
46199
+ ];
46070
46200
  const PAGE_SIZE$1 = 10;
46071
46201
  const PREFIX$1 = "pv";
46072
46202
  const ProductVariantSection = ({
@@ -46092,7 +46222,15 @@ const ProductVariantSection = ({
46092
46222
  ],
46093
46223
  PREFIX$1
46094
46224
  );
46095
- const columns = useColumns$1(product);
46225
+ const { hasAllPermissions } = hooks.usePermissions();
46226
+ const canEditDenominations = hasAllPermissions(
46227
+ EDIT_GIFT_CARD_DENOMINATIONS_PERMISSIONS
46228
+ );
46229
+ const canEditPrices = hasAllPermissions(EDIT_GIFT_CARD_PRICES_PERMISSIONS);
46230
+ const canDeleteDenomination = hasAllPermissions(
46231
+ DELETE_GIFT_CARD_DENOMINATION_PERMISSIONS
46232
+ );
46233
+ const columns = useColumns$1(product, canDeleteDenomination);
46096
46234
  const filters = useFilters();
46097
46235
  const { variants, count: count2, isPending, isError, error: error2 } = useProductVariants(
46098
46236
  product.id,
@@ -46132,16 +46270,20 @@ const ProductVariantSection = ({
46132
46270
  }
46133
46271
  },
46134
46272
  actions: [
46135
- {
46136
- label: "Edit denominations",
46137
- to: `denominations`
46138
- },
46139
- {
46140
- label: "Edit prices",
46141
- to: `prices`
46142
- }
46273
+ ...canEditDenominations ? [
46274
+ {
46275
+ label: "Edit denominations",
46276
+ to: `denominations`
46277
+ }
46278
+ ] : [],
46279
+ ...canEditPrices ? [
46280
+ {
46281
+ label: "Edit prices",
46282
+ to: `prices`
46283
+ }
46284
+ ] : []
46143
46285
  ],
46144
- actionMenu: {
46286
+ actionMenu: canEditPrices ? {
46145
46287
  groups: [
46146
46288
  {
46147
46289
  actions: [
@@ -46153,13 +46295,13 @@ const ProductVariantSection = ({
46153
46295
  ]
46154
46296
  }
46155
46297
  ]
46156
- },
46298
+ } : void 0,
46157
46299
  prefix: PREFIX$1
46158
46300
  }
46159
46301
  ) });
46160
46302
  };
46161
46303
  const columnHelper$2 = ui.createDataTableColumnHelper();
46162
- const useColumns$1 = (product) => {
46304
+ const useColumns$1 = (product, canDeleteDenomination) => {
46163
46305
  const navigate = reactRouterDom.useNavigate();
46164
46306
  const { mutateAsync } = useDeleteVariantLazy(product.id);
46165
46307
  const prompt = ui.usePrompt();
@@ -46239,11 +46381,13 @@ const useColumns$1 = (product) => {
46239
46381
  sortAscLabel: "Asc",
46240
46382
  sortDescLabel: "Desc"
46241
46383
  }),
46242
- columnHelper$2.action({
46243
- actions: getActions
46244
- })
46384
+ ...canDeleteDenomination ? [
46385
+ columnHelper$2.action({
46386
+ actions: getActions
46387
+ })
46388
+ ] : []
46245
46389
  ];
46246
- }, [optionColumns, dateColumns, getActions]);
46390
+ }, [optionColumns, dateColumns, getActions, canDeleteDenomination]);
46247
46391
  };
46248
46392
  const useFilters = () => {
46249
46393
  const dateFilters = useDataTableDateFilters$1();
@@ -46269,17 +46413,20 @@ const ProductDetail = () => {
46269
46413
  sections: {
46270
46414
  main: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
46271
46415
  /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "ProductGeneralSection", children: /* @__PURE__ */ jsxRuntime.jsx(ProductGeneralSection, { product }) }),
46272
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "ProductVariantSection", children: /* @__PURE__ */ jsxRuntime.jsx(ProductVariantSection, { product }) }),
46416
+ /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "ProductVariantSection", children: /* @__PURE__ */ jsxRuntime.jsx(hooks.PermissionGuard, { permission: "product_variant:read", children: /* @__PURE__ */ jsxRuntime.jsx(ProductVariantSection, { product }) }) }),
46273
46417
  /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "JsonViewSection", children: /* @__PURE__ */ jsxRuntime.jsx(JsonViewSection, { data: product }) })
46274
46418
  ] }),
46275
46419
  side: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
46276
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "ProductSalesChannelSection", children: /* @__PURE__ */ jsxRuntime.jsx(ProductSalesChannelSection, { product }) }),
46420
+ /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "ProductSalesChannelSection", children: /* @__PURE__ */ jsxRuntime.jsx(hooks.PermissionGuard, { permission: "sales_channel:read", children: /* @__PURE__ */ jsxRuntime.jsx(ProductSalesChannelSection, { product }) }) }),
46277
46421
  /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "ProductMediaSection", children: /* @__PURE__ */ jsxRuntime.jsx(ProductMediaSection, { product }) })
46278
46422
  ] })
46279
46423
  }
46280
46424
  }
46281
46425
  );
46282
46426
  };
46427
+ const handle$5 = {
46428
+ permissions: ["product:read"]
46429
+ };
46283
46430
  const DENOMINATION_OPTION_TITLE = "denomination";
46284
46431
  const EditProductSchema$1 = zod.z.object({
46285
46432
  denominations: zod.z.array(
@@ -46457,6 +46604,9 @@ const GiftCardProductEdit$1 = () => {
46457
46604
  !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditDenominationsForm, { product })
46458
46605
  ] });
46459
46606
  };
46607
+ const handle$4 = {
46608
+ permissions: EDIT_GIFT_CARD_DENOMINATIONS_PERMISSIONS
46609
+ };
46460
46610
  const EditProductSchema = zod.z.object({
46461
46611
  status: zod.z.enum(["draft", "published", "proposed", "rejected"]),
46462
46612
  title: zod.z.string().min(1),
@@ -46480,12 +46630,12 @@ const GiftCardProductEditForm = ({
46480
46630
  });
46481
46631
  const { mutateAsync, isPending } = useUpdateProduct(product.id);
46482
46632
  const handleSubmit = form.handleSubmit(async (data) => {
46483
- const { title, handle, status, ...optional2 } = data;
46633
+ const { title, handle: handle2, status, ...optional2 } = data;
46484
46634
  await mutateAsync(
46485
46635
  {
46486
46636
  ...optional2,
46487
46637
  title,
46488
- handle,
46638
+ handle: handle2,
46489
46639
  status
46490
46640
  },
46491
46641
  {
@@ -46631,6 +46781,9 @@ const GiftCardProductEdit = () => {
46631
46781
  !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditForm, { product })
46632
46782
  ] });
46633
46783
  };
46784
+ const handle$3 = {
46785
+ permissions: ["product:read", "product:update"]
46786
+ };
46634
46787
  const EditProductMediaForm = ({ product }) => {
46635
46788
  const [selection, setSelection] = React.useState({});
46636
46789
  const { handleSuccess } = useRouteModal();
@@ -46791,7 +46944,7 @@ const EditProductMediaForm = ({ product }) => {
46791
46944
  ] }) })
46792
46945
  }
46793
46946
  ),
46794
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-bg-base overflow-auto border-b px-6 py-4 lg:border-b-0 lg:border-l", children: /* @__PURE__ */ jsxRuntime.jsx(UploadMediaFormItem, { form, append }) })
46947
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-bg-base overflow-auto border-b px-6 py-4 lg:border-b-0 lg:border-l", children: /* @__PURE__ */ jsxRuntime.jsx(hooks.PermissionGuard, { permission: "file:create", children: /* @__PURE__ */ jsxRuntime.jsx(UploadMediaFormItem, { form, append }) }) })
46795
46948
  ] }) }),
46796
46949
  /* @__PURE__ */ jsxRuntime.jsx(ui.CommandBar, { open: !!selectionCount, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.CommandBar.Bar, { children: [
46797
46950
  /* @__PURE__ */ jsxRuntime.jsxs(ui.CommandBar.Value, { children: [
@@ -46961,6 +47114,8 @@ const ProductMediaGallery = ({ product }) => {
46961
47114
  const [curr, setCurr] = React.useState(state?.curr || 0);
46962
47115
  const prompt = ui.usePrompt();
46963
47116
  const { mutateAsync, isPending } = useUpdateProduct(product.id);
47117
+ const { hasPermission } = hooks.usePermissions();
47118
+ const canUpdate = hasPermission("product:update");
46964
47119
  const media = getMedia(product.images, product.thumbnail);
46965
47120
  const next = React.useCallback(() => {
46966
47121
  if (isPending) {
@@ -47029,7 +47184,7 @@ const ProductMediaGallery = ({ product }) => {
47029
47184
  const noMedia = !media.length;
47030
47185
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex size-full flex-col overflow-hidden", children: [
47031
47186
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
47032
- /* @__PURE__ */ jsxRuntime.jsxs(
47187
+ canUpdate && /* @__PURE__ */ jsxRuntime.jsxs(
47033
47188
  ui.IconButton,
47034
47189
  {
47035
47190
  size: "small",
@@ -47055,10 +47210,10 @@ const ProductMediaGallery = ({ product }) => {
47055
47210
  ]
47056
47211
  }
47057
47212
  ),
47058
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: { pathname: ".", search: "view=edit" }, children: "Edit" }) })
47213
+ canUpdate && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: { pathname: ".", search: "view=edit" }, children: "Edit" }) })
47059
47214
  ] }) }),
47060
47215
  /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-col overflow-hidden", children: [
47061
- /* @__PURE__ */ jsxRuntime.jsx(Canvas, { curr, media }),
47216
+ /* @__PURE__ */ jsxRuntime.jsx(Canvas, { curr, media, canUpdate }),
47062
47217
  /* @__PURE__ */ jsxRuntime.jsx(
47063
47218
  Preview,
47064
47219
  {
@@ -47072,7 +47227,11 @@ const ProductMediaGallery = ({ product }) => {
47072
47227
  ] })
47073
47228
  ] });
47074
47229
  };
47075
- const Canvas = ({ media, curr }) => {
47230
+ const Canvas = ({
47231
+ media,
47232
+ curr,
47233
+ canUpdate
47234
+ }) => {
47076
47235
  if (media.length === 0) {
47077
47236
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle flex size-full flex-col items-center justify-center gap-y-4 pb-8 pt-6", children: [
47078
47237
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center", children: [
@@ -47088,7 +47247,7 @@ const Canvas = ({ media, curr }) => {
47088
47247
  ),
47089
47248
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Add images to your product" })
47090
47249
  ] }),
47091
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: "?view=edit", children: "Add images" }) })
47250
+ canUpdate && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: "?view=edit", children: "Add images" }) })
47092
47251
  ] });
47093
47252
  }
47094
47253
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-bg-subtle relative size-full overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-full items-center justify-center p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative inline-block max-h-full max-w-full", children: [
@@ -47197,7 +47356,8 @@ const getView = (searchParams) => {
47197
47356
  };
47198
47357
  const ProductMediaView = ({ product }) => {
47199
47358
  const [searchParams, setSearchParams] = reactRouterDom.useSearchParams();
47200
- const view = getView(searchParams);
47359
+ const { hasPermission } = hooks.usePermissions();
47360
+ const view = hasPermission("product:update") ? getView(searchParams) : "gallery";
47201
47361
  const handleGoToView = (view2) => {
47202
47362
  return () => {
47203
47363
  setSearchParams({ view: view2 });
@@ -47241,10 +47401,20 @@ const ProductMedia = () => {
47241
47401
  ready && /* @__PURE__ */ jsxRuntime.jsx(ProductMediaView, { product })
47242
47402
  ] });
47243
47403
  };
47404
+ const handle$2 = {
47405
+ permissions: ["product:read"]
47406
+ };
47244
47407
  const VariantPricingForm = ({ form }) => {
47245
- const { store } = useStore$2();
47246
- const { regions } = useRegions({ limit: 9999 });
47247
- const { price_preferences: pricePreferences } = usePricePreferences({});
47408
+ const { hasPermission } = hooks.usePermissions();
47409
+ const { store } = useStore$1();
47410
+ const { regions } = useRegions(
47411
+ { limit: 9999 },
47412
+ { enabled: hasPermission("region:read") }
47413
+ );
47414
+ const { price_preferences: pricePreferences } = usePricePreferences(
47415
+ {},
47416
+ { enabled: hasPermission("price_preference:read") }
47417
+ );
47248
47418
  const { setCloseOnEscape } = useRouteModal();
47249
47419
  const columns = useVariantPriceGridColumns({
47250
47420
  currencies: store?.supported_currencies,
@@ -47306,7 +47476,11 @@ const PricingEdit = ({
47306
47476
  }) => {
47307
47477
  const { handleSuccess } = useRouteModal();
47308
47478
  const { mutateAsync, isPending } = useUpdateProductVariantsBatch(product.id);
47309
- const { regions } = useRegions({ limit: 9999 });
47479
+ const { hasPermission } = hooks.usePermissions();
47480
+ const { regions } = useRegions(
47481
+ { limit: 9999 },
47482
+ { enabled: hasPermission("region:read") }
47483
+ );
47310
47484
  const regionsCurrencyMap = React.useMemo(() => {
47311
47485
  if (!regions?.length) {
47312
47486
  return {};
@@ -47393,6 +47567,9 @@ const ProductPrices = () => {
47393
47567
  }
47394
47568
  return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { children: !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(PricingEdit, { product, variantId: variant_id }) });
47395
47569
  };
47570
+ const handle$1 = {
47571
+ permissions: EDIT_GIFT_CARD_PRICES_PERMISSIONS
47572
+ };
47396
47573
  const EditSalesChannelsSchema = zod__namespace.object({
47397
47574
  sales_channels: zod__namespace.array(zod__namespace.string()).optional()
47398
47575
  });
@@ -47498,6 +47675,9 @@ const ProductSalesChannels = () => {
47498
47675
  }
47499
47676
  return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { children: !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(EditSalesChannelsForm, { product }) });
47500
47677
  };
47678
+ const handle = {
47679
+ permissions: ["product:read", "sales_channel:read", "product:update"]
47680
+ };
47501
47681
  const widgetModule = { widgets: [
47502
47682
  {
47503
47683
  Component: CustomerStoreCreditWidget,
@@ -47517,112 +47697,129 @@ const widgetModule = { widgets: [
47517
47697
  ] };
47518
47698
  const routeModule = {
47519
47699
  routes: [
47700
+ {
47701
+ Component: StoreCreditAccountsPage,
47702
+ path: "/store-credit-accounts",
47703
+ handle: { label: config$3.label, translationNs: config$3.translationNs, permissions: config$3.permissions },
47704
+ children: [
47705
+ {
47706
+ Component: StoreCreditAccountCreate,
47707
+ path: "/store-credit-accounts/create",
47708
+ handle: handle$e
47709
+ }
47710
+ ]
47711
+ },
47520
47712
  {
47521
47713
  Component: GiftCardsPage,
47522
47714
  path: "/gift-cards",
47523
- handle: { label: config$3.label, translationNs: config$3.translationNs },
47715
+ handle: { label: config$2.label, translationNs: config$2.translationNs, permissions: config$2.permissions },
47524
47716
  children: [
47525
47717
  {
47526
47718
  Component: GiftCardCreate,
47527
- path: "/gift-cards/create"
47719
+ path: "/gift-cards/create",
47720
+ handle: handle$d
47528
47721
  }
47529
47722
  ]
47530
47723
  },
47531
47724
  {
47532
- Component: StoreCreditAccountsPage,
47533
- path: "/store-credit-accounts",
47534
- handle: { label: config$1.label, translationNs: config$1.translationNs },
47725
+ Component: StoreCreditAccountPage,
47726
+ path: "/store-credit-accounts/:id",
47727
+ handle: handle$c,
47535
47728
  children: [
47536
47729
  {
47537
- Component: StoreCreditAccountCreate,
47538
- path: "/store-credit-accounts/create"
47730
+ Component: Note$1,
47731
+ path: "/store-credit-accounts/:id/credit",
47732
+ handle: handle$b
47733
+ },
47734
+ {
47735
+ Component: Debit,
47736
+ path: "/store-credit-accounts/:id/debit",
47737
+ handle: handle$a
47539
47738
  }
47540
47739
  ]
47541
47740
  },
47542
47741
  {
47543
47742
  Component: GiftCardDetailsPage,
47544
47743
  path: "/gift-cards/:id",
47744
+ handle: handle$9,
47545
47745
  children: [
47546
47746
  {
47547
47747
  Component: GiftCardExpiration,
47548
- path: "/gift-cards/:id/expiration"
47748
+ path: "/gift-cards/:id/expiration",
47749
+ handle: handle$8
47549
47750
  },
47550
47751
  {
47551
- Component: Note$1,
47552
- path: "/gift-cards/:id/note"
47752
+ Component: Note,
47753
+ path: "/gift-cards/:id/note",
47754
+ handle: handle$7
47553
47755
  }
47554
47756
  ]
47555
47757
  },
47556
47758
  {
47557
47759
  Component: GiftCardProductsPage,
47558
47760
  path: "/gift-cards/gift-card-products",
47559
- handle: { label: config.label, translationNs: config.translationNs },
47761
+ handle: { label: config.label, translationNs: config.translationNs, permissions: config.permissions },
47560
47762
  children: [
47561
47763
  {
47562
47764
  Component: GiftCardProductCreate,
47563
- path: "/gift-cards/gift-card-products/create"
47564
- }
47565
- ]
47566
- },
47567
- {
47568
- Component: StoreCreditAccountPage,
47569
- path: "/store-credit-accounts/:id",
47570
- children: [
47571
- {
47572
- Component: Note,
47573
- path: "/store-credit-accounts/:id/credit"
47574
- },
47575
- {
47576
- Component: Debit,
47577
- path: "/store-credit-accounts/:id/debit"
47765
+ path: "/gift-cards/gift-card-products/create",
47766
+ handle: handle$6
47578
47767
  }
47579
47768
  ]
47580
47769
  },
47581
47770
  {
47582
47771
  Component: ProductDetail,
47583
47772
  path: "/gift-cards/gift-card-products/:id",
47773
+ handle: handle$5,
47584
47774
  children: [
47585
47775
  {
47586
47776
  Component: GiftCardProductEdit$1,
47587
- path: "/gift-cards/gift-card-products/:id/denominations"
47777
+ path: "/gift-cards/gift-card-products/:id/denominations",
47778
+ handle: handle$4
47588
47779
  },
47589
47780
  {
47590
47781
  Component: GiftCardProductEdit,
47591
- path: "/gift-cards/gift-card-products/:id/edit"
47782
+ path: "/gift-cards/gift-card-products/:id/edit",
47783
+ handle: handle$3
47592
47784
  }
47593
47785
  ]
47594
47786
  },
47595
47787
  {
47596
47788
  Component: ProductMedia,
47597
- path: "/gift-cards/gift-card-products/:id/media"
47789
+ path: "/gift-cards/gift-card-products/:id/media",
47790
+ handle: handle$2
47598
47791
  },
47599
47792
  {
47600
47793
  Component: ProductPrices,
47601
- path: "/gift-cards/gift-card-products/:id/prices"
47794
+ path: "/gift-cards/gift-card-products/:id/prices",
47795
+ handle: handle$1
47602
47796
  },
47603
47797
  {
47604
47798
  Component: ProductSalesChannels,
47605
- path: "/gift-cards/gift-card-products/:id/sales-channels"
47799
+ path: "/gift-cards/gift-card-products/:id/sales-channels",
47800
+ handle
47606
47801
  }
47607
47802
  ]
47608
47803
  };
47609
47804
  const menuItemModule = {
47610
47805
  menuItems: [
47611
47806
  {
47612
- label: config$3.label,
47613
- icon: config$3.icon,
47807
+ label: config$2.label,
47808
+ icon: config$2.icon,
47614
47809
  path: "/gift-cards",
47615
47810
  nested: void 0,
47616
47811
  rank: void 0,
47617
- translationNs: void 0
47812
+ translationNs: void 0,
47813
+ permissions: config$2.permissions
47618
47814
  },
47619
47815
  {
47620
- label: config$1.label,
47621
- icon: config$1.icon,
47816
+ label: config$3.label,
47817
+ icon: config$3.icon,
47622
47818
  path: "/store-credit-accounts",
47623
47819
  nested: void 0,
47624
47820
  rank: void 0,
47625
- translationNs: void 0
47821
+ translationNs: void 0,
47822
+ permissions: config$3.permissions
47626
47823
  },
47627
47824
  {
47628
47825
  label: config.label,
@@ -47630,7 +47827,8 @@ const menuItemModule = {
47630
47827
  path: "/gift-cards/gift-card-products",
47631
47828
  nested: void 0,
47632
47829
  rank: void 0,
47633
- translationNs: void 0
47830
+ translationNs: void 0,
47831
+ permissions: config.permissions
47634
47832
  }
47635
47833
  ]
47636
47834
  };