@medusajs/loyalty-plugin 2.22.3 → 2.22.4-preview-20261106081111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,17 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
3
3
  import { usePermissions, PermissionGuard } from "@medusajs/dashboard/hooks";
4
- import { DropdownMenu, IconButton, clx, Heading, Text, Tooltip, Button, Container as Container$1, StatusBadge, useDataTable, DataTable as DataTable$1, createDataTableFilterHelper, usePrompt, toast, Checkbox, createDataTableColumnHelper, Badge, Toaster, Label as Label$1, Hint as Hint$1, Prompt, Drawer, FocusModal, Divider, CurrencyInput, DatePicker, Textarea, Kbd, Copy, RadioGroup, Skeleton, Input, Alert, ProgressTabs, CommandBar, Select } from "@medusajs/ui";
4
+ import { DropdownMenu, IconButton, clx, Heading, Text, Tooltip, Button, Container as Container$1, StatusBadge, useDataTable, DataTable as DataTable$1, createDataTableFilterHelper, usePrompt, toast, Checkbox, createDataTableColumnHelper, Toaster, Label as Label$1, Hint as Hint$1, Prompt, Drawer, FocusModal, Divider, CurrencyInput, DatePicker, Textarea, Badge, Kbd, Copy, RadioGroup, Skeleton, Input, Alert, ProgressTabs, CommandBar, Select } from "@medusajs/ui";
5
5
  import { Link, useParams, useSearchParams, useNavigate, Outlet, useBlocker, useLocation } from "react-router-dom";
6
6
  import * as React from "react";
7
7
  import React__default, { createElement as createElement$1, useState, useCallback, useMemo, Fragment as Fragment$1, createContext, forwardRef as forwardRef$1, useId as useId$1, useContext, useEffect, useLayoutEffect, useRef, isValidElement, useReducer, useTransition, useImperativeHandle, useDeferredValue, Suspense, memo as memo$4, cloneElement } from "react";
8
- import { EllipsisHorizontal, InformationCircleSolid, ExclamationCircle, PlusMini, TriangleRightMini, Gift, Photo, PencilSquare, Trash, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, Tag, CreditCard, MinusMini, User, Share, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Calendar, ShoppingCart, AdjustmentsDone, Adjustments, TaxInclusive, TaxExclusive, XMark, ArrowDownTray, DotsSix, ThumbnailBadge, StackPerspective, XCircleSolid, TriangleLeftMini } from "@medusajs/icons";
8
+ import { EllipsisHorizontal, InformationCircleSolid, ExclamationCircle, PlusMini, TriangleRightMini, Gift, Photo, PencilSquare, Trash, Tag, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Calendar, ShoppingCart, AdjustmentsDone, Adjustments, TaxInclusive, TaxExclusive, XMark, ArrowDownTray, DotsSix, ThumbnailBadge, StackPerspective, CreditCard, MinusMini, User, Share, XCircleSolid, TriangleLeftMini } from "@medusajs/icons";
9
9
  import { useQuery, useQueryClient, useMutation, useInfiniteQuery, keepPreviousData } from "@tanstack/react-query";
10
10
  import Medusa, { FetchError } from "@medusajs/js-sdk";
11
11
  import { LayoutComposer } from "@medusajs/dashboard/components";
12
+ import { flushSync, createPortal, unstable_batchedUpdates } from "react-dom";
12
13
  import * as zod from "@medusajs/framework/zod";
13
14
  import { z } from "@medusajs/framework/zod";
14
- import { flushSync, createPortal, unstable_batchedUpdates } from "react-dom";
15
15
  const ActionMenu = ({ groups }) => {
16
16
  return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
17
17
  /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { size: "small", variant: "transparent", children: /* @__PURE__ */ jsx(EllipsisHorizontal, {}) }) }),
@@ -5774,7 +5774,7 @@ defineWidgetConfig({
5774
5774
  zone: "sales_channel.details.after",
5775
5775
  id: "medusa:sales-channel-gift-cards-widget"
5776
5776
  });
5777
- const StoreCreditIcon = (props) => {
5777
+ const GiftCardIcon = (props) => {
5778
5778
  return /* @__PURE__ */ jsxs(
5779
5779
  "svg",
5780
5780
  {
@@ -5785,49 +5785,199 @@ const StoreCreditIcon = (props) => {
5785
5785
  xmlns: "http://www.w3.org/2000/svg",
5786
5786
  ...props,
5787
5787
  children: [
5788
- /* @__PURE__ */ jsx("rect", { width: "15", height: "15", fill: "#8B5CF6" }),
5788
+ /* @__PURE__ */ jsx("rect", { width: "15", height: "15", fill: "#F97316" }),
5789
5789
  /* @__PURE__ */ jsx(
5790
5790
  "rect",
5791
5791
  {
5792
5792
  width: "15",
5793
5793
  height: "15",
5794
- fill: "url(#paint0_linear_29181_44790)",
5794
+ fill: "url(#paint0_linear_28788_25808)",
5795
5795
  fillOpacity: "0.2"
5796
5796
  }
5797
5797
  ),
5798
- /* @__PURE__ */ jsx(
5799
- "path",
5800
- {
5801
- d: "M12 6V5.813C12 4.675 11.075 3.75 9.938 3.75H5.063C3.925 3.75 3 4.675 3 5.813V6H12Z",
5802
- fill: "white"
5803
- }
5804
- ),
5805
- /* @__PURE__ */ jsx(
5806
- "path",
5807
- {
5808
- 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",
5809
- fill: "white"
5810
- }
5811
- ),
5812
- /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
5813
- "linearGradient",
5814
- {
5815
- id: "paint0_linear_29181_44790",
5816
- x1: "7.5",
5817
- y1: "0",
5818
- x2: "7.5",
5819
- y2: "15",
5820
- gradientUnits: "userSpaceOnUse",
5821
- children: [
5822
- /* @__PURE__ */ jsx("stop", { stopColor: "white" }),
5823
- /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
5824
- ]
5825
- }
5826
- ) })
5798
+ /* @__PURE__ */ jsxs("g", { clipPath: "url(#clip0_28788_25808)", children: [
5799
+ /* @__PURE__ */ jsx(
5800
+ "path",
5801
+ {
5802
+ 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",
5803
+ fill: "white"
5804
+ }
5805
+ ),
5806
+ /* @__PURE__ */ jsx(
5807
+ "path",
5808
+ {
5809
+ 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",
5810
+ fill: "white"
5811
+ }
5812
+ ),
5813
+ /* @__PURE__ */ jsx(
5814
+ "path",
5815
+ {
5816
+ 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",
5817
+ fill: "white"
5818
+ }
5819
+ ),
5820
+ /* @__PURE__ */ jsx(
5821
+ "path",
5822
+ {
5823
+ d: "M6.938 7.5H3.75V9.563C3.75 10.7 4.675 11.625 5.813 11.625H6.938V7.5Z",
5824
+ fill: "white"
5825
+ }
5826
+ ),
5827
+ /* @__PURE__ */ jsx(
5828
+ "path",
5829
+ {
5830
+ d: "M8.063 7.5V11.625H9.188C10.325 11.625 11.25 10.7 11.25 9.563V7.5H8.063Z",
5831
+ fill: "white"
5832
+ }
5833
+ )
5834
+ ] }),
5835
+ /* @__PURE__ */ jsxs("defs", { children: [
5836
+ /* @__PURE__ */ jsxs(
5837
+ "linearGradient",
5838
+ {
5839
+ id: "paint0_linear_28788_25808",
5840
+ x1: "7.5",
5841
+ y1: "0",
5842
+ x2: "7.5",
5843
+ y2: "15",
5844
+ gradientUnits: "userSpaceOnUse",
5845
+ children: [
5846
+ /* @__PURE__ */ jsx("stop", { stopColor: "white" }),
5847
+ /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
5848
+ ]
5849
+ }
5850
+ ),
5851
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_28788_25808", children: /* @__PURE__ */ jsx("rect", { width: "9", height: "9", fill: "white", transform: "translate(3 3)" }) })
5852
+ ] })
5827
5853
  ]
5828
5854
  }
5829
5855
  );
5830
5856
  };
