@medusajs/loyalty-plugin 2.22.2 → 2.22.3-snapshot-20261030141225

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.
@@ -8,8 +8,8 @@ const icons = require("@medusajs/icons");
8
8
  const reactQuery = require("@tanstack/react-query");
9
9
  const Medusa = require("@medusajs/js-sdk");
10
10
  const components = require("@medusajs/dashboard/components");
11
- const zod = require("@medusajs/framework/zod");
12
11
  const ReactDOM = require("react-dom");
12
+ const zod = require("@medusajs/framework/zod");
13
13
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
14
14
  function _interopNamespace(e) {
15
15
  if (e && e.__esModule) return e;
@@ -5764,7 +5764,7 @@ adminSdk.defineWidgetConfig({
5764
5764
  zone: "sales_channel.details.after",
5765
5765
  id: "medusa:sales-channel-gift-cards-widget"
5766
5766
  });
5767
- const StoreCreditIcon = (props) => {
5767
+ const GiftCardIcon = (props) => {
5768
5768
  return /* @__PURE__ */ jsxRuntime.jsxs(
5769
5769
  "svg",
5770
5770
  {
@@ -5775,49 +5775,197 @@ const StoreCreditIcon = (props) => {
5775
5775
  xmlns: "http://www.w3.org/2000/svg",
5776
5776
  ...props,
5777
5777
  children: [
5778
- /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "15", height: "15", fill: "#8B5CF6" }),
5778
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "15", height: "15", fill: "#F97316" }),
5779
5779
  /* @__PURE__ */ jsxRuntime.jsx(
5780
5780
  "rect",
5781
5781
  {
5782
5782
  width: "15",
5783
5783
  height: "15",
5784
- fill: "url(#paint0_linear_29181_44790)",
5784
+ fill: "url(#paint0_linear_28788_25808)",
5785
5785
  fillOpacity: "0.2"
5786
5786
  }
5787
5787
  ),
5788
- /* @__PURE__ */ jsxRuntime.jsx(
5789
- "path",
5790
- {
5791
- d: "M12 6V5.813C12 4.675 11.075 3.75 9.938 3.75H5.063C3.925 3.75 3 4.675 3 5.813V6H12Z",
5792
- fill: "white"
5793
- }
5794
- ),
5795
- /* @__PURE__ */ jsxRuntime.jsx(
5796
- "path",
5797
- {
5798
- 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",
5799
- fill: "white"
5800
- }
5801
- ),
5802
- /* @__PURE__ */ jsxRuntime.jsx("defs", { children: /* @__PURE__ */ jsxRuntime.jsxs(
5803
- "linearGradient",
5804
- {
5805
- id: "paint0_linear_29181_44790",
5806
- x1: "7.5",
5807
- y1: "0",
5808
- x2: "7.5",
5809
- y2: "15",
5810
- gradientUnits: "userSpaceOnUse",
5811
- children: [
5812
- /* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "white" }),
5813
- /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
5814
- ]
5815
- }
5816
- ) })
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
+ ] })
5817
5843
  ]
5818
5844
  }
5819
5845
  );
5820
5846
  };
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
+ };
5821
5969
  function getRelativeDate(date2) {
5822
5970
  const now = /* @__PURE__ */ new Date();
5823
5971
  return formatDistance(sub(new Date(date2), { minutes: 0 }), now, {
@@ -5835,51 +5983,30 @@ function formatDate(date2, withTime = true) {
5835
5983
  return format(new Date(date2), "dd MMM, yyyy");
5836
5984
  }
5837
5985
  const columnHelper$a = ui.createDataTableColumnHelper();
5838
- const useStoreCreditAccountTableColumns = () => {
5986
+ const useGiftCardTableColumns = () => {
5839
5987
  return React.useMemo(() => {
5840
5988
  return [
5841
- columnHelper$a.accessor("currency_code", {
5842
- header: "Currency",
5843
- cell: ({ row }) => {
5844
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", children: row.original.currency_code.toUpperCase() });
5845
- }
5846
- }),
5847
- columnHelper$a.accessor("customer.email", {
5848
- header: "Customer",
5989
+ columnHelper$a.accessor("code", {
5990
+ header: "Code",
5849
5991
  cell: ({ row }) => {
5850
- return row.original.customer?.email ?? "N/A";
5992
+ return row.original.code;
5851
5993
  }
5852
5994
  }),
5853
- columnHelper$a.accessor("balance", {
5854
- header: "Balance",
5995
+ columnHelper$a.accessor("line_item.product.title", {
5996
+ header: "Product",
5855
5997
  cell: ({ row }) => {
5856
- return formatAmount(
5857
- row.original.balance,
5858
- row.original.currency_code
5859
- );
5998
+ return row.original.line_item?.product?.title || "Custom Gift Card";
5860
5999
  }
5861
6000
  }),
5862
- columnHelper$a.accessor("credits", {
5863
- header: "Credits",
5864
- cell: ({ row }) => {
5865
- return formatAmount(
5866
- row.original.credits,
5867
- row.original.currency_code
5868
- );
5869
- }
6001
+ columnHelper$a.accessor("created_at", {
6002
+ header: "Date issued",
6003
+ cell: ({ row }) => getRelativeDate(row.original.created_at)
5870
6004
  }),
5871
- columnHelper$a.accessor("debits", {
5872
- header: "Debits",
6005
+ columnHelper$a.accessor("value", {
6006
+ header: "Value",
5873
6007
  cell: ({ row }) => {
5874
- return formatAmount(
5875
- row.original.debits,
5876
- row.original.currency_code
5877
- );
6008
+ return formatAmount(row.original.value, row.original.currency_code);
5878
6009
  }
5879
- }),
5880
- columnHelper$a.accessor("created_at", {
5881
- header: "Created at",
5882
- cell: ({ row }) => getRelativeDate(row.original.created_at)
5883
6010
  })
5884
6011
  ];
5885
6012
  }, []);
@@ -5926,83 +6053,75 @@ const useCustomerFilters = () => {
5926
6053
  ];
5927
6054
  }, [customerFilterOptions]);
5928
6055
  };
5929
- const useStoreCreditAccountFilters = () => {
6056
+ const useGiftCardFilters = () => {
5930
6057
  const dateFilterOptions = useDataTableDateFilters$1();
5931
6058
  const customerFilterOptions = useCustomerFilters();
5932
6059
  return React.useMemo(() => {
5933
6060
  return [...dateFilterOptions, ...customerFilterOptions];
5934
6061
  }, [dateFilterOptions, customerFilterOptions]);
5935
6062
  };
5936
- const useStoreCreditAccountsTableQuery = ({
6063
+ const useGiftCardTableQuery = ({
5937
6064
  prefix,
5938
6065
  pageSize = 20
5939
6066
  }) => {
5940
6067
  const queryObject = useQueryParams(
5941
- ["offset", "customer_id", "currency_code", "created_at", "updated_at"],
6068
+ ["q", "offset", "customer_id", "created_at", "updated_at"],
5942
6069
  prefix
5943
6070
  );
5944
- const {
5945
- offset: offset2,
5946
- created_at,
5947
- updated_at,
5948
- customer_id,
5949
- currency_code,
5950
- ...rest
5951
- } = queryObject;
6071
+ const { offset: offset2, created_at, updated_at, customer_id, ...rest } = queryObject;
5952
6072
  const searchParams = {
5953
6073
  limit: pageSize,
5954
6074
  offset: offset2 ? Number(offset2) : 0,
5955
6075
  created_at: created_at ? JSON.parse(created_at) : void 0,
5956
6076
  updated_at: updated_at ? JSON.parse(updated_at) : void 0,
5957
6077
  customer_id: customer_id ? JSON.parse(customer_id) : void 0,
5958
- currency_code: currency_code ? JSON.parse(currency_code) : void 0,
5959
6078
  ...rest
5960
6079
  };
5961
6080
  return searchParams;
5962
6081
  };
5963
6082
  const PAGE_SIZE$6 = 10;
5964
- function StoreCreditAccountsTable() {
5965
- const queryParams = useStoreCreditAccountsTableQuery({
6083
+ function GiftCardsTable() {
6084
+ const queryParams = useGiftCardTableQuery({
5966
6085
  pageSize: PAGE_SIZE$6
5967
6086
  });
5968
6087
  const {
5969
- store_credit_accounts: storeCreditAccounts,
6088
+ gift_cards: giftCards,
5970
6089
  isPending,
5971
6090
  count: count2
5972
- } = useStoreCreditAccounts({
6091
+ } = useGiftCards({
5973
6092
  ...queryParams,
5974
- order: queryParams.order ?? "-created_at"
6093
+ order: queryParams.order ?? "-created_at",
6094
+ fields: "+line_item.product.title"
5975
6095
  });
5976
- const columns = useStoreCreditAccountTableColumns();
5977
- const filters = useStoreCreditAccountFilters();
6096
+ const columns = useGiftCardTableColumns();
6097
+ const filters = useGiftCardFilters();
5978
6098
  return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
5979
6099
  /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
5980
6100
  DataTable,
5981
6101
  {
5982
- data: storeCreditAccounts ?? [],
6102
+ data: giftCards,
5983
6103
  getRowId: (row) => row.id,
5984
6104
  columns,
5985
6105
  filters,
5986
6106
  isLoading: isPending,
5987
6107
  pageSize: PAGE_SIZE$6,
5988
6108
  rowCount: count2,
5989
- enableSearch: false,
5990
- heading: "Store Credit Accounts",
6109
+ heading: "Gift Cards",
5991
6110
  rowHref: (row) => `${row.id}`,
5992
6111
  emptyState: {
5993
6112
  empty: {
5994
- heading: "No store credit accounts found",
5995
- description: "Create a new store credit account to get started."
6113
+ heading: "No gift cards found",
6114
+ description: "Create a gift card to get started."
5996
6115
  },
5997
6116
  filtered: {
5998
6117
  heading: "No results found",
5999
- description: "No store credit accounts match your filter criteria."
6118
+ description: "No gift cards match your filter criteria."
6000
6119
  }
6001
6120
  },
6002
6121
  actions: [
6003
6122
  {
6004
6123
  label: "Create",
6005
- to: "/store-credit-accounts/create"
6124
+ to: "create"
6006
6125
  }
6007
6126
  ]
6008
6127
  }
@@ -6010,15 +6129,16 @@ function StoreCreditAccountsTable() {
6010
6129
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
6011
6130
  ] });
6012
6131
  }
6013
- const StoreCreditAccountsPage = () => {
6132
+ const GiftCardsPage = () => {
6014
6133
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6015
6134
  /* @__PURE__ */ jsxRuntime.jsx(
6016
6135
  components.LayoutComposer,
6017
6136
  {
6018
- widgetsZonePrefix: "store_credit_account.list",
6019
- preferredLayoutId: "core:single-column",
6137
+ widgetsZonePrefix: "gift_card.list",
6138
+ preferredLayoutId: "core:two-column",
6020
6139
  sections: {
6021
- main: /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountsTable", children: /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountsTable, {}) })
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, {}) })
6022
6142
  }
6023
6143
  }
6024
6144
  ),
@@ -6026,8 +6146,8 @@ const StoreCreditAccountsPage = () => {
6026
6146
  ] });
6027
6147
  };
6028
6148
  const config$3 = adminSdk.defineRouteConfig({
6029
- label: "Store Credits",
6030
- icon: StoreCreditIcon
6149
+ label: "Gift Cards",
6150
+ icon: GiftCardIcon
6031
6151
  });
6032
6152
  function setRef$2(ref, value) {
6033
6153
  if (typeof ref === "function") {
@@ -10722,6 +10842,27 @@ const StackedFocusModal = Object.assign(Root, {
10722
10842
  Description,
10723
10843
  Title
10724
10844
  });
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
+ };
10725
10866
  const t$1 = (r, t2, s2) => {
10726
10867
  if (r && "reportValidity" in r) {
10727
10868
  const o2 = get$2(s2, t2);
@@ -13767,7 +13908,7 @@ function useStoreProps(store, props, key2, setKey) {
13767
13908
  });
13768
13909
  });
13769
13910
  }
13770
- function useStore$2(createStore2, props) {
13911
+ function useStore$1(createStore2, props) {
13771
13912
  const [store, setStore] = React__namespace.useState(() => createStore2(props));
13772
13913
  useSafeLayoutEffect(() => init(store), [store]);
13773
13914
  const useState = React__namespace.useCallback((keyOrSelector) => useStoreState(store, keyOrSelector), [store]);
@@ -14724,7 +14865,7 @@ function useDisclosureStoreProps(store, update, props) {
14724
14865
  return Object.assign(store, { disclosure: props.disclosure });
14725
14866
  }
14726
14867
  function useDisclosureStore(props = {}) {
14727
- const [store, update] = useStore$2(createDisclosureStore, props);
14868
+ const [store, update] = useStore$1(createDisclosureStore, props);
14728
14869
  return useDisclosureStoreProps(store, update, props);
14729
14870
  }
14730
14871
  const ctx$2 = createStoreContext([DialogContextProvider], [DialogScopedContextProvider]);
@@ -15533,7 +15674,7 @@ function useDialogStoreProps(store, update, props) {
15533
15674
  return useDisclosureStoreProps(store, update, props);
15534
15675
  }
15535
15676
  function useDialogStore(props = {}) {
15536
- const [store, update] = useStore$2(createDialogStore, props);
15677
+ const [store, update] = useStore$1(createDialogStore, props);
15537
15678
  return useDialogStoreProps(store, update, props);
15538
15679
  }
15539
15680
  function isHiddenDismiss(element, ...ids2) {
@@ -18849,7 +18990,7 @@ function useComboboxStoreProps(store, update, props) {
18849
18990
  }
18850
18991
  function useComboboxStore(props = {}) {
18851
18992
  props = useComboboxStoreOptions(props);
18852
- const [store, update] = useStore$2(createComboboxStore, props);
18993
+ const [store, update] = useStore$1(createComboboxStore, props);
18853
18994
  return useComboboxStoreProps(store, update, props);
18854
18995
  }
18855
18996
  function ComboboxProvider(props = {}) {
@@ -19968,369 +20109,6 @@ const ComboboxImpl = ({
19968
20109
  );
19969
20110
  };
19970
20111
  const Combobox2 = genericForwardRef(ComboboxImpl);
19971
- var isObject_1;
19972
- var hasRequiredIsObject;
19973
- function requireIsObject() {
19974
- if (hasRequiredIsObject) return isObject_1;
19975
- hasRequiredIsObject = 1;
19976
- function isObject2(value) {
19977
- var type = typeof value;
19978
- return value != null && (type == "object" || type == "function");
19979
- }
19980
- isObject_1 = isObject2;
19981
- return isObject_1;
19982
- }
19983
- var _freeGlobal;
19984
- var hasRequired_freeGlobal;
19985
- function require_freeGlobal() {
19986
- if (hasRequired_freeGlobal) return _freeGlobal;
19987
- hasRequired_freeGlobal = 1;
19988
- var freeGlobal = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
19989
- _freeGlobal = freeGlobal;
19990
- return _freeGlobal;
19991
- }
19992
- var _root;
19993
- var hasRequired_root;
19994
- function require_root() {
19995
- if (hasRequired_root) return _root;
19996
- hasRequired_root = 1;
19997
- var freeGlobal = require_freeGlobal();
19998
- var freeSelf = typeof self == "object" && self && self.Object === Object && self;
19999
- var root = freeGlobal || freeSelf || Function("return this")();
20000
- _root = root;
20001
- return _root;
20002
- }
20003
- var now_1;
20004
- var hasRequiredNow;
20005
- function requireNow() {
20006
- if (hasRequiredNow) return now_1;
20007
- hasRequiredNow = 1;
20008
- var root = require_root();
20009
- var now = function() {
20010
- return root.Date.now();
20011
- };
20012
- now_1 = now;
20013
- return now_1;
20014
- }
20015
- var _trimmedEndIndex;
20016
- var hasRequired_trimmedEndIndex;
20017
- function require_trimmedEndIndex() {
20018
- if (hasRequired_trimmedEndIndex) return _trimmedEndIndex;
20019
- hasRequired_trimmedEndIndex = 1;
20020
- var reWhitespace = /\s/;
20021
- function trimmedEndIndex(string2) {
20022
- var index = string2.length;
20023
- while (index-- && reWhitespace.test(string2.charAt(index))) {
20024
- }
20025
- return index;
20026
- }
20027
- _trimmedEndIndex = trimmedEndIndex;
20028
- return _trimmedEndIndex;
20029
- }
20030
- var _baseTrim;
20031
- var hasRequired_baseTrim;
20032
- function require_baseTrim() {
20033
- if (hasRequired_baseTrim) return _baseTrim;
20034
- hasRequired_baseTrim = 1;
20035
- var trimmedEndIndex = require_trimmedEndIndex();
20036
- var reTrimStart = /^\s+/;
20037
- function baseTrim(string2) {
20038
- return string2 ? string2.slice(0, trimmedEndIndex(string2) + 1).replace(reTrimStart, "") : string2;
20039
- }
20040
- _baseTrim = baseTrim;
20041
- return _baseTrim;
20042
- }
20043
- var _Symbol;
20044
- var hasRequired_Symbol;
20045
- function require_Symbol() {
20046
- if (hasRequired_Symbol) return _Symbol;
20047
- hasRequired_Symbol = 1;
20048
- var root = require_root();
20049
- var Symbol2 = root.Symbol;
20050
- _Symbol = Symbol2;
20051
- return _Symbol;
20052
- }
20053
- var _getRawTag;
20054
- var hasRequired_getRawTag;
20055
- function require_getRawTag() {
20056
- if (hasRequired_getRawTag) return _getRawTag;
20057
- hasRequired_getRawTag = 1;
20058
- var Symbol2 = require_Symbol();
20059
- var objectProto = Object.prototype;
20060
- var hasOwnProperty2 = objectProto.hasOwnProperty;
20061
- var nativeObjectToString = objectProto.toString;
20062
- var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
20063
- function getRawTag(value) {
20064
- var isOwn = hasOwnProperty2.call(value, symToStringTag), tag = value[symToStringTag];
20065
- try {
20066
- value[symToStringTag] = void 0;
20067
- var unmasked = true;
20068
- } catch (e) {
20069
- }
20070
- var result = nativeObjectToString.call(value);
20071
- if (unmasked) {
20072
- if (isOwn) {
20073
- value[symToStringTag] = tag;
20074
- } else {
20075
- delete value[symToStringTag];
20076
- }
20077
- }
20078
- return result;
20079
- }
20080
- _getRawTag = getRawTag;
20081
- return _getRawTag;
20082
- }
20083
- var _objectToString;
20084
- var hasRequired_objectToString;
20085
- function require_objectToString() {
20086
- if (hasRequired_objectToString) return _objectToString;
20087
- hasRequired_objectToString = 1;
20088
- var objectProto = Object.prototype;
20089
- var nativeObjectToString = objectProto.toString;
20090
- function objectToString(value) {
20091
- return nativeObjectToString.call(value);
20092
- }
20093
- _objectToString = objectToString;
20094
- return _objectToString;
20095
- }
20096
- var _baseGetTag;
20097
- var hasRequired_baseGetTag;
20098
- function require_baseGetTag() {
20099
- if (hasRequired_baseGetTag) return _baseGetTag;
20100
- hasRequired_baseGetTag = 1;
20101
- var Symbol2 = require_Symbol(), getRawTag = require_getRawTag(), objectToString = require_objectToString();
20102
- var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
20103
- var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
20104
- function baseGetTag(value) {
20105
- if (value == null) {
20106
- return value === void 0 ? undefinedTag : nullTag;
20107
- }
20108
- return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
20109
- }
20110
- _baseGetTag = baseGetTag;
20111
- return _baseGetTag;
20112
- }
20113
- var isObjectLike_1;
20114
- var hasRequiredIsObjectLike;
20115
- function requireIsObjectLike() {
20116
- if (hasRequiredIsObjectLike) return isObjectLike_1;
20117
- hasRequiredIsObjectLike = 1;
20118
- function isObjectLike(value) {
20119
- return value != null && typeof value == "object";
20120
- }
20121
- isObjectLike_1 = isObjectLike;
20122
- return isObjectLike_1;
20123
- }
20124
- var isSymbol_1;
20125
- var hasRequiredIsSymbol;
20126
- function requireIsSymbol() {
20127
- if (hasRequiredIsSymbol) return isSymbol_1;
20128
- hasRequiredIsSymbol = 1;
20129
- var baseGetTag = require_baseGetTag(), isObjectLike = requireIsObjectLike();
20130
- var symbolTag = "[object Symbol]";
20131
- function isSymbol(value) {
20132
- return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
20133
- }
20134
- isSymbol_1 = isSymbol;
20135
- return isSymbol_1;
20136
- }
20137
- var toNumber_1;
20138
- var hasRequiredToNumber;
20139
- function requireToNumber() {
20140
- if (hasRequiredToNumber) return toNumber_1;
20141
- hasRequiredToNumber = 1;
20142
- var baseTrim = require_baseTrim(), isObject2 = requireIsObject(), isSymbol = requireIsSymbol();
20143
- var NAN = 0 / 0;
20144
- var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
20145
- var reIsBinary = /^0b[01]+$/i;
20146
- var reIsOctal = /^0o[0-7]+$/i;
20147
- var freeParseInt = parseInt;
20148
- function toNumber(value) {
20149
- if (typeof value == "number") {
20150
- return value;
20151
- }
20152
- if (isSymbol(value)) {
20153
- return NAN;
20154
- }
20155
- if (isObject2(value)) {
20156
- var other = typeof value.valueOf == "function" ? value.valueOf() : value;
20157
- value = isObject2(other) ? other + "" : other;
20158
- }
20159
- if (typeof value != "string") {
20160
- return value === 0 ? value : +value;
20161
- }
20162
- value = baseTrim(value);
20163
- var isBinary = reIsBinary.test(value);
20164
- return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
20165
- }
20166
- toNumber_1 = toNumber;
20167
- return toNumber_1;
20168
- }
20169
- var debounce_1;
20170
- var hasRequiredDebounce;
20171
- function requireDebounce() {
20172
- if (hasRequiredDebounce) return debounce_1;
20173
- hasRequiredDebounce = 1;
20174
- var isObject2 = requireIsObject(), now = requireNow(), toNumber = requireToNumber();
20175
- var FUNC_ERROR_TEXT = "Expected a function";
20176
- var nativeMax = Math.max, nativeMin = Math.min;
20177
- function debounce2(func, wait, options) {
20178
- var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
20179
- if (typeof func != "function") {
20180
- throw new TypeError(FUNC_ERROR_TEXT);
20181
- }
20182
- wait = toNumber(wait) || 0;
20183
- if (isObject2(options)) {
20184
- leading = !!options.leading;
20185
- maxing = "maxWait" in options;
20186
- maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
20187
- trailing = "trailing" in options ? !!options.trailing : trailing;
20188
- }
20189
- function invokeFunc(time2) {
20190
- var args = lastArgs, thisArg = lastThis;
20191
- lastArgs = lastThis = void 0;
20192
- lastInvokeTime = time2;
20193
- result = func.apply(thisArg, args);
20194
- return result;
20195
- }
20196
- function leadingEdge(time2) {
20197
- lastInvokeTime = time2;
20198
- timerId = setTimeout(timerExpired, wait);
20199
- return leading ? invokeFunc(time2) : result;
20200
- }
20201
- function remainingWait(time2) {
20202
- var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
20203
- return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
20204
- }
20205
- function shouldInvoke(time2) {
20206
- var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime;
20207
- return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
20208
- }
20209
- function timerExpired() {
20210
- var time2 = now();
20211
- if (shouldInvoke(time2)) {
20212
- return trailingEdge(time2);
20213
- }
20214
- timerId = setTimeout(timerExpired, remainingWait(time2));
20215
- }
20216
- function trailingEdge(time2) {
20217
- timerId = void 0;
20218
- if (trailing && lastArgs) {
20219
- return invokeFunc(time2);
20220
- }
20221
- lastArgs = lastThis = void 0;
20222
- return result;
20223
- }
20224
- function cancel() {
20225
- if (timerId !== void 0) {
20226
- clearTimeout(timerId);
20227
- }
20228
- lastInvokeTime = 0;
20229
- lastArgs = lastCallTime = lastThis = timerId = void 0;
20230
- }
20231
- function flush() {
20232
- return timerId === void 0 ? result : trailingEdge(now());
20233
- }
20234
- function debounced() {
20235
- var time2 = now(), isInvoking = shouldInvoke(time2);
20236
- lastArgs = arguments;
20237
- lastThis = this;
20238
- lastCallTime = time2;
20239
- if (isInvoking) {
20240
- if (timerId === void 0) {
20241
- return leadingEdge(lastCallTime);
20242
- }
20243
- if (maxing) {
20244
- clearTimeout(timerId);
20245
- timerId = setTimeout(timerExpired, wait);
20246
- return invokeFunc(lastCallTime);
20247
- }
20248
- }
20249
- if (timerId === void 0) {
20250
- timerId = setTimeout(timerExpired, wait);
20251
- }
20252
- return result;
20253
- }
20254
- debounced.cancel = cancel;
20255
- debounced.flush = flush;
20256
- return debounced;
20257
- }
20258
- debounce_1 = debounce2;
20259
- return debounce_1;
20260
- }
20261
- var debounceExports = requireDebounce();
20262
- const debounce$1 = /* @__PURE__ */ getDefaultExportFromCjs(debounceExports);
20263
- const useDebouncedSearch = () => {
20264
- const [searchValue, onSearchValueChange] = React.useState("");
20265
- const [debouncedQuery, setDebouncedQuery] = React.useState("");
20266
- const debouncedUpdate = React.useCallback(
20267
- debounce$1((query) => setDebouncedQuery(query), 300),
20268
- []
20269
- );
20270
- React.useEffect(() => {
20271
- debouncedUpdate(searchValue);
20272
- return () => debouncedUpdate.cancel();
20273
- }, [searchValue, debouncedUpdate]);
20274
- return {
20275
- searchValue,
20276
- onSearchValueChange,
20277
- query: debouncedQuery || void 0
20278
- };
20279
- };
20280
- const useComboboxData = ({
20281
- queryKey,
20282
- queryFn,
20283
- getOptions,
20284
- defaultValue: defaultValue2,
20285
- defaultValueKey,
20286
- pageSize = 10
20287
- }) => {
20288
- const { searchValue, onSearchValueChange, query } = useDebouncedSearch();
20289
- const queryInitialDataBy = defaultValueKey || "id";
20290
- const { data: initialData } = reactQuery.useQuery({
20291
- queryKey,
20292
- queryFn: async () => {
20293
- return queryFn({
20294
- [queryInitialDataBy]: defaultValue2,
20295
- limit: Array.isArray(defaultValue2) ? defaultValue2.length : 1
20296
- });
20297
- },
20298
- enabled: !!defaultValue2
20299
- });
20300
- const { data, ...rest } = reactQuery.useInfiniteQuery({
20301
- queryKey: [...queryKey, query],
20302
- queryFn: async ({ pageParam = 0 }) => {
20303
- return await queryFn({
20304
- q: query,
20305
- limit: pageSize,
20306
- offset: pageParam
20307
- });
20308
- },
20309
- initialPageParam: 0,
20310
- getNextPageParam: (lastPage) => {
20311
- const moreItemsExist = lastPage.count > lastPage.offset + lastPage.limit;
20312
- return moreItemsExist ? lastPage.offset + lastPage.limit : void 0;
20313
- },
20314
- placeholderData: reactQuery.keepPreviousData
20315
- });
20316
- const options = data?.pages.flatMap((page) => getOptions(page)) ?? [];
20317
- const defaultOptions2 = initialData ? getOptions(initialData) : [];
20318
- const disabled = !rest.isPending && !options.length && !searchValue;
20319
- if (defaultValue2 && defaultOptions2.length && !searchValue) {
20320
- defaultOptions2.forEach((option) => {
20321
- if (!options.find((o2) => o2.value === option.value)) {
20322
- options.unshift(option);
20323
- }
20324
- });
20325
- }
20326
- return {
20327
- options,
20328
- searchValue,
20329
- onSearchValueChange,
20330
- disabled,
20331
- ...rest
20332
- };
20333
- };
20334
20112
  const currencies = {
20335
20113
  USD: {
20336
20114
  code: "USD",
@@ -21077,504 +20855,6 @@ const currencies = {
21077
20855
  decimal_digits: 0
21078
20856
  }
21079
20857
  };
21080
- const formSchema = zod.z.object({
21081
- currency_code: zod.z.string().min(1, "Please select a currency"),
21082
- customer_id: zod.z.string().optional()
21083
- });
21084
- const StoreCreditAccountCreateForm = () => {
21085
- const { handleSuccess } = useRouteModal();
21086
- const [searchParams] = reactRouterDom.useSearchParams();
21087
- const prefilledCustomerId = searchParams.get("prefill_customer_id") ?? "";
21088
- const form = useForm({
21089
- defaultValues: {
21090
- currency_code: "",
21091
- customer_id: prefilledCustomerId
21092
- },
21093
- resolver: u(formSchema)
21094
- });
21095
- const { mutateAsync: createStoreCreditAccount, isPending } = useCreateStoreCreditAccount();
21096
- const handleSubmit = form.handleSubmit(async (data) => {
21097
- if (!data.customer_id) {
21098
- delete data.customer_id;
21099
- }
21100
- await createStoreCreditAccount(data, {
21101
- onSuccess: (data2) => {
21102
- ui.toast.success(`Store credit account was successfully created.`);
21103
- handleSuccess(`../${data2.store_credit_account.id}`);
21104
- },
21105
- onError: (error2) => {
21106
- ui.toast.error(error2.message);
21107
- }
21108
- });
21109
- });
21110
- const [currencySearchValue, setCurrencySearchValue] = React.useState("");
21111
- const currencyOptions = React.useMemo(() => {
21112
- const options = Object.values(currencies).map((currency) => ({
21113
- label: `${currency.code} - ${currency.name} (${currency.symbol_native})`,
21114
- value: currency.code.toLowerCase()
21115
- }));
21116
- if (!currencySearchValue) {
21117
- return options;
21118
- }
21119
- return options.filter(
21120
- (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
21121
- );
21122
- }, [currencySearchValue]);
21123
- const {
21124
- options: customerOptions,
21125
- fetchNextPage,
21126
- isFetchingNextPage,
21127
- searchValue,
21128
- onSearchValueChange,
21129
- isLoading
21130
- } = useComboboxData({
21131
- queryKey: customersQueryKeys.list(),
21132
- defaultValue: prefilledCustomerId || void 0,
21133
- queryFn: async (params) => {
21134
- return sdk.admin.customer.list(params);
21135
- },
21136
- getOptions: (data) => {
21137
- return data.customers?.map((customer) => {
21138
- const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
21139
- const label = fullName ? `${customer.email} (${fullName})` : customer.email;
21140
- return {
21141
- label,
21142
- value: customer.id
21143
- };
21144
- }) || [];
21145
- }
21146
- });
21147
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Form, { form, children: [
21148
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "-my-2 w-full border-l" }) }),
21149
- /* @__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: [
21150
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
21151
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Create Store Credit Account" }),
21152
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new store credit account for a customer" })
21153
- ] }),
21154
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-x-4", children: [
21155
- /* @__PURE__ */ jsxRuntime.jsx(
21156
- Form$2.Field,
21157
- {
21158
- control: form.control,
21159
- name: "currency_code",
21160
- render: ({ field }) => {
21161
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "w-full", children: [
21162
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { className: "font-normal", children: "Currency" }),
21163
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
21164
- Combobox2,
21165
- {
21166
- value: field.value,
21167
- onChange: field.onChange,
21168
- searchValue: currencySearchValue,
21169
- onSearchValueChange: setCurrencySearchValue,
21170
- options: currencyOptions,
21171
- placeholder: "Search for a currency..."
21172
- }
21173
- ) }),
21174
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
21175
- ] });
21176
- }
21177
- }
21178
- ),
21179
- /* @__PURE__ */ jsxRuntime.jsx(
21180
- Form$2.Field,
21181
- {
21182
- control: form.control,
21183
- name: "customer_id",
21184
- render: ({ field }) => {
21185
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "w-full", children: [
21186
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { className: "font-normal", children: "Customer" }),
21187
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
21188
- Combobox2,
21189
- {
21190
- value: field.value,
21191
- onChange: field.onChange,
21192
- searchValue,
21193
- onSearchValueChange,
21194
- options: customerOptions,
21195
- placeholder: "Search for a customer...",
21196
- fetchNextPage,
21197
- isFetchingNextPage,
21198
- noResultsPlaceholder: isLoading ? "Loading customers..." : "No customers found"
21199
- }
21200
- ) }),
21201
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
21202
- ] });
21203
- }
21204
- }
21205
- )
21206
- ] })
21207
- ] }) }) }),
21208
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Footer, { children: [
21209
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, disabled: isPending, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", disabled: isPending, children: "Cancel" }) }),
21210
- /* @__PURE__ */ jsxRuntime.jsx(
21211
- ui.Button,
21212
- {
21213
- variant: "primary",
21214
- size: "small",
21215
- onClick: handleSubmit,
21216
- disabled: isPending,
21217
- children: "Create"
21218
- }
21219
- )
21220
- ] })
21221
- ] });
21222
- };
21223
- const StoreCreditAccountCreate = () => {
21224
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal, { children: [
21225
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Create Store Credit Account" }) }),
21226
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Create a new store credit account" }) }),
21227
- /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountCreateForm, {})
21228
- ] });
21229
- };
21230
- const GiftCardIcon = (props) => {
21231
- return /* @__PURE__ */ jsxRuntime.jsxs(
21232
- "svg",
21233
- {
21234
- width: "15",
21235
- height: "15",
21236
- viewBox: "0 0 15 15",
21237
- fill: "none",
21238
- xmlns: "http://www.w3.org/2000/svg",
21239
- ...props,
21240
- children: [
21241
- /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "15", height: "15", fill: "#F97316" }),
21242
- /* @__PURE__ */ jsxRuntime.jsx(
21243
- "rect",
21244
- {
21245
- width: "15",
21246
- height: "15",
21247
- fill: "url(#paint0_linear_28788_25808)",
21248
- fillOpacity: "0.2"
21249
- }
21250
- ),
21251
- /* @__PURE__ */ jsxRuntime.jsxs("g", { clipPath: "url(#clip0_28788_25808)", children: [
21252
- /* @__PURE__ */ jsxRuntime.jsx(
21253
- "path",
21254
- {
21255
- 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",
21256
- fill: "white"
21257
- }
21258
- ),
21259
- /* @__PURE__ */ jsxRuntime.jsx(
21260
- "path",
21261
- {
21262
- 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",
21263
- fill: "white"
21264
- }
21265
- ),
21266
- /* @__PURE__ */ jsxRuntime.jsx(
21267
- "path",
21268
- {
21269
- 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",
21270
- fill: "white"
21271
- }
21272
- ),
21273
- /* @__PURE__ */ jsxRuntime.jsx(
21274
- "path",
21275
- {
21276
- d: "M6.938 7.5H3.75V9.563C3.75 10.7 4.675 11.625 5.813 11.625H6.938V7.5Z",
21277
- fill: "white"
21278
- }
21279
- ),
21280
- /* @__PURE__ */ jsxRuntime.jsx(
21281
- "path",
21282
- {
21283
- d: "M8.063 7.5V11.625H9.188C10.325 11.625 11.25 10.7 11.25 9.563V7.5H8.063Z",
21284
- fill: "white"
21285
- }
21286
- )
21287
- ] }),
21288
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
21289
- /* @__PURE__ */ jsxRuntime.jsxs(
21290
- "linearGradient",
21291
- {
21292
- id: "paint0_linear_28788_25808",
21293
- x1: "7.5",
21294
- y1: "0",
21295
- x2: "7.5",
21296
- y2: "15",
21297
- gradientUnits: "userSpaceOnUse",
21298
- children: [
21299
- /* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "white" }),
21300
- /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
21301
- ]
21302
- }
21303
- ),
21304
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_28788_25808", children: /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "9", height: "9", fill: "white", transform: "translate(3 3)" }) })
21305
- ] })
21306
- ]
21307
- }
21308
- );
21309
- };
21310
- const GiftCardProductsSection = () => {
21311
- const { products: giftCardProducts, count: count2 = 0 } = useProducts({
21312
- is_giftcard: true
21313
- });
21314
- const slicedProducts = giftCardProducts?.slice(0, 3) ?? [];
21315
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
21316
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
21317
- /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Gift Card Products" }),
21318
- /* @__PURE__ */ jsxRuntime.jsx(
21319
- reactRouterDom.Link,
21320
- {
21321
- to: `/gift-cards/gift-card-products/create`,
21322
- className: "text-ui-fg-muted text-sm px-6",
21323
- children: "Create"
21324
- }
21325
- )
21326
- ] }),
21327
- giftCardProducts?.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(
21328
- NoRecords,
21329
- {
21330
- className: "px-10 py-4 h-[200px]",
21331
- title: "No gift card products",
21332
- message: "There are no gift card products to show. Create one to get started.",
21333
- action: {
21334
- to: "/gift-cards/gift-card-products/create",
21335
- label: "Create gift card product"
21336
- }
21337
- }
21338
- ),
21339
- slicedProducts.map((giftCardProduct) => /* @__PURE__ */ jsxRuntime.jsx(
21340
- SidebarLink,
21341
- {
21342
- to: `/gift-cards/gift-card-products/${giftCardProduct.id}`,
21343
- labelKey: giftCardProduct.title,
21344
- descriptionKey: giftCardProduct.title,
21345
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Tag, {})
21346
- }
21347
- )),
21348
- count2 > 3 && /* @__PURE__ */ jsxRuntime.jsx(
21349
- reactRouterDom.Link,
21350
- {
21351
- to: "/gift-cards/gift-card-products",
21352
- className: "text-ui-fg-muted text-sm px-6 py-4 flex items-center justify-center",
21353
- children: "View more"
21354
- }
21355
- )
21356
- ] });
21357
- };
21358
- const _giftCardQueryKey = queryKeysFactory("gift-card");
21359
- const giftCardQueryKey = {
21360
- ..._giftCardQueryKey,
21361
- orders: (id) => [..._giftCardQueryKey.detail(id), "orders"]
21362
- };
21363
- const useGiftCards = (query, options) => {
21364
- const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
21365
- query: query2,
21366
- headers
21367
- });
21368
- const { data, ...rest } = reactQuery.useQuery({
21369
- ...options,
21370
- queryFn: () => fetchGiftCards(query),
21371
- queryKey: giftCardQueryKey.list(query)
21372
- });
21373
- return { ...data, ...rest };
21374
- };
21375
- const useGiftCard = (id, query, options) => {
21376
- const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
21377
- query: query2,
21378
- headers
21379
- });
21380
- const { data, ...rest } = reactQuery.useQuery({
21381
- queryFn: () => fetchGiftCard(id, query),
21382
- queryKey: giftCardQueryKey.detail(id, query),
21383
- ...options
21384
- });
21385
- return { ...data, ...rest };
21386
- };
21387
- const useGiftCardOrders = (id, options) => {
21388
- const fetchGiftCardOrders = (id2, query, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}/orders`, {
21389
- query,
21390
- headers
21391
- });
21392
- const { data, ...rest } = reactQuery.useQuery({
21393
- queryFn: () => fetchGiftCardOrders(id),
21394
- queryKey: giftCardQueryKey.orders(id),
21395
- ...options
21396
- });
21397
- return { ...data, ...rest };
21398
- };
21399
- const useUpdateGiftCard = (id, options) => {
21400
- const queryClient = reactQuery.useQueryClient();
21401
- const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
21402
- body,
21403
- method: "POST"
21404
- });
21405
- return reactQuery.useMutation({
21406
- mutationFn: async (payload) => updateGiftCard(id, payload),
21407
- onSuccess: (data, variables, context) => {
21408
- queryClient.invalidateQueries({
21409
- queryKey: giftCardQueryKey.detail(id)
21410
- });
21411
- queryClient.invalidateQueries({
21412
- queryKey: giftCardQueryKey.lists()
21413
- });
21414
- },
21415
- ...options
21416
- });
21417
- };
21418
- const useCreateGiftCard = (options) => {
21419
- const queryClient = reactQuery.useQueryClient();
21420
- const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
21421
- body,
21422
- method: "POST"
21423
- });
21424
- return reactQuery.useMutation({
21425
- mutationFn: (body) => createGiftCard(body),
21426
- onSuccess: (data, variables, context) => {
21427
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
21428
- },
21429
- ...options
21430
- });
21431
- };
21432
- const columnHelper$9 = ui.createDataTableColumnHelper();
21433
- const useGiftCardTableColumns = () => {
21434
- return React.useMemo(() => {
21435
- return [
21436
- columnHelper$9.accessor("code", {
21437
- header: "Code",
21438
- cell: ({ row }) => {
21439
- return row.original.code;
21440
- }
21441
- }),
21442
- columnHelper$9.accessor("line_item.product.title", {
21443
- header: "Product",
21444
- cell: ({ row }) => {
21445
- return row.original.line_item?.product?.title || "Custom Gift Card";
21446
- }
21447
- }),
21448
- columnHelper$9.accessor("created_at", {
21449
- header: "Date issued",
21450
- cell: ({ row }) => getRelativeDate(row.original.created_at)
21451
- }),
21452
- columnHelper$9.accessor("value", {
21453
- header: "Value",
21454
- cell: ({ row }) => {
21455
- return formatAmount(row.original.value, row.original.currency_code);
21456
- }
21457
- })
21458
- ];
21459
- }, []);
21460
- };
21461
- const useGiftCardFilters = () => {
21462
- const dateFilterOptions = useDataTableDateFilters$1();
21463
- const customerFilterOptions = useCustomerFilters();
21464
- return React.useMemo(() => {
21465
- return [...dateFilterOptions, ...customerFilterOptions];
21466
- }, [dateFilterOptions, customerFilterOptions]);
21467
- };
21468
- const useGiftCardTableQuery = ({
21469
- prefix,
21470
- pageSize = 20
21471
- }) => {
21472
- const queryObject = useQueryParams(
21473
- ["q", "offset", "customer_id", "created_at", "updated_at"],
21474
- prefix
21475
- );
21476
- const { offset: offset2, created_at, updated_at, customer_id, ...rest } = queryObject;
21477
- const searchParams = {
21478
- limit: pageSize,
21479
- offset: offset2 ? Number(offset2) : 0,
21480
- created_at: created_at ? JSON.parse(created_at) : void 0,
21481
- updated_at: updated_at ? JSON.parse(updated_at) : void 0,
21482
- customer_id: customer_id ? JSON.parse(customer_id) : void 0,
21483
- ...rest
21484
- };
21485
- return searchParams;
21486
- };
21487
- const PAGE_SIZE$5 = 10;
21488
- function GiftCardsTable() {
21489
- const queryParams = useGiftCardTableQuery({
21490
- pageSize: PAGE_SIZE$5
21491
- });
21492
- const {
21493
- gift_cards: giftCards,
21494
- isPending,
21495
- count: count2
21496
- } = useGiftCards({
21497
- ...queryParams,
21498
- order: queryParams.order ?? "-created_at",
21499
- fields: "+line_item.product.title"
21500
- });
21501
- const columns = useGiftCardTableColumns();
21502
- const filters = useGiftCardFilters();
21503
- return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
21504
- /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
21505
- DataTable,
21506
- {
21507
- data: giftCards,
21508
- getRowId: (row) => row.id,
21509
- columns,
21510
- filters,
21511
- isLoading: isPending,
21512
- pageSize: PAGE_SIZE$5,
21513
- rowCount: count2,
21514
- heading: "Gift Cards",
21515
- rowHref: (row) => `${row.id}`,
21516
- emptyState: {
21517
- empty: {
21518
- heading: "No gift cards found",
21519
- description: "Create a gift card to get started."
21520
- },
21521
- filtered: {
21522
- heading: "No results found",
21523
- description: "No gift cards match your filter criteria."
21524
- }
21525
- },
21526
- actions: [
21527
- {
21528
- label: "Create",
21529
- to: "create"
21530
- }
21531
- ]
21532
- }
21533
- ) }),
21534
- /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
21535
- ] });
21536
- }
21537
- const GiftCardsPage = () => {
21538
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
21539
- /* @__PURE__ */ jsxRuntime.jsx(
21540
- components.LayoutComposer,
21541
- {
21542
- widgetsZonePrefix: "gift_card.list",
21543
- preferredLayoutId: "core:two-column",
21544
- sections: {
21545
- main: /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "GiftCardsTable", children: /* @__PURE__ */ jsxRuntime.jsx(GiftCardsTable, {}) }),
21546
- side: /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "GiftCardProductsSection", children: /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductsSection, {}) })
21547
- }
21548
- }
21549
- ),
21550
- /* @__PURE__ */ jsxRuntime.jsx(ui.Toaster, {})
21551
- ] });
21552
- };
21553
- const config$2 = adminSdk.defineRouteConfig({
21554
- label: "Gift Cards",
21555
- icon: GiftCardIcon
21556
- });
21557
- const STORE_QUERY_KEY = "store";
21558
- const storeQueryKeys = queryKeysFactory(STORE_QUERY_KEY);
21559
- async function retrieveActiveStore(query) {
21560
- const response = await sdk.admin.store.list(query);
21561
- const activeStore = response.stores?.[0];
21562
- if (!activeStore) {
21563
- throw new Medusa.FetchError("No active store found", "Not Found", 404);
21564
- }
21565
- return { store: activeStore };
21566
- }
21567
- const useStore$1 = (query, options) => {
21568
- const { data, ...rest } = reactQuery.useQuery({
21569
- queryFn: () => retrieveActiveStore(query),
21570
- queryKey: storeQueryKeys.details(),
21571
- ...options
21572
- });
21573
- return {
21574
- ...data,
21575
- ...rest
21576
- };
21577
- };
21578
20858
  function getEnumValues(entries) {
21579
20859
  const numericValues = Object.values(entries).filter((v) => typeof v === "number");
21580
20860
  const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
@@ -22241,7 +21521,7 @@ class $ZodEncodeError extends Error {
22241
21521
  }
22242
21522
  (_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__zod_globalConfig = {});
22243
21523
  const globalConfig = globalThis.__zod_globalConfig;
22244
- function config$1(newConfig) {
21524
+ function config$2(newConfig) {
22245
21525
  if (newConfig)
22246
21526
  Object.assign(globalConfig, newConfig);
22247
21527
  return globalConfig;
@@ -22367,7 +21647,7 @@ const _parse = (_Err) => {
22367
21647
  throw new $ZodAsyncError();
22368
21648
  }
22369
21649
  if (result.issues.length) {
22370
- const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
21650
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
22371
21651
  captureStackTrace(e, _params?.callee ?? fn);
22372
21652
  throw e;
22373
21653
  }
@@ -22382,7 +21662,7 @@ const _parseAsync = (_Err) => {
22382
21662
  if (result instanceof Promise)
22383
21663
  result = await result;
22384
21664
  if (result.issues.length) {
22385
- const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
21665
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
22386
21666
  captureStackTrace(e, params?.callee ?? fn);
22387
21667
  throw e;
22388
21668
  }
@@ -22404,7 +21684,7 @@ function failure(Err, issues, ctx2) {
22404
21684
  success: false,
22405
21685
  get error() {
22406
21686
  if (!error2) {
22407
- error2 = new Err(issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
21687
+ error2 = new Err(issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
22408
21688
  issues = void 0;
22409
21689
  ctx2 = void 0;
22410
21690
  }
@@ -23029,7 +22309,7 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
23029
22309
  own(this, "~standard", value);
23030
22310
  }
23031
22311
  });
23032
- const toStandardResult = (r, ctx2) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())) } : { value: r.value };
22312
+ const toStandardResult = (r, ctx2) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())) } : { value: r.value };
23033
22313
  async function validateAsync(inst, value) {
23034
22314
  const ctx2 = { async: true };
23035
22315
  return toStandardResult(await inst._zod.run({ value, issues: [] }, ctx2), ctx2);
@@ -23891,7 +23171,7 @@ function handleUnionResults(results, final, inst, ctx2) {
23891
23171
  code: "invalid_union",
23892
23172
  input: final.value,
23893
23173
  inst,
23894
- errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())))
23174
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())))
23895
23175
  });
23896
23176
  return final;
23897
23177
  }
@@ -24087,7 +23367,7 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
24087
23367
  payload.issues.push({
24088
23368
  code: "invalid_key",
24089
23369
  origin: "record",
24090
- issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())),
23370
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())),
24091
23371
  input: key2,
24092
23372
  path: [key2],
24093
23373
  inst
@@ -24167,7 +23447,7 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
24167
23447
  payload.issues.push({
24168
23448
  code: "invalid_key",
24169
23449
  origin: "record",
24170
- issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())),
23450
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())),
24171
23451
  input: key2,
24172
23452
  path: [key2],
24173
23453
  inst
@@ -24383,7 +23663,7 @@ function handleCatchResult(payload, result, def, ctx2) {
24383
23663
  ...result,
24384
23664
  value: payload.value,
24385
23665
  error: {
24386
- issues: result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1()))
23666
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2()))
24387
23667
  },
24388
23668
  input: payload.value
24389
23669
  });
@@ -26527,11 +25807,11 @@ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
26527
25807
  const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
26528
25808
  function _ensureDefaultLocale() {
26529
25809
  if (!globalConfig.localeError)
26530
- config$1(en());
25810
+ config$2(en());
26531
25811
  }
26532
25812
  function _ensureDefaultMemoizer() {
26533
25813
  if (!globalConfig.memoizer)
26534
- config$1({ memoizer: memoizer() });
25814
+ config$2({ memoizer: memoizer() });
26535
25815
  }
26536
25816
  const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
26537
25817
  _ensureDefaultLocale();
@@ -27635,727 +26915,733 @@ const GiftCardCreateForm = ({
27635
26915
  ] });
27636
26916
  };
27637
26917
  const GiftCardCreate = () => {
27638
- const { store, isLoading } = useStore$1({});
26918
+ const { store, isLoading } = useStore$2({});
27639
26919
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal, { children: [
27640
26920
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Create Gift Card" }) }),
27641
26921
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Create a new gift card" }) }),
27642
26922
  !isLoading && /* @__PURE__ */ jsxRuntime.jsx(GiftCardCreateForm, { store })
27643
26923
  ] });
27644
26924
  };
27645
- const StoreCreditAccountBalanceSection = ({
27646
- storeCreditAccount
27647
- }) => {
27648
- if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
27649
- return;
27650
- }
27651
- 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: [
27652
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-tag-green-icon h-8 w-1 rounded-full" }),
27653
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
27654
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", size: "small", className: "text-ui-fg-subtle", children: "Current Balance" }),
27655
- /* @__PURE__ */ jsxRuntime.jsx(
27656
- ui.Text,
27657
- {
27658
- weight: "plus",
27659
- size: "xlarge",
27660
- className: "tabular-nums text-ui-fg-base",
27661
- children: formatAmount(
27662
- storeCreditAccount.balance,
27663
- storeCreditAccount.currency_code
27664
- )
27665
- }
27666
- )
27667
- ] })
27668
- ] }) });
27669
- };
27670
- var __create = Object.create;
27671
- var __defProp = Object.defineProperty;
27672
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
27673
- var __getOwnPropNames = Object.getOwnPropertyNames;
27674
- var __getProtoOf = Object.getPrototypeOf;
27675
- var __hasOwnProp = Object.prototype.hasOwnProperty;
27676
- var __commonJS = (cb, mod) => function __require() {
27677
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
27678
- };
27679
- var __copyProps = (to, from, except, desc) => {
27680
- if (from && typeof from === "object" || typeof from === "function") {
27681
- for (let key2 of __getOwnPropNames(from))
27682
- if (!__hasOwnProp.call(to, key2) && key2 !== except)
27683
- __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
27684
- }
27685
- return to;
27686
- };
27687
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27688
- // If the importer is in node compatibility mode or this is not an ESM
27689
- // file that has been converted to a CommonJS file using a Babel-
27690
- // compatible transform (i.e. "__esModule" has not been set), then set
27691
- // "default" to the CommonJS "module.exports" for node compatibility.
27692
- __defProp(target, "default", { value: mod, enumerable: true }),
27693
- mod
27694
- ));
27695
- var require_toggle_selection = __commonJS({
27696
- "node_modules/toggle-selection/index.js"(exports2, module2) {
27697
- module2.exports = function() {
27698
- var selection = document.getSelection();
27699
- if (!selection.rangeCount) {
27700
- return function() {
27701
- };
27702
- }
27703
- var active = document.activeElement;
27704
- var ranges = [];
27705
- for (var i2 = 0; i2 < selection.rangeCount; i2++) {
27706
- ranges.push(selection.getRangeAt(i2));
27707
- }
27708
- switch (active.tagName.toUpperCase()) {
27709
- // .toUpperCase handles XHTML
27710
- case "INPUT":
27711
- case "TEXTAREA":
27712
- active.blur();
27713
- break;
27714
- default:
27715
- active = null;
27716
- break;
27717
- }
27718
- selection.removeAllRanges();
27719
- return function() {
27720
- selection.type === "Caret" && selection.removeAllRanges();
27721
- if (!selection.rangeCount) {
27722
- ranges.forEach(function(range) {
27723
- selection.addRange(range);
27724
- });
27725
- }
27726
- active && active.focus();
27727
- };
27728
- };
27729
- }
27730
- });
27731
- var import_index = __toESM(require_toggle_selection());
27732
- var toggle_selection_default = import_index.default;
27733
- var defaultMessage = "Copy to clipboard: #{key}, Enter";
27734
- function formatPromptMessage(message2) {
27735
- var isMac2 = navigator.userAgentData ? /mac/i.test(navigator.userAgentData.platform) : /mac os x/i.test(navigator.userAgent);
27736
- var copyKey = (isMac2 ? "⌘" : "Ctrl") + "+C";
27737
- return message2.replace(/#{\s*key\s*}/g, copyKey);
27738
- }
27739
- function buildClipboardItem(text2, format2) {
27740
- var items = {};
27741
- items["text/plain"] = new Blob([text2], { type: "text/plain" });
27742
- if (format2 && format2 !== "text/plain") {
27743
- items[format2] = new Blob([text2], { type: format2 });
27744
- }
27745
- return new ClipboardItem(items);
27746
- }
27747
- async function copyViaClipboardAPI(text2, options) {
27748
- if (!options.format && !options.onCopy) {
27749
- await navigator.clipboard.writeText(text2);
27750
- return true;
27751
- }
27752
- var item = buildClipboardItem(text2, options.format);
27753
- if (options.onCopy) {
27754
- item = options.onCopy(item) || item;
27755
- }
27756
- await navigator.clipboard.write([item]);
27757
- return true;
27758
- }
27759
- function createHiddenSpan(text2, options) {
27760
- var mark = document.createElement("span");
27761
- mark.textContent = text2;
27762
- mark.ariaHidden = "true";
27763
- mark.style.all = "unset";
27764
- mark.style.position = "fixed";
27765
- mark.style.top = "0";
27766
- mark.style.clip = "rect(0, 0, 0, 0)";
27767
- mark.style.whiteSpace = "pre";
27768
- mark.style.webkitUserSelect = "text";
27769
- mark.style.MozUserSelect = "text";
27770
- mark.style.msUserSelect = "text";
27771
- mark.style.userSelect = "text";
27772
- mark.addEventListener("copy", function(e) {
27773
- e.stopPropagation();
27774
- if (options.format) {
27775
- e.preventDefault();
27776
- if (e.clipboardData) {
27777
- e.clipboardData.setData(options.format, text2);
27778
- }
27779
- }
27780
- if (options.onCopy && e.clipboardData) {
27781
- options.onCopy(e.clipboardData);
27782
- }
27783
- });
27784
- return mark;
27785
- }
27786
- function findOpenedModalDialog() {
27787
- let element = document.activeElement;
27788
- while (element) {
27789
- if (element.tagName === "DIALOG" && element.open) {
27790
- return element;
27791
- }
27792
- element = element.parentElement;
27793
- }
27794
- return null;
27795
- }
27796
- function copyViaExecCommand(text2, options) {
27797
- var reselectPrevious = toggle_selection_default();
27798
- var range = document.createRange();
27799
- var selection = document.getSelection();
27800
- var mark = createHiddenSpan(text2, options);
27801
- var root = findOpenedModalDialog() || document.fullscreenElement || document.body;
27802
- var success = false;
27803
- try {
27804
- root.appendChild(mark);
27805
- range.selectNodeContents(mark);
27806
- selection.removeAllRanges();
27807
- selection.addRange(range);
27808
- var successful = document.execCommand("copy");
27809
- if (!successful) {
27810
- throw new Error("copy command was unsuccessful");
27811
- }
27812
- success = true;
27813
- } finally {
27814
- if (typeof selection.removeRange == "function") {
27815
- selection.removeRange(range);
27816
- } else {
27817
- selection.removeAllRanges();
27818
- }
27819
- root.removeChild(mark);
27820
- reselectPrevious();
27821
- }
27822
- return success;
27823
- }
27824
- async function copy$1(text2, options = {}) {
27825
- var debug2 = options.debug || false;
27826
- if (window.isSecureContext && navigator.clipboard) {
27827
- try {
27828
- return await copyViaClipboardAPI(text2, options);
27829
- } catch (err) {
27830
- debug2 && console.error("unable to copy using navigator.clipboard: ", err);
27831
- debug2 && console.warn("falling back to execCommand");
27832
- }
27833
- } else {
27834
- debug2 && !window.isSecureContext && console.warn("copy-to-clipboard: navigator.clipboard requires a secure context (HTTPS/localhost). Falling back to execCommand.");
27835
- }
27836
- try {
27837
- return copyViaExecCommand(text2, options);
27838
- } catch (err) {
27839
- debug2 && console.error("unable to copy using execCommand: ", err);
27840
- debug2 && console.error("falling back to prompt");
27841
- if (options.fallbackToPrompt) {
27842
- var message2 = formatPromptMessage("message" in options ? options.message : defaultMessage);
27843
- window.prompt(message2, text2);
27844
- }
27845
- }
27846
- return false;
27847
- }
27848
- var index_default = copy$1;
27849
- function DisplayId({ id, className }) {
27850
- const [open2, setOpen] = React.useState(false);
27851
- const onClick = () => {
27852
- index_default(id);
27853
- ui.toast.success("Copied to clipboard");
27854
- };
27855
- 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: [
27856
- "#",
27857
- id.slice(-7)
27858
- ] }) });
27859
- }
27860
- const StoreCreditAccountDetailsSection = ({
27861
- storeCreditAccount
27862
- }) => {
27863
- if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
27864
- return;
27865
- }
27866
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "flex justify-between gap-x-2 px-6 py-6", children: [
27867
- /* @__PURE__ */ jsxRuntime.jsxs(
27868
- ui.Text,
27869
- {
27870
- weight: "plus",
27871
- size: "xlarge",
27872
- className: "text-ui-fg-base flex gap-x-4",
27873
- children: [
27874
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
27875
- /* @__PURE__ */ jsxRuntime.jsx(CreditCardIcon, { className: "inline" }),
27876
- " "
27877
- ] }),
27878
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
27879
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle", children: [
27880
- storeCreditAccount.currency_code.toUpperCase(),
27881
- " Account"
27882
- ] }),
27883
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx(
27884
- ui.Text,
27885
- {
27886
- weight: "regular",
27887
- size: "small",
27888
- className: "text-ui-fg-base flex gap-x-4",
27889
- children: /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: storeCreditAccount.id })
27890
- }
27891
- ) })
27892
- ] })
27893
- ]
27894
- }
27895
- ),
27896
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-x-4", children: /* @__PURE__ */ jsxRuntime.jsx(
27897
- ActionMenu,
27898
- {
27899
- groups: [
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",
27900
26939
  {
27901
- actions: [
27902
- {
27903
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CreditCard, {}),
27904
- label: "Credit the account",
27905
- to: "credit"
27906
- },
27907
- {
27908
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.MinusMini, {}),
27909
- label: "Debit the account",
27910
- to: "debit",
27911
- disabled: !Number(storeCreditAccount.balance)
27912
- }
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",
26962
+ {
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" })
27913
26972
  ]
27914
26973
  }
27915
- ]
27916
- }
27917
- ) })
27918
- ] });
26974
+ ) })
26975
+ ]
26976
+ }
26977
+ );
27919
26978
  };
27920
- function StoreCreditAccountCustomerSection({
27921
- customerId
27922
- }) {
27923
- const { customer, isPending } = useCustomer(customerId, void 0, {
27924
- enabled: !!customerId
27925
- });
27926
- if (isPending || !customer) {
27927
- return null;
27928
- }
27929
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
27930
- /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Customer" }),
27931
- /* @__PURE__ */ jsxRuntime.jsx(
27932
- SidebarLink,
27933
- {
27934
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.User, {}),
27935
- labelKey: customer.email || "N/A",
27936
- descriptionKey: !customer.first_name && !customer.last_name ? "N/A" : `${customer.first_name} ${customer.last_name}`,
27937
- to: `/customers/${customer.id}`
27938
- },
27939
- customer.id
27940
- )
27941
- ] });
27942
- }
27943
- const columnHelper$8 = ui.createDataTableColumnHelper();
27944
- const useTransactionsTableColumns = () => {
26979
+ const columnHelper$9 = ui.createDataTableColumnHelper();
26980
+ const useStoreCreditAccountTableColumns = () => {
27945
26981
  return React.useMemo(() => {
27946
26982
  return [
27947
- columnHelper$8.accessor("id", {
27948
- header: "ID",
26983
+ columnHelper$9.accessor("currency_code", {
26984
+ header: "Currency",
27949
26985
  cell: ({ row }) => {
27950
- return /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: row.original.id });
26986
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", children: row.original.currency_code.toUpperCase() });
27951
26987
  }
27952
26988
  }),
27953
- columnHelper$8.accessor("created_at", {
27954
- header: "Created At",
27955
- cell: ({ row }) => formatDate(row.original.created_at, false)
26989
+ columnHelper$9.accessor("customer.email", {
26990
+ header: "Customer",
26991
+ cell: ({ row }) => {
26992
+ return row.original.customer?.email ?? "N/A";
26993
+ }
27956
26994
  }),
27957
- columnHelper$8.accessor("note", {
27958
- header: "Description",
27959
- cell: ({ row }) => row.original.note
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
+ }
27960
27003
  }),
27961
- columnHelper$8.accessor("note", {
27962
- header: "Note",
27004
+ columnHelper$9.accessor("credits", {
27005
+ header: "Credits",
27963
27006
  cell: ({ row }) => {
27964
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { title: row.original.note, className: "max-w-[300px] truncate", children: row.original.note || "-" });
27007
+ return formatAmount(
27008
+ row.original.credits,
27009
+ row.original.currency_code
27010
+ );
27965
27011
  }
27966
27012
  }),
27967
- columnHelper$8.accessor("amount", {
27968
- header: "Amount",
27013
+ columnHelper$9.accessor("debits", {
27014
+ header: "Debits",
27969
27015
  cell: ({ row }) => {
27970
- const isDebit = row.original.type === "debit";
27971
- return row.original.account.currency_code && formatAmount(
27972
- row.original.amount * (isDebit ? -1 : 1),
27973
- row.original.account.currency_code
27016
+ return formatAmount(
27017
+ row.original.debits,
27018
+ row.original.currency_code
27974
27019
  );
27975
27020
  }
27021
+ }),
27022
+ columnHelper$9.accessor("created_at", {
27023
+ header: "Created at",
27024
+ cell: ({ row }) => getRelativeDate(row.original.created_at)
27976
27025
  })
27977
27026
  ];
27978
27027
  }, []);
27979
27028
  };
27980
- const useTransactionsTableFilters = ({}) => {
27029
+ const useStoreCreditAccountFilters = () => {
27981
27030
  const dateFilterOptions = useDataTableDateFilters$1();
27031
+ const customerFilterOptions = useCustomerFilters();
27982
27032
  return React.useMemo(() => {
27983
- return [...dateFilterOptions];
27984
- }, [dateFilterOptions]);
27033
+ return [...dateFilterOptions, ...customerFilterOptions];
27034
+ }, [dateFilterOptions, customerFilterOptions]);
27985
27035
  };
27986
- const useTransactionsTableQuery = ({
27036
+ const useStoreCreditAccountsTableQuery = ({
27987
27037
  prefix,
27988
27038
  pageSize = 20
27989
27039
  }) => {
27990
27040
  const queryObject = useQueryParams(
27991
- ["offset", "limit", "currency_code", "created_at", "updated_at"],
27041
+ ["offset", "customer_id", "currency_code", "created_at", "updated_at"],
27992
27042
  prefix
27993
27043
  );
27994
- const { offset: offset2, limit, created_at, updated_at, ...rest } = queryObject;
27044
+ const {
27045
+ offset: offset2,
27046
+ created_at,
27047
+ updated_at,
27048
+ customer_id,
27049
+ currency_code,
27050
+ ...rest
27051
+ } = queryObject;
27995
27052
  const searchParams = {
27996
- limit: limit ? Number(limit) : pageSize,
27053
+ limit: pageSize,
27997
27054
  offset: offset2 ? Number(offset2) : 0,
27998
27055
  created_at: created_at ? JSON.parse(created_at) : void 0,
27999
27056
  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,
28000
27059
  ...rest
28001
27060
  };
28002
27061
  return searchParams;
28003
27062
  };
28004
- const PAGE_SIZE$4 = 10;
28005
- function TransactionsTable({ id }) {
28006
- const queryParams = useTransactionsTableQuery({
28007
- pageSize: PAGE_SIZE$4
27063
+ const PAGE_SIZE$5 = 10;
27064
+ function StoreCreditAccountsTable() {
27065
+ const queryParams = useStoreCreditAccountsTableQuery({
27066
+ pageSize: PAGE_SIZE$5
28008
27067
  });
28009
- const { transactions, isLoading, count: count2 } = useStoreCreditAccountTransactions(
28010
- id,
28011
- {
28012
- ...queryParams,
28013
- order: queryParams.order ?? "-created_at",
28014
- fields: "*account"
28015
- }
28016
- );
28017
- const columns = useTransactionsTableColumns();
28018
- const filters = useTransactionsTableFilters({});
27068
+ const {
27069
+ store_credit_accounts: storeCreditAccounts,
27070
+ isPending,
27071
+ count: count2
27072
+ } = useStoreCreditAccounts({
27073
+ ...queryParams,
27074
+ order: queryParams.order ?? "-created_at"
27075
+ });
27076
+ const columns = useStoreCreditAccountTableColumns();
27077
+ const filters = useStoreCreditAccountFilters();
28019
27078
  return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
28020
27079
  /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
28021
27080
  DataTable,
28022
27081
  {
28023
- data: transactions ?? [],
27082
+ data: storeCreditAccounts ?? [],
28024
27083
  getRowId: (row) => row.id,
28025
27084
  columns,
28026
27085
  filters,
28027
- isLoading,
28028
- pageSize: PAGE_SIZE$4,
27086
+ isLoading: isPending,
27087
+ pageSize: PAGE_SIZE$5,
28029
27088
  rowCount: count2,
28030
27089
  enableSearch: false,
28031
- heading: "Transactions",
27090
+ heading: "Store Credit Accounts",
27091
+ rowHref: (row) => `${row.id}`,
28032
27092
  emptyState: {
28033
27093
  empty: {
28034
- heading: "No transactions found"
27094
+ heading: "No store credit accounts found",
27095
+ description: "Create a new store credit account to get started."
28035
27096
  },
28036
27097
  filtered: {
28037
27098
  heading: "No results found",
28038
- description: "No transactions match your filter criteria."
27099
+ description: "No store credit accounts match your filter criteria."
28039
27100
  }
28040
- }
27101
+ },
27102
+ actions: [
27103
+ {
27104
+ label: "Create",
27105
+ to: "/store-credit-accounts/create"
27106
+ }
27107
+ ]
28041
27108
  }
28042
27109
  ) }),
28043
27110
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
28044
27111
  ] });
28045
27112
  }
28046
- function StoreCreditAccountCodeSection({ code }) {
28047
- if (!code) {
28048
- return null;
28049
- }
28050
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
28051
- /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Account Code" }),
28052
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-4 px-6 mb-2", children: [
28053
- /* @__PURE__ */ jsxRuntime.jsx(icons.Share, { className: "inline" }),
28054
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle text-sm", children: code })
28055
- ] })
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, {})
28056
27126
  ] });
28057
- }
28058
- const StoreCreditAccountPage = () => {
28059
- const { id } = reactRouterDom.useParams();
28060
- const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
28061
- id
28062
- );
28063
- if (!storeCreditAccount) {
28064
- return;
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");
28065
27140
  }
28066
- return /* @__PURE__ */ jsxRuntime.jsx(
28067
- components.LayoutComposer,
28068
- {
28069
- widgetsZonePrefix: "store_credit_account.details",
28070
- preferredLayoutId: "core:two-column",
28071
- data: storeCreditAccount,
28072
- sections: {
28073
- main: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
28074
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountDetailsSection", children: /* @__PURE__ */ jsxRuntime.jsx(
28075
- StoreCreditAccountDetailsSection,
28076
- {
28077
- storeCreditAccount
28078
- }
28079
- ) }),
28080
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "TransactionsTable", children: /* @__PURE__ */ jsxRuntime.jsx(TransactionsTable, { id: storeCreditAccount.id }) })
28081
- ] }),
28082
- side: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
28083
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountBalanceSection", children: /* @__PURE__ */ jsxRuntime.jsx(
28084
- StoreCreditAccountBalanceSection,
28085
- {
28086
- storeCreditAccount
28087
- }
28088
- ) }),
28089
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountCodeSection", children: /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountCodeSection, { code: storeCreditAccount.code }) }),
28090
- /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "StoreCreditAccountCustomerSection", children: /* @__PURE__ */ jsxRuntime.jsx(
28091
- StoreCreditAccountCustomerSection,
28092
- {
28093
- customerId: storeCreditAccount.customer_id
28094
- }
28095
- ) })
28096
- ] })
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;
27152
+ }
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];
28097
27237
  }
28098
27238
  }
28099
- );
28100
- };
28101
- const KeyboundForm = React__namespace.default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
28102
- const handleSubmit = (event) => {
28103
- event.preventDefault();
28104
- onSubmit?.(event);
28105
- };
28106
- const handleKeyDown = (event) => {
28107
- if (event.key === "Enter") {
28108
- if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
28109
- return;
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;
27326
+ }
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);
28110
27374
  }
28111
- event.preventDefault();
28112
- if (event.metaKey || event.ctrlKey) {
28113
- handleSubmit(event);
27375
+ timerId = setTimeout(timerExpired, remainingWait(time2));
27376
+ }
27377
+ function trailingEdge(time2) {
27378
+ timerId = void 0;
27379
+ if (trailing && lastArgs) {
27380
+ return invokeFunc(time2);
28114
27381
  }
27382
+ lastArgs = lastThis = void 0;
27383
+ return result;
28115
27384
  }
28116
- };
28117
- return /* @__PURE__ */ jsxRuntime.jsx(
28118
- "form",
28119
- {
28120
- ...rest,
28121
- onSubmit: handleSubmit,
28122
- onKeyDown: onKeyDown ?? handleKeyDown,
28123
- ref
27385
+ function cancel() {
27386
+ if (timerId !== void 0) {
27387
+ clearTimeout(timerId);
27388
+ }
27389
+ lastInvokeTime = 0;
27390
+ lastArgs = lastCallTime = lastThis = timerId = void 0;
28124
27391
  }
28125
- );
28126
- });
28127
- KeyboundForm.displayName = "KeyboundForm";
28128
- const Note$1 = () => {
28129
- const { id } = reactRouterDom.useParams();
28130
- const {
28131
- store_credit_account: storeCreditAccount,
28132
- isPending,
28133
- isError,
28134
- error: error2
28135
- } = useStoreCreditAccount(id, {});
28136
- if (isError) {
28137
- throw error2;
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;
27414
+ }
27415
+ debounced.cancel = cancel;
27416
+ debounced.flush = flush;
27417
+ return debounced;
28138
27418
  }
28139
- const isReady = !isPending && !!storeCreditAccount;
28140
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
28141
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
28142
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Credit store credit account" }) }),
28143
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Credit the store credit account" }) })
28144
- ] }),
28145
- isReady && /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountCreditForm, { storeCreditAccount })
28146
- ] });
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
+ );
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
+ };
28147
27440
  };
28148
- const StoreCreditAccountCreditForm = ({
28149
- storeCreditAccount
27441
+ const useComboboxData = ({
27442
+ queryKey,
27443
+ queryFn,
27444
+ getOptions,
27445
+ defaultValue: defaultValue2,
27446
+ defaultValueKey,
27447
+ pageSize = 10
28150
27448
  }) => {
28151
- const form = useForm({
28152
- defaultValues: {
28153
- amount: {
28154
- float: 0,
28155
- value: ""
28156
- },
28157
- note: ""
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
+ });
28158
27458
  },
28159
- resolver: u(schema$3)
27459
+ enabled: !!defaultValue2
28160
27460
  });
28161
- const { mutateAsync, isPending } = useCreditStoreCreditAccount(
28162
- storeCreditAccount.id
28163
- );
28164
- const { handleSuccess } = useRouteModal();
28165
- const onSubmit = form.handleSubmit(async (data) => {
28166
- if (data.amount.float <= 0) {
28167
- form.setError("amount", { message: "Amount must be greater than 0" });
28168
- return;
28169
- }
28170
- await mutateAsync(
28171
- { amount: data.amount.float, note: data.note },
28172
- {
28173
- onSuccess: () => handleSuccess(),
28174
- onError: (error2) => ui.toast.error(error2.message)
28175
- }
28176
- );
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;
27474
+ },
27475
+ placeholderData: reactQuery.keepPreviousData
28177
27476
  });
28178
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
28179
- KeyboundForm,
28180
- {
28181
- className: "flex flex-1 flex-col overflow-hidden",
28182
- onSubmit,
28183
- children: [
28184
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
28185
- /* @__PURE__ */ jsxRuntime.jsx(
28186
- Form$2.Field,
28187
- {
28188
- control: form.control,
28189
- name: "amount",
28190
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
28191
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Amount" }),
28192
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
28193
- ui.CurrencyInput,
28194
- {
28195
- min: 0,
28196
- placeholder: "0",
28197
- value: field.value.value,
28198
- onValueChange: (_value, _name, values) => {
28199
- field.onChange({
28200
- value: values?.value,
28201
- float: values?.float || null
28202
- });
28203
- },
28204
- symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
28205
- code: storeCreditAccount.currency_code.toUpperCase()
28206
- }
28207
- ) }),
28208
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
28209
- ] })
28210
- }
28211
- ),
28212
- /* @__PURE__ */ jsxRuntime.jsx(
28213
- Form$2.Field,
28214
- {
28215
- control: form.control,
28216
- name: "note",
28217
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
28218
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
28219
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
28220
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
28221
- ] })
28222
- }
28223
- )
28224
- ] }),
28225
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
28226
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
28227
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
28228
- ] }) })
28229
- ]
28230
- }
28231
- ) });
28232
- };
28233
- const schema$3 = zod.z.object({
28234
- note: zod.z.string(),
28235
- amount: zod.z.object({
28236
- float: zod.z.number(),
28237
- value: zod.z.string()
28238
- })
28239
- });
28240
- const Debit = () => {
28241
- const { id } = reactRouterDom.useParams();
28242
- const {
28243
- store_credit_account: storeCreditAccount,
28244
- isPending,
28245
- isError,
28246
- error: error2
28247
- } = useStoreCreditAccount(id, {});
28248
- if (isError) {
28249
- throw error2;
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);
27484
+ }
27485
+ });
28250
27486
  }
28251
- const isReady = !isPending && !!storeCreditAccount;
28252
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
28253
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
28254
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Debit store credit account" }) }),
28255
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Debit the store credit account" }) })
28256
- ] }),
28257
- isReady && /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountDebitForm, { storeCreditAccount })
28258
- ] });
27487
+ return {
27488
+ options,
27489
+ searchValue,
27490
+ onSearchValueChange,
27491
+ disabled,
27492
+ ...rest
27493
+ };
28259
27494
  };
28260
- const StoreCreditAccountDebitForm = ({
28261
- storeCreditAccount
28262
- }) => {
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()
27498
+ });
27499
+ const StoreCreditAccountCreateForm = () => {
27500
+ const { handleSuccess } = useRouteModal();
27501
+ const [searchParams] = reactRouterDom.useSearchParams();
27502
+ const prefilledCustomerId = searchParams.get("prefill_customer_id") ?? "";
28263
27503
  const form = useForm({
28264
27504
  defaultValues: {
28265
- amount: {
28266
- float: 0,
28267
- value: ""
28268
- },
28269
- note: ""
27505
+ currency_code: "",
27506
+ customer_id: prefilledCustomerId
28270
27507
  },
28271
- resolver: u(schema$2)
27508
+ resolver: u(formSchema)
28272
27509
  });
28273
- const { mutateAsync, isPending } = useDebitStoreCreditAccount(
28274
- storeCreditAccount.id
28275
- );
28276
- const { handleSuccess } = useRouteModal();
28277
- const balance = storeCreditAccount.balance ?? 0;
28278
- const onSubmit = form.handleSubmit(async (data) => {
28279
- if (data.amount.float <= 0) {
28280
- form.setError("amount", { message: "Amount must be greater than 0" });
28281
- return;
28282
- }
28283
- if (data.amount.float > balance) {
28284
- form.setError("amount", {
28285
- message: "Amount can't be greater than the current balance"
28286
- });
28287
- return;
27510
+ const { mutateAsync: createStoreCreditAccount, isPending } = useCreateStoreCreditAccount();
27511
+ const handleSubmit = form.handleSubmit(async (data) => {
27512
+ if (!data.customer_id) {
27513
+ delete data.customer_id;
28288
27514
  }
28289
- await mutateAsync(
28290
- { amount: data.amount.float, note: data.note },
28291
- {
28292
- onSuccess: () => handleSuccess(),
28293
- onError: (error2) => ui.toast.error(error2.message)
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);
28294
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;
27533
+ }
27534
+ return options.filter(
27535
+ (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
28295
27536
  );
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
+ }
28296
27561
  });
28297
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
28298
- KeyboundForm,
28299
- {
28300
- className: "flex flex-1 flex-col overflow-hidden",
28301
- onSubmit,
28302
- children: [
28303
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
28304
- /* @__PURE__ */ jsxRuntime.jsx(
28305
- Form$2.Field,
28306
- {
28307
- control: form.control,
28308
- name: "amount",
28309
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
28310
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Amount" }),
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" }),
28311
27578
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
28312
- ui.CurrencyInput,
27579
+ Combobox2,
28313
27580
  {
28314
- min: 0,
28315
- placeholder: "0",
28316
- value: field.value.value,
28317
- onValueChange: (_value, _name, values) => {
28318
- field.onChange({
28319
- value: values?.value,
28320
- float: values?.float || null
28321
- });
28322
- },
28323
- symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
28324
- code: storeCreditAccount.currency_code.toUpperCase()
27581
+ value: field.value,
27582
+ onChange: field.onChange,
27583
+ searchValue: currencySearchValue,
27584
+ onSearchValueChange: setCurrencySearchValue,
27585
+ options: currencyOptions,
27586
+ placeholder: "Search for a currency..."
28325
27587
  }
28326
27588
  ) }),
28327
27589
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
28328
- ] })
27590
+ ] });
28329
27591
  }
28330
- ),
28331
- /* @__PURE__ */ jsxRuntime.jsx(
28332
- Form$2.Field,
28333
- {
28334
- control: form.control,
28335
- name: "note",
28336
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
28337
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
28338
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
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
+ ) }),
28339
27616
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
28340
- ] })
27617
+ ] });
28341
27618
  }
28342
- )
28343
- ] }),
28344
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
28345
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
28346
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
28347
- ] }) })
28348
- ]
28349
- }
28350
- ) });
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
+ ] });
27637
+ };
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
+ ] });
28351
27644
  };
28352
- const schema$2 = zod.z.object({
28353
- note: zod.z.string(),
28354
- amount: zod.z.object({
28355
- float: zod.z.number(),
28356
- value: zod.z.string()
28357
- })
28358
- });
28359
27645
  function _extends() {
28360
27646
  return _extends = Object.assign ? Object.assign.bind() : function(n2) {
28361
27647
  for (var e = 1; e < arguments.length; e++) {
@@ -31035,6 +30321,299 @@ const GiftCardOrderSection = ({ giftCard }) => {
31035
30321
  ))
31036
30322
  ] });
31037
30323
  };
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
+ }
31038
30617
  const GiftCardTransactionsSection = ({
31039
30618
  storeCreditAccount
31040
30619
  }) => {
@@ -31084,6 +30663,33 @@ const GiftCardDetailsPage = () => {
31084
30663
  }
31085
30664
  );
31086
30665
  };
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";
31087
30693
  const GiftCardExpiration = () => {
31088
30694
  const { id } = reactRouterDom.useParams();
31089
30695
  const { gift_card: giftCard, isPending, isError, error: error2 } = useGiftCard(id);
@@ -31104,7 +30710,7 @@ const GiftCardExpirationForm = ({ giftCard }) => {
31104
30710
  defaultValues: {
31105
30711
  expires_at: giftCard.expires_at ? new Date(giftCard.expires_at) : null
31106
30712
  },
31107
- resolver: u(schema$1)
30713
+ resolver: u(schema$3)
31108
30714
  });
31109
30715
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
31110
30716
  const { handleSuccess } = useRouteModal();
@@ -31199,10 +30805,10 @@ const GiftCardExpirationForm = ({ giftCard }) => {
31199
30805
  }
31200
30806
  ) });
31201
30807
  };
31202
- const schema$1 = zod.z.object({
30808
+ const schema$3 = zod.z.object({
31203
30809
  expires_at: zod.z.date().nullish()
31204
30810
  });
31205
- const Note = () => {
30811
+ const Note$1 = () => {
31206
30812
  const { id } = reactRouterDom.useParams();
31207
30813
  const {
31208
30814
  gift_card: giftCard,
@@ -31227,7 +30833,7 @@ const GiftCardNoteForm = ({ giftCard }) => {
31227
30833
  defaultValues: {
31228
30834
  note: giftCard.note ?? ""
31229
30835
  },
31230
- resolver: u(schema)
30836
+ resolver: u(schema$2)
31231
30837
  });
31232
30838
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
31233
30839
  const { handleSuccess } = useRouteModal();
@@ -31266,7 +30872,7 @@ const GiftCardNoteForm = ({ giftCard }) => {
31266
30872
  }
31267
30873
  ) });
31268
30874
  };
31269
- const schema = zod.z.object({
30875
+ const schema$2 = zod.z.object({
31270
30876
  note: zod.z.string().optional()
31271
30877
  });
31272
30878
  const columnHelper$7 = createColumnHelper();
@@ -45757,7 +45363,7 @@ const GiftCardProductCreate = () => {
45757
45363
  isPending: isStorePending,
45758
45364
  isError: isStoreError,
45759
45365
  error: storeError
45760
- } = useStore$1({
45366
+ } = useStore$2({
45761
45367
  fields: "+default_sales_channel"
45762
45368
  });
45763
45369
  const {
@@ -45809,6 +45415,400 @@ const GiftCardProductCreate = () => {
45809
45415
  )
45810
45416
  ] });
45811
45417
  };
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
+ ) });
45804
+ };
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
45812
  const productStatusColor = (status) => {
45813
45813
  switch (status) {
45814
45814
  case "draft":
@@ -47242,7 +47242,7 @@ const ProductMedia = () => {
47242
47242
  ] });
47243
47243
  };
47244
47244
  const VariantPricingForm = ({ form }) => {
47245
- const { store } = useStore$1();
47245
+ const { store } = useStore$2();
47246
47246
  const { regions } = useRegions({ limit: 9999 });
47247
47247
  const { price_preferences: pricePreferences } = usePricePreferences({});
47248
47248
  const { setCloseOnEscape } = useRouteModal();
@@ -47517,21 +47517,10 @@ const widgetModule = { widgets: [
47517
47517
  ] };
47518
47518
  const routeModule = {
47519
47519
  routes: [
47520
- {
47521
- Component: StoreCreditAccountsPage,
47522
- path: "/store-credit-accounts",
47523
- handle: { label: config$3.label, translationNs: config$3.translationNs },
47524
- children: [
47525
- {
47526
- Component: StoreCreditAccountCreate,
47527
- path: "/store-credit-accounts/create"
47528
- }
47529
- ]
47530
- },
47531
47520
  {
47532
47521
  Component: GiftCardsPage,
47533
47522
  path: "/gift-cards",
47534
- handle: { label: config$2.label, translationNs: config$2.translationNs },
47523
+ handle: { label: config$3.label, translationNs: config$3.translationNs },
47535
47524
  children: [
47536
47525
  {
47537
47526
  Component: GiftCardCreate,
@@ -47540,16 +47529,13 @@ const routeModule = {
47540
47529
  ]
47541
47530
  },
47542
47531
  {
47543
- Component: StoreCreditAccountPage,
47544
- path: "/store-credit-accounts/:id",
47532
+ Component: StoreCreditAccountsPage,
47533
+ path: "/store-credit-accounts",
47534
+ handle: { label: config$1.label, translationNs: config$1.translationNs },
47545
47535
  children: [
47546
47536
  {
47547
- Component: Note$1,
47548
- path: "/store-credit-accounts/:id/credit"
47549
- },
47550
- {
47551
- Component: Debit,
47552
- path: "/store-credit-accounts/:id/debit"
47537
+ Component: StoreCreditAccountCreate,
47538
+ path: "/store-credit-accounts/create"
47553
47539
  }
47554
47540
  ]
47555
47541
  },
@@ -47562,7 +47548,7 @@ const routeModule = {
47562
47548
  path: "/gift-cards/:id/expiration"
47563
47549
  },
47564
47550
  {
47565
- Component: Note,
47551
+ Component: Note$1,
47566
47552
  path: "/gift-cards/:id/note"
47567
47553
  }
47568
47554
  ]
@@ -47578,6 +47564,20 @@ const routeModule = {
47578
47564
  }
47579
47565
  ]
47580
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"
47578
+ }
47579
+ ]
47580
+ },
47581
47581
  {
47582
47582
  Component: ProductDetail,
47583
47583
  path: "/gift-cards/gift-card-products/:id",
@@ -47611,15 +47611,15 @@ const menuItemModule = {
47611
47611
  {
47612
47612
  label: config$3.label,
47613
47613
  icon: config$3.icon,
47614
- path: "/store-credit-accounts",
47614
+ path: "/gift-cards",
47615
47615
  nested: void 0,
47616
47616
  rank: void 0,
47617
47617
  translationNs: void 0
47618
47618
  },
47619
47619
  {
47620
- label: config$2.label,
47621
- icon: config$2.icon,
47622
- path: "/gift-cards",
47620
+ label: config$1.label,
47621
+ icon: config$1.icon,
47622
+ path: "/store-credit-accounts",
47623
47623
  nested: void 0,
47624
47624
  rank: void 0,
47625
47625
  translationNs: void 0