5857
+ const GiftCardProductsSection = () => {
5858
+ const { hasPermission } = usePermissions();
5859
+ const canCreateProduct = hasPermission("product:create");
5860
+ const { products: giftCardProducts, count: count2 = 0 } = useProducts({
5861
+ is_giftcard: true
5862
+ });
5863
+ const slicedProducts = giftCardProducts?.slice(0, 3) ?? [];
5864
+ return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
5865
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
5866
+ /* @__PURE__ */ jsx(Header$5, { title: "Gift Card Products" }),
5867
+ canCreateProduct && /* @__PURE__ */ jsx(
5868
+ Link,
5869
+ {
5870
+ to: `/gift-cards/gift-card-products/create`,
5871
+ className: "text-ui-fg-muted text-sm px-6",
5872
+ children: "Create"
5873
+ }
5874
+ )
5875
+ ] }),
5876
+ giftCardProducts?.length === 0 && /* @__PURE__ */ jsx(
5877
+ NoRecords,
5878
+ {
5879
+ className: "px-10 py-4 h-[200px]",
5880
+ title: "No gift card products",
5881
+ message: "There are no gift card products to show. Create one to get started.",
5882
+ action: canCreateProduct ? {
5883
+ to: "/gift-cards/gift-card-products/create",
5884
+ label: "Create gift card product"
5885
+ } : void 0
5886
+ }
5887
+ ),
5888
+ slicedProducts.map((giftCardProduct) => /* @__PURE__ */ jsx(
5889
+ SidebarLink,
5890
+ {
5891
+ to: `/gift-cards/gift-card-products/${giftCardProduct.id}`,
5892
+ labelKey: giftCardProduct.title,
5893
+ descriptionKey: giftCardProduct.title,
5894
+ icon: /* @__PURE__ */ jsx(Tag, {})
5895
+ }
5896
+ )),
5897
+ count2 > 3 && /* @__PURE__ */ jsx(
5898
+ Link,
5899
+ {
5900
+ to: "/gift-cards/gift-card-products",
5901
+ className: "text-ui-fg-muted text-sm px-6 py-4 flex items-center justify-center",
5902
+ children: "View more"
5903
+ }
5904
+ )
5905
+ ] });
5906
+ };
5907
+ const _giftCardQueryKey = queryKeysFactory("gift-card");
5908
+ const giftCardQueryKey = {
5909
+ ..._giftCardQueryKey,
5910
+ orders: (id) => [..._giftCardQueryKey.detail(id), "orders"]
5911
+ };
5912
+ const useGiftCards = (query, options) => {
5913
+ const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
5914
+ query: query2,
5915
+ headers
5916
+ });
5917
+ const { data, ...rest } = useQuery({
5918
+ ...options,
5919
+ queryFn: () => fetchGiftCards(query),
5920
+ queryKey: giftCardQueryKey.list(query)
5921
+ });
5922
+ return { ...data, ...rest };
5923
+ };
5924
+ const useGiftCard = (id, query, options) => {
5925
+ const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
5926
+ query: query2,
5927
+ headers
5928
+ });
5929
+ const { data, ...rest } = useQuery({
5930
+ queryFn: () => fetchGiftCard(id, query),
5931
+ queryKey: giftCardQueryKey.detail(id, query),
5932
+ ...options
5933
+ });
5934
+ return { ...data, ...rest };
5935
+ };
5936
+ const useGiftCardOrders = (id, options) => {
5937
+ const fetchGiftCardOrders = (id2, query, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}/orders`, {
5938
+ query,
5939
+ headers
5940
+ });
5941
+ const { data, ...rest } = useQuery({
5942
+ queryFn: () => fetchGiftCardOrders(id),
5943
+ queryKey: giftCardQueryKey.orders(id),
5944
+ ...options
5945
+ });
5946
+ return { ...data, ...rest };
5947
+ };
5948
+ const useUpdateGiftCard = (id, options) => {
5949
+ const queryClient = useQueryClient();
5950
+ const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
5951
+ body,
5952
+ method: "POST"
5953
+ });
5954
+ return useMutation({
5955
+ mutationFn: async (payload) => updateGiftCard(id, payload),
5956
+ onSuccess: (data, variables, context) => {
5957
+ queryClient.invalidateQueries({
5958
+ queryKey: giftCardQueryKey.detail(id)
5959
+ });
5960
+ queryClient.invalidateQueries({
5961
+ queryKey: giftCardQueryKey.lists()
5962
+ });
5963
+ },
5964
+ ...options
5965
+ });
5966
+ };
5967
+ const useCreateGiftCard = (options) => {
5968
+ const queryClient = useQueryClient();
5969
+ const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
5970
+ body,
5971
+ method: "POST"
5972
+ });
5973
+ return useMutation({
5974
+ mutationFn: (body) => createGiftCard(body),
5975
+ onSuccess: (data, variables, context) => {
5976
+ queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
5977
+ },
5978
+ ...options
5979
+ });
5980
+ };
5831
5981
  function getRelativeDate(date2) {
5832
5982
  const now = /* @__PURE__ */ new Date();
5833
5983
  return formatDistance(sub(new Date(date2), { minutes: 0 }), now, {
@@ -5845,51 +5995,30 @@ function formatDate(date2, withTime = true) {
5845
5995
  return format(new Date(date2), "dd MMM, yyyy");
5846
5996
  }
5847
5997
  const columnHelper$a = createDataTableColumnHelper();
5848
- const useStoreCreditAccountTableColumns = () => {
5998
+ const useGiftCardTableColumns = () => {
5849
5999
  return useMemo(() => {
5850
6000
  return [
5851
- columnHelper$a.accessor("currency_code", {
5852
- header: "Currency",
5853
- cell: ({ row }) => {
5854
- return /* @__PURE__ */ jsx(Badge, { size: "2xsmall", children: row.original.currency_code.toUpperCase() });
5855
- }
5856
- }),
5857
- columnHelper$a.accessor("customer.email", {
5858
- header: "Customer",
6001
+ columnHelper$a.accessor("code", {
6002
+ header: "Code",
5859
6003
  cell: ({ row }) => {
5860
- return row.original.customer?.email ?? "N/A";
6004
+ return row.original.code;
5861
6005
  }
5862
6006
  }),
5863
- columnHelper$a.accessor("balance", {
5864
- header: "Balance",
6007
+ columnHelper$a.accessor("line_item.product.title", {
6008
+ header: "Product",
5865
6009
  cell: ({ row }) => {
5866
- return formatAmount(
5867
- row.original.balance,
5868
- row.original.currency_code
5869
- );
6010
+ return row.original.line_item?.product?.title || "Custom Gift Card";
5870
6011
  }
5871
6012
  }),
5872
- columnHelper$a.accessor("credits", {
5873
- header: "Credits",
5874
- cell: ({ row }) => {
5875
- return formatAmount(
5876
- row.original.credits,
5877
- row.original.currency_code
5878
- );
5879
- }
6013
+ columnHelper$a.accessor("created_at", {
6014
+ header: "Date issued",
6015
+ cell: ({ row }) => getRelativeDate(row.original.created_at)
5880
6016
  }),
5881
- columnHelper$a.accessor("debits", {
5882
- header: "Debits",
6017
+ columnHelper$a.accessor("value", {
6018
+ header: "Value",
5883
6019
  cell: ({ row }) => {
5884
- return formatAmount(
5885
- row.original.debits,
5886
- row.original.currency_code
5887
- );
6020
+ return formatAmount(row.original.value, row.original.currency_code);
5888
6021
  }
5889
- }),
5890
- columnHelper$a.accessor("created_at", {
5891
- header: "Created at",
5892
- cell: ({ row }) => getRelativeDate(row.original.created_at)
5893
6022
  })
5894
6023
  ];
5895
6024
  }, []);
@@ -5941,85 +6070,77 @@ const useCustomerFilters = () => {
5941
6070
  ];
5942
6071
  }, [canReadCustomers, customerFilterOptions]);
5943
6072
  };
5944
- const useStoreCreditAccountFilters = () => {
6073
+ const useGiftCardFilters = () => {
5945
6074
  const dateFilterOptions = useDataTableDateFilters$1();
5946
6075
  const customerFilterOptions = useCustomerFilters();
5947
6076
  return useMemo(() => {
5948
6077
  return [...dateFilterOptions, ...customerFilterOptions];
5949
6078
  }, [dateFilterOptions, customerFilterOptions]);
5950
6079
  };
5951
- const useStoreCreditAccountsTableQuery = ({
6080
+ const useGiftCardTableQuery = ({
5952
6081
  prefix,
5953
6082
  pageSize = 20
5954
6083
  }) => {
5955
6084
  const queryObject = useQueryParams(
5956
- ["offset", "customer_id", "currency_code", "created_at", "updated_at"],
6085
+ ["q", "offset", "customer_id", "created_at", "updated_at"],
5957
6086
  prefix
5958
6087
  );
5959
- const {
5960
- offset: offset2,
5961
- created_at,
5962
- updated_at,
5963
- customer_id,
5964
- currency_code,
5965
- ...rest
5966
- } = queryObject;
6088
+ const { offset: offset2, created_at, updated_at, customer_id, ...rest } = queryObject;
5967
6089
  const searchParams = {
5968
6090
  limit: pageSize,
5969
6091
  offset: offset2 ? Number(offset2) : 0,
5970
6092
  created_at: created_at ? JSON.parse(created_at) : void 0,
5971
6093
  updated_at: updated_at ? JSON.parse(updated_at) : void 0,
5972
6094
  customer_id: customer_id ? JSON.parse(customer_id) : void 0,
5973
- currency_code: currency_code ? JSON.parse(currency_code) : void 0,
5974
6095
  ...rest
5975
6096
  };
5976
6097
  return searchParams;
5977
6098
  };
5978
6099
  const PAGE_SIZE$6 = 10;
5979
- function StoreCreditAccountsTable() {
5980
- const queryParams = useStoreCreditAccountsTableQuery({
6100
+ function GiftCardsTable() {
6101
+ const queryParams = useGiftCardTableQuery({
5981
6102
  pageSize: PAGE_SIZE$6
5982
6103
  });
5983
6104
  const {
5984
- store_credit_accounts: storeCreditAccounts,
6105
+ gift_cards: giftCards,
5985
6106
  isPending,
5986
6107
  count: count2
5987
- } = useStoreCreditAccounts({
6108
+ } = useGiftCards({
5988
6109
  ...queryParams,
5989
- order: queryParams.order ?? "-created_at"
6110
+ order: queryParams.order ?? "-created_at",
6111
+ fields: "+line_item.product.title"
5990
6112
  });
5991
- const columns = useStoreCreditAccountTableColumns();
5992
- const filters = useStoreCreditAccountFilters();
6113
+ const columns = useGiftCardTableColumns();
6114
+ const filters = useGiftCardFilters();
5993
6115
  const { hasPermission } = usePermissions();
5994
- const canCreate = hasPermission("store_credit_account:create");
6116
+ const canCreate = hasPermission("gift_card:create");
5995
6117
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
5996
6118
  /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
5997
6119
  DataTable,
5998
6120
  {
5999
- data: storeCreditAccounts ?? [],
6121
+ data: giftCards,
6000
6122
  getRowId: (row) => row.id,
6001
6123
  columns,
6002
6124
  filters,
6003
6125
  isLoading: isPending,
6004
6126
  pageSize: PAGE_SIZE$6,
6005
6127
  rowCount: count2,
6006
- enableSearch: false,
6007
- heading: "Store Credit Accounts",
6128
+ heading: "Gift Cards",
6008
6129
  rowHref: (row) => `${row.id}`,
6009
6130
  emptyState: {
6010
6131
  empty: {
6011
- heading: "No store credit accounts found",
6012
- description: "Create a new store credit account to get started."
6132
+ heading: "No gift cards found",
6133
+ description: "Create a gift card to get started."
6013
6134
  },
6014
6135
  filtered: {
6015
6136
  heading: "No results found",
6016
- description: "No store credit accounts match your filter criteria."
6137
+ description: "No gift cards match your filter criteria."
6017
6138
  }
6018
6139
  },
6019
6140
  actions: canCreate ? [
6020
6141
  {
6021
6142
  label: "Create",
6022
- to: "/store-credit-accounts/create"
6143
+ to: "create"
6023
6144
  }
6024
6145
  ] : []
6025
6146
  }
@@ -6027,15 +6148,16 @@ function StoreCreditAccountsTable() {
6027
6148
  /* @__PURE__ */ jsx(Outlet, {})
6028
6149
  ] });
6029
6150
  }
6030
- const StoreCreditAccountsPage = () => {
6151
+ const GiftCardsPage = () => {
6031
6152
  return /* @__PURE__ */ jsxs(Fragment, { children: [
6032
6153
  /* @__PURE__ */ jsx(
6033
6154
  LayoutComposer,
6034
6155
  {
6035
- widgetsZonePrefix: "store_credit_account.list",
6036
- preferredLayoutId: "core:single-column",
6156
+ widgetsZonePrefix: "gift_card.list",
6157
+ preferredLayoutId: "core:two-column",
6037
6158
  sections: {
6038
- main: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountsTable", children: /* @__PURE__ */ jsx(StoreCreditAccountsTable, {}) })
6159
+ main: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "GiftCardsTable", children: /* @__PURE__ */ jsx(GiftCardsTable, {}) }),
6160
+ side: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "GiftCardProductsSection", children: /* @__PURE__ */ jsx(PermissionGuard, { permission: "product:read", children: /* @__PURE__ */ jsx(GiftCardProductsSection, {}) }) })
6039
6161
  }
6040
6162
  }
6041
6163
  ),
@@ -6043,9 +6165,9 @@ const StoreCreditAccountsPage = () => {
6043
6165
  ] });
6044
6166
  };
6045
6167
  const config$3 = defineRouteConfig({
6046
- label: "Store Credits",
6047
- icon: StoreCreditIcon,
6048
- permissions: ["store_credit_account:read"]
6168
+ label: "Gift Cards",
6169
+ icon: GiftCardIcon,
6170
+ permissions: ["gift_card:read"]
6049
6171
  });
6050
6172
  function setRef$2(ref, value) {
6051
6173
  if (typeof ref === "function") {
@@ -10740,6 +10862,27 @@ const StackedFocusModal = Object.assign(Root, {
10740
10862
  Description,
10741
10863
  Title
10742
10864
  });
10865
+ const STORE_QUERY_KEY = "store";
10866
+ const storeQueryKeys = queryKeysFactory(STORE_QUERY_KEY);
10867
+ async function retrieveActiveStore(query) {
10868
+ const response = await sdk.admin.store.list(query);
10869
+ const activeStore = response.stores?.[0];
10870
+ if (!activeStore) {
10871
+ throw new FetchError("No active store found", "Not Found", 404);
10872
+ }
10873
+ return { store: activeStore };
10874
+ }
10875
+ const useStore$2 = (query, options) => {
10876
+ const { data, ...rest } = useQuery({
10877
+ queryFn: () => retrieveActiveStore(query),
10878
+ queryKey: storeQueryKeys.details(),
10879
+ ...options
10880
+ });
10881
+ return {
10882
+ ...data,
10883
+ ...rest
10884
+ };
10885
+ };
10743
10886
  const t$1 = (r, t2, s2) => {
10744
10887
  if (r && "reportValidity" in r) {
10745
10888
  const o2 = get$2(s2, t2);
@@ -13785,7 +13928,7 @@ function useStoreProps(store, props, key2, setKey) {
13785
13928
  });
13786
13929
  });
13787
13930
  }
13788
- function useStore$2(createStore2, props) {
13931
+ function useStore$1(createStore2, props) {
13789
13932
  const [store, setStore] = React.useState(() => createStore2(props));
13790
13933
  useSafeLayoutEffect(() => init(store), [store]);
13791
13934
  const useState2 = React.useCallback((keyOrSelector) => useStoreState(store, keyOrSelector), [store]);
@@ -14742,7 +14885,7 @@ function useDisclosureStoreProps(store, update, props) {
14742
14885
  return Object.assign(store, { disclosure: props.disclosure });
14743
14886
  }
14744
14887
  function useDisclosureStore(props = {}) {
14745
- const [store, update] = useStore$2(createDisclosureStore, props);
14888
+ const [store, update] = useStore$1(createDisclosureStore, props);
14746
14889
  return useDisclosureStoreProps(store, update, props);
14747
14890
  }
14748
14891
  const ctx$2 = createStoreContext([DialogContextProvider], [DialogScopedContextProvider]);
@@ -15551,7 +15694,7 @@ function useDialogStoreProps(store, update, props) {
15551
15694
  return useDisclosureStoreProps(store, update, props);
15552
15695
  }
15553
15696
  function useDialogStore(props = {}) {
15554
- const [store, update] = useStore$2(createDialogStore, props);
15697
+ const [store, update] = useStore$1(createDialogStore, props);
15555
15698
  return useDialogStoreProps(store, update, props);
15556
15699
  }
15557
15700
  function isHiddenDismiss(element, ...ids2) {
@@ -18867,7 +19010,7 @@ function useComboboxStoreProps(store, update, props) {
18867
19010
  }
18868
19011
  function useComboboxStore(props = {}) {
18869
19012
  props = useComboboxStoreOptions(props);
18870
- const [store, update] = useStore$2(createComboboxStore, props);
19013
+ const [store, update] = useStore$1(createComboboxStore, props);
18871
19014
  return useComboboxStoreProps(store, update, props);
18872
19015
  }
18873
19016
  function ComboboxProvider(props = {}) {
@@ -19986,371 +20129,6 @@ const ComboboxImpl = ({
19986
20129
  );
19987
20130
  };
19988
20131
  const Combobox2 = genericForwardRef(ComboboxImpl);
19989
- var isObject_1;
19990
- var hasRequiredIsObject;
19991
- function requireIsObject() {
19992
- if (hasRequiredIsObject) return isObject_1;
19993
- hasRequiredIsObject = 1;
19994
- function isObject2(value) {
19995
- var type = typeof value;
19996
- return value != null && (type == "object" || type == "function");
19997
- }
19998
- isObject_1 = isObject2;
19999
- return isObject_1;
20000
- }
20001
- var _freeGlobal;
20002
- var hasRequired_freeGlobal;
20003
- function require_freeGlobal() {
20004
- if (hasRequired_freeGlobal) return _freeGlobal;
20005
- hasRequired_freeGlobal = 1;
20006
- var freeGlobal = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
20007
- _freeGlobal = freeGlobal;
20008
- return _freeGlobal;
20009
- }
20010
- var _root;
20011
- var hasRequired_root;
20012
- function require_root() {
20013
- if (hasRequired_root) return _root;
20014
- hasRequired_root = 1;
20015
- var freeGlobal = require_freeGlobal();
20016
- var freeSelf = typeof self == "object" && self && self.Object === Object && self;
20017
- var root = freeGlobal || freeSelf || Function("return this")();
20018
- _root = root;
20019
- return _root;
20020
- }
20021
- var now_1;
20022
- var hasRequiredNow;
20023
- function requireNow() {
20024
- if (hasRequiredNow) return now_1;
20025
- hasRequiredNow = 1;
20026
- var root = require_root();
20027
- var now = function() {
20028
- return root.Date.now();
20029
- };
20030
- now_1 = now;
20031
- return now_1;
20032
- }
20033
- var _trimmedEndIndex;
20034
- var hasRequired_trimmedEndIndex;
20035
- function require_trimmedEndIndex() {
20036
- if (hasRequired_trimmedEndIndex) return _trimmedEndIndex;
20037
- hasRequired_trimmedEndIndex = 1;
20038
- var reWhitespace = /\s/;
20039
- function trimmedEndIndex(string2) {
20040
- var index = string2.length;
20041
- while (index-- && reWhitespace.test(string2.charAt(index))) {
20042
- }
20043
- return index;
20044
- }
20045
- _trimmedEndIndex = trimmedEndIndex;
20046
- return _trimmedEndIndex;
20047
- }
20048
- var _baseTrim;
20049
- var hasRequired_baseTrim;
20050
- function require_baseTrim() {
20051
- if (hasRequired_baseTrim) return _baseTrim;
20052
- hasRequired_baseTrim = 1;
20053
- var trimmedEndIndex = require_trimmedEndIndex();
20054
- var reTrimStart = /^\s+/;
20055
- function baseTrim(string2) {
20056
- return string2 ? string2.slice(0, trimmedEndIndex(string2) + 1).replace(reTrimStart, "") : string2;
20057
- }
20058
- _baseTrim = baseTrim;
20059
- return _baseTrim;
20060
- }
20061
- var _Symbol;
20062
- var hasRequired_Symbol;
20063
- function require_Symbol() {
20064
- if (hasRequired_Symbol) return _Symbol;
20065
- hasRequired_Symbol = 1;
20066
- var root = require_root();
20067
- var Symbol2 = root.Symbol;
20068
- _Symbol = Symbol2;
20069
- return _Symbol;
20070
- }
20071
- var _getRawTag;
20072
- var hasRequired_getRawTag;
20073
- function require_getRawTag() {
20074
- if (hasRequired_getRawTag) return _getRawTag;
20075
- hasRequired_getRawTag = 1;
20076
- var Symbol2 = require_Symbol();
20077
- var objectProto = Object.prototype;
20078
- var hasOwnProperty2 = objectProto.hasOwnProperty;
20079
- var nativeObjectToString = objectProto.toString;
20080
- var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
20081
- function getRawTag(value) {
20082
- var isOwn = hasOwnProperty2.call(value, symToStringTag), tag = value[symToStringTag];
20083
- try {
20084
- value[symToStringTag] = void 0;
20085
- var unmasked = true;
20086
- } catch (e) {
20087
- }
20088
- var result = nativeObjectToString.call(value);
20089
- if (unmasked) {
20090
- if (isOwn) {
20091
- value[symToStringTag] = tag;
20092
- } else {
20093
- delete value[symToStringTag];
20094
- }
20095
- }
20096
- return result;
20097
- }
20098
- _getRawTag = getRawTag;
20099
- return _getRawTag;
20100
- }
20101
- var _objectToString;
20102
- var hasRequired_objectToString;
20103
- function require_objectToString() {
20104
- if (hasRequired_objectToString) return _objectToString;
20105
- hasRequired_objectToString = 1;
20106
- var objectProto = Object.prototype;
20107
- var nativeObjectToString = objectProto.toString;
20108
- function objectToString(value) {
20109
- return nativeObjectToString.call(value);
20110
- }
20111
- _objectToString = objectToString;
20112
- return _objectToString;
20113
- }
20114
- var _baseGetTag;
20115
- var hasRequired_baseGetTag;
20116
- function require_baseGetTag() {
20117
- if (hasRequired_baseGetTag) return _baseGetTag;
20118
- hasRequired_baseGetTag = 1;
20119
- var Symbol2 = require_Symbol(), getRawTag = require_getRawTag(), objectToString = require_objectToString();
20120
- var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
20121
- var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
20122
- function baseGetTag(value) {
20123
- if (value == null) {
20124
- return value === void 0 ? undefinedTag : nullTag;
20125
- }
20126
- return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
20127
- }
20128
- _baseGetTag = baseGetTag;
20129
- return _baseGetTag;
20130
- }
20131
- var isObjectLike_1;
20132
- var hasRequiredIsObjectLike;
20133
- function requireIsObjectLike() {
20134
- if (hasRequiredIsObjectLike) return isObjectLike_1;
20135
- hasRequiredIsObjectLike = 1;
20136
- function isObjectLike(value) {
20137
- return value != null && typeof value == "object";
20138
- }
20139
- isObjectLike_1 = isObjectLike;
20140
- return isObjectLike_1;
20141
- }
20142
- var isSymbol_1;
20143
- var hasRequiredIsSymbol;
20144
- function requireIsSymbol() {
20145
- if (hasRequiredIsSymbol) return isSymbol_1;
20146
- hasRequiredIsSymbol = 1;
20147
- var baseGetTag = require_baseGetTag(), isObjectLike = requireIsObjectLike();
20148
- var symbolTag = "[object Symbol]";
20149
- function isSymbol(value) {
20150
- return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
20151
- }
20152
- isSymbol_1 = isSymbol;
20153
- return isSymbol_1;
20154
- }
20155
- var toNumber_1;
20156
- var hasRequiredToNumber;
20157
- function requireToNumber() {
20158
- if (hasRequiredToNumber) return toNumber_1;
20159
- hasRequiredToNumber = 1;
20160
- var baseTrim = require_baseTrim(), isObject2 = requireIsObject(), isSymbol = requireIsSymbol();
20161
- var NAN = 0 / 0;
20162
- var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
20163
- var reIsBinary = /^0b[01]+$/i;
20164
- var reIsOctal = /^0o[0-7]+$/i;
20165
- var freeParseInt = parseInt;
20166
- function toNumber(value) {
20167
- if (typeof value == "number") {
20168
- return value;
20169
- }
20170
- if (isSymbol(value)) {
20171
- return NAN;
20172
- }
20173
- if (isObject2(value)) {
20174
- var other = typeof value.valueOf == "function" ? value.valueOf() : value;
20175
- value = isObject2(other) ? other + "" : other;
20176
- }
20177
- if (typeof value != "string") {
20178
- return value === 0 ? value : +value;
20179
- }
20180
- value = baseTrim(value);
20181
- var isBinary = reIsBinary.test(value);
20182
- return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
20183
- }
20184
- toNumber_1 = toNumber;
20185
- return toNumber_1;
20186
- }
20187
- var debounce_1;
20188
- var hasRequiredDebounce;
20189
- function requireDebounce() {
20190
- if (hasRequiredDebounce) return debounce_1;
20191
- hasRequiredDebounce = 1;
20192
- var isObject2 = requireIsObject(), now = requireNow(), toNumber = requireToNumber();
20193
- var FUNC_ERROR_TEXT = "Expected a function";
20194
- var nativeMax = Math.max, nativeMin = Math.min;
20195
- function debounce2(func, wait, options) {
20196
- var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
20197
- if (typeof func != "function") {
20198
- throw new TypeError(FUNC_ERROR_TEXT);
20199
- }
20200
- wait = toNumber(wait) || 0;
20201
- if (isObject2(options)) {
20202
- leading = !!options.leading;
20203
- maxing = "maxWait" in options;
20204
- maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
20205
- trailing = "trailing" in options ? !!options.trailing : trailing;
20206
- }
20207
- function invokeFunc(time2) {
20208
- var args = lastArgs, thisArg = lastThis;
20209
- lastArgs = lastThis = void 0;
20210
- lastInvokeTime = time2;
20211
- result = func.apply(thisArg, args);
20212
- return result;
20213
- }
20214
- function leadingEdge(time2) {
20215
- lastInvokeTime = time2;
20216
- timerId = setTimeout(timerExpired, wait);
20217
- return leading ? invokeFunc(time2) : result;
20218
- }
20219
- function remainingWait(time2) {
20220
- var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
20221
- return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
20222
- }
20223
- function shouldInvoke(time2) {
20224
- var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime;
20225
- return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
20226
- }
20227
- function timerExpired() {
20228
- var time2 = now();
20229
- if (shouldInvoke(time2)) {
20230
- return trailingEdge(time2);
20231
- }
20232
- timerId = setTimeout(timerExpired, remainingWait(time2));
20233
- }
20234
- function trailingEdge(time2) {
20235
- timerId = void 0;
20236
- if (trailing && lastArgs) {
20237
- return invokeFunc(time2);
20238
- }
20239
- lastArgs = lastThis = void 0;
20240
- return result;
20241
- }
20242
- function cancel() {
20243
- if (timerId !== void 0) {
20244
- clearTimeout(timerId);
20245
- }
20246
- lastInvokeTime = 0;
20247
- lastArgs = lastCallTime = lastThis = timerId = void 0;
20248
- }
20249
- function flush() {
20250
- return timerId === void 0 ? result : trailingEdge(now());
20251
- }
20252
- function debounced() {
20253
- var time2 = now(), isInvoking = shouldInvoke(time2);
20254
- lastArgs = arguments;
20255
- lastThis = this;
20256
- lastCallTime = time2;
20257
- if (isInvoking) {
20258
- if (timerId === void 0) {
20259
- return leadingEdge(lastCallTime);
20260
- }
20261
- if (maxing) {
20262
- clearTimeout(timerId);
20263
- timerId = setTimeout(timerExpired, wait);
20264
- return invokeFunc(lastCallTime);
20265
- }
20266
- }
20267
- if (timerId === void 0) {
20268
- timerId = setTimeout(timerExpired, wait);
20269
- }
20270
- return result;
20271
- }
20272
- debounced.cancel = cancel;
20273
- debounced.flush = flush;
20274
- return debounced;
20275
- }
20276
- debounce_1 = debounce2;
20277
- return debounce_1;
20278
- }
20279
- var debounceExports = requireDebounce();
20280
- const debounce$1 = /* @__PURE__ */ getDefaultExportFromCjs(debounceExports);
20281
- const useDebouncedSearch = () => {
20282
- const [searchValue, onSearchValueChange] = useState("");
20283
- const [debouncedQuery, setDebouncedQuery] = useState("");
20284
- const debouncedUpdate = useCallback(
20285
- debounce$1((query) => setDebouncedQuery(query), 300),
20286
- []
20287
- );
20288
- useEffect(() => {
20289
- debouncedUpdate(searchValue);
20290
- return () => debouncedUpdate.cancel();
20291
- }, [searchValue, debouncedUpdate]);
20292
- return {
20293
- searchValue,
20294
- onSearchValueChange,
20295
- query: debouncedQuery || void 0
20296
- };
20297
- };
20298
- const useComboboxData = ({
20299
- queryKey,
20300
- queryFn,
20301
- getOptions,
20302
- defaultValue: defaultValue2,
20303
- defaultValueKey,
20304
- pageSize = 10,
20305
- enabled = true
20306
- }) => {
20307
- const { searchValue, onSearchValueChange, query } = useDebouncedSearch();
20308
- const queryInitialDataBy = defaultValueKey || "id";
20309
- const { data: initialData } = useQuery({
20310
- queryKey,
20311
- queryFn: async () => {
20312
- return queryFn({
20313
- [queryInitialDataBy]: defaultValue2,
20314
- limit: Array.isArray(defaultValue2) ? defaultValue2.length : 1
20315
- });
20316
- },
20317
- enabled: enabled && !!defaultValue2
20318
- });
20319
- const { data, ...rest } = useInfiniteQuery({
20320
- queryKey: [...queryKey, query],
20321
- queryFn: async ({ pageParam = 0 }) => {
20322
- return await queryFn({
20323
- q: query,
20324
- limit: pageSize,
20325
- offset: pageParam
20326
- });
20327
- },
20328
- initialPageParam: 0,
20329
- getNextPageParam: (lastPage) => {
20330
- const moreItemsExist = lastPage.count > lastPage.offset + lastPage.limit;
20331
- return moreItemsExist ? lastPage.offset + lastPage.limit : void 0;
20332
- },
20333
- placeholderData: keepPreviousData,
20334
- enabled
20335
- });
20336
- const options = data?.pages.flatMap((page) => getOptions(page)) ?? [];
20337
- const defaultOptions2 = initialData ? getOptions(initialData) : [];
20338
- const disabled = !rest.isPending && !options.length && !searchValue;
20339
- if (defaultValue2 && defaultOptions2.length && !searchValue) {
20340
- defaultOptions2.forEach((option) => {
20341
- if (!options.find((o2) => o2.value === option.value)) {
20342
- options.unshift(option);
20343
- }
20344
- });
20345
- }
20346
- return {
20347
- options,
20348
- searchValue,
20349
- onSearchValueChange,
20350
- disabled,
20351
- ...rest
20352
- };
20353
- };
20354
20132
  const currencies = {
20355
20133
  USD: {
20356
20134
  code: "USD",
@@ -21103,515 +20881,6 @@ const currencies = {
21103
20881
  decimal_digits: 0
21104
20882
  }
21105
20883
  };
21106
- const formSchema = z.object({
21107
- currency_code: z.string().min(1, "Please select a currency"),
21108
- customer_id: z.string().optional()
21109
- });
21110
- const StoreCreditAccountCreateForm = () => {
21111
- const { handleSuccess } = useRouteModal();
21112
- const [searchParams] = useSearchParams();
21113
- const prefilledCustomerId = searchParams.get("prefill_customer_id") ?? "";
21114
- const { hasPermission } = usePermissions();
21115
- const canReadCustomers = hasPermission("customer:read");
21116
- const form = useForm({
21117
- defaultValues: {
21118
- currency_code: "",
21119
- customer_id: prefilledCustomerId
21120
- },
21121
- resolver: u(formSchema)
21122
- });
21123
- const { mutateAsync: createStoreCreditAccount, isPending } = useCreateStoreCreditAccount();
21124
- const handleSubmit = form.handleSubmit(async (data) => {
21125
- if (!data.customer_id) {
21126
- delete data.customer_id;
21127
- }
21128
- await createStoreCreditAccount(data, {
21129
- onSuccess: (data2) => {
21130
- toast.success(`Store credit account was successfully created.`);
21131
- handleSuccess(`../${data2.store_credit_account.id}`);
21132
- },
21133
- onError: (error2) => {
21134
- toast.error(error2.message);
21135
- }
21136
- });
21137
- });
21138
- const [currencySearchValue, setCurrencySearchValue] = useState("");
21139
- const currencyOptions = useMemo(() => {
21140
- const options = Object.values(currencies).map((currency) => ({
21141
- label: `${currency.code} - ${currency.name} (${currency.symbol_native})`,
21142
- value: currency.code.toLowerCase()
21143
- }));
21144
- if (!currencySearchValue) {
21145
- return options;
21146
- }
21147
- return options.filter(
21148
- (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
21149
- );
21150
- }, [currencySearchValue]);
21151
- const {
21152
- options: customerOptions,
21153
- fetchNextPage,
21154
- isFetchingNextPage,
21155
- searchValue,
21156
- onSearchValueChange,
21157
- isLoading
21158
- } = useComboboxData({
21159
- queryKey: customersQueryKeys.list(),
21160
- defaultValue: prefilledCustomerId || void 0,
21161
- enabled: canReadCustomers,
21162
- queryFn: async (params) => {
21163
- return sdk.admin.customer.list(params);
21164
- },
21165
- getOptions: (data) => {
21166
- return data.customers?.map((customer) => {
21167
- const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
21168
- const label = fullName ? `${customer.email} (${fullName})` : customer.email;
21169
- return {
21170
- label,
21171
- value: customer.id
21172
- };
21173
- }) || [];
21174
- }
21175
- });
21176
- return /* @__PURE__ */ jsxs(RouteFocusModal.Form, { form, children: [
21177
- /* @__PURE__ */ jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsx("div", { className: "-my-2 w-full border-l" }) }),
21178
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "size-full overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center p-16", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8", children: [
21179
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
21180
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Create Store Credit Account" }),
21181
- /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new store credit account for a customer" })
21182
- ] }),
21183
- /* @__PURE__ */ jsxs("div", { className: "flex gap-x-4", children: [
21184
- /* @__PURE__ */ jsx(
21185
- Form$2.Field,
21186
- {
21187
- control: form.control,
21188
- name: "currency_code",
21189
- render: ({ field }) => {
21190
- return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
21191
- /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Currency" }),
21192
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
21193
- Combobox2,
21194
- {
21195
- value: field.value,
21196
- onChange: field.onChange,
21197
- searchValue: currencySearchValue,
21198
- onSearchValueChange: setCurrencySearchValue,
21199
- options: currencyOptions,
21200
- placeholder: "Search for a currency..."
21201
- }
21202
- ) }),
21203
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
21204
- ] });
21205
- }
21206
- }
21207
- ),
21208
- canReadCustomers && /* @__PURE__ */ jsx(
21209
- Form$2.Field,
21210
- {
21211
- control: form.control,
21212
- name: "customer_id",
21213
- render: ({ field }) => {
21214
- return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
21215
- /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Customer" }),
21216
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
21217
- Combobox2,
21218
- {
21219
- value: field.value,
21220
- onChange: field.onChange,
21221
- searchValue,
21222
- onSearchValueChange,
21223
- options: customerOptions,
21224
- placeholder: "Search for a customer...",
21225
- fetchNextPage,
21226
- isFetchingNextPage,
21227
- noResultsPlaceholder: isLoading ? "Loading customers..." : "No customers found"
21228
- }
21229
- ) }),
21230
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
21231
- ] });
21232
- }
21233
- }
21234
- )
21235
- ] })
21236
- ] }) }) }),
21237
- /* @__PURE__ */ jsxs(RouteFocusModal.Footer, { children: [
21238
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, disabled: isPending, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", disabled: isPending, children: "Cancel" }) }),
21239
- /* @__PURE__ */ jsx(
21240
- Button,
21241
- {
21242
- variant: "primary",
21243
- size: "small",
21244
- onClick: handleSubmit,
21245
- disabled: isPending,
21246
- children: "Create"
21247
- }
21248
- )
21249
- ] })
21250
- ] });
21251
- };
21252
- const StoreCreditAccountCreate = () => {
21253
- return /* @__PURE__ */ jsxs(RouteFocusModal, { children: [
21254
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create Store Credit Account" }) }),
21255
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create a new store credit account" }) }),
21256
- /* @__PURE__ */ jsx(StoreCreditAccountCreateForm, {})
21257
- ] });
21258
- };
21259
- const handle$e = {
21260
- permissions: ["store_credit_account:create"]
21261
- };
21262
- const GiftCardIcon = (props) => {
21263
- return /* @__PURE__ */ jsxs(
21264
- "svg",
21265
- {
21266
- width: "15",
21267
- height: "15",
21268
- viewBox: "0 0 15 15",
21269
- fill: "none",
21270
- xmlns: "http://www.w3.org/2000/svg",
21271
- ...props,
21272
- children: [
21273
- /* @__PURE__ */ jsx("rect", { width: "15", height: "15", fill: "#F97316" }),
21274
- /* @__PURE__ */ jsx(
21275
- "rect",
21276
- {
21277
- width: "15",
21278
- height: "15",
21279
- fill: "url(#paint0_linear_28788_25808)",
21280
- fillOpacity: "0.2"
21281
- }
21282
- ),
21283
- /* @__PURE__ */ jsxs("g", { clipPath: "url(#clip0_28788_25808)", children: [
21284
- /* @__PURE__ */ jsx(
21285
- "path",
21286
- {
21287
- 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",
21288
- fill: "white"
21289
- }
21290
- ),
21291
- /* @__PURE__ */ jsx(
21292
- "path",
21293
- {
21294
- 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",
21295
- fill: "white"
21296
- }
21297
- ),
21298
- /* @__PURE__ */ jsx(
21299
- "path",
21300
- {
21301
- 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",
21302
- fill: "white"
21303
- }
21304
- ),
21305
- /* @__PURE__ */ jsx(
21306
- "path",
21307
- {
21308
- d: "M6.938 7.5H3.75V9.563C3.75 10.7 4.675 11.625 5.813 11.625H6.938V7.5Z",
21309
- fill: "white"
21310
- }
21311
- ),
21312
- /* @__PURE__ */ jsx(
21313
- "path",
21314
- {
21315
- d: "M8.063 7.5V11.625H9.188C10.325 11.625 11.25 10.7 11.25 9.563V7.5H8.063Z",
21316
- fill: "white"
21317
- }
21318
- )
21319
- ] }),
21320
- /* @__PURE__ */ jsxs("defs", { children: [
21321
- /* @__PURE__ */ jsxs(
21322
- "linearGradient",
21323
- {
21324
- id: "paint0_linear_28788_25808",
21325
- x1: "7.5",
21326
- y1: "0",
21327
- x2: "7.5",
21328
- y2: "15",
21329
- gradientUnits: "userSpaceOnUse",
21330
- children: [
21331
- /* @__PURE__ */ jsx("stop", { stopColor: "white" }),
21332
- /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
21333
- ]
21334
- }
21335
- ),
21336
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_28788_25808", children: /* @__PURE__ */ jsx("rect", { width: "9", height: "9", fill: "white", transform: "translate(3 3)" }) })
21337
- ] })
21338
- ]
21339
- }
21340
- );
21341
- };
21342
- const GiftCardProductsSection = () => {
21343
- const { hasPermission } = usePermissions();
21344
- const canCreateProduct = hasPermission("product:create");
21345
- const { products: giftCardProducts, count: count2 = 0 } = useProducts({
21346
- is_giftcard: true
21347
- });
21348
- const slicedProducts = giftCardProducts?.slice(0, 3) ?? [];
21349
- return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
21350
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
21351
- /* @__PURE__ */ jsx(Header$5, { title: "Gift Card Products" }),
21352
- canCreateProduct && /* @__PURE__ */ jsx(
21353
- Link,
21354
- {
21355
- to: `/gift-cards/gift-card-products/create`,
21356
- className: "text-ui-fg-muted text-sm px-6",
21357
- children: "Create"
21358
- }
21359
- )
21360
- ] }),
21361
- giftCardProducts?.length === 0 && /* @__PURE__ */ jsx(
21362
- NoRecords,
21363
- {
21364
- className: "px-10 py-4 h-[200px]",
21365
- title: "No gift card products",
21366
- message: "There are no gift card products to show. Create one to get started.",
21367
- action: canCreateProduct ? {
21368
- to: "/gift-cards/gift-card-products/create",
21369
- label: "Create gift card product"
21370
- } : void 0
21371
- }
21372
- ),
21373
- slicedProducts.map((giftCardProduct) => /* @__PURE__ */ jsx(
21374
- SidebarLink,
21375
- {
21376
- to: `/gift-cards/gift-card-products/${giftCardProduct.id}`,
21377
- labelKey: giftCardProduct.title,
21378
- descriptionKey: giftCardProduct.title,
21379
- icon: /* @__PURE__ */ jsx(Tag, {})
21380
- }
21381
- )),
21382
- count2 > 3 && /* @__PURE__ */ jsx(
21383
- Link,
21384
- {
21385
- to: "/gift-cards/gift-card-products",
21386
- className: "text-ui-fg-muted text-sm px-6 py-4 flex items-center justify-center",
21387
- children: "View more"
21388
- }
21389
- )
21390
- ] });
21391
- };
21392
- const _giftCardQueryKey = queryKeysFactory("gift-card");
21393
- const giftCardQueryKey = {
21394
- ..._giftCardQueryKey,
21395
- orders: (id) => [..._giftCardQueryKey.detail(id), "orders"]
21396
- };
21397
- const useGiftCards = (query, options) => {
21398
- const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
21399
- query: query2,
21400
- headers
21401
- });
21402
- const { data, ...rest } = useQuery({
21403
- ...options,
21404
- queryFn: () => fetchGiftCards(query),
21405
- queryKey: giftCardQueryKey.list(query)
21406
- });
21407
- return { ...data, ...rest };
21408
- };
21409
- const useGiftCard = (id, query, options) => {
21410
- const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
21411
- query: query2,
21412
- headers
21413
- });
21414
- const { data, ...rest } = useQuery({
21415
- queryFn: () => fetchGiftCard(id, query),
21416
- queryKey: giftCardQueryKey.detail(id, query),
21417
- ...options
21418
- });
21419
- return { ...data, ...rest };
21420
- };
21421
- const useGiftCardOrders = (id, options) => {
21422
- const fetchGiftCardOrders = (id2, query, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}/orders`, {
21423
- query,
21424
- headers
21425
- });
21426
- const { data, ...rest } = useQuery({
21427
- queryFn: () => fetchGiftCardOrders(id),
21428
- queryKey: giftCardQueryKey.orders(id),
21429
- ...options
21430
- });
21431
- return { ...data, ...rest };
21432
- };
21433
- const useUpdateGiftCard = (id, options) => {
21434
- const queryClient = useQueryClient();
21435
- const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
21436
- body,
21437
- method: "POST"
21438
- });
21439
- return useMutation({
21440
- mutationFn: async (payload) => updateGiftCard(id, payload),
21441
- onSuccess: (data, variables, context) => {
21442
- queryClient.invalidateQueries({
21443
- queryKey: giftCardQueryKey.detail(id)
21444
- });
21445
- queryClient.invalidateQueries({
21446
- queryKey: giftCardQueryKey.lists()
21447
- });
21448
- },
21449
- ...options
21450
- });
21451
- };
21452
- const useCreateGiftCard = (options) => {
21453
- const queryClient = useQueryClient();
21454
- const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
21455
- body,
21456
- method: "POST"
21457
- });
21458
- return useMutation({
21459
- mutationFn: (body) => createGiftCard(body),
21460
- onSuccess: (data, variables, context) => {
21461
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
21462
- },
21463
- ...options
21464
- });
21465
- };
21466
- const columnHelper$9 = createDataTableColumnHelper();
21467
- const useGiftCardTableColumns = () => {
21468
- return useMemo(() => {
21469
- return [
21470
- columnHelper$9.accessor("code", {
21471
- header: "Code",
21472
- cell: ({ row }) => {
21473
- return row.original.code;
21474
- }
21475
- }),
21476
- columnHelper$9.accessor("line_item.product.title", {
21477
- header: "Product",
21478
- cell: ({ row }) => {
21479
- return row.original.line_item?.product?.title || "Custom Gift Card";
21480
- }
21481
- }),
21482
- columnHelper$9.accessor("created_at", {
21483
- header: "Date issued",
21484
- cell: ({ row }) => getRelativeDate(row.original.created_at)
21485
- }),
21486
- columnHelper$9.accessor("value", {
21487
- header: "Value",
21488
- cell: ({ row }) => {
21489
- return formatAmount(row.original.value, row.original.currency_code);
21490
- }
21491
- })
21492
- ];
21493
- }, []);
21494
- };
21495
- const useGiftCardFilters = () => {
21496
- const dateFilterOptions = useDataTableDateFilters$1();
21497
- const customerFilterOptions = useCustomerFilters();
21498
- return useMemo(() => {
21499
- return [...dateFilterOptions, ...customerFilterOptions];
21500
- }, [dateFilterOptions, customerFilterOptions]);
21501
- };
21502
- const useGiftCardTableQuery = ({
21503
- prefix,
21504
- pageSize = 20
21505
- }) => {
21506
- const queryObject = useQueryParams(
21507
- ["q", "offset", "customer_id", "created_at", "updated_at"],
21508
- prefix
21509
- );
21510
- const { offset: offset2, created_at, updated_at, customer_id, ...rest } = queryObject;
21511
- const searchParams = {
21512
- limit: pageSize,
21513
- offset: offset2 ? Number(offset2) : 0,
21514
- created_at: created_at ? JSON.parse(created_at) : void 0,
21515
- updated_at: updated_at ? JSON.parse(updated_at) : void 0,
21516
- customer_id: customer_id ? JSON.parse(customer_id) : void 0,
21517
- ...rest
21518
- };
21519
- return searchParams;
21520
- };
21521
- const PAGE_SIZE$5 = 10;
21522
- function GiftCardsTable() {
21523
- const queryParams = useGiftCardTableQuery({
21524
- pageSize: PAGE_SIZE$5
21525
- });
21526
- const {
21527
- gift_cards: giftCards,
21528
- isPending,
21529
- count: count2
21530
- } = useGiftCards({
21531
- ...queryParams,
21532
- order: queryParams.order ?? "-created_at",
21533
- fields: "+line_item.product.title"
21534
- });
21535
- const columns = useGiftCardTableColumns();
21536
- const filters = useGiftCardFilters();
21537
- const { hasPermission } = usePermissions();
21538
- const canCreate = hasPermission("gift_card:create");
21539
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [
21540
- /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
21541
- DataTable,
21542
- {
21543
- data: giftCards,
21544
- getRowId: (row) => row.id,
21545
- columns,
21546
- filters,
21547
- isLoading: isPending,
21548
- pageSize: PAGE_SIZE$5,
21549
- rowCount: count2,
21550
- heading: "Gift Cards",
21551
- rowHref: (row) => `${row.id}`,
21552
- emptyState: {
21553
- empty: {
21554
- heading: "No gift cards found",
21555
- description: "Create a gift card to get started."
21556
- },
21557
- filtered: {
21558
- heading: "No results found",
21559
- description: "No gift cards match your filter criteria."
21560
- }
21561
- },
21562
- actions: canCreate ? [
21563
- {
21564
- label: "Create",
21565
- to: "create"
21566
- }
21567
- ] : []
21568
- }
21569
- ) }),
21570
- /* @__PURE__ */ jsx(Outlet, {})
21571
- ] });
21572
- }
21573
- const GiftCardsPage = () => {
21574
- return /* @__PURE__ */ jsxs(Fragment, { children: [
21575
- /* @__PURE__ */ jsx(
21576
- LayoutComposer,
21577
- {
21578
- widgetsZonePrefix: "gift_card.list",
21579
- preferredLayoutId: "core:two-column",
21580
- sections: {
21581
- main: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "GiftCardsTable", children: /* @__PURE__ */ jsx(GiftCardsTable, {}) }),
21582
- side: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "GiftCardProductsSection", children: /* @__PURE__ */ jsx(PermissionGuard, { permission: "product:read", children: /* @__PURE__ */ jsx(GiftCardProductsSection, {}) }) })
21583
- }
21584
- }
21585
- ),
21586
- /* @__PURE__ */ jsx(Toaster, {})
21587
- ] });
21588
- };
21589
- const config$2 = defineRouteConfig({
21590
- label: "Gift Cards",
21591
- icon: GiftCardIcon,
21592
- permissions: ["gift_card:read"]
21593
- });
21594
- const STORE_QUERY_KEY = "store";
21595
- const storeQueryKeys = queryKeysFactory(STORE_QUERY_KEY);
21596
- async function retrieveActiveStore(query) {
21597
- const response = await sdk.admin.store.list(query);
21598
- const activeStore = response.stores?.[0];
21599
- if (!activeStore) {
21600
- throw new FetchError("No active store found", "Not Found", 404);
21601
- }
21602
- return { store: activeStore };
21603
- }
21604
- const useStore$1 = (query, options) => {
21605
- const { data, ...rest } = useQuery({
21606
- queryFn: () => retrieveActiveStore(query),
21607
- queryKey: storeQueryKeys.details(),
21608
- ...options
21609
- });
21610
- return {
21611
- ...data,
21612
- ...rest
21613
- };
21614
- };
21615
20884
  function getEnumValues(entries) {
21616
20885
  const numericValues = Object.values(entries).filter((v) => typeof v === "number");
21617
20886
  const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
@@ -22278,7 +21547,7 @@ class $ZodEncodeError extends Error {
22278
21547
  }
22279
21548
  (_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__zod_globalConfig = {});
22280
21549
  const globalConfig = globalThis.__zod_globalConfig;
22281
- function config$1(newConfig) {
21550
+ function config$2(newConfig) {
22282
21551
  if (newConfig)
22283
21552
  Object.assign(globalConfig, newConfig);
22284
21553
  return globalConfig;
@@ -22404,7 +21673,7 @@ const _parse = (_Err) => {
22404
21673
  throw new $ZodAsyncError();
22405
21674
  }
22406
21675
  if (result.issues.length) {
22407
- const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
21676
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
22408
21677
  captureStackTrace(e, _params?.callee ?? fn);
22409
21678
  throw e;
22410
21679
  }
@@ -22419,7 +21688,7 @@ const _parseAsync = (_Err) => {
22419
21688
  if (result instanceof Promise)
22420
21689
  result = await result;
22421
21690
  if (result.issues.length) {
22422
- const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
21691
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
22423
21692
  captureStackTrace(e, params?.callee ?? fn);
22424
21693
  throw e;
22425
21694
  }
@@ -22441,7 +21710,7 @@ function failure(Err, issues, ctx2) {
22441
21710
  success: false,
22442
21711
  get error() {
22443
21712
  if (!error2) {
22444
- error2 = new Err(issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
21713
+ error2 = new Err(issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
22445
21714
  issues = void 0;
22446
21715
  ctx2 = void 0;
22447
21716
  }
@@ -23066,7 +22335,7 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
23066
22335
  own(this, "~standard", value);
23067
22336
  }
23068
22337
  });
23069
- const toStandardResult = (r, ctx2) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())) } : { value: r.value };
22338
+ const toStandardResult = (r, ctx2) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())) } : { value: r.value };
23070
22339
  async function validateAsync(inst, value) {
23071
22340
  const ctx2 = { async: true };
23072
22341
  return toStandardResult(await inst._zod.run({ value, issues: [] }, ctx2), ctx2);
@@ -23928,7 +23197,7 @@ function handleUnionResults(results, final, inst, ctx2) {
23928
23197
  code: "invalid_union",
23929
23198
  input: final.value,
23930
23199
  inst,
23931
- errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())))
23200
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())))
23932
23201
  });
23933
23202
  return final;
23934
23203
  }
@@ -24124,7 +23393,7 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
24124
23393
  payload.issues.push({
24125
23394
  code: "invalid_key",
24126
23395
  origin: "record",
24127
- issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())),
23396
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())),
24128
23397
  input: key2,
24129
23398
  path: [key2],
24130
23399
  inst
@@ -24204,7 +23473,7 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
24204
23473
  payload.issues.push({
24205
23474
  code: "invalid_key",
24206
23475
  origin: "record",
24207
- issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())),
23476
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())),
24208
23477
  input: key2,
24209
23478
  path: [key2],
24210
23479
  inst
@@ -24420,7 +23689,7 @@ function handleCatchResult(payload, result, def, ctx2) {
24420
23689
  ...result,
24421
23690
  value: payload.value,
24422
23691
  error: {
24423
- issues: result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1()))
23692
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2()))
24424
23693
  },
24425
23694
  input: payload.value
24426
23695
  });
@@ -26564,11 +25833,11 @@ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
26564
25833
  const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
26565
25834
  function _ensureDefaultLocale() {
26566
25835
  if (!globalConfig.localeError)
26567
- config$1(en());
25836
+ config$2(en());
26568
25837
  }
26569
25838
  function _ensureDefaultMemoizer() {
26570
25839
  if (!globalConfig.memoizer)
26571
- config$1({ memoizer: memoizer() });
25840
+ config$2({ memoizer: memoizer() });
26572
25841
  }
26573
25842
  const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
26574
25843
  _ensureDefaultLocale();
@@ -27672,742 +26941,746 @@ const GiftCardCreateForm = ({
27672
26941
  ] });
27673
26942
  };
27674
26943
  const GiftCardCreate = () => {
27675
- const { store, isLoading } = useStore$1({});
26944
+ const { store, isLoading } = useStore$2({});
27676
26945
  return /* @__PURE__ */ jsxs(RouteFocusModal, { children: [
27677
26946
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create Gift Card" }) }),
27678
26947
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create a new gift card" }) }),
27679
26948
  !isLoading && /* @__PURE__ */ jsx(GiftCardCreateForm, { store })
27680
26949
  ] });
27681
26950
  };
27682
- const handle$d = {
26951
+ const handle$e = {
27683
26952
  permissions: ["gift_card:create", "store:read"]
27684
26953
  };
27685
- const StoreCreditAccountBalanceSection = ({
27686
- storeCreditAccount
27687
- }) => {
27688
- if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
27689
- return;
27690
- }
27691
- return /* @__PURE__ */ jsx(Container$1, { className: "grid grid-cols-2 gap-x-2 px-6 py-4", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-x-3", children: [
27692
- /* @__PURE__ */ jsx("div", { className: "bg-ui-tag-green-icon h-8 w-1 rounded-full" }),
27693
- /* @__PURE__ */ jsxs("div", { children: [
27694
- /* @__PURE__ */ jsx(Text, { weight: "plus", size: "small", className: "text-ui-fg-subtle", children: "Current Balance" }),
27695
- /* @__PURE__ */ jsx(
27696
- Text,
27697
- {
27698
- weight: "plus",
27699
- size: "xlarge",
27700
- className: "tabular-nums text-ui-fg-base",
27701
- children: formatAmount(
27702
- storeCreditAccount.balance,
27703
- storeCreditAccount.currency_code
27704
- )
27705
- }
27706
- )
27707
- ] })
27708
- ] }) });
27709
- };
27710
- var __create = Object.create;
27711
- var __defProp = Object.defineProperty;
27712
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
27713
- var __getOwnPropNames = Object.getOwnPropertyNames;
27714
- var __getProtoOf = Object.getPrototypeOf;
27715
- var __hasOwnProp = Object.prototype.hasOwnProperty;
27716
- var __commonJS = (cb, mod) => function __require() {
27717
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
27718
- };
27719
- var __copyProps = (to, from, except, desc) => {
27720
- if (from && typeof from === "object" || typeof from === "function") {
27721
- for (let key2 of __getOwnPropNames(from))
27722
- if (!__hasOwnProp.call(to, key2) && key2 !== except)
27723
- __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
27724
- }
27725
- return to;
27726
- };
27727
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27728
- // If the importer is in node compatibility mode or this is not an ESM
27729
- // file that has been converted to a CommonJS file using a Babel-
27730
- // compatible transform (i.e. "__esModule" has not been set), then set
27731
- // "default" to the CommonJS "module.exports" for node compatibility.
27732
- __defProp(target, "default", { value: mod, enumerable: true }),
27733
- mod
27734
- ));
27735
- var require_toggle_selection = __commonJS({
27736
- "node_modules/toggle-selection/index.js"(exports, module) {
27737
- module.exports = function() {
27738
- var selection = document.getSelection();
27739
- if (!selection.rangeCount) {
27740
- return function() {
27741
- };
27742
- }
27743
- var active = document.activeElement;
27744
- var ranges = [];
27745
- for (var i2 = 0; i2 < selection.rangeCount; i2++) {
27746
- ranges.push(selection.getRangeAt(i2));
27747
- }
27748
- switch (active.tagName.toUpperCase()) {
27749
- // .toUpperCase handles XHTML
27750
- case "INPUT":
27751
- case "TEXTAREA":
27752
- active.blur();
27753
- break;
27754
- default:
27755
- active = null;
27756
- break;
27757
- }
27758
- selection.removeAllRanges();
27759
- return function() {
27760
- selection.type === "Caret" && selection.removeAllRanges();
27761
- if (!selection.rangeCount) {
27762
- ranges.forEach(function(range) {
27763
- selection.addRange(range);
27764
- });
27765
- }
27766
- active && active.focus();
27767
- };
27768
- };
27769
- }
27770
- });
27771
- var import_index = __toESM(require_toggle_selection());
27772
- var toggle_selection_default = import_index.default;
27773
- var defaultMessage = "Copy to clipboard: #{key}, Enter";
27774
- function formatPromptMessage(message2) {
27775
- var isMac2 = navigator.userAgentData ? /mac/i.test(navigator.userAgentData.platform) : /mac os x/i.test(navigator.userAgent);
27776
- var copyKey = (isMac2 ? "⌘" : "Ctrl") + "+C";
27777
- return message2.replace(/#{\s*key\s*}/g, copyKey);
27778
- }
27779
- function buildClipboardItem(text2, format2) {
27780
- var items = {};
27781
- items["text/plain"] = new Blob([text2], { type: "text/plain" });
27782
- if (format2 && format2 !== "text/plain") {
27783
- items[format2] = new Blob([text2], { type: format2 });
27784
- }
27785
- return new ClipboardItem(items);
27786
- }
27787
- async function copyViaClipboardAPI(text2, options) {
27788
- if (!options.format && !options.onCopy) {
27789
- await navigator.clipboard.writeText(text2);
27790
- return true;
27791
- }
27792
- var item = buildClipboardItem(text2, options.format);
27793
- if (options.onCopy) {
27794
- item = options.onCopy(item) || item;
27795
- }
27796
- await navigator.clipboard.write([item]);
27797
- return true;
27798
- }
27799
- function createHiddenSpan(text2, options) {
27800
- var mark = document.createElement("span");
27801
- mark.textContent = text2;
27802
- mark.ariaHidden = "true";
27803
- mark.style.all = "unset";
27804
- mark.style.position = "fixed";
27805
- mark.style.top = "0";
27806
- mark.style.clip = "rect(0, 0, 0, 0)";
27807
- mark.style.whiteSpace = "pre";
27808
- mark.style.webkitUserSelect = "text";
27809
- mark.style.MozUserSelect = "text";
27810
- mark.style.msUserSelect = "text";
27811
- mark.style.userSelect = "text";
27812
- mark.addEventListener("copy", function(e) {
27813
- e.stopPropagation();
27814
- if (options.format) {
27815
- e.preventDefault();
27816
- if (e.clipboardData) {
27817
- e.clipboardData.setData(options.format, text2);
27818
- }
27819
- }
27820
- if (options.onCopy && e.clipboardData) {
27821
- options.onCopy(e.clipboardData);
27822
- }
27823
- });
27824
- return mark;
27825
- }
27826
- function findOpenedModalDialog() {
27827
- let element = document.activeElement;
27828
- while (element) {
27829
- if (element.tagName === "DIALOG" && element.open) {
27830
- return element;
27831
- }
27832
- element = element.parentElement;
27833
- }
27834
- return null;
27835
- }
27836
- function copyViaExecCommand(text2, options) {
27837
- var reselectPrevious = toggle_selection_default();
27838
- var range = document.createRange();
27839
- var selection = document.getSelection();
27840
- var mark = createHiddenSpan(text2, options);
27841
- var root = findOpenedModalDialog() || document.fullscreenElement || document.body;
27842
- var success = false;
27843
- try {
27844
- root.appendChild(mark);
27845
- range.selectNodeContents(mark);
27846
- selection.removeAllRanges();
27847
- selection.addRange(range);
27848
- var successful = document.execCommand("copy");
27849
- if (!successful) {
27850
- throw new Error("copy command was unsuccessful");
27851
- }
27852
- success = true;
27853
- } finally {
27854
- if (typeof selection.removeRange == "function") {
27855
- selection.removeRange(range);
27856
- } else {
27857
- selection.removeAllRanges();
27858
- }
27859
- root.removeChild(mark);
27860
- reselectPrevious();
27861
- }
27862
- return success;
27863
- }
27864
- async function copy$1(text2, options = {}) {
27865
- var debug2 = options.debug || false;
27866
- if (window.isSecureContext && navigator.clipboard) {
27867
- try {
27868
- return await copyViaClipboardAPI(text2, options);
27869
- } catch (err) {
27870
- debug2 && console.error("unable to copy using navigator.clipboard: ", err);
27871
- debug2 && console.warn("falling back to execCommand");
27872
- }
27873
- } else {
27874
- debug2 && !window.isSecureContext && console.warn("copy-to-clipboard: navigator.clipboard requires a secure context (HTTPS/localhost). Falling back to execCommand.");
27875
- }
27876
- try {
27877
- return copyViaExecCommand(text2, options);
27878
- } catch (err) {
27879
- debug2 && console.error("unable to copy using execCommand: ", err);
27880
- debug2 && console.error("falling back to prompt");
27881
- if (options.fallbackToPrompt) {
27882
- var message2 = formatPromptMessage("message" in options ? options.message : defaultMessage);
27883
- window.prompt(message2, text2);
27884
- }
27885
- }
27886
- return false;
27887
- }
27888
- var index_default = copy$1;
27889
- function DisplayId({ id, className }) {
27890
- const [open2, setOpen] = useState(false);
27891
- const onClick = () => {
27892
- index_default(id);
27893
- toast.success("Copied to clipboard");
27894
- };
27895
- return /* @__PURE__ */ jsx(Tooltip, { maxWidth: 260, content: id, open: open2, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs("span", { onClick, className: clx("cursor-pointer", className), children: [
27896
- "#",
27897
- id.slice(-7)
27898
- ] }) });
27899
- }
27900
- const StoreCreditAccountDetailsSection = ({
27901
- storeCreditAccount
27902
- }) => {
27903
- const { hasPermission } = usePermissions();
27904
- const canUpdate = hasPermission("store_credit_account:update");
27905
- if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
27906
- return;
27907
- }
27908
- return /* @__PURE__ */ jsxs(Container$1, { className: "flex justify-between gap-x-2 px-6 py-6", children: [
27909
- /* @__PURE__ */ jsxs(
27910
- Text,
27911
- {
27912
- weight: "plus",
27913
- size: "xlarge",
27914
- className: "text-ui-fg-base flex gap-x-4",
27915
- children: [
27916
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
27917
- /* @__PURE__ */ jsx(CreditCardIcon, { className: "inline" }),
27918
- " "
27919
- ] }),
27920
- /* @__PURE__ */ jsxs("div", { children: [
27921
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle", children: [
27922
- storeCreditAccount.currency_code.toUpperCase(),
27923
- " Account"
27924
- ] }),
27925
- /* @__PURE__ */ jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsx(
27926
- Text,
27927
- {
27928
- weight: "regular",
27929
- size: "small",
27930
- className: "text-ui-fg-base flex gap-x-4",
27931
- children: /* @__PURE__ */ jsx(DisplayId, { id: storeCreditAccount.id })
27932
- }
27933
- ) })
27934
- ] })
27935
- ]
27936
- }
27937
- ),
27938
- canUpdate && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-x-4", children: /* @__PURE__ */ jsx(
27939
- ActionMenu,
27940
- {
27941
- groups: [
26954
+ const StoreCreditIcon = (props) => {
26955
+ return /* @__PURE__ */ jsxs(
26956
+ "svg",
26957
+ {
26958
+ width: "15",
26959
+ height: "15",
26960
+ viewBox: "0 0 15 15",
26961
+ fill: "none",
26962
+ xmlns: "http://www.w3.org/2000/svg",
26963
+ ...props,
26964
+ children: [
26965
+ /* @__PURE__ */ jsx("rect", { width: "15", height: "15", fill: "#8B5CF6" }),
26966
+ /* @__PURE__ */ jsx(
26967
+ "rect",
27942
26968
  {
27943
- actions: [
27944
- {
27945
- icon: /* @__PURE__ */ jsx(CreditCard, {}),
27946
- label: "Credit the account",
27947
- to: "credit"
27948
- },
27949
- {
27950
- icon: /* @__PURE__ */ jsx(MinusMini, {}),
27951
- label: "Debit the account",
27952
- to: "debit",
27953
- disabled: !Number(storeCreditAccount.balance)
27954
- }
26969
+ width: "15",
26970
+ height: "15",
26971
+ fill: "url(#paint0_linear_29181_44790)",
26972
+ fillOpacity: "0.2"
26973
+ }
26974
+ ),
26975
+ /* @__PURE__ */ jsx(
26976
+ "path",
26977
+ {
26978
+ d: "M12 6V5.813C12 4.675 11.075 3.75 9.938 3.75H5.063C3.925 3.75 3 4.675 3 5.813V6H12Z",
26979
+ fill: "white"
26980
+ }
26981
+ ),
26982
+ /* @__PURE__ */ jsx(
26983
+ "path",
26984
+ {
26985
+ 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",
26986
+ fill: "white"
26987
+ }
26988
+ ),
26989
+ /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
26990
+ "linearGradient",
26991
+ {
26992
+ id: "paint0_linear_29181_44790",
26993
+ x1: "7.5",
26994
+ y1: "0",
26995
+ x2: "7.5",
26996
+ y2: "15",
26997
+ gradientUnits: "userSpaceOnUse",
26998
+ children: [
26999
+ /* @__PURE__ */ jsx("stop", { stopColor: "white" }),
27000
+ /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
27955
27001
  ]
27956
27002
  }
27957
- ]
27958
- }
27959
- ) })
27960
- ] });
27003
+ ) })
27004
+ ]
27005
+ }
27006
+ );
27961
27007
  };
27962
- function StoreCreditAccountCustomerSection({
27963
- customerId
27964
- }) {
27965
- const { hasPermission } = usePermissions();
27966
- const canReadCustomer = hasPermission("customer:read");
27967
- const { customer, isPending } = useCustomer(customerId, void 0, {
27968
- enabled: !!customerId && canReadCustomer
27969
- });
27970
- if (!canReadCustomer || isPending || !customer) {
27971
- return null;
27972
- }
27973
- return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
27974
- /* @__PURE__ */ jsx(Header$5, { title: "Customer" }),
27975
- /* @__PURE__ */ jsx(
27976
- SidebarLink,
27977
- {
27978
- icon: /* @__PURE__ */ jsx(User, {}),
27979
- labelKey: customer.email || "N/A",
27980
- descriptionKey: !customer.first_name && !customer.last_name ? "N/A" : `${customer.first_name} ${customer.last_name}`,
27981
- to: `/customers/${customer.id}`
27982
- },
27983
- customer.id
27984
- )
27985
- ] });
27986
- }
27987
- const columnHelper$8 = createDataTableColumnHelper();
27988
- const useTransactionsTableColumns = () => {
27008
+ const columnHelper$9 = createDataTableColumnHelper();
27009
+ const useStoreCreditAccountTableColumns = () => {
27989
27010
  return useMemo(() => {
27990
27011
  return [
27991
- columnHelper$8.accessor("id", {
27992
- header: "ID",
27012
+ columnHelper$9.accessor("currency_code", {
27013
+ header: "Currency",
27993
27014
  cell: ({ row }) => {
27994
- return /* @__PURE__ */ jsx(DisplayId, { id: row.original.id });
27015
+ return /* @__PURE__ */ jsx(Badge, { size: "2xsmall", children: row.original.currency_code.toUpperCase() });
27995
27016
  }
27996
27017
  }),
27997
- columnHelper$8.accessor("created_at", {
27998
- header: "Created At",
27999
- cell: ({ row }) => formatDate(row.original.created_at, false)
27018
+ columnHelper$9.accessor("customer.email", {
27019
+ header: "Customer",
27020
+ cell: ({ row }) => {
27021
+ return row.original.customer?.email ?? "N/A";
27022
+ }
28000
27023
  }),
28001
- columnHelper$8.accessor("note", {
28002
- header: "Description",
28003
- cell: ({ row }) => row.original.note
27024
+ columnHelper$9.accessor("balance", {
27025
+ header: "Balance",
27026
+ cell: ({ row }) => {
27027
+ return formatAmount(
27028
+ row.original.balance,
27029
+ row.original.currency_code
27030
+ );
27031
+ }
28004
27032
  }),
28005
- columnHelper$8.accessor("note", {
28006
- header: "Note",
27033
+ columnHelper$9.accessor("credits", {
27034
+ header: "Credits",
28007
27035
  cell: ({ row }) => {
28008
- return /* @__PURE__ */ jsx(Text, { title: row.original.note, className: "max-w-[300px] truncate", children: row.original.note || "-" });
27036
+ return formatAmount(
27037
+ row.original.credits,
27038
+ row.original.currency_code
27039
+ );
28009
27040
  }
28010
27041
  }),
28011
- columnHelper$8.accessor("amount", {
28012
- header: "Amount",
27042
+ columnHelper$9.accessor("debits", {
27043
+ header: "Debits",
28013
27044
  cell: ({ row }) => {
28014
- const isDebit = row.original.type === "debit";
28015
- return row.original.account.currency_code && formatAmount(
28016
- row.original.amount * (isDebit ? -1 : 1),
28017
- row.original.account.currency_code
27045
+ return formatAmount(
27046
+ row.original.debits,
27047
+ row.original.currency_code
28018
27048
  );
28019
27049
  }
27050
+ }),
27051
+ columnHelper$9.accessor("created_at", {
27052
+ header: "Created at",
27053
+ cell: ({ row }) => getRelativeDate(row.original.created_at)
28020
27054
  })
28021
27055
  ];
28022
27056
  }, []);
28023
27057
  };
28024
- const useTransactionsTableFilters = ({}) => {
27058
+ const useStoreCreditAccountFilters = () => {
28025
27059
  const dateFilterOptions = useDataTableDateFilters$1();
27060
+ const customerFilterOptions = useCustomerFilters();
28026
27061
  return useMemo(() => {
28027
- return [...dateFilterOptions];
28028
- }, [dateFilterOptions]);
27062
+ return [...dateFilterOptions, ...customerFilterOptions];
27063
+ }, [dateFilterOptions, customerFilterOptions]);
28029
27064
  };
28030
- const useTransactionsTableQuery = ({
27065
+ const useStoreCreditAccountsTableQuery = ({
28031
27066
  prefix,
28032
27067
  pageSize = 20
28033
27068
  }) => {
28034
27069
  const queryObject = useQueryParams(
28035
- ["offset", "limit", "currency_code", "created_at", "updated_at"],
27070
+ ["offset", "customer_id", "currency_code", "created_at", "updated_at"],
28036
27071
  prefix
28037
27072
  );
28038
- const { offset: offset2, limit, created_at, updated_at, ...rest } = queryObject;
27073
+ const {
27074
+ offset: offset2,
27075
+ created_at,
27076
+ updated_at,
27077
+ customer_id,
27078
+ currency_code,
27079
+ ...rest
27080
+ } = queryObject;
28039
27081
  const searchParams = {
28040
- limit: limit ? Number(limit) : pageSize,
27082
+ limit: pageSize,
28041
27083
  offset: offset2 ? Number(offset2) : 0,
28042
27084
  created_at: created_at ? JSON.parse(created_at) : void 0,
28043
27085
  updated_at: updated_at ? JSON.parse(updated_at) : void 0,
27086
+ customer_id: customer_id ? JSON.parse(customer_id) : void 0,
27087
+ currency_code: currency_code ? JSON.parse(currency_code) : void 0,
28044
27088
  ...rest
28045
27089
  };
28046
27090
  return searchParams;
28047
27091
  };
28048
- const PAGE_SIZE$4 = 10;
28049
- function TransactionsTable({ id }) {
28050
- const queryParams = useTransactionsTableQuery({
28051
- pageSize: PAGE_SIZE$4
27092
+ const PAGE_SIZE$5 = 10;
27093
+ function StoreCreditAccountsTable() {
27094
+ const queryParams = useStoreCreditAccountsTableQuery({
27095
+ pageSize: PAGE_SIZE$5
28052
27096
  });
28053
- const { transactions, isLoading, count: count2 } = useStoreCreditAccountTransactions(
28054
- id,
28055
- {
28056
- ...queryParams,
28057
- order: queryParams.order ?? "-created_at",
28058
- fields: "*account"
28059
- }
28060
- );
28061
- const columns = useTransactionsTableColumns();
28062
- const filters = useTransactionsTableFilters({});
27097
+ const {
27098
+ store_credit_accounts: storeCreditAccounts,
27099
+ isPending,
27100
+ count: count2
27101
+ } = useStoreCreditAccounts({
27102
+ ...queryParams,
27103
+ order: queryParams.order ?? "-created_at"
27104
+ });
27105
+ const columns = useStoreCreditAccountTableColumns();
27106
+ const filters = useStoreCreditAccountFilters();
27107
+ const { hasPermission } = usePermissions();
27108
+ const canCreate = hasPermission("store_credit_account:create");
28063
27109
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
28064
27110
  /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
28065
27111
  DataTable,
28066
27112
  {
28067
- data: transactions ?? [],
27113
+ data: storeCreditAccounts ?? [],
28068
27114
  getRowId: (row) => row.id,
28069
27115
  columns,
28070
27116
  filters,
28071
- isLoading,
28072
- pageSize: PAGE_SIZE$4,
27117
+ isLoading: isPending,
27118
+ pageSize: PAGE_SIZE$5,
28073
27119
  rowCount: count2,
28074
27120
  enableSearch: false,
28075
- heading: "Transactions",
27121
+ heading: "Store Credit Accounts",
27122
+ rowHref: (row) => `${row.id}`,
28076
27123
  emptyState: {
28077
27124
  empty: {
28078
- heading: "No transactions found"
27125
+ heading: "No store credit accounts found",
27126
+ description: "Create a new store credit account to get started."
28079
27127
  },
28080
27128
  filtered: {
28081
27129
  heading: "No results found",
28082
- description: "No transactions match your filter criteria."
27130
+ description: "No store credit accounts match your filter criteria."
28083
27131
  }
28084
- }
27132
+ },
27133
+ actions: canCreate ? [
27134
+ {
27135
+ label: "Create",
27136
+ to: "/store-credit-accounts/create"
27137
+ }
27138
+ ] : []
28085
27139
  }
28086
27140
  ) }),
28087
27141
  /* @__PURE__ */ jsx(Outlet, {})
28088
27142
  ] });
28089
27143
  }
28090
- function StoreCreditAccountCodeSection({ code }) {
28091
- if (!code) {
28092
- return null;
28093
- }
28094
- return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
28095
- /* @__PURE__ */ jsx(Header$5, { title: "Account Code" }),
28096
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-4 px-6 mb-2", children: [
28097
- /* @__PURE__ */ jsx(Share, { className: "inline" }),
28098
- /* @__PURE__ */ jsx("div", { className: "text-ui-fg-subtle text-sm", children: code })
28099
- ] })
27144
+ const StoreCreditAccountsPage = () => {
27145
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
27146
+ /* @__PURE__ */ jsx(
27147
+ LayoutComposer,
27148
+ {
27149
+ widgetsZonePrefix: "store_credit_account.list",
27150
+ preferredLayoutId: "core:single-column",
27151
+ sections: {
27152
+ main: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountsTable", children: /* @__PURE__ */ jsx(StoreCreditAccountsTable, {}) })
27153
+ }
27154
+ }
27155
+ ),
27156
+ /* @__PURE__ */ jsx(Toaster, {})
28100
27157
  ] });
28101
- }
28102
- const StoreCreditAccountPage = () => {
28103
- const { id } = useParams();
28104
- const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
28105
- id
28106
- );
28107
- if (!storeCreditAccount) {
28108
- return;
28109
- }
28110
- return /* @__PURE__ */ jsx(
28111
- LayoutComposer,
28112
- {
28113
- widgetsZonePrefix: "store_credit_account.details",
28114
- preferredLayoutId: "core:two-column",
28115
- data: storeCreditAccount,
28116
- sections: {
28117
- main: /* @__PURE__ */ jsxs(Fragment, { children: [
28118
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountDetailsSection", children: /* @__PURE__ */ jsx(
28119
- StoreCreditAccountDetailsSection,
28120
- {
28121
- storeCreditAccount
28122
- }
28123
- ) }),
28124
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "TransactionsTable", children: /* @__PURE__ */ jsx(TransactionsTable, { id: storeCreditAccount.id }) })
28125
- ] }),
28126
- side: /* @__PURE__ */ jsxs(Fragment, { children: [
28127
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountBalanceSection", children: /* @__PURE__ */ jsx(
28128
- StoreCreditAccountBalanceSection,
28129
- {
28130
- storeCreditAccount
28131
- }
28132
- ) }),
28133
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountCodeSection", children: /* @__PURE__ */ jsx(StoreCreditAccountCodeSection, { code: storeCreditAccount.code }) }),
28134
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountCustomerSection", children: /* @__PURE__ */ jsx(
28135
- StoreCreditAccountCustomerSection,
28136
- {
28137
- customerId: storeCreditAccount.customer_id
28138
- }
28139
- ) })
28140
- ] })
28141
- }
28142
- }
28143
- );
28144
27158
  };
28145
- const handle$c = {
27159
+ const config$1 = defineRouteConfig({
27160
+ label: "Store Credits",
27161
+ icon: StoreCreditIcon,
28146
27162
  permissions: ["store_credit_account:read"]
28147
- };
28148
- const KeyboundForm = React__default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
28149
- const handleSubmit = (event) => {
28150
- event.preventDefault();
28151
- onSubmit?.(event);
27163
+ });
27164
+ var isObject_1;
27165
+ var hasRequiredIsObject;
27166
+ function requireIsObject() {
27167
+ if (hasRequiredIsObject) return isObject_1;
27168
+ hasRequiredIsObject = 1;
27169
+ function isObject2(value) {
27170
+ var type = typeof value;
27171
+ return value != null && (type == "object" || type == "function");
27172
+ }
27173
+ isObject_1 = isObject2;
27174
+ return isObject_1;
27175
+ }
27176
+ var _freeGlobal;
27177
+ var hasRequired_freeGlobal;
27178
+ function require_freeGlobal() {
27179
+ if (hasRequired_freeGlobal) return _freeGlobal;
27180
+ hasRequired_freeGlobal = 1;
27181
+ var freeGlobal = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
27182
+ _freeGlobal = freeGlobal;
27183
+ return _freeGlobal;
27184
+ }
27185
+ var _root;
27186
+ var hasRequired_root;
27187
+ function require_root() {
27188
+ if (hasRequired_root) return _root;
27189
+ hasRequired_root = 1;
27190
+ var freeGlobal = require_freeGlobal();
27191
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
27192
+ var root = freeGlobal || freeSelf || Function("return this")();
27193
+ _root = root;
27194
+ return _root;
27195
+ }
27196
+ var now_1;
27197
+ var hasRequiredNow;
27198
+ function requireNow() {
27199
+ if (hasRequiredNow) return now_1;
27200
+ hasRequiredNow = 1;
27201
+ var root = require_root();
27202
+ var now = function() {
27203
+ return root.Date.now();
28152
27204
  };
28153
- const handleKeyDown = (event) => {
28154
- if (event.key === "Enter") {
28155
- if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
28156
- return;
27205
+ now_1 = now;
27206
+ return now_1;
27207
+ }
27208
+ var _trimmedEndIndex;
27209
+ var hasRequired_trimmedEndIndex;
27210
+ function require_trimmedEndIndex() {
27211
+ if (hasRequired_trimmedEndIndex) return _trimmedEndIndex;
27212
+ hasRequired_trimmedEndIndex = 1;
27213
+ var reWhitespace = /\s/;
27214
+ function trimmedEndIndex(string2) {
27215
+ var index = string2.length;
27216
+ while (index-- && reWhitespace.test(string2.charAt(index))) {
27217
+ }
27218
+ return index;
27219
+ }
27220
+ _trimmedEndIndex = trimmedEndIndex;
27221
+ return _trimmedEndIndex;
27222
+ }
27223
+ var _baseTrim;
27224
+ var hasRequired_baseTrim;
27225
+ function require_baseTrim() {
27226
+ if (hasRequired_baseTrim) return _baseTrim;
27227
+ hasRequired_baseTrim = 1;
27228
+ var trimmedEndIndex = require_trimmedEndIndex();
27229
+ var reTrimStart = /^\s+/;
27230
+ function baseTrim(string2) {
27231
+ return string2 ? string2.slice(0, trimmedEndIndex(string2) + 1).replace(reTrimStart, "") : string2;
27232
+ }
27233
+ _baseTrim = baseTrim;
27234
+ return _baseTrim;
27235
+ }
27236
+ var _Symbol;
27237
+ var hasRequired_Symbol;
27238
+ function require_Symbol() {
27239
+ if (hasRequired_Symbol) return _Symbol;
27240
+ hasRequired_Symbol = 1;
27241
+ var root = require_root();
27242
+ var Symbol2 = root.Symbol;
27243
+ _Symbol = Symbol2;
27244
+ return _Symbol;
27245
+ }
27246
+ var _getRawTag;
27247
+ var hasRequired_getRawTag;
27248
+ function require_getRawTag() {
27249
+ if (hasRequired_getRawTag) return _getRawTag;
27250
+ hasRequired_getRawTag = 1;
27251
+ var Symbol2 = require_Symbol();
27252
+ var objectProto = Object.prototype;
27253
+ var hasOwnProperty2 = objectProto.hasOwnProperty;
27254
+ var nativeObjectToString = objectProto.toString;
27255
+ var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
27256
+ function getRawTag(value) {
27257
+ var isOwn = hasOwnProperty2.call(value, symToStringTag), tag = value[symToStringTag];
27258
+ try {
27259
+ value[symToStringTag] = void 0;
27260
+ var unmasked = true;
27261
+ } catch (e) {
27262
+ }
27263
+ var result = nativeObjectToString.call(value);
27264
+ if (unmasked) {
27265
+ if (isOwn) {
27266
+ value[symToStringTag] = tag;
27267
+ } else {
27268
+ delete value[symToStringTag];
28157
27269
  }
28158
- event.preventDefault();
28159
- if (event.metaKey || event.ctrlKey) {
28160
- handleSubmit(event);
27270
+ }
27271
+ return result;
27272
+ }
27273
+ _getRawTag = getRawTag;
27274
+ return _getRawTag;
27275
+ }
27276
+ var _objectToString;
27277
+ var hasRequired_objectToString;
27278
+ function require_objectToString() {
27279
+ if (hasRequired_objectToString) return _objectToString;
27280
+ hasRequired_objectToString = 1;
27281
+ var objectProto = Object.prototype;
27282
+ var nativeObjectToString = objectProto.toString;
27283
+ function objectToString(value) {
27284
+ return nativeObjectToString.call(value);
27285
+ }
27286
+ _objectToString = objectToString;
27287
+ return _objectToString;
27288
+ }
27289
+ var _baseGetTag;
27290
+ var hasRequired_baseGetTag;
27291
+ function require_baseGetTag() {
27292
+ if (hasRequired_baseGetTag) return _baseGetTag;
27293
+ hasRequired_baseGetTag = 1;
27294
+ var Symbol2 = require_Symbol(), getRawTag = require_getRawTag(), objectToString = require_objectToString();
27295
+ var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
27296
+ var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
27297
+ function baseGetTag(value) {
27298
+ if (value == null) {
27299
+ return value === void 0 ? undefinedTag : nullTag;
27300
+ }
27301
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
27302
+ }
27303
+ _baseGetTag = baseGetTag;
27304
+ return _baseGetTag;
27305
+ }
27306
+ var isObjectLike_1;
27307
+ var hasRequiredIsObjectLike;
27308
+ function requireIsObjectLike() {
27309
+ if (hasRequiredIsObjectLike) return isObjectLike_1;
27310
+ hasRequiredIsObjectLike = 1;
27311
+ function isObjectLike(value) {
27312
+ return value != null && typeof value == "object";
27313
+ }
27314
+ isObjectLike_1 = isObjectLike;
27315
+ return isObjectLike_1;
27316
+ }
27317
+ var isSymbol_1;
27318
+ var hasRequiredIsSymbol;
27319
+ function requireIsSymbol() {
27320
+ if (hasRequiredIsSymbol) return isSymbol_1;
27321
+ hasRequiredIsSymbol = 1;
27322
+ var baseGetTag = require_baseGetTag(), isObjectLike = requireIsObjectLike();
27323
+ var symbolTag = "[object Symbol]";
27324
+ function isSymbol(value) {
27325
+ return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
27326
+ }
27327
+ isSymbol_1 = isSymbol;
27328
+ return isSymbol_1;
27329
+ }
27330
+ var toNumber_1;
27331
+ var hasRequiredToNumber;
27332
+ function requireToNumber() {
27333
+ if (hasRequiredToNumber) return toNumber_1;
27334
+ hasRequiredToNumber = 1;
27335
+ var baseTrim = require_baseTrim(), isObject2 = requireIsObject(), isSymbol = requireIsSymbol();
27336
+ var NAN = 0 / 0;
27337
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
27338
+ var reIsBinary = /^0b[01]+$/i;
27339
+ var reIsOctal = /^0o[0-7]+$/i;
27340
+ var freeParseInt = parseInt;
27341
+ function toNumber(value) {
27342
+ if (typeof value == "number") {
27343
+ return value;
27344
+ }
27345
+ if (isSymbol(value)) {
27346
+ return NAN;
27347
+ }
27348
+ if (isObject2(value)) {
27349
+ var other = typeof value.valueOf == "function" ? value.valueOf() : value;
27350
+ value = isObject2(other) ? other + "" : other;
27351
+ }
27352
+ if (typeof value != "string") {
27353
+ return value === 0 ? value : +value;
27354
+ }
27355
+ value = baseTrim(value);
27356
+ var isBinary = reIsBinary.test(value);
27357
+ return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
27358
+ }
27359
+ toNumber_1 = toNumber;
27360
+ return toNumber_1;
27361
+ }
27362
+ var debounce_1;
27363
+ var hasRequiredDebounce;
27364
+ function requireDebounce() {
27365
+ if (hasRequiredDebounce) return debounce_1;
27366
+ hasRequiredDebounce = 1;
27367
+ var isObject2 = requireIsObject(), now = requireNow(), toNumber = requireToNumber();
27368
+ var FUNC_ERROR_TEXT = "Expected a function";
27369
+ var nativeMax = Math.max, nativeMin = Math.min;
27370
+ function debounce2(func, wait, options) {
27371
+ var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
27372
+ if (typeof func != "function") {
27373
+ throw new TypeError(FUNC_ERROR_TEXT);
27374
+ }
27375
+ wait = toNumber(wait) || 0;
27376
+ if (isObject2(options)) {
27377
+ leading = !!options.leading;
27378
+ maxing = "maxWait" in options;
27379
+ maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
27380
+ trailing = "trailing" in options ? !!options.trailing : trailing;
27381
+ }
27382
+ function invokeFunc(time2) {
27383
+ var args = lastArgs, thisArg = lastThis;
27384
+ lastArgs = lastThis = void 0;
27385
+ lastInvokeTime = time2;
27386
+ result = func.apply(thisArg, args);
27387
+ return result;
27388
+ }
27389
+ function leadingEdge(time2) {
27390
+ lastInvokeTime = time2;
27391
+ timerId = setTimeout(timerExpired, wait);
27392
+ return leading ? invokeFunc(time2) : result;
27393
+ }
27394
+ function remainingWait(time2) {
27395
+ var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
27396
+ return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
27397
+ }
27398
+ function shouldInvoke(time2) {
27399
+ var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime;
27400
+ return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
27401
+ }
27402
+ function timerExpired() {
27403
+ var time2 = now();
27404
+ if (shouldInvoke(time2)) {
27405
+ return trailingEdge(time2);
28161
27406
  }
27407
+ timerId = setTimeout(timerExpired, remainingWait(time2));
28162
27408
  }
28163
- };
28164
- return /* @__PURE__ */ jsx(
28165
- "form",
28166
- {
28167
- ...rest,
28168
- onSubmit: handleSubmit,
28169
- onKeyDown: onKeyDown ?? handleKeyDown,
28170
- ref
27409
+ function trailingEdge(time2) {
27410
+ timerId = void 0;
27411
+ if (trailing && lastArgs) {
27412
+ return invokeFunc(time2);
27413
+ }
27414
+ lastArgs = lastThis = void 0;
27415
+ return result;
28171
27416
  }
28172
- );
28173
- });
28174
- KeyboundForm.displayName = "KeyboundForm";
28175
- const Note$1 = () => {
28176
- const { id } = useParams();
28177
- const {
28178
- store_credit_account: storeCreditAccount,
28179
- isPending,
28180
- isError,
28181
- error: error2
28182
- } = useStoreCreditAccount(id, {});
28183
- if (isError) {
28184
- throw error2;
27417
+ function cancel() {
27418
+ if (timerId !== void 0) {
27419
+ clearTimeout(timerId);
27420
+ }
27421
+ lastInvokeTime = 0;
27422
+ lastArgs = lastCallTime = lastThis = timerId = void 0;
27423
+ }
27424
+ function flush() {
27425
+ return timerId === void 0 ? result : trailingEdge(now());
27426
+ }
27427
+ function debounced() {
27428
+ var time2 = now(), isInvoking = shouldInvoke(time2);
27429
+ lastArgs = arguments;
27430
+ lastThis = this;
27431
+ lastCallTime = time2;
27432
+ if (isInvoking) {
27433
+ if (timerId === void 0) {
27434
+ return leadingEdge(lastCallTime);
27435
+ }
27436
+ if (maxing) {
27437
+ clearTimeout(timerId);
27438
+ timerId = setTimeout(timerExpired, wait);
27439
+ return invokeFunc(lastCallTime);
27440
+ }
27441
+ }
27442
+ if (timerId === void 0) {
27443
+ timerId = setTimeout(timerExpired, wait);
27444
+ }
27445
+ return result;
27446
+ }
27447
+ debounced.cancel = cancel;
27448
+ debounced.flush = flush;
27449
+ return debounced;
28185
27450
  }
28186
- const isReady = !isPending && !!storeCreditAccount;
28187
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
28188
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
28189
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Credit store credit account" }) }),
28190
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Credit the store credit account" }) })
28191
- ] }),
28192
- isReady && /* @__PURE__ */ jsx(StoreCreditAccountCreditForm, { storeCreditAccount })
28193
- ] });
27451
+ debounce_1 = debounce2;
27452
+ return debounce_1;
27453
+ }
27454
+ var debounceExports = requireDebounce();
27455
+ const debounce$1 = /* @__PURE__ */ getDefaultExportFromCjs(debounceExports);
27456
+ const useDebouncedSearch = () => {
27457
+ const [searchValue, onSearchValueChange] = useState("");
27458
+ const [debouncedQuery, setDebouncedQuery] = useState("");
27459
+ const debouncedUpdate = useCallback(
27460
+ debounce$1((query) => setDebouncedQuery(query), 300),
27461
+ []
27462
+ );
27463
+ useEffect(() => {
27464
+ debouncedUpdate(searchValue);
27465
+ return () => debouncedUpdate.cancel();
27466
+ }, [searchValue, debouncedUpdate]);
27467
+ return {
27468
+ searchValue,
27469
+ onSearchValueChange,
27470
+ query: debouncedQuery || void 0
27471
+ };
28194
27472
  };
28195
- const StoreCreditAccountCreditForm = ({
28196
- storeCreditAccount
27473
+ const useComboboxData = ({
27474
+ queryKey,
27475
+ queryFn,
27476
+ getOptions,
27477
+ defaultValue: defaultValue2,
27478
+ defaultValueKey,
27479
+ pageSize = 10,
27480
+ enabled = true
28197
27481
  }) => {
28198
- const form = useForm({
28199
- defaultValues: {
28200
- amount: {
28201
- float: 0,
28202
- value: ""
28203
- },
28204
- note: ""
27482
+ const { searchValue, onSearchValueChange, query } = useDebouncedSearch();
27483
+ const queryInitialDataBy = defaultValueKey || "id";
27484
+ const { data: initialData } = useQuery({
27485
+ queryKey,
27486
+ queryFn: async () => {
27487
+ return queryFn({
27488
+ [queryInitialDataBy]: defaultValue2,
27489
+ limit: Array.isArray(defaultValue2) ? defaultValue2.length : 1
27490
+ });
28205
27491
  },
28206
- resolver: u(schema$3)
27492
+ enabled: enabled && !!defaultValue2
28207
27493
  });
28208
- const { mutateAsync, isPending } = useCreditStoreCreditAccount(
28209
- storeCreditAccount.id
28210
- );
28211
- const { handleSuccess } = useRouteModal();
28212
- const onSubmit = form.handleSubmit(async (data) => {
28213
- if (data.amount.float <= 0) {
28214
- form.setError("amount", { message: "Amount must be greater than 0" });
28215
- return;
28216
- }
28217
- await mutateAsync(
28218
- { amount: data.amount.float, note: data.note },
28219
- {
28220
- onSuccess: () => handleSuccess(),
28221
- onError: (error2) => toast.error(error2.message)
28222
- }
28223
- );
27494
+ const { data, ...rest } = useInfiniteQuery({
27495
+ queryKey: [...queryKey, query],
27496
+ queryFn: async ({ pageParam = 0 }) => {
27497
+ return await queryFn({
27498
+ q: query,
27499
+ limit: pageSize,
27500
+ offset: pageParam
27501
+ });
27502
+ },
27503
+ initialPageParam: 0,
27504
+ getNextPageParam: (lastPage) => {
27505
+ const moreItemsExist = lastPage.count > lastPage.offset + lastPage.limit;
27506
+ return moreItemsExist ? lastPage.offset + lastPage.limit : void 0;
27507
+ },
27508
+ placeholderData: keepPreviousData,
27509
+ enabled
28224
27510
  });
28225
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
28226
- KeyboundForm,
28227
- {
28228
- className: "flex flex-1 flex-col overflow-hidden",
28229
- onSubmit,
28230
- children: [
28231
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
28232
- /* @__PURE__ */ jsx(
28233
- Form$2.Field,
28234
- {
28235
- control: form.control,
28236
- name: "amount",
28237
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
28238
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Amount" }),
28239
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
28240
- CurrencyInput,
28241
- {
28242
- min: 0,
28243
- placeholder: "0",
28244
- value: field.value.value,
28245
- onValueChange: (_value, _name, values) => {
28246
- field.onChange({
28247
- value: values?.value,
28248
- float: values?.float || null
28249
- });
28250
- },
28251
- symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
28252
- code: storeCreditAccount.currency_code.toUpperCase()
28253
- }
28254
- ) }),
28255
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
28256
- ] })
28257
- }
28258
- ),
28259
- /* @__PURE__ */ jsx(
28260
- Form$2.Field,
28261
- {
28262
- control: form.control,
28263
- name: "note",
28264
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
28265
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
28266
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
28267
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
28268
- ] })
28269
- }
28270
- )
28271
- ] }),
28272
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
28273
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
28274
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
28275
- ] }) })
28276
- ]
28277
- }
28278
- ) });
28279
- };
28280
- const schema$3 = z.object({
28281
- note: z.string(),
28282
- amount: z.object({
28283
- float: z.number(),
28284
- value: z.string()
28285
- })
28286
- });
28287
- const handle$b = {
28288
- permissions: ["store_credit_account:read", "store_credit_account:update"]
28289
- };
28290
- const Debit = () => {
28291
- const { id } = useParams();
28292
- const {
28293
- store_credit_account: storeCreditAccount,
28294
- isPending,
28295
- isError,
28296
- error: error2
28297
- } = useStoreCreditAccount(id, {});
28298
- if (isError) {
28299
- throw error2;
27511
+ const options = data?.pages.flatMap((page) => getOptions(page)) ?? [];
27512
+ const defaultOptions2 = initialData ? getOptions(initialData) : [];
27513
+ const disabled = !rest.isPending && !options.length && !searchValue;
27514
+ if (defaultValue2 && defaultOptions2.length && !searchValue) {
27515
+ defaultOptions2.forEach((option) => {
27516
+ if (!options.find((o2) => o2.value === option.value)) {
27517
+ options.unshift(option);
27518
+ }
27519
+ });
28300
27520
  }
28301
- const isReady = !isPending && !!storeCreditAccount;
28302
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
28303
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
28304
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Debit store credit account" }) }),
28305
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Debit the store credit account" }) })
28306
- ] }),
28307
- isReady && /* @__PURE__ */ jsx(StoreCreditAccountDebitForm, { storeCreditAccount })
28308
- ] });
27521
+ return {
27522
+ options,
27523
+ searchValue,
27524
+ onSearchValueChange,
27525
+ disabled,
27526
+ ...rest
27527
+ };
28309
27528
  };
28310
- const StoreCreditAccountDebitForm = ({
28311
- storeCreditAccount
28312
- }) => {
27529
+ const formSchema = z.object({
27530
+ currency_code: z.string().min(1, "Please select a currency"),
27531
+ customer_id: z.string().optional()
27532
+ });
27533
+ const StoreCreditAccountCreateForm = () => {
27534
+ const { handleSuccess } = useRouteModal();
27535
+ const [searchParams] = useSearchParams();
27536
+ const prefilledCustomerId = searchParams.get("prefill_customer_id") ?? "";
27537
+ const { hasPermission } = usePermissions();
27538
+ const canReadCustomers = hasPermission("customer:read");
28313
27539
  const form = useForm({
28314
27540
  defaultValues: {
28315
- amount: {
28316
- float: 0,
28317
- value: ""
28318
- },
28319
- note: ""
27541
+ currency_code: "",
27542
+ customer_id: prefilledCustomerId
28320
27543
  },
28321
- resolver: u(schema$2)
27544
+ resolver: u(formSchema)
28322
27545
  });
28323
- const { mutateAsync, isPending } = useDebitStoreCreditAccount(
28324
- storeCreditAccount.id
28325
- );
28326
- const { handleSuccess } = useRouteModal();
28327
- const balance = storeCreditAccount.balance ?? 0;
28328
- const onSubmit = form.handleSubmit(async (data) => {
28329
- if (data.amount.float <= 0) {
28330
- form.setError("amount", { message: "Amount must be greater than 0" });
28331
- return;
28332
- }
28333
- if (data.amount.float > balance) {
28334
- form.setError("amount", {
28335
- message: "Amount can't be greater than the current balance"
28336
- });
28337
- return;
27546
+ const { mutateAsync: createStoreCreditAccount, isPending } = useCreateStoreCreditAccount();
27547
+ const handleSubmit = form.handleSubmit(async (data) => {
27548
+ if (!data.customer_id) {
27549
+ delete data.customer_id;
28338
27550
  }
28339
- await mutateAsync(
28340
- { amount: data.amount.float, note: data.note },
28341
- {
28342
- onSuccess: () => handleSuccess(),
28343
- onError: (error2) => toast.error(error2.message)
27551
+ await createStoreCreditAccount(data, {
27552
+ onSuccess: (data2) => {
27553
+ toast.success(`Store credit account was successfully created.`);
27554
+ handleSuccess(`../${data2.store_credit_account.id}`);
27555
+ },
27556
+ onError: (error2) => {
27557
+ toast.error(error2.message);
28344
27558
  }
27559
+ });
27560
+ });
27561
+ const [currencySearchValue, setCurrencySearchValue] = useState("");
27562
+ const currencyOptions = useMemo(() => {
27563
+ const options = Object.values(currencies).map((currency) => ({
27564
+ label: `${currency.code} - ${currency.name} (${currency.symbol_native})`,
27565
+ value: currency.code.toLowerCase()
27566
+ }));
27567
+ if (!currencySearchValue) {
27568
+ return options;
27569
+ }
27570
+ return options.filter(
27571
+ (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
28345
27572
  );
27573
+ }, [currencySearchValue]);
27574
+ const {
27575
+ options: customerOptions,
27576
+ fetchNextPage,
27577
+ isFetchingNextPage,
27578
+ searchValue,
27579
+ onSearchValueChange,
27580
+ isLoading
27581
+ } = useComboboxData({
27582
+ queryKey: customersQueryKeys.list(),
27583
+ defaultValue: prefilledCustomerId || void 0,
27584
+ enabled: canReadCustomers,
27585
+ queryFn: async (params) => {
27586
+ return sdk.admin.customer.list(params);
27587
+ },
27588
+ getOptions: (data) => {
27589
+ return data.customers?.map((customer) => {
27590
+ const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
27591
+ const label = fullName ? `${customer.email} (${fullName})` : customer.email;
27592
+ return {
27593
+ label,
27594
+ value: customer.id
27595
+ };
27596
+ }) || [];
27597
+ }
28346
27598
  });
28347
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
28348
- KeyboundForm,
28349
- {
28350
- className: "flex flex-1 flex-col overflow-hidden",
28351
- onSubmit,
28352
- children: [
28353
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
28354
- /* @__PURE__ */ jsx(
28355
- Form$2.Field,
28356
- {
28357
- control: form.control,
28358
- name: "amount",
28359
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
28360
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Amount" }),
27599
+ return /* @__PURE__ */ jsxs(RouteFocusModal.Form, { form, children: [
27600
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsx("div", { className: "-my-2 w-full border-l" }) }),
27601
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "size-full overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center p-16", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8", children: [
27602
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
27603
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Create Store Credit Account" }),
27604
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new store credit account for a customer" })
27605
+ ] }),
27606
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-x-4", children: [
27607
+ /* @__PURE__ */ jsx(
27608
+ Form$2.Field,
27609
+ {
27610
+ control: form.control,
27611
+ name: "currency_code",
27612
+ render: ({ field }) => {
27613
+ return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
27614
+ /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Currency" }),
28361
27615
  /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
28362
- CurrencyInput,
27616
+ Combobox2,
28363
27617
  {
28364
- min: 0,
28365
- placeholder: "0",
28366
- value: field.value.value,
28367
- onValueChange: (_value, _name, values) => {
28368
- field.onChange({
28369
- value: values?.value,
28370
- float: values?.float || null
28371
- });
28372
- },
28373
- symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
28374
- code: storeCreditAccount.currency_code.toUpperCase()
27618
+ value: field.value,
27619
+ onChange: field.onChange,
27620
+ searchValue: currencySearchValue,
27621
+ onSearchValueChange: setCurrencySearchValue,
27622
+ options: currencyOptions,
27623
+ placeholder: "Search for a currency..."
28375
27624
  }
28376
27625
  ) }),
28377
27626
  /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
28378
- ] })
27627
+ ] });
28379
27628
  }
28380
- ),
28381
- /* @__PURE__ */ jsx(
28382
- Form$2.Field,
28383
- {
28384
- control: form.control,
28385
- name: "note",
28386
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
28387
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
28388
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
27629
+ }
27630
+ ),
27631
+ canReadCustomers && /* @__PURE__ */ jsx(
27632
+ Form$2.Field,
27633
+ {
27634
+ control: form.control,
27635
+ name: "customer_id",
27636
+ render: ({ field }) => {
27637
+ return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
27638
+ /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Customer" }),
27639
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
27640
+ Combobox2,
27641
+ {
27642
+ value: field.value,
27643
+ onChange: field.onChange,
27644
+ searchValue,
27645
+ onSearchValueChange,
27646
+ options: customerOptions,
27647
+ placeholder: "Search for a customer...",
27648
+ fetchNextPage,
27649
+ isFetchingNextPage,
27650
+ noResultsPlaceholder: isLoading ? "Loading customers..." : "No customers found"
27651
+ }
27652
+ ) }),
28389
27653
  /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
28390
- ] })
27654
+ ] });
28391
27655
  }
28392
- )
28393
- ] }),
28394
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
28395
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
28396
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
28397
- ] }) })
28398
- ]
28399
- }
28400
- ) });
27656
+ }
27657
+ )
27658
+ ] })
27659
+ ] }) }) }),
27660
+ /* @__PURE__ */ jsxs(RouteFocusModal.Footer, { children: [
27661
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, disabled: isPending, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", disabled: isPending, children: "Cancel" }) }),
27662
+ /* @__PURE__ */ jsx(
27663
+ Button,
27664
+ {
27665
+ variant: "primary",
27666
+ size: "small",
27667
+ onClick: handleSubmit,
27668
+ disabled: isPending,
27669
+ children: "Create"
27670
+ }
27671
+ )
27672
+ ] })
27673
+ ] });
28401
27674
  };
28402
- const schema$2 = z.object({
28403
- note: z.string(),
28404
- amount: z.object({
28405
- float: z.number(),
28406
- value: z.string()
28407
- })
28408
- });
28409
- const handle$a = {
28410
- permissions: ["store_credit_account:read", "store_credit_account:update"]
27675
+ const StoreCreditAccountCreate = () => {
27676
+ return /* @__PURE__ */ jsxs(RouteFocusModal, { children: [
27677
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create Store Credit Account" }) }),
27678
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create a new store credit account" }) }),
27679
+ /* @__PURE__ */ jsx(StoreCreditAccountCreateForm, {})
27680
+ ] });
27681
+ };
27682
+ const handle$d = {
27683
+ permissions: ["store_credit_account:create"]
28411
27684
  };
28412
27685
  function _extends() {
28413
27686
  return _extends = Object.assign ? Object.assign.bind() : function(n2) {
@@ -31092,6 +30365,299 @@ const GiftCardOrderSection = ({ giftCard }) => {
31092
30365
  ))
31093
30366
  ] });
31094
30367
  };
30368
+ var __create = Object.create;
30369
+ var __defProp = Object.defineProperty;
30370
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
30371
+ var __getOwnPropNames = Object.getOwnPropertyNames;
30372
+ var __getProtoOf = Object.getPrototypeOf;
30373
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
30374
+ var __commonJS = (cb, mod) => function __require() {
30375
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
30376
+ };
30377
+ var __copyProps = (to, from, except, desc) => {
30378
+ if (from && typeof from === "object" || typeof from === "function") {
30379
+ for (let key2 of __getOwnPropNames(from))
30380
+ if (!__hasOwnProp.call(to, key2) && key2 !== except)
30381
+ __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
30382
+ }
30383
+ return to;
30384
+ };
30385
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30386
+ // If the importer is in node compatibility mode or this is not an ESM
30387
+ // file that has been converted to a CommonJS file using a Babel-
30388
+ // compatible transform (i.e. "__esModule" has not been set), then set
30389
+ // "default" to the CommonJS "module.exports" for node compatibility.
30390
+ __defProp(target, "default", { value: mod, enumerable: true }),
30391
+ mod
30392
+ ));
30393
+ var require_toggle_selection = __commonJS({
30394
+ "node_modules/toggle-selection/index.js"(exports, module) {
30395
+ module.exports = function() {
30396
+ var selection = document.getSelection();
30397
+ if (!selection.rangeCount) {
30398
+ return function() {
30399
+ };
30400
+ }
30401
+ var active = document.activeElement;
30402
+ var ranges = [];
30403
+ for (var i2 = 0; i2 < selection.rangeCount; i2++) {
30404
+ ranges.push(selection.getRangeAt(i2));
30405
+ }
30406
+ switch (active.tagName.toUpperCase()) {
30407
+ // .toUpperCase handles XHTML
30408
+ case "INPUT":
30409
+ case "TEXTAREA":
30410
+ active.blur();
30411
+ break;
30412
+ default:
30413
+ active = null;
30414
+ break;
30415
+ }
30416
+ selection.removeAllRanges();
30417
+ return function() {
30418
+ selection.type === "Caret" && selection.removeAllRanges();
30419
+ if (!selection.rangeCount) {
30420
+ ranges.forEach(function(range) {
30421
+ selection.addRange(range);
30422
+ });
30423
+ }
30424
+ active && active.focus();
30425
+ };
30426
+ };
30427
+ }
30428
+ });
30429
+ var import_index = __toESM(require_toggle_selection());
30430
+ var toggle_selection_default = import_index.default;
30431
+ var defaultMessage = "Copy to clipboard: #{key}, Enter";
30432
+ function formatPromptMessage(message2) {
30433
+ var isMac2 = navigator.userAgentData ? /mac/i.test(navigator.userAgentData.platform) : /mac os x/i.test(navigator.userAgent);
30434
+ var copyKey = (isMac2 ? "⌘" : "Ctrl") + "+C";
30435
+ return message2.replace(/#{\s*key\s*}/g, copyKey);
30436
+ }
30437
+ function buildClipboardItem(text2, format2) {
30438
+ var items = {};
30439
+ items["text/plain"] = new Blob([text2], { type: "text/plain" });
30440
+ if (format2 && format2 !== "text/plain") {
30441
+ items[format2] = new Blob([text2], { type: format2 });
30442
+ }
30443
+ return new ClipboardItem(items);
30444
+ }
30445
+ async function copyViaClipboardAPI(text2, options) {
30446
+ if (!options.format && !options.onCopy) {
30447
+ await navigator.clipboard.writeText(text2);
30448
+ return true;
30449
+ }
30450
+ var item = buildClipboardItem(text2, options.format);
30451
+ if (options.onCopy) {
30452
+ item = options.onCopy(item) || item;
30453
+ }
30454
+ await navigator.clipboard.write([item]);
30455
+ return true;
30456
+ }
30457
+ function createHiddenSpan(text2, options) {
30458
+ var mark = document.createElement("span");
30459
+ mark.textContent = text2;
30460
+ mark.ariaHidden = "true";
30461
+ mark.style.all = "unset";
30462
+ mark.style.position = "fixed";
30463
+ mark.style.top = "0";
30464
+ mark.style.clip = "rect(0, 0, 0, 0)";
30465
+ mark.style.whiteSpace = "pre";
30466
+ mark.style.webkitUserSelect = "text";
30467
+ mark.style.MozUserSelect = "text";
30468
+ mark.style.msUserSelect = "text";
30469
+ mark.style.userSelect = "text";
30470
+ mark.addEventListener("copy", function(e) {
30471
+ e.stopPropagation();
30472
+ if (options.format) {
30473
+ e.preventDefault();
30474
+ if (e.clipboardData) {
30475
+ e.clipboardData.setData(options.format, text2);
30476
+ }
30477
+ }
30478
+ if (options.onCopy && e.clipboardData) {
30479
+ options.onCopy(e.clipboardData);
30480
+ }
30481
+ });
30482
+ return mark;
30483
+ }
30484
+ function findOpenedModalDialog() {
30485
+ let element = document.activeElement;
30486
+ while (element) {
30487
+ if (element.tagName === "DIALOG" && element.open) {
30488
+ return element;
30489
+ }
30490
+ element = element.parentElement;
30491
+ }
30492
+ return null;
30493
+ }
30494
+ function copyViaExecCommand(text2, options) {
30495
+ var reselectPrevious = toggle_selection_default();
30496
+ var range = document.createRange();
30497
+ var selection = document.getSelection();
30498
+ var mark = createHiddenSpan(text2, options);
30499
+ var root = findOpenedModalDialog() || document.fullscreenElement || document.body;
30500
+ var success = false;
30501
+ try {
30502
+ root.appendChild(mark);
30503
+ range.selectNodeContents(mark);
30504
+ selection.removeAllRanges();
30505
+ selection.addRange(range);
30506
+ var successful = document.execCommand("copy");
30507
+ if (!successful) {
30508
+ throw new Error("copy command was unsuccessful");
30509
+ }
30510
+ success = true;
30511
+ } finally {
30512
+ if (typeof selection.removeRange == "function") {
30513
+ selection.removeRange(range);
30514
+ } else {
30515
+ selection.removeAllRanges();
30516
+ }
30517
+ root.removeChild(mark);
30518
+ reselectPrevious();
30519
+ }
30520
+ return success;
30521
+ }
30522
+ async function copy$1(text2, options = {}) {
30523
+ var debug2 = options.debug || false;
30524
+ if (window.isSecureContext && navigator.clipboard) {
30525
+ try {
30526
+ return await copyViaClipboardAPI(text2, options);
30527
+ } catch (err) {
30528
+ debug2 && console.error("unable to copy using navigator.clipboard: ", err);
30529
+ debug2 && console.warn("falling back to execCommand");
30530
+ }
30531
+ } else {
30532
+ debug2 && !window.isSecureContext && console.warn("copy-to-clipboard: navigator.clipboard requires a secure context (HTTPS/localhost). Falling back to execCommand.");
30533
+ }
30534
+ try {
30535
+ return copyViaExecCommand(text2, options);
30536
+ } catch (err) {
30537
+ debug2 && console.error("unable to copy using execCommand: ", err);
30538
+ debug2 && console.error("falling back to prompt");
30539
+ if (options.fallbackToPrompt) {
30540
+ var message2 = formatPromptMessage("message" in options ? options.message : defaultMessage);
30541
+ window.prompt(message2, text2);
30542
+ }
30543
+ }
30544
+ return false;
30545
+ }
30546
+ var index_default = copy$1;
30547
+ function DisplayId({ id, className }) {
30548
+ const [open2, setOpen] = useState(false);
30549
+ const onClick = () => {
30550
+ index_default(id);
30551
+ toast.success("Copied to clipboard");
30552
+ };
30553
+ return /* @__PURE__ */ jsx(Tooltip, { maxWidth: 260, content: id, open: open2, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs("span", { onClick, className: clx("cursor-pointer", className), children: [
30554
+ "#",
30555
+ id.slice(-7)
30556
+ ] }) });
30557
+ }
30558
+ const columnHelper$8 = createDataTableColumnHelper();
30559
+ const useTransactionsTableColumns = () => {
30560
+ return useMemo(() => {
30561
+ return [
30562
+ columnHelper$8.accessor("id", {
30563
+ header: "ID",
30564
+ cell: ({ row }) => {
30565
+ return /* @__PURE__ */ jsx(DisplayId, { id: row.original.id });
30566
+ }
30567
+ }),
30568
+ columnHelper$8.accessor("created_at", {
30569
+ header: "Created At",
30570
+ cell: ({ row }) => formatDate(row.original.created_at, false)
30571
+ }),
30572
+ columnHelper$8.accessor("note", {
30573
+ header: "Description",
30574
+ cell: ({ row }) => row.original.note
30575
+ }),
30576
+ columnHelper$8.accessor("note", {
30577
+ header: "Note",
30578
+ cell: ({ row }) => {
30579
+ return /* @__PURE__ */ jsx(Text, { title: row.original.note, className: "max-w-[300px] truncate", children: row.original.note || "-" });
30580
+ }
30581
+ }),
30582
+ columnHelper$8.accessor("amount", {
30583
+ header: "Amount",
30584
+ cell: ({ row }) => {
30585
+ const isDebit = row.original.type === "debit";
30586
+ return row.original.account.currency_code && formatAmount(
30587
+ row.original.amount * (isDebit ? -1 : 1),
30588
+ row.original.account.currency_code
30589
+ );
30590
+ }
30591
+ })
30592
+ ];
30593
+ }, []);
30594
+ };
30595
+ const useTransactionsTableFilters = ({}) => {
30596
+ const dateFilterOptions = useDataTableDateFilters$1();
30597
+ return useMemo(() => {
30598
+ return [...dateFilterOptions];
30599
+ }, [dateFilterOptions]);
30600
+ };
30601
+ const useTransactionsTableQuery = ({
30602
+ prefix,
30603
+ pageSize = 20
30604
+ }) => {
30605
+ const queryObject = useQueryParams(
30606
+ ["offset", "limit", "currency_code", "created_at", "updated_at"],
30607
+ prefix
30608
+ );
30609
+ const { offset: offset2, limit, created_at, updated_at, ...rest } = queryObject;
30610
+ const searchParams = {
30611
+ limit: limit ? Number(limit) : pageSize,
30612
+ offset: offset2 ? Number(offset2) : 0,
30613
+ created_at: created_at ? JSON.parse(created_at) : void 0,
30614
+ updated_at: updated_at ? JSON.parse(updated_at) : void 0,
30615
+ ...rest
30616
+ };
30617
+ return searchParams;
30618
+ };
30619
+ const PAGE_SIZE$4 = 10;
30620
+ function TransactionsTable({ id }) {
30621
+ const queryParams = useTransactionsTableQuery({
30622
+ pageSize: PAGE_SIZE$4
30623
+ });
30624
+ const { transactions, isLoading, count: count2 } = useStoreCreditAccountTransactions(
30625
+ id,
30626
+ {
30627
+ ...queryParams,
30628
+ order: queryParams.order ?? "-created_at",
30629
+ fields: "*account"
30630
+ }
30631
+ );
30632
+ const columns = useTransactionsTableColumns();
30633
+ const filters = useTransactionsTableFilters({});
30634
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
30635
+ /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
30636
+ DataTable,
30637
+ {
30638
+ data: transactions ?? [],
30639
+ getRowId: (row) => row.id,
30640
+ columns,
30641
+ filters,
30642
+ isLoading,
30643
+ pageSize: PAGE_SIZE$4,
30644
+ rowCount: count2,
30645
+ enableSearch: false,
30646
+ heading: "Transactions",
30647
+ emptyState: {
30648
+ empty: {
30649
+ heading: "No transactions found"
30650
+ },
30651
+ filtered: {
30652
+ heading: "No results found",
30653
+ description: "No transactions match your filter criteria."
30654
+ }
30655
+ }
30656
+ }
30657
+ ) }),
30658
+ /* @__PURE__ */ jsx(Outlet, {})
30659
+ ] });
30660
+ }
31095
30661
  const GiftCardTransactionsSection = ({
31096
30662
  storeCreditAccount
31097
30663
  }) => {
@@ -31143,9 +30709,36 @@ const GiftCardDetailsPage = () => {
31143
30709
  }
31144
30710
  );
31145
30711
  };
31146
- const handle$9 = {
30712
+ const handle$c = {
31147
30713
  permissions: ["gift_card:read"]
31148
30714
  };
30715
+ const KeyboundForm = React__default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
30716
+ const handleSubmit = (event) => {
30717
+ event.preventDefault();
30718
+ onSubmit?.(event);
30719
+ };
30720
+ const handleKeyDown = (event) => {
30721
+ if (event.key === "Enter") {
30722
+ if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
30723
+ return;
30724
+ }
30725
+ event.preventDefault();
30726
+ if (event.metaKey || event.ctrlKey) {
30727
+ handleSubmit(event);
30728
+ }
30729
+ }
30730
+ };
30731
+ return /* @__PURE__ */ jsx(
30732
+ "form",
30733
+ {
30734
+ ...rest,
30735
+ onSubmit: handleSubmit,
30736
+ onKeyDown: onKeyDown ?? handleKeyDown,
30737
+ ref
30738
+ }
30739
+ );
30740
+ });
30741
+ KeyboundForm.displayName = "KeyboundForm";
31149
30742
  const GiftCardExpiration = () => {
31150
30743
  const { id } = useParams();
31151
30744
  const { gift_card: giftCard, isPending, isError, error: error2 } = useGiftCard(id);
@@ -31166,7 +30759,7 @@ const GiftCardExpirationForm = ({ giftCard }) => {
31166
30759
  defaultValues: {
31167
30760
  expires_at: giftCard.expires_at ? new Date(giftCard.expires_at) : null
31168
30761
  },
31169
- resolver: u(schema$1)
30762
+ resolver: u(schema$3)
31170
30763
  });
31171
30764
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
31172
30765
  const { handleSuccess } = useRouteModal();
@@ -31261,13 +30854,13 @@ const GiftCardExpirationForm = ({ giftCard }) => {
31261
30854
  }
31262
30855
  ) });
31263
30856
  };
31264
- const schema$1 = z.object({
30857
+ const schema$3 = z.object({
31265
30858
  expires_at: z.date().nullish()
31266
30859
  });
31267
- const handle$8 = {
30860
+ const handle$b = {
31268
30861
  permissions: ["gift_card:read", "gift_card:update"]
31269
30862
  };
31270
- const Note = () => {
30863
+ const Note$1 = () => {
31271
30864
  const { id } = useParams();
31272
30865
  const {
31273
30866
  gift_card: giftCard,
@@ -31292,7 +30885,7 @@ const GiftCardNoteForm = ({ giftCard }) => {
31292
30885
  defaultValues: {
31293
30886
  note: giftCard.note ?? ""
31294
30887
  },
31295
- resolver: u(schema)
30888
+ resolver: u(schema$2)
31296
30889
  });
31297
30890
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
31298
30891
  const { handleSuccess } = useRouteModal();
@@ -31331,10 +30924,10 @@ const GiftCardNoteForm = ({ giftCard }) => {
31331
30924
  }
31332
30925
  ) });
31333
30926
  };
31334
- const schema = z.object({
30927
+ const schema$2 = z.object({
31335
30928
  note: z.string().optional()
31336
30929
  });
31337
- const handle$7 = {
30930
+ const handle$a = {
31338
30931
  permissions: ["gift_card:read", "gift_card:update"]
31339
30932
  };
31340
30933
  const columnHelper$7 = createColumnHelper();
@@ -45828,7 +45421,7 @@ const GiftCardProductCreate = () => {
45828
45421
  isPending: isStorePending,
45829
45422
  isError: isStoreError,
45830
45423
  error: storeError
45831
- } = useStore$1({
45424
+ } = useStore$2({
45832
45425
  fields: "+default_sales_channel"
45833
45426
  });
45834
45427
  const {
@@ -45880,7 +45473,7 @@ const GiftCardProductCreate = () => {
45880
45473
  )
45881
45474
  ] });
45882
45475
  };
45883
- const handle$6 = {
45476
+ const handle$9 = {
45884
45477
  permissions: [
45885
45478
  "product:create",
45886
45479
  "store:read",
@@ -45889,6 +45482,413 @@ const handle$6 = {
45889
45482
  "price_preference:read"
45890
45483
  ]
45891
45484
  };
45485
+ const StoreCreditAccountBalanceSection = ({
45486
+ storeCreditAccount
45487
+ }) => {
45488
+ if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
45489
+ return;
45490
+ }
45491
+ return /* @__PURE__ */ jsx(Container$1, { className: "grid grid-cols-2 gap-x-2 px-6 py-4", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-x-3", children: [
45492
+ /* @__PURE__ */ jsx("div", { className: "bg-ui-tag-green-icon h-8 w-1 rounded-full" }),
45493
+ /* @__PURE__ */ jsxs("div", { children: [
45494
+ /* @__PURE__ */ jsx(Text, { weight: "plus", size: "small", className: "text-ui-fg-subtle", children: "Current Balance" }),
45495
+ /* @__PURE__ */ jsx(
45496
+ Text,
45497
+ {
45498
+ weight: "plus",
45499
+ size: "xlarge",
45500
+ className: "tabular-nums text-ui-fg-base",
45501
+ children: formatAmount(
45502
+ storeCreditAccount.balance,
45503
+ storeCreditAccount.currency_code
45504
+ )
45505
+ }
45506
+ )
45507
+ ] })
45508
+ ] }) });
45509
+ };
45510
+ const StoreCreditAccountDetailsSection = ({
45511
+ storeCreditAccount
45512
+ }) => {
45513
+ const { hasPermission } = usePermissions();
45514
+ const canUpdate = hasPermission("store_credit_account:update");
45515
+ if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
45516
+ return;
45517
+ }
45518
+ return /* @__PURE__ */ jsxs(Container$1, { className: "flex justify-between gap-x-2 px-6 py-6", children: [
45519
+ /* @__PURE__ */ jsxs(
45520
+ Text,
45521
+ {
45522
+ weight: "plus",
45523
+ size: "xlarge",
45524
+ className: "text-ui-fg-base flex gap-x-4",
45525
+ children: [
45526
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
45527
+ /* @__PURE__ */ jsx(CreditCardIcon, { className: "inline" }),
45528
+ " "
45529
+ ] }),
45530
+ /* @__PURE__ */ jsxs("div", { children: [
45531
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle", children: [
45532
+ storeCreditAccount.currency_code.toUpperCase(),
45533
+ " Account"
45534
+ ] }),
45535
+ /* @__PURE__ */ jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsx(
45536
+ Text,
45537
+ {
45538
+ weight: "regular",
45539
+ size: "small",
45540
+ className: "text-ui-fg-base flex gap-x-4",
45541
+ children: /* @__PURE__ */ jsx(DisplayId, { id: storeCreditAccount.id })
45542
+ }
45543
+ ) })
45544
+ ] })
45545
+ ]
45546
+ }
45547
+ ),
45548
+ canUpdate && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-x-4", children: /* @__PURE__ */ jsx(
45549
+ ActionMenu,
45550
+ {
45551
+ groups: [
45552
+ {
45553
+ actions: [
45554
+ {
45555
+ icon: /* @__PURE__ */ jsx(CreditCard, {}),
45556
+ label: "Credit the account",
45557
+ to: "credit"
45558
+ },
45559
+ {
45560
+ icon: /* @__PURE__ */ jsx(MinusMini, {}),
45561
+ label: "Debit the account",
45562
+ to: "debit",
45563
+ disabled: !Number(storeCreditAccount.balance)
45564
+ }
45565
+ ]
45566
+ }
45567
+ ]
45568
+ }
45569
+ ) })
45570
+ ] });
45571
+ };
45572
+ function StoreCreditAccountCustomerSection({
45573
+ customerId
45574
+ }) {
45575
+ const { hasPermission } = usePermissions();
45576
+ const canReadCustomer = hasPermission("customer:read");
45577
+ const { customer, isPending } = useCustomer(customerId, void 0, {
45578
+ enabled: !!customerId && canReadCustomer
45579
+ });
45580
+ if (!canReadCustomer || isPending || !customer) {
45581
+ return null;
45582
+ }
45583
+ return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
45584
+ /* @__PURE__ */ jsx(Header$5, { title: "Customer" }),
45585
+ /* @__PURE__ */ jsx(
45586
+ SidebarLink,
45587
+ {
45588
+ icon: /* @__PURE__ */ jsx(User, {}),
45589
+ labelKey: customer.email || "N/A",
45590
+ descriptionKey: !customer.first_name && !customer.last_name ? "N/A" : `${customer.first_name} ${customer.last_name}`,
45591
+ to: `/customers/${customer.id}`
45592
+ },
45593
+ customer.id
45594
+ )
45595
+ ] });
45596
+ }
45597
+ function StoreCreditAccountCodeSection({ code }) {
45598
+ if (!code) {
45599
+ return null;
45600
+ }
45601
+ return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
45602
+ /* @__PURE__ */ jsx(Header$5, { title: "Account Code" }),
45603
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-4 px-6 mb-2", children: [
45604
+ /* @__PURE__ */ jsx(Share, { className: "inline" }),
45605
+ /* @__PURE__ */ jsx("div", { className: "text-ui-fg-subtle text-sm", children: code })
45606
+ ] })
45607
+ ] });
45608
+ }
45609
+ const StoreCreditAccountPage = () => {
45610
+ const { id } = useParams();
45611
+ const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
45612
+ id
45613
+ );
45614
+ if (!storeCreditAccount) {
45615
+ return;
45616
+ }
45617
+ return /* @__PURE__ */ jsx(
45618
+ LayoutComposer,
45619
+ {
45620
+ widgetsZonePrefix: "store_credit_account.details",
45621
+ preferredLayoutId: "core:two-column",
45622
+ data: storeCreditAccount,
45623
+ sections: {
45624
+ main: /* @__PURE__ */ jsxs(Fragment, { children: [
45625
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountDetailsSection", children: /* @__PURE__ */ jsx(
45626
+ StoreCreditAccountDetailsSection,
45627
+ {
45628
+ storeCreditAccount
45629
+ }
45630
+ ) }),
45631
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "TransactionsTable", children: /* @__PURE__ */ jsx(TransactionsTable, { id: storeCreditAccount.id }) })
45632
+ ] }),
45633
+ side: /* @__PURE__ */ jsxs(Fragment, { children: [
45634
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountBalanceSection", children: /* @__PURE__ */ jsx(
45635
+ StoreCreditAccountBalanceSection,
45636
+ {
45637
+ storeCreditAccount
45638
+ }
45639
+ ) }),
45640
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountCodeSection", children: /* @__PURE__ */ jsx(StoreCreditAccountCodeSection, { code: storeCreditAccount.code }) }),
45641
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountCustomerSection", children: /* @__PURE__ */ jsx(
45642
+ StoreCreditAccountCustomerSection,
45643
+ {
45644
+ customerId: storeCreditAccount.customer_id
45645
+ }
45646
+ ) })
45647
+ ] })
45648
+ }
45649
+ }
45650
+ );
45651
+ };
45652
+ const handle$8 = {
45653
+ permissions: ["store_credit_account:read"]
45654
+ };
45655
+ const Note = () => {
45656
+ const { id } = useParams();
45657
+ const {
45658
+ store_credit_account: storeCreditAccount,
45659
+ isPending,
45660
+ isError,
45661
+ error: error2
45662
+ } = useStoreCreditAccount(id, {});
45663
+ if (isError) {
45664
+ throw error2;
45665
+ }
45666
+ const isReady = !isPending && !!storeCreditAccount;
45667
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
45668
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
45669
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Credit store credit account" }) }),
45670
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Credit the store credit account" }) })
45671
+ ] }),
45672
+ isReady && /* @__PURE__ */ jsx(StoreCreditAccountCreditForm, { storeCreditAccount })
45673
+ ] });
45674
+ };
45675
+ const StoreCreditAccountCreditForm = ({
45676
+ storeCreditAccount
45677
+ }) => {
45678
+ const form = useForm({
45679
+ defaultValues: {
45680
+ amount: {
45681
+ float: 0,
45682
+ value: ""
45683
+ },
45684
+ note: ""
45685
+ },
45686
+ resolver: u(schema$1)
45687
+ });
45688
+ const { mutateAsync, isPending } = useCreditStoreCreditAccount(
45689
+ storeCreditAccount.id
45690
+ );
45691
+ const { handleSuccess } = useRouteModal();
45692
+ const onSubmit = form.handleSubmit(async (data) => {
45693
+ if (data.amount.float <= 0) {
45694
+ form.setError("amount", { message: "Amount must be greater than 0" });
45695
+ return;
45696
+ }
45697
+ await mutateAsync(
45698
+ { amount: data.amount.float, note: data.note },
45699
+ {
45700
+ onSuccess: () => handleSuccess(),
45701
+ onError: (error2) => toast.error(error2.message)
45702
+ }
45703
+ );
45704
+ });
45705
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
45706
+ KeyboundForm,
45707
+ {
45708
+ className: "flex flex-1 flex-col overflow-hidden",
45709
+ onSubmit,
45710
+ children: [
45711
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
45712
+ /* @__PURE__ */ jsx(
45713
+ Form$2.Field,
45714
+ {
45715
+ control: form.control,
45716
+ name: "amount",
45717
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
45718
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Amount" }),
45719
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
45720
+ CurrencyInput,
45721
+ {
45722
+ min: 0,
45723
+ placeholder: "0",
45724
+ value: field.value.value,
45725
+ onValueChange: (_value, _name, values) => {
45726
+ field.onChange({
45727
+ value: values?.value,
45728
+ float: values?.float || null
45729
+ });
45730
+ },
45731
+ symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
45732
+ code: storeCreditAccount.currency_code.toUpperCase()
45733
+ }
45734
+ ) }),
45735
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
45736
+ ] })
45737
+ }
45738
+ ),
45739
+ /* @__PURE__ */ jsx(
45740
+ Form$2.Field,
45741
+ {
45742
+ control: form.control,
45743
+ name: "note",
45744
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
45745
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
45746
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
45747
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
45748
+ ] })
45749
+ }
45750
+ )
45751
+ ] }),
45752
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
45753
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
45754
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
45755
+ ] }) })
45756
+ ]
45757
+ }
45758
+ ) });
45759
+ };
45760
+ const schema$1 = z.object({
45761
+ note: z.string(),
45762
+ amount: z.object({
45763
+ float: z.number(),
45764
+ value: z.string()
45765
+ })
45766
+ });
45767
+ const handle$7 = {
45768
+ permissions: ["store_credit_account:read", "store_credit_account:update"]
45769
+ };
45770
+ const Debit = () => {
45771
+ const { id } = useParams();
45772
+ const {
45773
+ store_credit_account: storeCreditAccount,
45774
+ isPending,
45775
+ isError,
45776
+ error: error2
45777
+ } = useStoreCreditAccount(id, {});
45778
+ if (isError) {
45779
+ throw error2;
45780
+ }
45781
+ const isReady = !isPending && !!storeCreditAccount;
45782
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
45783
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
45784
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Debit store credit account" }) }),
45785
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Debit the store credit account" }) })
45786
+ ] }),
45787
+ isReady && /* @__PURE__ */ jsx(StoreCreditAccountDebitForm, { storeCreditAccount })
45788
+ ] });
45789
+ };
45790
+ const StoreCreditAccountDebitForm = ({
45791
+ storeCreditAccount
45792
+ }) => {
45793
+ const form = useForm({
45794
+ defaultValues: {
45795
+ amount: {
45796
+ float: 0,
45797
+ value: ""
45798
+ },
45799
+ note: ""
45800
+ },
45801
+ resolver: u(schema)
45802
+ });
45803
+ const { mutateAsync, isPending } = useDebitStoreCreditAccount(
45804
+ storeCreditAccount.id
45805
+ );
45806
+ const { handleSuccess } = useRouteModal();
45807
+ const balance = storeCreditAccount.balance ?? 0;
45808
+ const onSubmit = form.handleSubmit(async (data) => {
45809
+ if (data.amount.float <= 0) {
45810
+ form.setError("amount", { message: "Amount must be greater than 0" });
45811
+ return;
45812
+ }
45813
+ if (data.amount.float > balance) {
45814
+ form.setError("amount", {
45815
+ message: "Amount can't be greater than the current balance"
45816
+ });
45817
+ return;
45818
+ }
45819
+ await mutateAsync(
45820
+ { amount: data.amount.float, note: data.note },
45821
+ {
45822
+ onSuccess: () => handleSuccess(),
45823
+ onError: (error2) => toast.error(error2.message)
45824
+ }
45825
+ );
45826
+ });
45827
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
45828
+ KeyboundForm,
45829
+ {
45830
+ className: "flex flex-1 flex-col overflow-hidden",
45831
+ onSubmit,
45832
+ children: [
45833
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
45834
+ /* @__PURE__ */ jsx(
45835
+ Form$2.Field,
45836
+ {
45837
+ control: form.control,
45838
+ name: "amount",
45839
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
45840
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Amount" }),
45841
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
45842
+ CurrencyInput,
45843
+ {
45844
+ min: 0,
45845
+ placeholder: "0",
45846
+ value: field.value.value,
45847
+ onValueChange: (_value, _name, values) => {
45848
+ field.onChange({
45849
+ value: values?.value,
45850
+ float: values?.float || null
45851
+ });
45852
+ },
45853
+ symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
45854
+ code: storeCreditAccount.currency_code.toUpperCase()
45855
+ }
45856
+ ) }),
45857
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
45858
+ ] })
45859
+ }
45860
+ ),
45861
+ /* @__PURE__ */ jsx(
45862
+ Form$2.Field,
45863
+ {
45864
+ control: form.control,
45865
+ name: "note",
45866
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
45867
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
45868
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
45869
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
45870
+ ] })
45871
+ }
45872
+ )
45873
+ ] }),
45874
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
45875
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
45876
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
45877
+ ] }) })
45878
+ ]
45879
+ }
45880
+ ) });
45881
+ };
45882
+ const schema = z.object({
45883
+ note: z.string(),
45884
+ amount: z.object({
45885
+ float: z.number(),
45886
+ value: z.string()
45887
+ })
45888
+ });
45889
+ const handle$6 = {
45890
+ permissions: ["store_credit_account:read", "store_credit_account:update"]
45891
+ };
45892
45892
  const productStatusColor = (status) => {
45893
45893
  switch (status) {
45894
45894
  case "draft":
@@ -47386,7 +47386,7 @@ const handle$2 = {
47386
47386
  };
47387
47387
  const VariantPricingForm = ({ form }) => {
47388
47388
  const { hasPermission } = usePermissions();
47389
- const { store } = useStore$1();
47389
+ const { store } = useStore$2();
47390
47390
  const { regions } = useRegions(
47391
47391
  { limit: 9999 },
47392
47392
  { enabled: hasPermission("region:read") }
@@ -47677,61 +47677,44 @@ const widgetModule = { widgets: [
47677
47677
  ] };
47678
47678
  const routeModule = {
47679
47679
  routes: [
47680
- {
47681
- Component: StoreCreditAccountsPage,
47682
- path: "/store-credit-accounts",
47683
- handle: { label: config$3.label, translationNs: config$3.translationNs, permissions: config$3.permissions },
47684
- children: [
47685
- {
47686
- Component: StoreCreditAccountCreate,
47687
- path: "/store-credit-accounts/create",
47688
- handle: handle$e
47689
- }
47690
- ]
47691
- },
47692
47680
  {
47693
47681
  Component: GiftCardsPage,
47694
47682
  path: "/gift-cards",
47695
- handle: { label: config$2.label, translationNs: config$2.translationNs, permissions: config$2.permissions },
47683
+ handle: { label: config$3.label, translationNs: config$3.translationNs, permissions: config$3.permissions },
47696
47684
  children: [
47697
47685
  {
47698
47686
  Component: GiftCardCreate,
47699
47687
  path: "/gift-cards/create",
47700
- handle: handle$d
47688
+ handle: handle$e
47701
47689
  }
47702
47690
  ]
47703
47691
  },
47704
47692
  {
47705
- Component: StoreCreditAccountPage,
47706
- path: "/store-credit-accounts/:id",
47707
- handle: handle$c,
47693
+ Component: StoreCreditAccountsPage,
47694
+ path: "/store-credit-accounts",
47695
+ handle: { label: config$1.label, translationNs: config$1.translationNs, permissions: config$1.permissions },
47708
47696
  children: [
47709
47697
  {
47710
- Component: Note$1,
47711
- path: "/store-credit-accounts/:id/credit",
47712
- handle: handle$b
47713
- },
47714
- {
47715
- Component: Debit,
47716
- path: "/store-credit-accounts/:id/debit",
47717
- handle: handle$a
47698
+ Component: StoreCreditAccountCreate,
47699
+ path: "/store-credit-accounts/create",
47700
+ handle: handle$d
47718
47701
  }
47719
47702
  ]
47720
47703
  },
47721
47704
  {
47722
47705
  Component: GiftCardDetailsPage,
47723
47706
  path: "/gift-cards/:id",
47724
- handle: handle$9,
47707
+ handle: handle$c,
47725
47708
  children: [
47726
47709
  {
47727
47710
  Component: GiftCardExpiration,
47728
47711
  path: "/gift-cards/:id/expiration",
47729
- handle: handle$8
47712
+ handle: handle$b
47730
47713
  },
47731
47714
  {
47732
- Component: Note,
47715
+ Component: Note$1,
47733
47716
  path: "/gift-cards/:id/note",
47734
- handle: handle$7
47717
+ handle: handle$a
47735
47718
  }
47736
47719
  ]
47737
47720
  },
@@ -47743,6 +47726,23 @@ const routeModule = {
47743
47726
  {
47744
47727
  Component: GiftCardProductCreate,
47745
47728
  path: "/gift-cards/gift-card-products/create",
47729
+ handle: handle$9
47730
+ }
47731
+ ]
47732
+ },
47733
+ {
47734
+ Component: StoreCreditAccountPage,
47735
+ path: "/store-credit-accounts/:id",
47736
+ handle: handle$8,
47737
+ children: [
47738
+ {
47739
+ Component: Note,
47740
+ path: "/store-credit-accounts/:id/credit",
47741
+ handle: handle$7
47742
+ },
47743
+ {
47744
+ Component: Debit,
47745
+ path: "/store-credit-accounts/:id/debit",
47746
47746
  handle: handle$6
47747
47747
  }
47748
47748
  ]
@@ -47784,22 +47784,22 @@ const routeModule = {
47784
47784
  const menuItemModule = {
47785
47785
  menuItems: [
47786
47786
  {
47787
- label: config$2.label,
47788
- icon: config$2.icon,
47787
+ label: config$3.label,
47788
+ icon: config$3.icon,
47789
47789
  path: "/gift-cards",
47790
47790
  nested: void 0,
47791
47791
  rank: void 0,
47792
47792
  translationNs: void 0,
47793
- permissions: config$2.permissions
47793
+ permissions: config$3.permissions
47794
47794
  },
47795
47795
  {
47796
- label: config$3.label,
47797
- icon: config$3.icon,
47796
+ label: config$1.label,
47797
+ icon: config$1.icon,
47798
47798
  path: "/store-credit-accounts",
47799
47799
  nested: void 0,
47800
47800
  rank: void 0,
47801
47801
  translationNs: void 0,
47802
- permissions: config$3.permissions
47802
+ permissions: config$1.permissions
47803
47803
  },
47804
47804
  {
47805
47805
  label: config.label,