@medusajs/loyalty-plugin 2.22.2-preview-20261029142542 → 2.22.2

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,16 +1,16 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
3
- import { DropdownMenu, IconButton, clx, Heading, Text, Tooltip, Button, Container as Container$1, StatusBadge, useDataTable, DataTable as DataTable$1, createDataTableFilterHelper, usePrompt, Checkbox, toast, 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";
3
+ import { DropdownMenu, IconButton, clx, Heading, Text, Tooltip, Button, Container as Container$1, StatusBadge, useDataTable, DataTable as DataTable$1, createDataTableFilterHelper, usePrompt, Checkbox, toast, 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
4
  import { Link, useParams, useSearchParams, useNavigate, Outlet, useBlocker, useLocation } from "react-router-dom";
5
5
  import * as React from "react";
6
6
  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";
7
- 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";
7
+ 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
8
  import { useQuery, useQueryClient, useMutation, useInfiniteQuery, keepPreviousData } from "@tanstack/react-query";
9
9
  import Medusa, { FetchError } from "@medusajs/js-sdk";
10
10
  import { LayoutComposer } from "@medusajs/dashboard/components";
11
- import { flushSync, createPortal, unstable_batchedUpdates } from "react-dom";
12
11
  import * as zod from "@medusajs/framework/zod";
13
12
  import { z } from "@medusajs/framework/zod";
13
+ import { flushSync, createPortal, unstable_batchedUpdates } from "react-dom";
14
14
  const ActionMenu = ({ groups }) => {
15
15
  return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
16
16
  /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { size: "small", variant: "transparent", children: /* @__PURE__ */ jsx(EllipsisHorizontal, {}) }) }),
@@ -5744,7 +5744,7 @@ defineWidgetConfig({
5744
5744
  zone: "sales_channel.details.after",
5745
5745
  id: "medusa:sales-channel-gift-cards-widget"
5746
5746
  });
5747
- const GiftCardIcon = (props) => {
5747
+ const StoreCreditIcon = (props) => {
5748
5748
  return /* @__PURE__ */ jsxs(
5749
5749
  "svg",
5750
5750
  {
@@ -5755,197 +5755,49 @@ const GiftCardIcon = (props) => {
5755
5755
  xmlns: "http://www.w3.org/2000/svg",
5756
5756
  ...props,
5757
5757
  children: [
5758
- /* @__PURE__ */ jsx("rect", { width: "15", height: "15", fill: "#F97316" }),
5758
+ /* @__PURE__ */ jsx("rect", { width: "15", height: "15", fill: "#8B5CF6" }),
5759
5759
  /* @__PURE__ */ jsx(
5760
5760
  "rect",
5761
5761
  {
5762
5762
  width: "15",
5763
5763
  height: "15",
5764
- fill: "url(#paint0_linear_28788_25808)",
5764
+ fill: "url(#paint0_linear_29181_44790)",
5765
5765
  fillOpacity: "0.2"
5766
5766
  }
5767
5767
  ),
5768
- /* @__PURE__ */ jsxs("g", { clipPath: "url(#clip0_28788_25808)", children: [
5769
- /* @__PURE__ */ jsx(
5770
- "path",
5771
- {
5772
- 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",
5773
- fill: "white"
5774
- }
5775
- ),
5776
- /* @__PURE__ */ jsx(
5777
- "path",
5778
- {
5779
- 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",
5780
- fill: "white"
5781
- }
5782
- ),
5783
- /* @__PURE__ */ jsx(
5784
- "path",
5785
- {
5786
- 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",
5787
- fill: "white"
5788
- }
5789
- ),
5790
- /* @__PURE__ */ jsx(
5791
- "path",
5792
- {
5793
- d: "M6.938 7.5H3.75V9.563C3.75 10.7 4.675 11.625 5.813 11.625H6.938V7.5Z",
5794
- fill: "white"
5795
- }
5796
- ),
5797
- /* @__PURE__ */ jsx(
5798
- "path",
5799
- {
5800
- d: "M8.063 7.5V11.625H9.188C10.325 11.625 11.25 10.7 11.25 9.563V7.5H8.063Z",
5801
- fill: "white"
5802
- }
5803
- )
5804
- ] }),
5805
- /* @__PURE__ */ jsxs("defs", { children: [
5806
- /* @__PURE__ */ jsxs(
5807
- "linearGradient",
5808
- {
5809
- id: "paint0_linear_28788_25808",
5810
- x1: "7.5",
5811
- y1: "0",
5812
- x2: "7.5",
5813
- y2: "15",
5814
- gradientUnits: "userSpaceOnUse",
5815
- children: [
5816
- /* @__PURE__ */ jsx("stop", { stopColor: "white" }),
5817
- /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
5818
- ]
5819
- }
5820
- ),
5821
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_28788_25808", children: /* @__PURE__ */ jsx("rect", { width: "9", height: "9", fill: "white", transform: "translate(3 3)" }) })
5822
- ] })
5768
+ /* @__PURE__ */ jsx(
5769
+ "path",
5770
+ {
5771
+ d: "M12 6V5.813C12 4.675 11.075 3.75 9.938 3.75H5.063C3.925 3.75 3 4.675 3 5.813V6H12Z",
5772
+ fill: "white"
5773
+ }
5774
+ ),
5775
+ /* @__PURE__ */ jsx(
5776
+ "path",
5777
+ {
5778
+ 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",
5779
+ fill: "white"
5780
+ }
5781
+ ),
5782
+ /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
5783
+ "linearGradient",
5784
+ {
5785
+ id: "paint0_linear_29181_44790",
5786
+ x1: "7.5",
5787
+ y1: "0",
5788
+ x2: "7.5",
5789
+ y2: "15",
5790
+ gradientUnits: "userSpaceOnUse",
5791
+ children: [
5792
+ /* @__PURE__ */ jsx("stop", { stopColor: "white" }),
5793
+ /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
5794
+ ]
5795
+ }
5796
+ ) })
5823
5797
  ]
5824
5798
  }
5825
5799
  );
5826
5800
  };
5827
- const GiftCardProductsSection = () => {
5828
- const { products: giftCardProducts, count: count2 = 0 } = useProducts({
5829
- is_giftcard: true
5830
- });
5831
- const slicedProducts = giftCardProducts?.slice(0, 3) ?? [];
5832
- return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
5833
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
5834
- /* @__PURE__ */ jsx(Header$5, { title: "Gift Card Products" }),
5835
- /* @__PURE__ */ jsx(
5836
- Link,
5837
- {
5838
- to: `/gift-cards/gift-card-products/create`,
5839
- className: "text-ui-fg-muted text-sm px-6",
5840
- children: "Create"
5841
- }
5842
- )
5843
- ] }),
5844
- giftCardProducts?.length === 0 && /* @__PURE__ */ jsx(
5845
- NoRecords,
5846
- {
5847
- className: "px-10 py-4 h-[200px]",
5848
- title: "No gift card products",
5849
- message: "There are no gift card products to show. Create one to get started.",
5850
- action: {
5851
- to: "/gift-cards/gift-card-products/create",
5852
- label: "Create gift card product"
5853
- }
5854
- }
5855
- ),
5856
- slicedProducts.map((giftCardProduct) => /* @__PURE__ */ jsx(
5857
- SidebarLink,
5858
- {
5859
- to: `/gift-cards/gift-card-products/${giftCardProduct.id}`,
5860
- labelKey: giftCardProduct.title,
5861
- descriptionKey: giftCardProduct.title,
5862
- icon: /* @__PURE__ */ jsx(Tag, {})
5863
- }
5864
- )),
5865
- count2 > 3 && /* @__PURE__ */ jsx(
5866
- Link,
5867
- {
5868
- to: "/gift-cards/gift-card-products",
5869
- className: "text-ui-fg-muted text-sm px-6 py-4 flex items-center justify-center",
5870
- children: "View more"
5871
- }
5872
- )
5873
- ] });
5874
- };
5875
- const _giftCardQueryKey = queryKeysFactory("gift-card");
5876
- const giftCardQueryKey = {
5877
- ..._giftCardQueryKey,
5878
- orders: (id) => [..._giftCardQueryKey.detail(id), "orders"]
5879
- };
5880
- const useGiftCards = (query, options) => {
5881
- const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
5882
- query: query2,
5883
- headers
5884
- });
5885
- const { data, ...rest } = useQuery({
5886
- ...options,
5887
- queryFn: () => fetchGiftCards(query),
5888
- queryKey: giftCardQueryKey.list(query)
5889
- });
5890
- return { ...data, ...rest };
5891
- };
5892
- const useGiftCard = (id, query, options) => {
5893
- const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
5894
- query: query2,
5895
- headers
5896
- });
5897
- const { data, ...rest } = useQuery({
5898
- queryFn: () => fetchGiftCard(id, query),
5899
- queryKey: giftCardQueryKey.detail(id, query),
5900
- ...options
5901
- });
5902
- return { ...data, ...rest };
5903
- };
5904
- const useGiftCardOrders = (id, options) => {
5905
- const fetchGiftCardOrders = (id2, query, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}/orders`, {
5906
- query,
5907
- headers
5908
- });
5909
- const { data, ...rest } = useQuery({
5910
- queryFn: () => fetchGiftCardOrders(id),
5911
- queryKey: giftCardQueryKey.orders(id),
5912
- ...options
5913
- });
5914
- return { ...data, ...rest };
5915
- };
5916
- const useUpdateGiftCard = (id, options) => {
5917
- const queryClient = useQueryClient();
5918
- const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
5919
- body,
5920
- method: "POST"
5921
- });
5922
- return useMutation({
5923
- mutationFn: async (payload) => updateGiftCard(id, payload),
5924
- onSuccess: (data, variables, context) => {
5925
- queryClient.invalidateQueries({
5926
- queryKey: giftCardQueryKey.detail(id)
5927
- });
5928
- queryClient.invalidateQueries({
5929
- queryKey: giftCardQueryKey.lists()
5930
- });
5931
- },
5932
- ...options
5933
- });
5934
- };
5935
- const useCreateGiftCard = (options) => {
5936
- const queryClient = useQueryClient();
5937
- const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
5938
- body,
5939
- method: "POST"
5940
- });
5941
- return useMutation({
5942
- mutationFn: (body) => createGiftCard(body),
5943
- onSuccess: (data, variables, context) => {
5944
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
5945
- },
5946
- ...options
5947
- });
5948
- };
5949
5801
  function getRelativeDate(date2) {
5950
5802
  const now = /* @__PURE__ */ new Date();
5951
5803
  return formatDistance(sub(new Date(date2), { minutes: 0 }), now, {
@@ -5963,30 +5815,51 @@ function formatDate(date2, withTime = true) {
5963
5815
  return format(new Date(date2), "dd MMM, yyyy");
5964
5816
  }
5965
5817
  const columnHelper$a = createDataTableColumnHelper();
5966
- const useGiftCardTableColumns = () => {
5818
+ const useStoreCreditAccountTableColumns = () => {
5967
5819
  return useMemo(() => {
5968
5820
  return [
5969
- columnHelper$a.accessor("code", {
5970
- header: "Code",
5821
+ columnHelper$a.accessor("currency_code", {
5822
+ header: "Currency",
5971
5823
  cell: ({ row }) => {
5972
- return row.original.code;
5824
+ return /* @__PURE__ */ jsx(Badge, { size: "2xsmall", children: row.original.currency_code.toUpperCase() });
5973
5825
  }
5974
5826
  }),
5975
- columnHelper$a.accessor("line_item.product.title", {
5976
- header: "Product",
5827
+ columnHelper$a.accessor("customer.email", {
5828
+ header: "Customer",
5977
5829
  cell: ({ row }) => {
5978
- return row.original.line_item?.product?.title || "Custom Gift Card";
5830
+ return row.original.customer?.email ?? "N/A";
5979
5831
  }
5980
5832
  }),
5981
- columnHelper$a.accessor("created_at", {
5982
- header: "Date issued",
5983
- cell: ({ row }) => getRelativeDate(row.original.created_at)
5833
+ columnHelper$a.accessor("balance", {
5834
+ header: "Balance",
5835
+ cell: ({ row }) => {
5836
+ return formatAmount(
5837
+ row.original.balance,
5838
+ row.original.currency_code
5839
+ );
5840
+ }
5984
5841
  }),
5985
- columnHelper$a.accessor("value", {
5986
- header: "Value",
5842
+ columnHelper$a.accessor("credits", {
5843
+ header: "Credits",
5987
5844
  cell: ({ row }) => {
5988
- return formatAmount(row.original.value, row.original.currency_code);
5845
+ return formatAmount(
5846
+ row.original.credits,
5847
+ row.original.currency_code
5848
+ );
5849
+ }
5850
+ }),
5851
+ columnHelper$a.accessor("debits", {
5852
+ header: "Debits",
5853
+ cell: ({ row }) => {
5854
+ return formatAmount(
5855
+ row.original.debits,
5856
+ row.original.currency_code
5857
+ );
5989
5858
  }
5859
+ }),
5860
+ columnHelper$a.accessor("created_at", {
5861
+ header: "Created at",
5862
+ cell: ({ row }) => getRelativeDate(row.original.created_at)
5990
5863
  })
5991
5864
  ];
5992
5865
  }, []);
@@ -6033,75 +5906,83 @@ const useCustomerFilters = () => {
6033
5906
  ];
6034
5907
  }, [customerFilterOptions]);
6035
5908
  };
6036
- const useGiftCardFilters = () => {
5909
+ const useStoreCreditAccountFilters = () => {
6037
5910
  const dateFilterOptions = useDataTableDateFilters$1();
6038
5911
  const customerFilterOptions = useCustomerFilters();
6039
5912
  return useMemo(() => {
6040
5913
  return [...dateFilterOptions, ...customerFilterOptions];
6041
5914
  }, [dateFilterOptions, customerFilterOptions]);
6042
5915
  };
6043
- const useGiftCardTableQuery = ({
5916
+ const useStoreCreditAccountsTableQuery = ({
6044
5917
  prefix,
6045
5918
  pageSize = 20
6046
5919
  }) => {
6047
5920
  const queryObject = useQueryParams(
6048
- ["q", "offset", "customer_id", "created_at", "updated_at"],
5921
+ ["offset", "customer_id", "currency_code", "created_at", "updated_at"],
6049
5922
  prefix
6050
5923
  );
6051
- const { offset: offset2, created_at, updated_at, customer_id, ...rest } = queryObject;
5924
+ const {
5925
+ offset: offset2,
5926
+ created_at,
5927
+ updated_at,
5928
+ customer_id,
5929
+ currency_code,
5930
+ ...rest
5931
+ } = queryObject;
6052
5932
  const searchParams = {
6053
5933
  limit: pageSize,
6054
5934
  offset: offset2 ? Number(offset2) : 0,
6055
5935
  created_at: created_at ? JSON.parse(created_at) : void 0,
6056
5936
  updated_at: updated_at ? JSON.parse(updated_at) : void 0,
6057
5937
  customer_id: customer_id ? JSON.parse(customer_id) : void 0,
5938
+ currency_code: currency_code ? JSON.parse(currency_code) : void 0,
6058
5939
  ...rest
6059
5940
  };
6060
5941
  return searchParams;
6061
5942
  };
6062
5943
  const PAGE_SIZE$6 = 10;
6063
- function GiftCardsTable() {
6064
- const queryParams = useGiftCardTableQuery({
5944
+ function StoreCreditAccountsTable() {
5945
+ const queryParams = useStoreCreditAccountsTableQuery({
6065
5946
  pageSize: PAGE_SIZE$6
6066
5947
  });
6067
5948
  const {
6068
- gift_cards: giftCards,
5949
+ store_credit_accounts: storeCreditAccounts,
6069
5950
  isPending,
6070
5951
  count: count2
6071
- } = useGiftCards({
5952
+ } = useStoreCreditAccounts({
6072
5953
  ...queryParams,
6073
- order: queryParams.order ?? "-created_at",
6074
- fields: "+line_item.product.title"
5954
+ order: queryParams.order ?? "-created_at"
6075
5955
  });
6076
- const columns = useGiftCardTableColumns();
6077
- const filters = useGiftCardFilters();
5956
+ const columns = useStoreCreditAccountTableColumns();
5957
+ const filters = useStoreCreditAccountFilters();
6078
5958
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
6079
5959
  /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
6080
5960
  DataTable,
6081
5961
  {
6082
- data: giftCards,
5962
+ data: storeCreditAccounts ?? [],
6083
5963
  getRowId: (row) => row.id,
6084
5964
  columns,
6085
5965
  filters,
6086
5966
  isLoading: isPending,
6087
5967
  pageSize: PAGE_SIZE$6,
6088
5968
  rowCount: count2,
6089
- heading: "Gift Cards",
5969
+ enableSearch: false,
5970
+ heading: "Store Credit Accounts",
6090
5971
  rowHref: (row) => `${row.id}`,
6091
5972
  emptyState: {
6092
5973
  empty: {
6093
- heading: "No gift cards found",
6094
- description: "Create a gift card to get started."
5974
+ heading: "No store credit accounts found",
5975
+ description: "Create a new store credit account to get started."
6095
5976
  },
6096
5977
  filtered: {
6097
5978
  heading: "No results found",
6098
- description: "No gift cards match your filter criteria."
5979
+ description: "No store credit accounts match your filter criteria."
6099
5980
  }
6100
5981
  },
6101
5982
  actions: [
6102
5983
  {
6103
5984
  label: "Create",
6104
- to: "create"
5985
+ to: "/store-credit-accounts/create"
6105
5986
  }
6106
5987
  ]
6107
5988
  }
@@ -6109,16 +5990,15 @@ function GiftCardsTable() {
6109
5990
  /* @__PURE__ */ jsx(Outlet, {})
6110
5991
  ] });
6111
5992
  }
6112
- const GiftCardsPage = () => {
5993
+ const StoreCreditAccountsPage = () => {
6113
5994
  return /* @__PURE__ */ jsxs(Fragment, { children: [
6114
5995
  /* @__PURE__ */ jsx(
6115
5996
  LayoutComposer,
6116
5997
  {
6117
- widgetsZonePrefix: "gift_card.list",
6118
- preferredLayoutId: "core:two-column",
5998
+ widgetsZonePrefix: "store_credit_account.list",
5999
+ preferredLayoutId: "core:single-column",
6119
6000
  sections: {
6120
- main: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "GiftCardsTable", children: /* @__PURE__ */ jsx(GiftCardsTable, {}) }),
6121
- side: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "GiftCardProductsSection", children: /* @__PURE__ */ jsx(GiftCardProductsSection, {}) })
6001
+ main: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountsTable", children: /* @__PURE__ */ jsx(StoreCreditAccountsTable, {}) })
6122
6002
  }
6123
6003
  }
6124
6004
  ),
@@ -6126,8 +6006,8 @@ const GiftCardsPage = () => {
6126
6006
  ] });
6127
6007
  };
6128
6008
  const config$3 = defineRouteConfig({
6129
- label: "Gift Cards",
6130
- icon: GiftCardIcon
6009
+ label: "Store Credits",
6010
+ icon: StoreCreditIcon
6131
6011
  });
6132
6012
  function setRef$2(ref, value) {
6133
6013
  if (typeof ref === "function") {
@@ -10822,27 +10702,6 @@ const StackedFocusModal = Object.assign(Root, {
10822
10702
  Description,
10823
10703
  Title
10824
10704
  });
10825
- const STORE_QUERY_KEY = "store";
10826
- const storeQueryKeys = queryKeysFactory(STORE_QUERY_KEY);
10827
- async function retrieveActiveStore(query) {
10828
- const response = await sdk.admin.store.list(query);
10829
- const activeStore = response.stores?.[0];
10830
- if (!activeStore) {
10831
- throw new FetchError("No active store found", "Not Found", 404);
10832
- }
10833
- return { store: activeStore };
10834
- }
10835
- const useStore$2 = (query, options) => {
10836
- const { data, ...rest } = useQuery({
10837
- queryFn: () => retrieveActiveStore(query),
10838
- queryKey: storeQueryKeys.details(),
10839
- ...options
10840
- });
10841
- return {
10842
- ...data,
10843
- ...rest
10844
- };
10845
- };
10846
10705
  const t$1 = (r, t2, s2) => {
10847
10706
  if (r && "reportValidity" in r) {
10848
10707
  const o2 = get$2(s2, t2);
@@ -13888,7 +13747,7 @@ function useStoreProps(store, props, key2, setKey) {
13888
13747
  });
13889
13748
  });
13890
13749
  }
13891
- function useStore$1(createStore2, props) {
13750
+ function useStore$2(createStore2, props) {
13892
13751
  const [store, setStore] = React.useState(() => createStore2(props));
13893
13752
  useSafeLayoutEffect(() => init(store), [store]);
13894
13753
  const useState2 = React.useCallback((keyOrSelector) => useStoreState(store, keyOrSelector), [store]);
@@ -14845,7 +14704,7 @@ function useDisclosureStoreProps(store, update, props) {
14845
14704
  return Object.assign(store, { disclosure: props.disclosure });
14846
14705
  }
14847
14706
  function useDisclosureStore(props = {}) {
14848
- const [store, update] = useStore$1(createDisclosureStore, props);
14707
+ const [store, update] = useStore$2(createDisclosureStore, props);
14849
14708
  return useDisclosureStoreProps(store, update, props);
14850
14709
  }
14851
14710
  const ctx$2 = createStoreContext([DialogContextProvider], [DialogScopedContextProvider]);
@@ -15654,7 +15513,7 @@ function useDialogStoreProps(store, update, props) {
15654
15513
  return useDisclosureStoreProps(store, update, props);
15655
15514
  }
15656
15515
  function useDialogStore(props = {}) {
15657
- const [store, update] = useStore$1(createDialogStore, props);
15516
+ const [store, update] = useStore$2(createDialogStore, props);
15658
15517
  return useDialogStoreProps(store, update, props);
15659
15518
  }
15660
15519
  function isHiddenDismiss(element, ...ids2) {
@@ -18970,7 +18829,7 @@ function useComboboxStoreProps(store, update, props) {
18970
18829
  }
18971
18830
  function useComboboxStore(props = {}) {
18972
18831
  props = useComboboxStoreOptions(props);
18973
- const [store, update] = useStore$1(createComboboxStore, props);
18832
+ const [store, update] = useStore$2(createComboboxStore, props);
18974
18833
  return useComboboxStoreProps(store, update, props);
18975
18834
  }
18976
18835
  function ComboboxProvider(props = {}) {
@@ -20089,6 +19948,369 @@ const ComboboxImpl = ({
20089
19948
  );
20090
19949
  };
20091
19950
  const Combobox2 = genericForwardRef(ComboboxImpl);
19951
+ var isObject_1;
19952
+ var hasRequiredIsObject;
19953
+ function requireIsObject() {
19954
+ if (hasRequiredIsObject) return isObject_1;
19955
+ hasRequiredIsObject = 1;
19956
+ function isObject2(value) {
19957
+ var type = typeof value;
19958
+ return value != null && (type == "object" || type == "function");
19959
+ }
19960
+ isObject_1 = isObject2;
19961
+ return isObject_1;
19962
+ }
19963
+ var _freeGlobal;
19964
+ var hasRequired_freeGlobal;
19965
+ function require_freeGlobal() {
19966
+ if (hasRequired_freeGlobal) return _freeGlobal;
19967
+ hasRequired_freeGlobal = 1;
19968
+ var freeGlobal = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
19969
+ _freeGlobal = freeGlobal;
19970
+ return _freeGlobal;
19971
+ }
19972
+ var _root;
19973
+ var hasRequired_root;
19974
+ function require_root() {
19975
+ if (hasRequired_root) return _root;
19976
+ hasRequired_root = 1;
19977
+ var freeGlobal = require_freeGlobal();
19978
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
19979
+ var root = freeGlobal || freeSelf || Function("return this")();
19980
+ _root = root;
19981
+ return _root;
19982
+ }
19983
+ var now_1;
19984
+ var hasRequiredNow;
19985
+ function requireNow() {
19986
+ if (hasRequiredNow) return now_1;
19987
+ hasRequiredNow = 1;
19988
+ var root = require_root();
19989
+ var now = function() {
19990
+ return root.Date.now();
19991
+ };
19992
+ now_1 = now;
19993
+ return now_1;
19994
+ }
19995
+ var _trimmedEndIndex;
19996
+ var hasRequired_trimmedEndIndex;
19997
+ function require_trimmedEndIndex() {
19998
+ if (hasRequired_trimmedEndIndex) return _trimmedEndIndex;
19999
+ hasRequired_trimmedEndIndex = 1;
20000
+ var reWhitespace = /\s/;
20001
+ function trimmedEndIndex(string2) {
20002
+ var index = string2.length;
20003
+ while (index-- && reWhitespace.test(string2.charAt(index))) {
20004
+ }
20005
+ return index;
20006
+ }
20007
+ _trimmedEndIndex = trimmedEndIndex;
20008
+ return _trimmedEndIndex;
20009
+ }
20010
+ var _baseTrim;
20011
+ var hasRequired_baseTrim;
20012
+ function require_baseTrim() {
20013
+ if (hasRequired_baseTrim) return _baseTrim;
20014
+ hasRequired_baseTrim = 1;
20015
+ var trimmedEndIndex = require_trimmedEndIndex();
20016
+ var reTrimStart = /^\s+/;
20017
+ function baseTrim(string2) {
20018
+ return string2 ? string2.slice(0, trimmedEndIndex(string2) + 1).replace(reTrimStart, "") : string2;
20019
+ }
20020
+ _baseTrim = baseTrim;
20021
+ return _baseTrim;
20022
+ }
20023
+ var _Symbol;
20024
+ var hasRequired_Symbol;
20025
+ function require_Symbol() {
20026
+ if (hasRequired_Symbol) return _Symbol;
20027
+ hasRequired_Symbol = 1;
20028
+ var root = require_root();
20029
+ var Symbol2 = root.Symbol;
20030
+ _Symbol = Symbol2;
20031
+ return _Symbol;
20032
+ }
20033
+ var _getRawTag;
20034
+ var hasRequired_getRawTag;
20035
+ function require_getRawTag() {
20036
+ if (hasRequired_getRawTag) return _getRawTag;
20037
+ hasRequired_getRawTag = 1;
20038
+ var Symbol2 = require_Symbol();
20039
+ var objectProto = Object.prototype;
20040
+ var hasOwnProperty2 = objectProto.hasOwnProperty;
20041
+ var nativeObjectToString = objectProto.toString;
20042
+ var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
20043
+ function getRawTag(value) {
20044
+ var isOwn = hasOwnProperty2.call(value, symToStringTag), tag = value[symToStringTag];
20045
+ try {
20046
+ value[symToStringTag] = void 0;
20047
+ var unmasked = true;
20048
+ } catch (e) {
20049
+ }
20050
+ var result = nativeObjectToString.call(value);
20051
+ if (unmasked) {
20052
+ if (isOwn) {
20053
+ value[symToStringTag] = tag;
20054
+ } else {
20055
+ delete value[symToStringTag];
20056
+ }
20057
+ }
20058
+ return result;
20059
+ }
20060
+ _getRawTag = getRawTag;
20061
+ return _getRawTag;
20062
+ }
20063
+ var _objectToString;
20064
+ var hasRequired_objectToString;
20065
+ function require_objectToString() {
20066
+ if (hasRequired_objectToString) return _objectToString;
20067
+ hasRequired_objectToString = 1;
20068
+ var objectProto = Object.prototype;
20069
+ var nativeObjectToString = objectProto.toString;
20070
+ function objectToString(value) {
20071
+ return nativeObjectToString.call(value);
20072
+ }
20073
+ _objectToString = objectToString;
20074
+ return _objectToString;
20075
+ }
20076
+ var _baseGetTag;
20077
+ var hasRequired_baseGetTag;
20078
+ function require_baseGetTag() {
20079
+ if (hasRequired_baseGetTag) return _baseGetTag;
20080
+ hasRequired_baseGetTag = 1;
20081
+ var Symbol2 = require_Symbol(), getRawTag = require_getRawTag(), objectToString = require_objectToString();
20082
+ var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
20083
+ var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
20084
+ function baseGetTag(value) {
20085
+ if (value == null) {
20086
+ return value === void 0 ? undefinedTag : nullTag;
20087
+ }
20088
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
20089
+ }
20090
+ _baseGetTag = baseGetTag;
20091
+ return _baseGetTag;
20092
+ }
20093
+ var isObjectLike_1;
20094
+ var hasRequiredIsObjectLike;
20095
+ function requireIsObjectLike() {
20096
+ if (hasRequiredIsObjectLike) return isObjectLike_1;
20097
+ hasRequiredIsObjectLike = 1;
20098
+ function isObjectLike(value) {
20099
+ return value != null && typeof value == "object";
20100
+ }
20101
+ isObjectLike_1 = isObjectLike;
20102
+ return isObjectLike_1;
20103
+ }
20104
+ var isSymbol_1;
20105
+ var hasRequiredIsSymbol;
20106
+ function requireIsSymbol() {
20107
+ if (hasRequiredIsSymbol) return isSymbol_1;
20108
+ hasRequiredIsSymbol = 1;
20109
+ var baseGetTag = require_baseGetTag(), isObjectLike = requireIsObjectLike();
20110
+ var symbolTag = "[object Symbol]";
20111
+ function isSymbol(value) {
20112
+ return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
20113
+ }
20114
+ isSymbol_1 = isSymbol;
20115
+ return isSymbol_1;
20116
+ }
20117
+ var toNumber_1;
20118
+ var hasRequiredToNumber;
20119
+ function requireToNumber() {
20120
+ if (hasRequiredToNumber) return toNumber_1;
20121
+ hasRequiredToNumber = 1;
20122
+ var baseTrim = require_baseTrim(), isObject2 = requireIsObject(), isSymbol = requireIsSymbol();
20123
+ var NAN = 0 / 0;
20124
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
20125
+ var reIsBinary = /^0b[01]+$/i;
20126
+ var reIsOctal = /^0o[0-7]+$/i;
20127
+ var freeParseInt = parseInt;
20128
+ function toNumber(value) {
20129
+ if (typeof value == "number") {
20130
+ return value;
20131
+ }
20132
+ if (isSymbol(value)) {
20133
+ return NAN;
20134
+ }
20135
+ if (isObject2(value)) {
20136
+ var other = typeof value.valueOf == "function" ? value.valueOf() : value;
20137
+ value = isObject2(other) ? other + "" : other;
20138
+ }
20139
+ if (typeof value != "string") {
20140
+ return value === 0 ? value : +value;
20141
+ }
20142
+ value = baseTrim(value);
20143
+ var isBinary = reIsBinary.test(value);
20144
+ return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
20145
+ }
20146
+ toNumber_1 = toNumber;
20147
+ return toNumber_1;
20148
+ }
20149
+ var debounce_1;
20150
+ var hasRequiredDebounce;
20151
+ function requireDebounce() {
20152
+ if (hasRequiredDebounce) return debounce_1;
20153
+ hasRequiredDebounce = 1;
20154
+ var isObject2 = requireIsObject(), now = requireNow(), toNumber = requireToNumber();
20155
+ var FUNC_ERROR_TEXT = "Expected a function";
20156
+ var nativeMax = Math.max, nativeMin = Math.min;
20157
+ function debounce2(func, wait, options) {
20158
+ var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
20159
+ if (typeof func != "function") {
20160
+ throw new TypeError(FUNC_ERROR_TEXT);
20161
+ }
20162
+ wait = toNumber(wait) || 0;
20163
+ if (isObject2(options)) {
20164
+ leading = !!options.leading;
20165
+ maxing = "maxWait" in options;
20166
+ maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
20167
+ trailing = "trailing" in options ? !!options.trailing : trailing;
20168
+ }
20169
+ function invokeFunc(time2) {
20170
+ var args = lastArgs, thisArg = lastThis;
20171
+ lastArgs = lastThis = void 0;
20172
+ lastInvokeTime = time2;
20173
+ result = func.apply(thisArg, args);
20174
+ return result;
20175
+ }
20176
+ function leadingEdge(time2) {
20177
+ lastInvokeTime = time2;
20178
+ timerId = setTimeout(timerExpired, wait);
20179
+ return leading ? invokeFunc(time2) : result;
20180
+ }
20181
+ function remainingWait(time2) {
20182
+ var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
20183
+ return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
20184
+ }
20185
+ function shouldInvoke(time2) {
20186
+ var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime;
20187
+ return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
20188
+ }
20189
+ function timerExpired() {
20190
+ var time2 = now();
20191
+ if (shouldInvoke(time2)) {
20192
+ return trailingEdge(time2);
20193
+ }
20194
+ timerId = setTimeout(timerExpired, remainingWait(time2));
20195
+ }
20196
+ function trailingEdge(time2) {
20197
+ timerId = void 0;
20198
+ if (trailing && lastArgs) {
20199
+ return invokeFunc(time2);
20200
+ }
20201
+ lastArgs = lastThis = void 0;
20202
+ return result;
20203
+ }
20204
+ function cancel() {
20205
+ if (timerId !== void 0) {
20206
+ clearTimeout(timerId);
20207
+ }
20208
+ lastInvokeTime = 0;
20209
+ lastArgs = lastCallTime = lastThis = timerId = void 0;
20210
+ }
20211
+ function flush() {
20212
+ return timerId === void 0 ? result : trailingEdge(now());
20213
+ }
20214
+ function debounced() {
20215
+ var time2 = now(), isInvoking = shouldInvoke(time2);
20216
+ lastArgs = arguments;
20217
+ lastThis = this;
20218
+ lastCallTime = time2;
20219
+ if (isInvoking) {
20220
+ if (timerId === void 0) {
20221
+ return leadingEdge(lastCallTime);
20222
+ }
20223
+ if (maxing) {
20224
+ clearTimeout(timerId);
20225
+ timerId = setTimeout(timerExpired, wait);
20226
+ return invokeFunc(lastCallTime);
20227
+ }
20228
+ }
20229
+ if (timerId === void 0) {
20230
+ timerId = setTimeout(timerExpired, wait);
20231
+ }
20232
+ return result;
20233
+ }
20234
+ debounced.cancel = cancel;
20235
+ debounced.flush = flush;
20236
+ return debounced;
20237
+ }
20238
+ debounce_1 = debounce2;
20239
+ return debounce_1;
20240
+ }
20241
+ var debounceExports = requireDebounce();
20242
+ const debounce$1 = /* @__PURE__ */ getDefaultExportFromCjs(debounceExports);
20243
+ const useDebouncedSearch = () => {
20244
+ const [searchValue, onSearchValueChange] = useState("");
20245
+ const [debouncedQuery, setDebouncedQuery] = useState("");
20246
+ const debouncedUpdate = useCallback(
20247
+ debounce$1((query) => setDebouncedQuery(query), 300),
20248
+ []
20249
+ );
20250
+ useEffect(() => {
20251
+ debouncedUpdate(searchValue);
20252
+ return () => debouncedUpdate.cancel();
20253
+ }, [searchValue, debouncedUpdate]);
20254
+ return {
20255
+ searchValue,
20256
+ onSearchValueChange,
20257
+ query: debouncedQuery || void 0
20258
+ };
20259
+ };
20260
+ const useComboboxData = ({
20261
+ queryKey,
20262
+ queryFn,
20263
+ getOptions,
20264
+ defaultValue: defaultValue2,
20265
+ defaultValueKey,
20266
+ pageSize = 10
20267
+ }) => {
20268
+ const { searchValue, onSearchValueChange, query } = useDebouncedSearch();
20269
+ const queryInitialDataBy = defaultValueKey || "id";
20270
+ const { data: initialData } = useQuery({
20271
+ queryKey,
20272
+ queryFn: async () => {
20273
+ return queryFn({
20274
+ [queryInitialDataBy]: defaultValue2,
20275
+ limit: Array.isArray(defaultValue2) ? defaultValue2.length : 1
20276
+ });
20277
+ },
20278
+ enabled: !!defaultValue2
20279
+ });
20280
+ const { data, ...rest } = useInfiniteQuery({
20281
+ queryKey: [...queryKey, query],
20282
+ queryFn: async ({ pageParam = 0 }) => {
20283
+ return await queryFn({
20284
+ q: query,
20285
+ limit: pageSize,
20286
+ offset: pageParam
20287
+ });
20288
+ },
20289
+ initialPageParam: 0,
20290
+ getNextPageParam: (lastPage) => {
20291
+ const moreItemsExist = lastPage.count > lastPage.offset + lastPage.limit;
20292
+ return moreItemsExist ? lastPage.offset + lastPage.limit : void 0;
20293
+ },
20294
+ placeholderData: keepPreviousData
20295
+ });
20296
+ const options = data?.pages.flatMap((page) => getOptions(page)) ?? [];
20297
+ const defaultOptions2 = initialData ? getOptions(initialData) : [];
20298
+ const disabled = !rest.isPending && !options.length && !searchValue;
20299
+ if (defaultValue2 && defaultOptions2.length && !searchValue) {
20300
+ defaultOptions2.forEach((option) => {
20301
+ if (!options.find((o2) => o2.value === option.value)) {
20302
+ options.unshift(option);
20303
+ }
20304
+ });
20305
+ }
20306
+ return {
20307
+ options,
20308
+ searchValue,
20309
+ onSearchValueChange,
20310
+ disabled,
20311
+ ...rest
20312
+ };
20313
+ };
20092
20314
  const currencies = {
20093
20315
  USD: {
20094
20316
  code: "USD",
@@ -20835,6 +21057,504 @@ const currencies = {
20835
21057
  decimal_digits: 0
20836
21058
  }
20837
21059
  };
21060
+ const formSchema = z.object({
21061
+ currency_code: z.string().min(1, "Please select a currency"),
21062
+ customer_id: z.string().optional()
21063
+ });
21064
+ const StoreCreditAccountCreateForm = () => {
21065
+ const { handleSuccess } = useRouteModal();
21066
+ const [searchParams] = useSearchParams();
21067
+ const prefilledCustomerId = searchParams.get("prefill_customer_id") ?? "";
21068
+ const form = useForm({
21069
+ defaultValues: {
21070
+ currency_code: "",
21071
+ customer_id: prefilledCustomerId
21072
+ },
21073
+ resolver: u(formSchema)
21074
+ });
21075
+ const { mutateAsync: createStoreCreditAccount, isPending } = useCreateStoreCreditAccount();
21076
+ const handleSubmit = form.handleSubmit(async (data) => {
21077
+ if (!data.customer_id) {
21078
+ delete data.customer_id;
21079
+ }
21080
+ await createStoreCreditAccount(data, {
21081
+ onSuccess: (data2) => {
21082
+ toast.success(`Store credit account was successfully created.`);
21083
+ handleSuccess(`../${data2.store_credit_account.id}`);
21084
+ },
21085
+ onError: (error2) => {
21086
+ toast.error(error2.message);
21087
+ }
21088
+ });
21089
+ });
21090
+ const [currencySearchValue, setCurrencySearchValue] = useState("");
21091
+ const currencyOptions = useMemo(() => {
21092
+ const options = Object.values(currencies).map((currency) => ({
21093
+ label: `${currency.code} - ${currency.name} (${currency.symbol_native})`,
21094
+ value: currency.code.toLowerCase()
21095
+ }));
21096
+ if (!currencySearchValue) {
21097
+ return options;
21098
+ }
21099
+ return options.filter(
21100
+ (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
21101
+ );
21102
+ }, [currencySearchValue]);
21103
+ const {
21104
+ options: customerOptions,
21105
+ fetchNextPage,
21106
+ isFetchingNextPage,
21107
+ searchValue,
21108
+ onSearchValueChange,
21109
+ isLoading
21110
+ } = useComboboxData({
21111
+ queryKey: customersQueryKeys.list(),
21112
+ defaultValue: prefilledCustomerId || void 0,
21113
+ queryFn: async (params) => {
21114
+ return sdk.admin.customer.list(params);
21115
+ },
21116
+ getOptions: (data) => {
21117
+ return data.customers?.map((customer) => {
21118
+ const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
21119
+ const label = fullName ? `${customer.email} (${fullName})` : customer.email;
21120
+ return {
21121
+ label,
21122
+ value: customer.id
21123
+ };
21124
+ }) || [];
21125
+ }
21126
+ });
21127
+ return /* @__PURE__ */ jsxs(RouteFocusModal.Form, { form, children: [
21128
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsx("div", { className: "-my-2 w-full border-l" }) }),
21129
+ /* @__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: [
21130
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
21131
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Create Store Credit Account" }),
21132
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new store credit account for a customer" })
21133
+ ] }),
21134
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-x-4", children: [
21135
+ /* @__PURE__ */ jsx(
21136
+ Form$2.Field,
21137
+ {
21138
+ control: form.control,
21139
+ name: "currency_code",
21140
+ render: ({ field }) => {
21141
+ return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
21142
+ /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Currency" }),
21143
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
21144
+ Combobox2,
21145
+ {
21146
+ value: field.value,
21147
+ onChange: field.onChange,
21148
+ searchValue: currencySearchValue,
21149
+ onSearchValueChange: setCurrencySearchValue,
21150
+ options: currencyOptions,
21151
+ placeholder: "Search for a currency..."
21152
+ }
21153
+ ) }),
21154
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
21155
+ ] });
21156
+ }
21157
+ }
21158
+ ),
21159
+ /* @__PURE__ */ jsx(
21160
+ Form$2.Field,
21161
+ {
21162
+ control: form.control,
21163
+ name: "customer_id",
21164
+ render: ({ field }) => {
21165
+ return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
21166
+ /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Customer" }),
21167
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
21168
+ Combobox2,
21169
+ {
21170
+ value: field.value,
21171
+ onChange: field.onChange,
21172
+ searchValue,
21173
+ onSearchValueChange,
21174
+ options: customerOptions,
21175
+ placeholder: "Search for a customer...",
21176
+ fetchNextPage,
21177
+ isFetchingNextPage,
21178
+ noResultsPlaceholder: isLoading ? "Loading customers..." : "No customers found"
21179
+ }
21180
+ ) }),
21181
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
21182
+ ] });
21183
+ }
21184
+ }
21185
+ )
21186
+ ] })
21187
+ ] }) }) }),
21188
+ /* @__PURE__ */ jsxs(RouteFocusModal.Footer, { children: [
21189
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, disabled: isPending, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", disabled: isPending, children: "Cancel" }) }),
21190
+ /* @__PURE__ */ jsx(
21191
+ Button,
21192
+ {
21193
+ variant: "primary",
21194
+ size: "small",
21195
+ onClick: handleSubmit,
21196
+ disabled: isPending,
21197
+ children: "Create"
21198
+ }
21199
+ )
21200
+ ] })
21201
+ ] });
21202
+ };
21203
+ const StoreCreditAccountCreate = () => {
21204
+ return /* @__PURE__ */ jsxs(RouteFocusModal, { children: [
21205
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create Store Credit Account" }) }),
21206
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create a new store credit account" }) }),
21207
+ /* @__PURE__ */ jsx(StoreCreditAccountCreateForm, {})
21208
+ ] });
21209
+ };
21210
+ const GiftCardIcon = (props) => {
21211
+ return /* @__PURE__ */ jsxs(
21212
+ "svg",
21213
+ {
21214
+ width: "15",
21215
+ height: "15",
21216
+ viewBox: "0 0 15 15",
21217
+ fill: "none",
21218
+ xmlns: "http://www.w3.org/2000/svg",
21219
+ ...props,
21220
+ children: [
21221
+ /* @__PURE__ */ jsx("rect", { width: "15", height: "15", fill: "#F97316" }),
21222
+ /* @__PURE__ */ jsx(
21223
+ "rect",
21224
+ {
21225
+ width: "15",
21226
+ height: "15",
21227
+ fill: "url(#paint0_linear_28788_25808)",
21228
+ fillOpacity: "0.2"
21229
+ }
21230
+ ),
21231
+ /* @__PURE__ */ jsxs("g", { clipPath: "url(#clip0_28788_25808)", children: [
21232
+ /* @__PURE__ */ jsx(
21233
+ "path",
21234
+ {
21235
+ 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",
21236
+ fill: "white"
21237
+ }
21238
+ ),
21239
+ /* @__PURE__ */ jsx(
21240
+ "path",
21241
+ {
21242
+ 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",
21243
+ fill: "white"
21244
+ }
21245
+ ),
21246
+ /* @__PURE__ */ jsx(
21247
+ "path",
21248
+ {
21249
+ 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",
21250
+ fill: "white"
21251
+ }
21252
+ ),
21253
+ /* @__PURE__ */ jsx(
21254
+ "path",
21255
+ {
21256
+ d: "M6.938 7.5H3.75V9.563C3.75 10.7 4.675 11.625 5.813 11.625H6.938V7.5Z",
21257
+ fill: "white"
21258
+ }
21259
+ ),
21260
+ /* @__PURE__ */ jsx(
21261
+ "path",
21262
+ {
21263
+ d: "M8.063 7.5V11.625H9.188C10.325 11.625 11.25 10.7 11.25 9.563V7.5H8.063Z",
21264
+ fill: "white"
21265
+ }
21266
+ )
21267
+ ] }),
21268
+ /* @__PURE__ */ jsxs("defs", { children: [
21269
+ /* @__PURE__ */ jsxs(
21270
+ "linearGradient",
21271
+ {
21272
+ id: "paint0_linear_28788_25808",
21273
+ x1: "7.5",
21274
+ y1: "0",
21275
+ x2: "7.5",
21276
+ y2: "15",
21277
+ gradientUnits: "userSpaceOnUse",
21278
+ children: [
21279
+ /* @__PURE__ */ jsx("stop", { stopColor: "white" }),
21280
+ /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
21281
+ ]
21282
+ }
21283
+ ),
21284
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_28788_25808", children: /* @__PURE__ */ jsx("rect", { width: "9", height: "9", fill: "white", transform: "translate(3 3)" }) })
21285
+ ] })
21286
+ ]
21287
+ }
21288
+ );
21289
+ };
21290
+ const GiftCardProductsSection = () => {
21291
+ const { products: giftCardProducts, count: count2 = 0 } = useProducts({
21292
+ is_giftcard: true
21293
+ });
21294
+ const slicedProducts = giftCardProducts?.slice(0, 3) ?? [];
21295
+ return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
21296
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
21297
+ /* @__PURE__ */ jsx(Header$5, { title: "Gift Card Products" }),
21298
+ /* @__PURE__ */ jsx(
21299
+ Link,
21300
+ {
21301
+ to: `/gift-cards/gift-card-products/create`,
21302
+ className: "text-ui-fg-muted text-sm px-6",
21303
+ children: "Create"
21304
+ }
21305
+ )
21306
+ ] }),
21307
+ giftCardProducts?.length === 0 && /* @__PURE__ */ jsx(
21308
+ NoRecords,
21309
+ {
21310
+ className: "px-10 py-4 h-[200px]",
21311
+ title: "No gift card products",
21312
+ message: "There are no gift card products to show. Create one to get started.",
21313
+ action: {
21314
+ to: "/gift-cards/gift-card-products/create",
21315
+ label: "Create gift card product"
21316
+ }
21317
+ }
21318
+ ),
21319
+ slicedProducts.map((giftCardProduct) => /* @__PURE__ */ jsx(
21320
+ SidebarLink,
21321
+ {
21322
+ to: `/gift-cards/gift-card-products/${giftCardProduct.id}`,
21323
+ labelKey: giftCardProduct.title,
21324
+ descriptionKey: giftCardProduct.title,
21325
+ icon: /* @__PURE__ */ jsx(Tag, {})
21326
+ }
21327
+ )),
21328
+ count2 > 3 && /* @__PURE__ */ jsx(
21329
+ Link,
21330
+ {
21331
+ to: "/gift-cards/gift-card-products",
21332
+ className: "text-ui-fg-muted text-sm px-6 py-4 flex items-center justify-center",
21333
+ children: "View more"
21334
+ }
21335
+ )
21336
+ ] });
21337
+ };
21338
+ const _giftCardQueryKey = queryKeysFactory("gift-card");
21339
+ const giftCardQueryKey = {
21340
+ ..._giftCardQueryKey,
21341
+ orders: (id) => [..._giftCardQueryKey.detail(id), "orders"]
21342
+ };
21343
+ const useGiftCards = (query, options) => {
21344
+ const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
21345
+ query: query2,
21346
+ headers
21347
+ });
21348
+ const { data, ...rest } = useQuery({
21349
+ ...options,
21350
+ queryFn: () => fetchGiftCards(query),
21351
+ queryKey: giftCardQueryKey.list(query)
21352
+ });
21353
+ return { ...data, ...rest };
21354
+ };
21355
+ const useGiftCard = (id, query, options) => {
21356
+ const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
21357
+ query: query2,
21358
+ headers
21359
+ });
21360
+ const { data, ...rest } = useQuery({
21361
+ queryFn: () => fetchGiftCard(id, query),
21362
+ queryKey: giftCardQueryKey.detail(id, query),
21363
+ ...options
21364
+ });
21365
+ return { ...data, ...rest };
21366
+ };
21367
+ const useGiftCardOrders = (id, options) => {
21368
+ const fetchGiftCardOrders = (id2, query, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}/orders`, {
21369
+ query,
21370
+ headers
21371
+ });
21372
+ const { data, ...rest } = useQuery({
21373
+ queryFn: () => fetchGiftCardOrders(id),
21374
+ queryKey: giftCardQueryKey.orders(id),
21375
+ ...options
21376
+ });
21377
+ return { ...data, ...rest };
21378
+ };
21379
+ const useUpdateGiftCard = (id, options) => {
21380
+ const queryClient = useQueryClient();
21381
+ const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
21382
+ body,
21383
+ method: "POST"
21384
+ });
21385
+ return useMutation({
21386
+ mutationFn: async (payload) => updateGiftCard(id, payload),
21387
+ onSuccess: (data, variables, context) => {
21388
+ queryClient.invalidateQueries({
21389
+ queryKey: giftCardQueryKey.detail(id)
21390
+ });
21391
+ queryClient.invalidateQueries({
21392
+ queryKey: giftCardQueryKey.lists()
21393
+ });
21394
+ },
21395
+ ...options
21396
+ });
21397
+ };
21398
+ const useCreateGiftCard = (options) => {
21399
+ const queryClient = useQueryClient();
21400
+ const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
21401
+ body,
21402
+ method: "POST"
21403
+ });
21404
+ return useMutation({
21405
+ mutationFn: (body) => createGiftCard(body),
21406
+ onSuccess: (data, variables, context) => {
21407
+ queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
21408
+ },
21409
+ ...options
21410
+ });
21411
+ };
21412
+ const columnHelper$9 = createDataTableColumnHelper();
21413
+ const useGiftCardTableColumns = () => {
21414
+ return useMemo(() => {
21415
+ return [
21416
+ columnHelper$9.accessor("code", {
21417
+ header: "Code",
21418
+ cell: ({ row }) => {
21419
+ return row.original.code;
21420
+ }
21421
+ }),
21422
+ columnHelper$9.accessor("line_item.product.title", {
21423
+ header: "Product",
21424
+ cell: ({ row }) => {
21425
+ return row.original.line_item?.product?.title || "Custom Gift Card";
21426
+ }
21427
+ }),
21428
+ columnHelper$9.accessor("created_at", {
21429
+ header: "Date issued",
21430
+ cell: ({ row }) => getRelativeDate(row.original.created_at)
21431
+ }),
21432
+ columnHelper$9.accessor("value", {
21433
+ header: "Value",
21434
+ cell: ({ row }) => {
21435
+ return formatAmount(row.original.value, row.original.currency_code);
21436
+ }
21437
+ })
21438
+ ];
21439
+ }, []);
21440
+ };
21441
+ const useGiftCardFilters = () => {
21442
+ const dateFilterOptions = useDataTableDateFilters$1();
21443
+ const customerFilterOptions = useCustomerFilters();
21444
+ return useMemo(() => {
21445
+ return [...dateFilterOptions, ...customerFilterOptions];
21446
+ }, [dateFilterOptions, customerFilterOptions]);
21447
+ };
21448
+ const useGiftCardTableQuery = ({
21449
+ prefix,
21450
+ pageSize = 20
21451
+ }) => {
21452
+ const queryObject = useQueryParams(
21453
+ ["q", "offset", "customer_id", "created_at", "updated_at"],
21454
+ prefix
21455
+ );
21456
+ const { offset: offset2, created_at, updated_at, customer_id, ...rest } = queryObject;
21457
+ const searchParams = {
21458
+ limit: pageSize,
21459
+ offset: offset2 ? Number(offset2) : 0,
21460
+ created_at: created_at ? JSON.parse(created_at) : void 0,
21461
+ updated_at: updated_at ? JSON.parse(updated_at) : void 0,
21462
+ customer_id: customer_id ? JSON.parse(customer_id) : void 0,
21463
+ ...rest
21464
+ };
21465
+ return searchParams;
21466
+ };
21467
+ const PAGE_SIZE$5 = 10;
21468
+ function GiftCardsTable() {
21469
+ const queryParams = useGiftCardTableQuery({
21470
+ pageSize: PAGE_SIZE$5
21471
+ });
21472
+ const {
21473
+ gift_cards: giftCards,
21474
+ isPending,
21475
+ count: count2
21476
+ } = useGiftCards({
21477
+ ...queryParams,
21478
+ order: queryParams.order ?? "-created_at",
21479
+ fields: "+line_item.product.title"
21480
+ });
21481
+ const columns = useGiftCardTableColumns();
21482
+ const filters = useGiftCardFilters();
21483
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
21484
+ /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
21485
+ DataTable,
21486
+ {
21487
+ data: giftCards,
21488
+ getRowId: (row) => row.id,
21489
+ columns,
21490
+ filters,
21491
+ isLoading: isPending,
21492
+ pageSize: PAGE_SIZE$5,
21493
+ rowCount: count2,
21494
+ heading: "Gift Cards",
21495
+ rowHref: (row) => `${row.id}`,
21496
+ emptyState: {
21497
+ empty: {
21498
+ heading: "No gift cards found",
21499
+ description: "Create a gift card to get started."
21500
+ },
21501
+ filtered: {
21502
+ heading: "No results found",
21503
+ description: "No gift cards match your filter criteria."
21504
+ }
21505
+ },
21506
+ actions: [
21507
+ {
21508
+ label: "Create",
21509
+ to: "create"
21510
+ }
21511
+ ]
21512
+ }
21513
+ ) }),
21514
+ /* @__PURE__ */ jsx(Outlet, {})
21515
+ ] });
21516
+ }
21517
+ const GiftCardsPage = () => {
21518
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
21519
+ /* @__PURE__ */ jsx(
21520
+ LayoutComposer,
21521
+ {
21522
+ widgetsZonePrefix: "gift_card.list",
21523
+ preferredLayoutId: "core:two-column",
21524
+ sections: {
21525
+ main: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "GiftCardsTable", children: /* @__PURE__ */ jsx(GiftCardsTable, {}) }),
21526
+ side: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "GiftCardProductsSection", children: /* @__PURE__ */ jsx(GiftCardProductsSection, {}) })
21527
+ }
21528
+ }
21529
+ ),
21530
+ /* @__PURE__ */ jsx(Toaster, {})
21531
+ ] });
21532
+ };
21533
+ const config$2 = defineRouteConfig({
21534
+ label: "Gift Cards",
21535
+ icon: GiftCardIcon
21536
+ });
21537
+ const STORE_QUERY_KEY = "store";
21538
+ const storeQueryKeys = queryKeysFactory(STORE_QUERY_KEY);
21539
+ async function retrieveActiveStore(query) {
21540
+ const response = await sdk.admin.store.list(query);
21541
+ const activeStore = response.stores?.[0];
21542
+ if (!activeStore) {
21543
+ throw new FetchError("No active store found", "Not Found", 404);
21544
+ }
21545
+ return { store: activeStore };
21546
+ }
21547
+ const useStore$1 = (query, options) => {
21548
+ const { data, ...rest } = useQuery({
21549
+ queryFn: () => retrieveActiveStore(query),
21550
+ queryKey: storeQueryKeys.details(),
21551
+ ...options
21552
+ });
21553
+ return {
21554
+ ...data,
21555
+ ...rest
21556
+ };
21557
+ };
20838
21558
  function getEnumValues(entries) {
20839
21559
  const numericValues = Object.values(entries).filter((v) => typeof v === "number");
20840
21560
  const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
@@ -21501,7 +22221,7 @@ class $ZodEncodeError extends Error {
21501
22221
  }
21502
22222
  (_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__zod_globalConfig = {});
21503
22223
  const globalConfig = globalThis.__zod_globalConfig;
21504
- function config$2(newConfig) {
22224
+ function config$1(newConfig) {
21505
22225
  if (newConfig)
21506
22226
  Object.assign(globalConfig, newConfig);
21507
22227
  return globalConfig;
@@ -21627,7 +22347,7 @@ const _parse = (_Err) => {
21627
22347
  throw new $ZodAsyncError();
21628
22348
  }
21629
22349
  if (result.issues.length) {
21630
- const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
22350
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
21631
22351
  captureStackTrace(e, _params?.callee ?? fn);
21632
22352
  throw e;
21633
22353
  }
@@ -21642,7 +22362,7 @@ const _parseAsync = (_Err) => {
21642
22362
  if (result instanceof Promise)
21643
22363
  result = await result;
21644
22364
  if (result.issues.length) {
21645
- const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
22365
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
21646
22366
  captureStackTrace(e, params?.callee ?? fn);
21647
22367
  throw e;
21648
22368
  }
@@ -21664,7 +22384,7 @@ function failure(Err, issues, ctx2) {
21664
22384
  success: false,
21665
22385
  get error() {
21666
22386
  if (!error2) {
21667
- error2 = new Err(issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
22387
+ error2 = new Err(issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
21668
22388
  issues = void 0;
21669
22389
  ctx2 = void 0;
21670
22390
  }
@@ -22289,7 +23009,7 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
22289
23009
  own(this, "~standard", value);
22290
23010
  }
22291
23011
  });
22292
- const toStandardResult = (r, ctx2) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())) } : { value: r.value };
23012
+ const toStandardResult = (r, ctx2) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())) } : { value: r.value };
22293
23013
  async function validateAsync(inst, value) {
22294
23014
  const ctx2 = { async: true };
22295
23015
  return toStandardResult(await inst._zod.run({ value, issues: [] }, ctx2), ctx2);
@@ -23151,7 +23871,7 @@ function handleUnionResults(results, final, inst, ctx2) {
23151
23871
  code: "invalid_union",
23152
23872
  input: final.value,
23153
23873
  inst,
23154
- errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())))
23874
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())))
23155
23875
  });
23156
23876
  return final;
23157
23877
  }
@@ -23347,7 +24067,7 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
23347
24067
  payload.issues.push({
23348
24068
  code: "invalid_key",
23349
24069
  origin: "record",
23350
- issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())),
24070
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())),
23351
24071
  input: key2,
23352
24072
  path: [key2],
23353
24073
  inst
@@ -23427,7 +24147,7 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
23427
24147
  payload.issues.push({
23428
24148
  code: "invalid_key",
23429
24149
  origin: "record",
23430
- issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())),
24150
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())),
23431
24151
  input: key2,
23432
24152
  path: [key2],
23433
24153
  inst
@@ -23643,7 +24363,7 @@ function handleCatchResult(payload, result, def, ctx2) {
23643
24363
  ...result,
23644
24364
  value: payload.value,
23645
24365
  error: {
23646
- issues: result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2()))
24366
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1()))
23647
24367
  },
23648
24368
  input: payload.value
23649
24369
  });
@@ -25787,11 +26507,11 @@ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
25787
26507
  const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
25788
26508
  function _ensureDefaultLocale() {
25789
26509
  if (!globalConfig.localeError)
25790
- config$2(en());
26510
+ config$1(en());
25791
26511
  }
25792
26512
  function _ensureDefaultMemoizer() {
25793
26513
  if (!globalConfig.memoizer)
25794
- config$2({ memoizer: memoizer() });
26514
+ config$1({ memoizer: memoizer() });
25795
26515
  }
25796
26516
  const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
25797
26517
  _ensureDefaultLocale();
@@ -26895,733 +27615,727 @@ const GiftCardCreateForm = ({
26895
27615
  ] });
26896
27616
  };
26897
27617
  const GiftCardCreate = () => {
26898
- const { store, isLoading } = useStore$2({});
27618
+ const { store, isLoading } = useStore$1({});
26899
27619
  return /* @__PURE__ */ jsxs(RouteFocusModal, { children: [
26900
27620
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create Gift Card" }) }),
26901
27621
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create a new gift card" }) }),
26902
27622
  !isLoading && /* @__PURE__ */ jsx(GiftCardCreateForm, { store })
26903
27623
  ] });
26904
27624
  };
26905
- const StoreCreditIcon = (props) => {
26906
- return /* @__PURE__ */ jsxs(
26907
- "svg",
26908
- {
26909
- width: "15",
26910
- height: "15",
26911
- viewBox: "0 0 15 15",
26912
- fill: "none",
26913
- xmlns: "http://www.w3.org/2000/svg",
26914
- ...props,
26915
- children: [
26916
- /* @__PURE__ */ jsx("rect", { width: "15", height: "15", fill: "#8B5CF6" }),
26917
- /* @__PURE__ */ jsx(
26918
- "rect",
26919
- {
26920
- width: "15",
26921
- height: "15",
26922
- fill: "url(#paint0_linear_29181_44790)",
26923
- fillOpacity: "0.2"
26924
- }
26925
- ),
26926
- /* @__PURE__ */ jsx(
26927
- "path",
26928
- {
26929
- d: "M12 6V5.813C12 4.675 11.075 3.75 9.938 3.75H5.063C3.925 3.75 3 4.675 3 5.813V6H12Z",
26930
- fill: "white"
26931
- }
26932
- ),
26933
- /* @__PURE__ */ jsx(
26934
- "path",
26935
- {
26936
- 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",
26937
- fill: "white"
26938
- }
26939
- ),
26940
- /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
26941
- "linearGradient",
27625
+ const StoreCreditAccountBalanceSection = ({
27626
+ storeCreditAccount
27627
+ }) => {
27628
+ if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
27629
+ return;
27630
+ }
27631
+ 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: [
27632
+ /* @__PURE__ */ jsx("div", { className: "bg-ui-tag-green-icon h-8 w-1 rounded-full" }),
27633
+ /* @__PURE__ */ jsxs("div", { children: [
27634
+ /* @__PURE__ */ jsx(Text, { weight: "plus", size: "small", className: "text-ui-fg-subtle", children: "Current Balance" }),
27635
+ /* @__PURE__ */ jsx(
27636
+ Text,
27637
+ {
27638
+ weight: "plus",
27639
+ size: "xlarge",
27640
+ className: "tabular-nums text-ui-fg-base",
27641
+ children: formatAmount(
27642
+ storeCreditAccount.balance,
27643
+ storeCreditAccount.currency_code
27644
+ )
27645
+ }
27646
+ )
27647
+ ] })
27648
+ ] }) });
27649
+ };
27650
+ var __create = Object.create;
27651
+ var __defProp = Object.defineProperty;
27652
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
27653
+ var __getOwnPropNames = Object.getOwnPropertyNames;
27654
+ var __getProtoOf = Object.getPrototypeOf;
27655
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
27656
+ var __commonJS = (cb, mod) => function __require() {
27657
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
27658
+ };
27659
+ var __copyProps = (to, from, except, desc) => {
27660
+ if (from && typeof from === "object" || typeof from === "function") {
27661
+ for (let key2 of __getOwnPropNames(from))
27662
+ if (!__hasOwnProp.call(to, key2) && key2 !== except)
27663
+ __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
27664
+ }
27665
+ return to;
27666
+ };
27667
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27668
+ // If the importer is in node compatibility mode or this is not an ESM
27669
+ // file that has been converted to a CommonJS file using a Babel-
27670
+ // compatible transform (i.e. "__esModule" has not been set), then set
27671
+ // "default" to the CommonJS "module.exports" for node compatibility.
27672
+ __defProp(target, "default", { value: mod, enumerable: true }),
27673
+ mod
27674
+ ));
27675
+ var require_toggle_selection = __commonJS({
27676
+ "node_modules/toggle-selection/index.js"(exports, module) {
27677
+ module.exports = function() {
27678
+ var selection = document.getSelection();
27679
+ if (!selection.rangeCount) {
27680
+ return function() {
27681
+ };
27682
+ }
27683
+ var active = document.activeElement;
27684
+ var ranges = [];
27685
+ for (var i2 = 0; i2 < selection.rangeCount; i2++) {
27686
+ ranges.push(selection.getRangeAt(i2));
27687
+ }
27688
+ switch (active.tagName.toUpperCase()) {
27689
+ // .toUpperCase handles XHTML
27690
+ case "INPUT":
27691
+ case "TEXTAREA":
27692
+ active.blur();
27693
+ break;
27694
+ default:
27695
+ active = null;
27696
+ break;
27697
+ }
27698
+ selection.removeAllRanges();
27699
+ return function() {
27700
+ selection.type === "Caret" && selection.removeAllRanges();
27701
+ if (!selection.rangeCount) {
27702
+ ranges.forEach(function(range) {
27703
+ selection.addRange(range);
27704
+ });
27705
+ }
27706
+ active && active.focus();
27707
+ };
27708
+ };
27709
+ }
27710
+ });
27711
+ var import_index = __toESM(require_toggle_selection());
27712
+ var toggle_selection_default = import_index.default;
27713
+ var defaultMessage = "Copy to clipboard: #{key}, Enter";
27714
+ function formatPromptMessage(message2) {
27715
+ var isMac2 = navigator.userAgentData ? /mac/i.test(navigator.userAgentData.platform) : /mac os x/i.test(navigator.userAgent);
27716
+ var copyKey = (isMac2 ? "⌘" : "Ctrl") + "+C";
27717
+ return message2.replace(/#{\s*key\s*}/g, copyKey);
27718
+ }
27719
+ function buildClipboardItem(text2, format2) {
27720
+ var items = {};
27721
+ items["text/plain"] = new Blob([text2], { type: "text/plain" });
27722
+ if (format2 && format2 !== "text/plain") {
27723
+ items[format2] = new Blob([text2], { type: format2 });
27724
+ }
27725
+ return new ClipboardItem(items);
27726
+ }
27727
+ async function copyViaClipboardAPI(text2, options) {
27728
+ if (!options.format && !options.onCopy) {
27729
+ await navigator.clipboard.writeText(text2);
27730
+ return true;
27731
+ }
27732
+ var item = buildClipboardItem(text2, options.format);
27733
+ if (options.onCopy) {
27734
+ item = options.onCopy(item) || item;
27735
+ }
27736
+ await navigator.clipboard.write([item]);
27737
+ return true;
27738
+ }
27739
+ function createHiddenSpan(text2, options) {
27740
+ var mark = document.createElement("span");
27741
+ mark.textContent = text2;
27742
+ mark.ariaHidden = "true";
27743
+ mark.style.all = "unset";
27744
+ mark.style.position = "fixed";
27745
+ mark.style.top = "0";
27746
+ mark.style.clip = "rect(0, 0, 0, 0)";
27747
+ mark.style.whiteSpace = "pre";
27748
+ mark.style.webkitUserSelect = "text";
27749
+ mark.style.MozUserSelect = "text";
27750
+ mark.style.msUserSelect = "text";
27751
+ mark.style.userSelect = "text";
27752
+ mark.addEventListener("copy", function(e) {
27753
+ e.stopPropagation();
27754
+ if (options.format) {
27755
+ e.preventDefault();
27756
+ if (e.clipboardData) {
27757
+ e.clipboardData.setData(options.format, text2);
27758
+ }
27759
+ }
27760
+ if (options.onCopy && e.clipboardData) {
27761
+ options.onCopy(e.clipboardData);
27762
+ }
27763
+ });
27764
+ return mark;
27765
+ }
27766
+ function findOpenedModalDialog() {
27767
+ let element = document.activeElement;
27768
+ while (element) {
27769
+ if (element.tagName === "DIALOG" && element.open) {
27770
+ return element;
27771
+ }
27772
+ element = element.parentElement;
27773
+ }
27774
+ return null;
27775
+ }
27776
+ function copyViaExecCommand(text2, options) {
27777
+ var reselectPrevious = toggle_selection_default();
27778
+ var range = document.createRange();
27779
+ var selection = document.getSelection();
27780
+ var mark = createHiddenSpan(text2, options);
27781
+ var root = findOpenedModalDialog() || document.fullscreenElement || document.body;
27782
+ var success = false;
27783
+ try {
27784
+ root.appendChild(mark);
27785
+ range.selectNodeContents(mark);
27786
+ selection.removeAllRanges();
27787
+ selection.addRange(range);
27788
+ var successful = document.execCommand("copy");
27789
+ if (!successful) {
27790
+ throw new Error("copy command was unsuccessful");
27791
+ }
27792
+ success = true;
27793
+ } finally {
27794
+ if (typeof selection.removeRange == "function") {
27795
+ selection.removeRange(range);
27796
+ } else {
27797
+ selection.removeAllRanges();
27798
+ }
27799
+ root.removeChild(mark);
27800
+ reselectPrevious();
27801
+ }
27802
+ return success;
27803
+ }
27804
+ async function copy$1(text2, options = {}) {
27805
+ var debug2 = options.debug || false;
27806
+ if (window.isSecureContext && navigator.clipboard) {
27807
+ try {
27808
+ return await copyViaClipboardAPI(text2, options);
27809
+ } catch (err) {
27810
+ debug2 && console.error("unable to copy using navigator.clipboard: ", err);
27811
+ debug2 && console.warn("falling back to execCommand");
27812
+ }
27813
+ } else {
27814
+ debug2 && !window.isSecureContext && console.warn("copy-to-clipboard: navigator.clipboard requires a secure context (HTTPS/localhost). Falling back to execCommand.");
27815
+ }
27816
+ try {
27817
+ return copyViaExecCommand(text2, options);
27818
+ } catch (err) {
27819
+ debug2 && console.error("unable to copy using execCommand: ", err);
27820
+ debug2 && console.error("falling back to prompt");
27821
+ if (options.fallbackToPrompt) {
27822
+ var message2 = formatPromptMessage("message" in options ? options.message : defaultMessage);
27823
+ window.prompt(message2, text2);
27824
+ }
27825
+ }
27826
+ return false;
27827
+ }
27828
+ var index_default = copy$1;
27829
+ function DisplayId({ id, className }) {
27830
+ const [open2, setOpen] = useState(false);
27831
+ const onClick = () => {
27832
+ index_default(id);
27833
+ toast.success("Copied to clipboard");
27834
+ };
27835
+ return /* @__PURE__ */ jsx(Tooltip, { maxWidth: 260, content: id, open: open2, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs("span", { onClick, className: clx("cursor-pointer", className), children: [
27836
+ "#",
27837
+ id.slice(-7)
27838
+ ] }) });
27839
+ }
27840
+ const StoreCreditAccountDetailsSection = ({
27841
+ storeCreditAccount
27842
+ }) => {
27843
+ if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
27844
+ return;
27845
+ }
27846
+ return /* @__PURE__ */ jsxs(Container$1, { className: "flex justify-between gap-x-2 px-6 py-6", children: [
27847
+ /* @__PURE__ */ jsxs(
27848
+ Text,
27849
+ {
27850
+ weight: "plus",
27851
+ size: "xlarge",
27852
+ className: "text-ui-fg-base flex gap-x-4",
27853
+ children: [
27854
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
27855
+ /* @__PURE__ */ jsx(CreditCardIcon, { className: "inline" }),
27856
+ " "
27857
+ ] }),
27858
+ /* @__PURE__ */ jsxs("div", { children: [
27859
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle", children: [
27860
+ storeCreditAccount.currency_code.toUpperCase(),
27861
+ " Account"
27862
+ ] }),
27863
+ /* @__PURE__ */ jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsx(
27864
+ Text,
27865
+ {
27866
+ weight: "regular",
27867
+ size: "small",
27868
+ className: "text-ui-fg-base flex gap-x-4",
27869
+ children: /* @__PURE__ */ jsx(DisplayId, { id: storeCreditAccount.id })
27870
+ }
27871
+ ) })
27872
+ ] })
27873
+ ]
27874
+ }
27875
+ ),
27876
+ /* @__PURE__ */ jsx("div", { className: "flex items-center gap-x-4", children: /* @__PURE__ */ jsx(
27877
+ ActionMenu,
27878
+ {
27879
+ groups: [
26942
27880
  {
26943
- id: "paint0_linear_29181_44790",
26944
- x1: "7.5",
26945
- y1: "0",
26946
- x2: "7.5",
26947
- y2: "15",
26948
- gradientUnits: "userSpaceOnUse",
26949
- children: [
26950
- /* @__PURE__ */ jsx("stop", { stopColor: "white" }),
26951
- /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
27881
+ actions: [
27882
+ {
27883
+ icon: /* @__PURE__ */ jsx(CreditCard, {}),
27884
+ label: "Credit the account",
27885
+ to: "credit"
27886
+ },
27887
+ {
27888
+ icon: /* @__PURE__ */ jsx(MinusMini, {}),
27889
+ label: "Debit the account",
27890
+ to: "debit",
27891
+ disabled: !Number(storeCreditAccount.balance)
27892
+ }
26952
27893
  ]
26953
27894
  }
26954
- ) })
26955
- ]
26956
- }
26957
- );
27895
+ ]
27896
+ }
27897
+ ) })
27898
+ ] });
26958
27899
  };
26959
- const columnHelper$9 = createDataTableColumnHelper();
26960
- const useStoreCreditAccountTableColumns = () => {
27900
+ function StoreCreditAccountCustomerSection({
27901
+ customerId
27902
+ }) {
27903
+ const { customer, isPending } = useCustomer(customerId, void 0, {
27904
+ enabled: !!customerId
27905
+ });
27906
+ if (isPending || !customer) {
27907
+ return null;
27908
+ }
27909
+ return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
27910
+ /* @__PURE__ */ jsx(Header$5, { title: "Customer" }),
27911
+ /* @__PURE__ */ jsx(
27912
+ SidebarLink,
27913
+ {
27914
+ icon: /* @__PURE__ */ jsx(User, {}),
27915
+ labelKey: customer.email || "N/A",
27916
+ descriptionKey: !customer.first_name && !customer.last_name ? "N/A" : `${customer.first_name} ${customer.last_name}`,
27917
+ to: `/customers/${customer.id}`
27918
+ },
27919
+ customer.id
27920
+ )
27921
+ ] });
27922
+ }
27923
+ const columnHelper$8 = createDataTableColumnHelper();
27924
+ const useTransactionsTableColumns = () => {
26961
27925
  return useMemo(() => {
26962
27926
  return [
26963
- columnHelper$9.accessor("currency_code", {
26964
- header: "Currency",
27927
+ columnHelper$8.accessor("id", {
27928
+ header: "ID",
26965
27929
  cell: ({ row }) => {
26966
- return /* @__PURE__ */ jsx(Badge, { size: "2xsmall", children: row.original.currency_code.toUpperCase() });
27930
+ return /* @__PURE__ */ jsx(DisplayId, { id: row.original.id });
26967
27931
  }
26968
27932
  }),
26969
- columnHelper$9.accessor("customer.email", {
26970
- header: "Customer",
26971
- cell: ({ row }) => {
26972
- return row.original.customer?.email ?? "N/A";
26973
- }
27933
+ columnHelper$8.accessor("created_at", {
27934
+ header: "Created At",
27935
+ cell: ({ row }) => formatDate(row.original.created_at, false)
26974
27936
  }),
26975
- columnHelper$9.accessor("balance", {
26976
- header: "Balance",
26977
- cell: ({ row }) => {
26978
- return formatAmount(
26979
- row.original.balance,
26980
- row.original.currency_code
26981
- );
26982
- }
27937
+ columnHelper$8.accessor("note", {
27938
+ header: "Description",
27939
+ cell: ({ row }) => row.original.note
26983
27940
  }),
26984
- columnHelper$9.accessor("credits", {
26985
- header: "Credits",
27941
+ columnHelper$8.accessor("note", {
27942
+ header: "Note",
26986
27943
  cell: ({ row }) => {
26987
- return formatAmount(
26988
- row.original.credits,
26989
- row.original.currency_code
26990
- );
27944
+ return /* @__PURE__ */ jsx(Text, { title: row.original.note, className: "max-w-[300px] truncate", children: row.original.note || "-" });
26991
27945
  }
26992
27946
  }),
26993
- columnHelper$9.accessor("debits", {
26994
- header: "Debits",
27947
+ columnHelper$8.accessor("amount", {
27948
+ header: "Amount",
26995
27949
  cell: ({ row }) => {
26996
- return formatAmount(
26997
- row.original.debits,
26998
- row.original.currency_code
27950
+ const isDebit = row.original.type === "debit";
27951
+ return row.original.account.currency_code && formatAmount(
27952
+ row.original.amount * (isDebit ? -1 : 1),
27953
+ row.original.account.currency_code
26999
27954
  );
27000
27955
  }
27001
- }),
27002
- columnHelper$9.accessor("created_at", {
27003
- header: "Created at",
27004
- cell: ({ row }) => getRelativeDate(row.original.created_at)
27005
27956
  })
27006
27957
  ];
27007
27958
  }, []);
27008
27959
  };
27009
- const useStoreCreditAccountFilters = () => {
27960
+ const useTransactionsTableFilters = ({}) => {
27010
27961
  const dateFilterOptions = useDataTableDateFilters$1();
27011
- const customerFilterOptions = useCustomerFilters();
27012
27962
  return useMemo(() => {
27013
- return [...dateFilterOptions, ...customerFilterOptions];
27014
- }, [dateFilterOptions, customerFilterOptions]);
27963
+ return [...dateFilterOptions];
27964
+ }, [dateFilterOptions]);
27015
27965
  };
27016
- const useStoreCreditAccountsTableQuery = ({
27966
+ const useTransactionsTableQuery = ({
27017
27967
  prefix,
27018
27968
  pageSize = 20
27019
27969
  }) => {
27020
27970
  const queryObject = useQueryParams(
27021
- ["offset", "customer_id", "currency_code", "created_at", "updated_at"],
27971
+ ["offset", "limit", "currency_code", "created_at", "updated_at"],
27022
27972
  prefix
27023
27973
  );
27024
- const {
27025
- offset: offset2,
27026
- created_at,
27027
- updated_at,
27028
- customer_id,
27029
- currency_code,
27030
- ...rest
27031
- } = queryObject;
27974
+ const { offset: offset2, limit, created_at, updated_at, ...rest } = queryObject;
27032
27975
  const searchParams = {
27033
- limit: pageSize,
27976
+ limit: limit ? Number(limit) : pageSize,
27034
27977
  offset: offset2 ? Number(offset2) : 0,
27035
27978
  created_at: created_at ? JSON.parse(created_at) : void 0,
27036
27979
  updated_at: updated_at ? JSON.parse(updated_at) : void 0,
27037
- customer_id: customer_id ? JSON.parse(customer_id) : void 0,
27038
- currency_code: currency_code ? JSON.parse(currency_code) : void 0,
27039
27980
  ...rest
27040
27981
  };
27041
27982
  return searchParams;
27042
27983
  };
27043
- const PAGE_SIZE$5 = 10;
27044
- function StoreCreditAccountsTable() {
27045
- const queryParams = useStoreCreditAccountsTableQuery({
27046
- pageSize: PAGE_SIZE$5
27047
- });
27048
- const {
27049
- store_credit_accounts: storeCreditAccounts,
27050
- isPending,
27051
- count: count2
27052
- } = useStoreCreditAccounts({
27053
- ...queryParams,
27054
- order: queryParams.order ?? "-created_at"
27984
+ const PAGE_SIZE$4 = 10;
27985
+ function TransactionsTable({ id }) {
27986
+ const queryParams = useTransactionsTableQuery({
27987
+ pageSize: PAGE_SIZE$4
27055
27988
  });
27056
- const columns = useStoreCreditAccountTableColumns();
27057
- const filters = useStoreCreditAccountFilters();
27989
+ const { transactions, isLoading, count: count2 } = useStoreCreditAccountTransactions(
27990
+ id,
27991
+ {
27992
+ ...queryParams,
27993
+ order: queryParams.order ?? "-created_at",
27994
+ fields: "*account"
27995
+ }
27996
+ );
27997
+ const columns = useTransactionsTableColumns();
27998
+ const filters = useTransactionsTableFilters({});
27058
27999
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
27059
28000
  /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
27060
28001
  DataTable,
27061
28002
  {
27062
- data: storeCreditAccounts ?? [],
28003
+ data: transactions ?? [],
27063
28004
  getRowId: (row) => row.id,
27064
28005
  columns,
27065
28006
  filters,
27066
- isLoading: isPending,
27067
- pageSize: PAGE_SIZE$5,
28007
+ isLoading,
28008
+ pageSize: PAGE_SIZE$4,
27068
28009
  rowCount: count2,
27069
28010
  enableSearch: false,
27070
- heading: "Store Credit Accounts",
27071
- rowHref: (row) => `${row.id}`,
28011
+ heading: "Transactions",
27072
28012
  emptyState: {
27073
28013
  empty: {
27074
- heading: "No store credit accounts found",
27075
- description: "Create a new store credit account to get started."
28014
+ heading: "No transactions found"
27076
28015
  },
27077
28016
  filtered: {
27078
28017
  heading: "No results found",
27079
- description: "No store credit accounts match your filter criteria."
27080
- }
27081
- },
27082
- actions: [
27083
- {
27084
- label: "Create",
27085
- to: "/store-credit-accounts/create"
28018
+ description: "No transactions match your filter criteria."
27086
28019
  }
27087
- ]
28020
+ }
27088
28021
  }
27089
28022
  ) }),
27090
28023
  /* @__PURE__ */ jsx(Outlet, {})
27091
28024
  ] });
27092
28025
  }
27093
- const StoreCreditAccountsPage = () => {
27094
- return /* @__PURE__ */ jsxs(Fragment, { children: [
27095
- /* @__PURE__ */ jsx(
27096
- LayoutComposer,
27097
- {
27098
- widgetsZonePrefix: "store_credit_account.list",
27099
- preferredLayoutId: "core:single-column",
27100
- sections: {
27101
- main: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountsTable", children: /* @__PURE__ */ jsx(StoreCreditAccountsTable, {}) })
27102
- }
27103
- }
27104
- ),
27105
- /* @__PURE__ */ jsx(Toaster, {})
27106
- ] });
27107
- };
27108
- const config$1 = defineRouteConfig({
27109
- label: "Store Credits",
27110
- icon: StoreCreditIcon
27111
- });
27112
- var isObject_1;
27113
- var hasRequiredIsObject;
27114
- function requireIsObject() {
27115
- if (hasRequiredIsObject) return isObject_1;
27116
- hasRequiredIsObject = 1;
27117
- function isObject2(value) {
27118
- var type = typeof value;
27119
- return value != null && (type == "object" || type == "function");
28026
+ function StoreCreditAccountCodeSection({ code }) {
28027
+ if (!code) {
28028
+ return null;
27120
28029
  }
27121
- isObject_1 = isObject2;
27122
- return isObject_1;
28030
+ return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
28031
+ /* @__PURE__ */ jsx(Header$5, { title: "Account Code" }),
28032
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-4 px-6 mb-2", children: [
28033
+ /* @__PURE__ */ jsx(Share, { className: "inline" }),
28034
+ /* @__PURE__ */ jsx("div", { className: "text-ui-fg-subtle text-sm", children: code })
28035
+ ] })
28036
+ ] });
27123
28037
  }
27124
- var _freeGlobal;
27125
- var hasRequired_freeGlobal;
27126
- function require_freeGlobal() {
27127
- if (hasRequired_freeGlobal) return _freeGlobal;
27128
- hasRequired_freeGlobal = 1;
27129
- var freeGlobal = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
27130
- _freeGlobal = freeGlobal;
27131
- return _freeGlobal;
27132
- }
27133
- var _root;
27134
- var hasRequired_root;
27135
- function require_root() {
27136
- if (hasRequired_root) return _root;
27137
- hasRequired_root = 1;
27138
- var freeGlobal = require_freeGlobal();
27139
- var freeSelf = typeof self == "object" && self && self.Object === Object && self;
27140
- var root = freeGlobal || freeSelf || Function("return this")();
27141
- _root = root;
27142
- return _root;
27143
- }
27144
- var now_1;
27145
- var hasRequiredNow;
27146
- function requireNow() {
27147
- if (hasRequiredNow) return now_1;
27148
- hasRequiredNow = 1;
27149
- var root = require_root();
27150
- var now = function() {
27151
- return root.Date.now();
27152
- };
27153
- now_1 = now;
27154
- return now_1;
27155
- }
27156
- var _trimmedEndIndex;
27157
- var hasRequired_trimmedEndIndex;
27158
- function require_trimmedEndIndex() {
27159
- if (hasRequired_trimmedEndIndex) return _trimmedEndIndex;
27160
- hasRequired_trimmedEndIndex = 1;
27161
- var reWhitespace = /\s/;
27162
- function trimmedEndIndex(string2) {
27163
- var index = string2.length;
27164
- while (index-- && reWhitespace.test(string2.charAt(index))) {
27165
- }
27166
- return index;
27167
- }
27168
- _trimmedEndIndex = trimmedEndIndex;
27169
- return _trimmedEndIndex;
27170
- }
27171
- var _baseTrim;
27172
- var hasRequired_baseTrim;
27173
- function require_baseTrim() {
27174
- if (hasRequired_baseTrim) return _baseTrim;
27175
- hasRequired_baseTrim = 1;
27176
- var trimmedEndIndex = require_trimmedEndIndex();
27177
- var reTrimStart = /^\s+/;
27178
- function baseTrim(string2) {
27179
- return string2 ? string2.slice(0, trimmedEndIndex(string2) + 1).replace(reTrimStart, "") : string2;
27180
- }
27181
- _baseTrim = baseTrim;
27182
- return _baseTrim;
27183
- }
27184
- var _Symbol;
27185
- var hasRequired_Symbol;
27186
- function require_Symbol() {
27187
- if (hasRequired_Symbol) return _Symbol;
27188
- hasRequired_Symbol = 1;
27189
- var root = require_root();
27190
- var Symbol2 = root.Symbol;
27191
- _Symbol = Symbol2;
27192
- return _Symbol;
27193
- }
27194
- var _getRawTag;
27195
- var hasRequired_getRawTag;
27196
- function require_getRawTag() {
27197
- if (hasRequired_getRawTag) return _getRawTag;
27198
- hasRequired_getRawTag = 1;
27199
- var Symbol2 = require_Symbol();
27200
- var objectProto = Object.prototype;
27201
- var hasOwnProperty2 = objectProto.hasOwnProperty;
27202
- var nativeObjectToString = objectProto.toString;
27203
- var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
27204
- function getRawTag(value) {
27205
- var isOwn = hasOwnProperty2.call(value, symToStringTag), tag = value[symToStringTag];
27206
- try {
27207
- value[symToStringTag] = void 0;
27208
- var unmasked = true;
27209
- } catch (e) {
27210
- }
27211
- var result = nativeObjectToString.call(value);
27212
- if (unmasked) {
27213
- if (isOwn) {
27214
- value[symToStringTag] = tag;
27215
- } else {
27216
- delete value[symToStringTag];
27217
- }
27218
- }
27219
- return result;
27220
- }
27221
- _getRawTag = getRawTag;
27222
- return _getRawTag;
27223
- }
27224
- var _objectToString;
27225
- var hasRequired_objectToString;
27226
- function require_objectToString() {
27227
- if (hasRequired_objectToString) return _objectToString;
27228
- hasRequired_objectToString = 1;
27229
- var objectProto = Object.prototype;
27230
- var nativeObjectToString = objectProto.toString;
27231
- function objectToString(value) {
27232
- return nativeObjectToString.call(value);
27233
- }
27234
- _objectToString = objectToString;
27235
- return _objectToString;
27236
- }
27237
- var _baseGetTag;
27238
- var hasRequired_baseGetTag;
27239
- function require_baseGetTag() {
27240
- if (hasRequired_baseGetTag) return _baseGetTag;
27241
- hasRequired_baseGetTag = 1;
27242
- var Symbol2 = require_Symbol(), getRawTag = require_getRawTag(), objectToString = require_objectToString();
27243
- var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
27244
- var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
27245
- function baseGetTag(value) {
27246
- if (value == null) {
27247
- return value === void 0 ? undefinedTag : nullTag;
27248
- }
27249
- return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
27250
- }
27251
- _baseGetTag = baseGetTag;
27252
- return _baseGetTag;
27253
- }
27254
- var isObjectLike_1;
27255
- var hasRequiredIsObjectLike;
27256
- function requireIsObjectLike() {
27257
- if (hasRequiredIsObjectLike) return isObjectLike_1;
27258
- hasRequiredIsObjectLike = 1;
27259
- function isObjectLike(value) {
27260
- return value != null && typeof value == "object";
27261
- }
27262
- isObjectLike_1 = isObjectLike;
27263
- return isObjectLike_1;
27264
- }
27265
- var isSymbol_1;
27266
- var hasRequiredIsSymbol;
27267
- function requireIsSymbol() {
27268
- if (hasRequiredIsSymbol) return isSymbol_1;
27269
- hasRequiredIsSymbol = 1;
27270
- var baseGetTag = require_baseGetTag(), isObjectLike = requireIsObjectLike();
27271
- var symbolTag = "[object Symbol]";
27272
- function isSymbol(value) {
27273
- return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
27274
- }
27275
- isSymbol_1 = isSymbol;
27276
- return isSymbol_1;
27277
- }
27278
- var toNumber_1;
27279
- var hasRequiredToNumber;
27280
- function requireToNumber() {
27281
- if (hasRequiredToNumber) return toNumber_1;
27282
- hasRequiredToNumber = 1;
27283
- var baseTrim = require_baseTrim(), isObject2 = requireIsObject(), isSymbol = requireIsSymbol();
27284
- var NAN = 0 / 0;
27285
- var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
27286
- var reIsBinary = /^0b[01]+$/i;
27287
- var reIsOctal = /^0o[0-7]+$/i;
27288
- var freeParseInt = parseInt;
27289
- function toNumber(value) {
27290
- if (typeof value == "number") {
27291
- return value;
27292
- }
27293
- if (isSymbol(value)) {
27294
- return NAN;
27295
- }
27296
- if (isObject2(value)) {
27297
- var other = typeof value.valueOf == "function" ? value.valueOf() : value;
27298
- value = isObject2(other) ? other + "" : other;
27299
- }
27300
- if (typeof value != "string") {
27301
- return value === 0 ? value : +value;
27302
- }
27303
- value = baseTrim(value);
27304
- var isBinary = reIsBinary.test(value);
27305
- return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
28038
+ const StoreCreditAccountPage = () => {
28039
+ const { id } = useParams();
28040
+ const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
28041
+ id
28042
+ );
28043
+ if (!storeCreditAccount) {
28044
+ return;
27306
28045
  }
27307
- toNumber_1 = toNumber;
27308
- return toNumber_1;
27309
- }
27310
- var debounce_1;
27311
- var hasRequiredDebounce;
27312
- function requireDebounce() {
27313
- if (hasRequiredDebounce) return debounce_1;
27314
- hasRequiredDebounce = 1;
27315
- var isObject2 = requireIsObject(), now = requireNow(), toNumber = requireToNumber();
27316
- var FUNC_ERROR_TEXT = "Expected a function";
27317
- var nativeMax = Math.max, nativeMin = Math.min;
27318
- function debounce2(func, wait, options) {
27319
- var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
27320
- if (typeof func != "function") {
27321
- throw new TypeError(FUNC_ERROR_TEXT);
27322
- }
27323
- wait = toNumber(wait) || 0;
27324
- if (isObject2(options)) {
27325
- leading = !!options.leading;
27326
- maxing = "maxWait" in options;
27327
- maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
27328
- trailing = "trailing" in options ? !!options.trailing : trailing;
27329
- }
27330
- function invokeFunc(time2) {
27331
- var args = lastArgs, thisArg = lastThis;
27332
- lastArgs = lastThis = void 0;
27333
- lastInvokeTime = time2;
27334
- result = func.apply(thisArg, args);
27335
- return result;
27336
- }
27337
- function leadingEdge(time2) {
27338
- lastInvokeTime = time2;
27339
- timerId = setTimeout(timerExpired, wait);
27340
- return leading ? invokeFunc(time2) : result;
27341
- }
27342
- function remainingWait(time2) {
27343
- var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
27344
- return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
27345
- }
27346
- function shouldInvoke(time2) {
27347
- var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime;
27348
- return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
27349
- }
27350
- function timerExpired() {
27351
- var time2 = now();
27352
- if (shouldInvoke(time2)) {
27353
- return trailingEdge(time2);
28046
+ return /* @__PURE__ */ jsx(
28047
+ LayoutComposer,
28048
+ {
28049
+ widgetsZonePrefix: "store_credit_account.details",
28050
+ preferredLayoutId: "core:two-column",
28051
+ data: storeCreditAccount,
28052
+ sections: {
28053
+ main: /* @__PURE__ */ jsxs(Fragment, { children: [
28054
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountDetailsSection", children: /* @__PURE__ */ jsx(
28055
+ StoreCreditAccountDetailsSection,
28056
+ {
28057
+ storeCreditAccount
28058
+ }
28059
+ ) }),
28060
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "TransactionsTable", children: /* @__PURE__ */ jsx(TransactionsTable, { id: storeCreditAccount.id }) })
28061
+ ] }),
28062
+ side: /* @__PURE__ */ jsxs(Fragment, { children: [
28063
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountBalanceSection", children: /* @__PURE__ */ jsx(
28064
+ StoreCreditAccountBalanceSection,
28065
+ {
28066
+ storeCreditAccount
28067
+ }
28068
+ ) }),
28069
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountCodeSection", children: /* @__PURE__ */ jsx(StoreCreditAccountCodeSection, { code: storeCreditAccount.code }) }),
28070
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountCustomerSection", children: /* @__PURE__ */ jsx(
28071
+ StoreCreditAccountCustomerSection,
28072
+ {
28073
+ customerId: storeCreditAccount.customer_id
28074
+ }
28075
+ ) })
28076
+ ] })
27354
28077
  }
27355
- timerId = setTimeout(timerExpired, remainingWait(time2));
27356
28078
  }
27357
- function trailingEdge(time2) {
27358
- timerId = void 0;
27359
- if (trailing && lastArgs) {
27360
- return invokeFunc(time2);
28079
+ );
28080
+ };
28081
+ const KeyboundForm = React__default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
28082
+ const handleSubmit = (event) => {
28083
+ event.preventDefault();
28084
+ onSubmit?.(event);
28085
+ };
28086
+ const handleKeyDown = (event) => {
28087
+ if (event.key === "Enter") {
28088
+ if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
28089
+ return;
27361
28090
  }
27362
- lastArgs = lastThis = void 0;
27363
- return result;
27364
- }
27365
- function cancel() {
27366
- if (timerId !== void 0) {
27367
- clearTimeout(timerId);
28091
+ event.preventDefault();
28092
+ if (event.metaKey || event.ctrlKey) {
28093
+ handleSubmit(event);
27368
28094
  }
27369
- lastInvokeTime = 0;
27370
- lastArgs = lastCallTime = lastThis = timerId = void 0;
27371
28095
  }
27372
- function flush() {
27373
- return timerId === void 0 ? result : trailingEdge(now());
27374
- }
27375
- function debounced() {
27376
- var time2 = now(), isInvoking = shouldInvoke(time2);
27377
- lastArgs = arguments;
27378
- lastThis = this;
27379
- lastCallTime = time2;
27380
- if (isInvoking) {
27381
- if (timerId === void 0) {
27382
- return leadingEdge(lastCallTime);
27383
- }
27384
- if (maxing) {
27385
- clearTimeout(timerId);
27386
- timerId = setTimeout(timerExpired, wait);
27387
- return invokeFunc(lastCallTime);
27388
- }
27389
- }
27390
- if (timerId === void 0) {
27391
- timerId = setTimeout(timerExpired, wait);
27392
- }
27393
- return result;
28096
+ };
28097
+ return /* @__PURE__ */ jsx(
28098
+ "form",
28099
+ {
28100
+ ...rest,
28101
+ onSubmit: handleSubmit,
28102
+ onKeyDown: onKeyDown ?? handleKeyDown,
28103
+ ref
27394
28104
  }
27395
- debounced.cancel = cancel;
27396
- debounced.flush = flush;
27397
- return debounced;
27398
- }
27399
- debounce_1 = debounce2;
27400
- return debounce_1;
27401
- }
27402
- var debounceExports = requireDebounce();
27403
- const debounce$1 = /* @__PURE__ */ getDefaultExportFromCjs(debounceExports);
27404
- const useDebouncedSearch = () => {
27405
- const [searchValue, onSearchValueChange] = useState("");
27406
- const [debouncedQuery, setDebouncedQuery] = useState("");
27407
- const debouncedUpdate = useCallback(
27408
- debounce$1((query) => setDebouncedQuery(query), 300),
27409
- []
27410
28105
  );
27411
- useEffect(() => {
27412
- debouncedUpdate(searchValue);
27413
- return () => debouncedUpdate.cancel();
27414
- }, [searchValue, debouncedUpdate]);
27415
- return {
27416
- searchValue,
27417
- onSearchValueChange,
27418
- query: debouncedQuery || void 0
27419
- };
28106
+ });
28107
+ KeyboundForm.displayName = "KeyboundForm";
28108
+ const Note$1 = () => {
28109
+ const { id } = useParams();
28110
+ const {
28111
+ store_credit_account: storeCreditAccount,
28112
+ isPending,
28113
+ isError,
28114
+ error: error2
28115
+ } = useStoreCreditAccount(id, {});
28116
+ if (isError) {
28117
+ throw error2;
28118
+ }
28119
+ const isReady = !isPending && !!storeCreditAccount;
28120
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
28121
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
28122
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Credit store credit account" }) }),
28123
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Credit the store credit account" }) })
28124
+ ] }),
28125
+ isReady && /* @__PURE__ */ jsx(StoreCreditAccountCreditForm, { storeCreditAccount })
28126
+ ] });
27420
28127
  };
27421
- const useComboboxData = ({
27422
- queryKey,
27423
- queryFn,
27424
- getOptions,
27425
- defaultValue: defaultValue2,
27426
- defaultValueKey,
27427
- pageSize = 10
28128
+ const StoreCreditAccountCreditForm = ({
28129
+ storeCreditAccount
27428
28130
  }) => {
27429
- const { searchValue, onSearchValueChange, query } = useDebouncedSearch();
27430
- const queryInitialDataBy = defaultValueKey || "id";
27431
- const { data: initialData } = useQuery({
27432
- queryKey,
27433
- queryFn: async () => {
27434
- return queryFn({
27435
- [queryInitialDataBy]: defaultValue2,
27436
- limit: Array.isArray(defaultValue2) ? defaultValue2.length : 1
27437
- });
27438
- },
27439
- enabled: !!defaultValue2
27440
- });
27441
- const { data, ...rest } = useInfiniteQuery({
27442
- queryKey: [...queryKey, query],
27443
- queryFn: async ({ pageParam = 0 }) => {
27444
- return await queryFn({
27445
- q: query,
27446
- limit: pageSize,
27447
- offset: pageParam
27448
- });
27449
- },
27450
- initialPageParam: 0,
27451
- getNextPageParam: (lastPage) => {
27452
- const moreItemsExist = lastPage.count > lastPage.offset + lastPage.limit;
27453
- return moreItemsExist ? lastPage.offset + lastPage.limit : void 0;
28131
+ const form = useForm({
28132
+ defaultValues: {
28133
+ amount: {
28134
+ float: 0,
28135
+ value: ""
28136
+ },
28137
+ note: ""
27454
28138
  },
27455
- placeholderData: keepPreviousData
28139
+ resolver: u(schema$3)
27456
28140
  });
27457
- const options = data?.pages.flatMap((page) => getOptions(page)) ?? [];
27458
- const defaultOptions2 = initialData ? getOptions(initialData) : [];
27459
- const disabled = !rest.isPending && !options.length && !searchValue;
27460
- if (defaultValue2 && defaultOptions2.length && !searchValue) {
27461
- defaultOptions2.forEach((option) => {
27462
- if (!options.find((o2) => o2.value === option.value)) {
27463
- options.unshift(option);
28141
+ const { mutateAsync, isPending } = useCreditStoreCreditAccount(
28142
+ storeCreditAccount.id
28143
+ );
28144
+ const { handleSuccess } = useRouteModal();
28145
+ const onSubmit = form.handleSubmit(async (data) => {
28146
+ if (data.amount.float <= 0) {
28147
+ form.setError("amount", { message: "Amount must be greater than 0" });
28148
+ return;
28149
+ }
28150
+ await mutateAsync(
28151
+ { amount: data.amount.float, note: data.note },
28152
+ {
28153
+ onSuccess: () => handleSuccess(),
28154
+ onError: (error2) => toast.error(error2.message)
27464
28155
  }
27465
- });
27466
- }
27467
- return {
27468
- options,
27469
- searchValue,
27470
- onSearchValueChange,
27471
- disabled,
27472
- ...rest
27473
- };
28156
+ );
28157
+ });
28158
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
28159
+ KeyboundForm,
28160
+ {
28161
+ className: "flex flex-1 flex-col overflow-hidden",
28162
+ onSubmit,
28163
+ children: [
28164
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
28165
+ /* @__PURE__ */ jsx(
28166
+ Form$2.Field,
28167
+ {
28168
+ control: form.control,
28169
+ name: "amount",
28170
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
28171
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Amount" }),
28172
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
28173
+ CurrencyInput,
28174
+ {
28175
+ min: 0,
28176
+ placeholder: "0",
28177
+ value: field.value.value,
28178
+ onValueChange: (_value, _name, values) => {
28179
+ field.onChange({
28180
+ value: values?.value,
28181
+ float: values?.float || null
28182
+ });
28183
+ },
28184
+ symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
28185
+ code: storeCreditAccount.currency_code.toUpperCase()
28186
+ }
28187
+ ) }),
28188
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
28189
+ ] })
28190
+ }
28191
+ ),
28192
+ /* @__PURE__ */ jsx(
28193
+ Form$2.Field,
28194
+ {
28195
+ control: form.control,
28196
+ name: "note",
28197
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
28198
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
28199
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
28200
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
28201
+ ] })
28202
+ }
28203
+ )
28204
+ ] }),
28205
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
28206
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
28207
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
28208
+ ] }) })
28209
+ ]
28210
+ }
28211
+ ) });
27474
28212
  };
27475
- const formSchema = z.object({
27476
- currency_code: z.string().min(1, "Please select a currency"),
27477
- customer_id: z.string().optional()
28213
+ const schema$3 = z.object({
28214
+ note: z.string(),
28215
+ amount: z.object({
28216
+ float: z.number(),
28217
+ value: z.string()
28218
+ })
27478
28219
  });
27479
- const StoreCreditAccountCreateForm = () => {
27480
- const { handleSuccess } = useRouteModal();
27481
- const [searchParams] = useSearchParams();
27482
- const prefilledCustomerId = searchParams.get("prefill_customer_id") ?? "";
28220
+ const Debit = () => {
28221
+ const { id } = useParams();
28222
+ const {
28223
+ store_credit_account: storeCreditAccount,
28224
+ isPending,
28225
+ isError,
28226
+ error: error2
28227
+ } = useStoreCreditAccount(id, {});
28228
+ if (isError) {
28229
+ throw error2;
28230
+ }
28231
+ const isReady = !isPending && !!storeCreditAccount;
28232
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
28233
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
28234
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Debit store credit account" }) }),
28235
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Debit the store credit account" }) })
28236
+ ] }),
28237
+ isReady && /* @__PURE__ */ jsx(StoreCreditAccountDebitForm, { storeCreditAccount })
28238
+ ] });
28239
+ };
28240
+ const StoreCreditAccountDebitForm = ({
28241
+ storeCreditAccount
28242
+ }) => {
27483
28243
  const form = useForm({
27484
28244
  defaultValues: {
27485
- currency_code: "",
27486
- customer_id: prefilledCustomerId
28245
+ amount: {
28246
+ float: 0,
28247
+ value: ""
28248
+ },
28249
+ note: ""
27487
28250
  },
27488
- resolver: u(formSchema)
28251
+ resolver: u(schema$2)
27489
28252
  });
27490
- const { mutateAsync: createStoreCreditAccount, isPending } = useCreateStoreCreditAccount();
27491
- const handleSubmit = form.handleSubmit(async (data) => {
27492
- if (!data.customer_id) {
27493
- delete data.customer_id;
28253
+ const { mutateAsync, isPending } = useDebitStoreCreditAccount(
28254
+ storeCreditAccount.id
28255
+ );
28256
+ const { handleSuccess } = useRouteModal();
28257
+ const balance = storeCreditAccount.balance ?? 0;
28258
+ const onSubmit = form.handleSubmit(async (data) => {
28259
+ if (data.amount.float <= 0) {
28260
+ form.setError("amount", { message: "Amount must be greater than 0" });
28261
+ return;
27494
28262
  }
27495
- await createStoreCreditAccount(data, {
27496
- onSuccess: (data2) => {
27497
- toast.success(`Store credit account was successfully created.`);
27498
- handleSuccess(`../${data2.store_credit_account.id}`);
27499
- },
27500
- onError: (error2) => {
27501
- toast.error(error2.message);
27502
- }
27503
- });
27504
- });
27505
- const [currencySearchValue, setCurrencySearchValue] = useState("");
27506
- const currencyOptions = useMemo(() => {
27507
- const options = Object.values(currencies).map((currency) => ({
27508
- label: `${currency.code} - ${currency.name} (${currency.symbol_native})`,
27509
- value: currency.code.toLowerCase()
27510
- }));
27511
- if (!currencySearchValue) {
27512
- return options;
28263
+ if (data.amount.float > balance) {
28264
+ form.setError("amount", {
28265
+ message: "Amount can't be greater than the current balance"
28266
+ });
28267
+ return;
27513
28268
  }
27514
- return options.filter(
27515
- (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
28269
+ await mutateAsync(
28270
+ { amount: data.amount.float, note: data.note },
28271
+ {
28272
+ onSuccess: () => handleSuccess(),
28273
+ onError: (error2) => toast.error(error2.message)
28274
+ }
27516
28275
  );
27517
- }, [currencySearchValue]);
27518
- const {
27519
- options: customerOptions,
27520
- fetchNextPage,
27521
- isFetchingNextPage,
27522
- searchValue,
27523
- onSearchValueChange,
27524
- isLoading
27525
- } = useComboboxData({
27526
- queryKey: customersQueryKeys.list(),
27527
- defaultValue: prefilledCustomerId || void 0,
27528
- queryFn: async (params) => {
27529
- return sdk.admin.customer.list(params);
27530
- },
27531
- getOptions: (data) => {
27532
- return data.customers?.map((customer) => {
27533
- const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
27534
- const label = fullName ? `${customer.email} (${fullName})` : customer.email;
27535
- return {
27536
- label,
27537
- value: customer.id
27538
- };
27539
- }) || [];
27540
- }
27541
28276
  });
27542
- return /* @__PURE__ */ jsxs(RouteFocusModal.Form, { form, children: [
27543
- /* @__PURE__ */ jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsx("div", { className: "-my-2 w-full border-l" }) }),
27544
- /* @__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: [
27545
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
27546
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Create Store Credit Account" }),
27547
- /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new store credit account for a customer" })
27548
- ] }),
27549
- /* @__PURE__ */ jsxs("div", { className: "flex gap-x-4", children: [
27550
- /* @__PURE__ */ jsx(
27551
- Form$2.Field,
27552
- {
27553
- control: form.control,
27554
- name: "currency_code",
27555
- render: ({ field }) => {
27556
- return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
27557
- /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Currency" }),
28277
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
28278
+ KeyboundForm,
28279
+ {
28280
+ className: "flex flex-1 flex-col overflow-hidden",
28281
+ onSubmit,
28282
+ children: [
28283
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
28284
+ /* @__PURE__ */ jsx(
28285
+ Form$2.Field,
28286
+ {
28287
+ control: form.control,
28288
+ name: "amount",
28289
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
28290
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Amount" }),
27558
28291
  /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
27559
- Combobox2,
28292
+ CurrencyInput,
27560
28293
  {
27561
- value: field.value,
27562
- onChange: field.onChange,
27563
- searchValue: currencySearchValue,
27564
- onSearchValueChange: setCurrencySearchValue,
27565
- options: currencyOptions,
27566
- placeholder: "Search for a currency..."
28294
+ min: 0,
28295
+ placeholder: "0",
28296
+ value: field.value.value,
28297
+ onValueChange: (_value, _name, values) => {
28298
+ field.onChange({
28299
+ value: values?.value,
28300
+ float: values?.float || null
28301
+ });
28302
+ },
28303
+ symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
28304
+ code: storeCreditAccount.currency_code.toUpperCase()
27567
28305
  }
27568
28306
  ) }),
27569
28307
  /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
27570
- ] });
28308
+ ] })
27571
28309
  }
27572
- }
27573
- ),
27574
- /* @__PURE__ */ jsx(
27575
- Form$2.Field,
27576
- {
27577
- control: form.control,
27578
- name: "customer_id",
27579
- render: ({ field }) => {
27580
- return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
27581
- /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Customer" }),
27582
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
27583
- Combobox2,
27584
- {
27585
- value: field.value,
27586
- onChange: field.onChange,
27587
- searchValue,
27588
- onSearchValueChange,
27589
- options: customerOptions,
27590
- placeholder: "Search for a customer...",
27591
- fetchNextPage,
27592
- isFetchingNextPage,
27593
- noResultsPlaceholder: isLoading ? "Loading customers..." : "No customers found"
27594
- }
27595
- ) }),
28310
+ ),
28311
+ /* @__PURE__ */ jsx(
28312
+ Form$2.Field,
28313
+ {
28314
+ control: form.control,
28315
+ name: "note",
28316
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
28317
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
28318
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
27596
28319
  /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
27597
- ] });
28320
+ ] })
27598
28321
  }
27599
- }
27600
- )
27601
- ] })
27602
- ] }) }) }),
27603
- /* @__PURE__ */ jsxs(RouteFocusModal.Footer, { children: [
27604
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, disabled: isPending, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", disabled: isPending, children: "Cancel" }) }),
27605
- /* @__PURE__ */ jsx(
27606
- Button,
27607
- {
27608
- variant: "primary",
27609
- size: "small",
27610
- onClick: handleSubmit,
27611
- disabled: isPending,
27612
- children: "Create"
27613
- }
27614
- )
27615
- ] })
27616
- ] });
27617
- };
27618
- const StoreCreditAccountCreate = () => {
27619
- return /* @__PURE__ */ jsxs(RouteFocusModal, { children: [
27620
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create Store Credit Account" }) }),
27621
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create a new store credit account" }) }),
27622
- /* @__PURE__ */ jsx(StoreCreditAccountCreateForm, {})
27623
- ] });
28322
+ )
28323
+ ] }),
28324
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
28325
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
28326
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
28327
+ ] }) })
28328
+ ]
28329
+ }
28330
+ ) });
27624
28331
  };
28332
+ const schema$2 = z.object({
28333
+ note: z.string(),
28334
+ amount: z.object({
28335
+ float: z.number(),
28336
+ value: z.string()
28337
+ })
28338
+ });
27625
28339
  function _extends() {
27626
28340
  return _extends = Object.assign ? Object.assign.bind() : function(n2) {
27627
28341
  for (var e = 1; e < arguments.length; e++) {
@@ -30301,299 +31015,6 @@ const GiftCardOrderSection = ({ giftCard }) => {
30301
31015
  ))
30302
31016
  ] });
30303
31017
  };
30304
- var __create = Object.create;
30305
- var __defProp = Object.defineProperty;
30306
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
30307
- var __getOwnPropNames = Object.getOwnPropertyNames;
30308
- var __getProtoOf = Object.getPrototypeOf;
30309
- var __hasOwnProp = Object.prototype.hasOwnProperty;
30310
- var __commonJS = (cb, mod) => function __require() {
30311
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
30312
- };
30313
- var __copyProps = (to, from, except, desc) => {
30314
- if (from && typeof from === "object" || typeof from === "function") {
30315
- for (let key2 of __getOwnPropNames(from))
30316
- if (!__hasOwnProp.call(to, key2) && key2 !== except)
30317
- __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
30318
- }
30319
- return to;
30320
- };
30321
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30322
- // If the importer is in node compatibility mode or this is not an ESM
30323
- // file that has been converted to a CommonJS file using a Babel-
30324
- // compatible transform (i.e. "__esModule" has not been set), then set
30325
- // "default" to the CommonJS "module.exports" for node compatibility.
30326
- __defProp(target, "default", { value: mod, enumerable: true }),
30327
- mod
30328
- ));
30329
- var require_toggle_selection = __commonJS({
30330
- "node_modules/toggle-selection/index.js"(exports, module) {
30331
- module.exports = function() {
30332
- var selection = document.getSelection();
30333
- if (!selection.rangeCount) {
30334
- return function() {
30335
- };
30336
- }
30337
- var active = document.activeElement;
30338
- var ranges = [];
30339
- for (var i2 = 0; i2 < selection.rangeCount; i2++) {
30340
- ranges.push(selection.getRangeAt(i2));
30341
- }
30342
- switch (active.tagName.toUpperCase()) {
30343
- // .toUpperCase handles XHTML
30344
- case "INPUT":
30345
- case "TEXTAREA":
30346
- active.blur();
30347
- break;
30348
- default:
30349
- active = null;
30350
- break;
30351
- }
30352
- selection.removeAllRanges();
30353
- return function() {
30354
- selection.type === "Caret" && selection.removeAllRanges();
30355
- if (!selection.rangeCount) {
30356
- ranges.forEach(function(range) {
30357
- selection.addRange(range);
30358
- });
30359
- }
30360
- active && active.focus();
30361
- };
30362
- };
30363
- }
30364
- });
30365
- var import_index = __toESM(require_toggle_selection());
30366
- var toggle_selection_default = import_index.default;
30367
- var defaultMessage = "Copy to clipboard: #{key}, Enter";
30368
- function formatPromptMessage(message2) {
30369
- var isMac2 = navigator.userAgentData ? /mac/i.test(navigator.userAgentData.platform) : /mac os x/i.test(navigator.userAgent);
30370
- var copyKey = (isMac2 ? "⌘" : "Ctrl") + "+C";
30371
- return message2.replace(/#{\s*key\s*}/g, copyKey);
30372
- }
30373
- function buildClipboardItem(text2, format2) {
30374
- var items = {};
30375
- items["text/plain"] = new Blob([text2], { type: "text/plain" });
30376
- if (format2 && format2 !== "text/plain") {
30377
- items[format2] = new Blob([text2], { type: format2 });
30378
- }
30379
- return new ClipboardItem(items);
30380
- }
30381
- async function copyViaClipboardAPI(text2, options) {
30382
- if (!options.format && !options.onCopy) {
30383
- await navigator.clipboard.writeText(text2);
30384
- return true;
30385
- }
30386
- var item = buildClipboardItem(text2, options.format);
30387
- if (options.onCopy) {
30388
- item = options.onCopy(item) || item;
30389
- }
30390
- await navigator.clipboard.write([item]);
30391
- return true;
30392
- }
30393
- function createHiddenSpan(text2, options) {
30394
- var mark = document.createElement("span");
30395
- mark.textContent = text2;
30396
- mark.ariaHidden = "true";
30397
- mark.style.all = "unset";
30398
- mark.style.position = "fixed";
30399
- mark.style.top = "0";
30400
- mark.style.clip = "rect(0, 0, 0, 0)";
30401
- mark.style.whiteSpace = "pre";
30402
- mark.style.webkitUserSelect = "text";
30403
- mark.style.MozUserSelect = "text";
30404
- mark.style.msUserSelect = "text";
30405
- mark.style.userSelect = "text";
30406
- mark.addEventListener("copy", function(e) {
30407
- e.stopPropagation();
30408
- if (options.format) {
30409
- e.preventDefault();
30410
- if (e.clipboardData) {
30411
- e.clipboardData.setData(options.format, text2);
30412
- }
30413
- }
30414
- if (options.onCopy && e.clipboardData) {
30415
- options.onCopy(e.clipboardData);
30416
- }
30417
- });
30418
- return mark;
30419
- }
30420
- function findOpenedModalDialog() {
30421
- let element = document.activeElement;
30422
- while (element) {
30423
- if (element.tagName === "DIALOG" && element.open) {
30424
- return element;
30425
- }
30426
- element = element.parentElement;
30427
- }
30428
- return null;
30429
- }
30430
- function copyViaExecCommand(text2, options) {
30431
- var reselectPrevious = toggle_selection_default();
30432
- var range = document.createRange();
30433
- var selection = document.getSelection();
30434
- var mark = createHiddenSpan(text2, options);
30435
- var root = findOpenedModalDialog() || document.fullscreenElement || document.body;
30436
- var success = false;
30437
- try {
30438
- root.appendChild(mark);
30439
- range.selectNodeContents(mark);
30440
- selection.removeAllRanges();
30441
- selection.addRange(range);
30442
- var successful = document.execCommand("copy");
30443
- if (!successful) {
30444
- throw new Error("copy command was unsuccessful");
30445
- }
30446
- success = true;
30447
- } finally {
30448
- if (typeof selection.removeRange == "function") {
30449
- selection.removeRange(range);
30450
- } else {
30451
- selection.removeAllRanges();
30452
- }
30453
- root.removeChild(mark);
30454
- reselectPrevious();
30455
- }
30456
- return success;
30457
- }
30458
- async function copy$1(text2, options = {}) {
30459
- var debug2 = options.debug || false;
30460
- if (window.isSecureContext && navigator.clipboard) {
30461
- try {
30462
- return await copyViaClipboardAPI(text2, options);
30463
- } catch (err) {
30464
- debug2 && console.error("unable to copy using navigator.clipboard: ", err);
30465
- debug2 && console.warn("falling back to execCommand");
30466
- }
30467
- } else {
30468
- debug2 && !window.isSecureContext && console.warn("copy-to-clipboard: navigator.clipboard requires a secure context (HTTPS/localhost). Falling back to execCommand.");
30469
- }
30470
- try {
30471
- return copyViaExecCommand(text2, options);
30472
- } catch (err) {
30473
- debug2 && console.error("unable to copy using execCommand: ", err);
30474
- debug2 && console.error("falling back to prompt");
30475
- if (options.fallbackToPrompt) {
30476
- var message2 = formatPromptMessage("message" in options ? options.message : defaultMessage);
30477
- window.prompt(message2, text2);
30478
- }
30479
- }
30480
- return false;
30481
- }
30482
- var index_default = copy$1;
30483
- function DisplayId({ id, className }) {
30484
- const [open2, setOpen] = useState(false);
30485
- const onClick = () => {
30486
- index_default(id);
30487
- toast.success("Copied to clipboard");
30488
- };
30489
- return /* @__PURE__ */ jsx(Tooltip, { maxWidth: 260, content: id, open: open2, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs("span", { onClick, className: clx("cursor-pointer", className), children: [
30490
- "#",
30491
- id.slice(-7)
30492
- ] }) });
30493
- }
30494
- const columnHelper$8 = createDataTableColumnHelper();
30495
- const useTransactionsTableColumns = () => {
30496
- return useMemo(() => {
30497
- return [
30498
- columnHelper$8.accessor("id", {
30499
- header: "ID",
30500
- cell: ({ row }) => {
30501
- return /* @__PURE__ */ jsx(DisplayId, { id: row.original.id });
30502
- }
30503
- }),
30504
- columnHelper$8.accessor("created_at", {
30505
- header: "Created At",
30506
- cell: ({ row }) => formatDate(row.original.created_at, false)
30507
- }),
30508
- columnHelper$8.accessor("note", {
30509
- header: "Description",
30510
- cell: ({ row }) => row.original.note
30511
- }),
30512
- columnHelper$8.accessor("note", {
30513
- header: "Note",
30514
- cell: ({ row }) => {
30515
- return /* @__PURE__ */ jsx(Text, { title: row.original.note, className: "max-w-[300px] truncate", children: row.original.note || "-" });
30516
- }
30517
- }),
30518
- columnHelper$8.accessor("amount", {
30519
- header: "Amount",
30520
- cell: ({ row }) => {
30521
- const isDebit = row.original.type === "debit";
30522
- return row.original.account.currency_code && formatAmount(
30523
- row.original.amount * (isDebit ? -1 : 1),
30524
- row.original.account.currency_code
30525
- );
30526
- }
30527
- })
30528
- ];
30529
- }, []);
30530
- };
30531
- const useTransactionsTableFilters = ({}) => {
30532
- const dateFilterOptions = useDataTableDateFilters$1();
30533
- return useMemo(() => {
30534
- return [...dateFilterOptions];
30535
- }, [dateFilterOptions]);
30536
- };
30537
- const useTransactionsTableQuery = ({
30538
- prefix,
30539
- pageSize = 20
30540
- }) => {
30541
- const queryObject = useQueryParams(
30542
- ["offset", "limit", "currency_code", "created_at", "updated_at"],
30543
- prefix
30544
- );
30545
- const { offset: offset2, limit, created_at, updated_at, ...rest } = queryObject;
30546
- const searchParams = {
30547
- limit: limit ? Number(limit) : pageSize,
30548
- offset: offset2 ? Number(offset2) : 0,
30549
- created_at: created_at ? JSON.parse(created_at) : void 0,
30550
- updated_at: updated_at ? JSON.parse(updated_at) : void 0,
30551
- ...rest
30552
- };
30553
- return searchParams;
30554
- };
30555
- const PAGE_SIZE$4 = 10;
30556
- function TransactionsTable({ id }) {
30557
- const queryParams = useTransactionsTableQuery({
30558
- pageSize: PAGE_SIZE$4
30559
- });
30560
- const { transactions, isLoading, count: count2 } = useStoreCreditAccountTransactions(
30561
- id,
30562
- {
30563
- ...queryParams,
30564
- order: queryParams.order ?? "-created_at",
30565
- fields: "*account"
30566
- }
30567
- );
30568
- const columns = useTransactionsTableColumns();
30569
- const filters = useTransactionsTableFilters({});
30570
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [
30571
- /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
30572
- DataTable,
30573
- {
30574
- data: transactions ?? [],
30575
- getRowId: (row) => row.id,
30576
- columns,
30577
- filters,
30578
- isLoading,
30579
- pageSize: PAGE_SIZE$4,
30580
- rowCount: count2,
30581
- enableSearch: false,
30582
- heading: "Transactions",
30583
- emptyState: {
30584
- empty: {
30585
- heading: "No transactions found"
30586
- },
30587
- filtered: {
30588
- heading: "No results found",
30589
- description: "No transactions match your filter criteria."
30590
- }
30591
- }
30592
- }
30593
- ) }),
30594
- /* @__PURE__ */ jsx(Outlet, {})
30595
- ] });
30596
- }
30597
31018
  const GiftCardTransactionsSection = ({
30598
31019
  storeCreditAccount
30599
31020
  }) => {
@@ -30643,33 +31064,6 @@ const GiftCardDetailsPage = () => {
30643
31064
  }
30644
31065
  );
30645
31066
  };
30646
- const KeyboundForm = React__default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
30647
- const handleSubmit = (event) => {
30648
- event.preventDefault();
30649
- onSubmit?.(event);
30650
- };
30651
- const handleKeyDown = (event) => {
30652
- if (event.key === "Enter") {
30653
- if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
30654
- return;
30655
- }
30656
- event.preventDefault();
30657
- if (event.metaKey || event.ctrlKey) {
30658
- handleSubmit(event);
30659
- }
30660
- }
30661
- };
30662
- return /* @__PURE__ */ jsx(
30663
- "form",
30664
- {
30665
- ...rest,
30666
- onSubmit: handleSubmit,
30667
- onKeyDown: onKeyDown ?? handleKeyDown,
30668
- ref
30669
- }
30670
- );
30671
- });
30672
- KeyboundForm.displayName = "KeyboundForm";
30673
31067
  const GiftCardExpiration = () => {
30674
31068
  const { id } = useParams();
30675
31069
  const { gift_card: giftCard, isPending, isError, error: error2 } = useGiftCard(id);
@@ -30690,7 +31084,7 @@ const GiftCardExpirationForm = ({ giftCard }) => {
30690
31084
  defaultValues: {
30691
31085
  expires_at: giftCard.expires_at ? new Date(giftCard.expires_at) : null
30692
31086
  },
30693
- resolver: u(schema$3)
31087
+ resolver: u(schema$1)
30694
31088
  });
30695
31089
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
30696
31090
  const { handleSuccess } = useRouteModal();
@@ -30785,10 +31179,10 @@ const GiftCardExpirationForm = ({ giftCard }) => {
30785
31179
  }
30786
31180
  ) });
30787
31181
  };
30788
- const schema$3 = z.object({
31182
+ const schema$1 = z.object({
30789
31183
  expires_at: z.date().nullish()
30790
31184
  });
30791
- const Note$1 = () => {
31185
+ const Note = () => {
30792
31186
  const { id } = useParams();
30793
31187
  const {
30794
31188
  gift_card: giftCard,
@@ -30813,7 +31207,7 @@ const GiftCardNoteForm = ({ giftCard }) => {
30813
31207
  defaultValues: {
30814
31208
  note: giftCard.note ?? ""
30815
31209
  },
30816
- resolver: u(schema$2)
31210
+ resolver: u(schema)
30817
31211
  });
30818
31212
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
30819
31213
  const { handleSuccess } = useRouteModal();
@@ -30852,7 +31246,7 @@ const GiftCardNoteForm = ({ giftCard }) => {
30852
31246
  }
30853
31247
  ) });
30854
31248
  };
30855
- const schema$2 = z.object({
31249
+ const schema = z.object({
30856
31250
  note: z.string().optional()
30857
31251
  });
30858
31252
  const columnHelper$7 = createColumnHelper();
@@ -45343,7 +45737,7 @@ const GiftCardProductCreate = () => {
45343
45737
  isPending: isStorePending,
45344
45738
  isError: isStoreError,
45345
45739
  error: storeError
45346
- } = useStore$2({
45740
+ } = useStore$1({
45347
45741
  fields: "+default_sales_channel"
45348
45742
  });
45349
45743
  const {
@@ -45395,400 +45789,6 @@ const GiftCardProductCreate = () => {
45395
45789
  )
45396
45790
  ] });
45397
45791
  };
45398
- const StoreCreditAccountBalanceSection = ({
45399
- storeCreditAccount
45400
- }) => {
45401
- if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
45402
- return;
45403
- }
45404
- 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: [
45405
- /* @__PURE__ */ jsx("div", { className: "bg-ui-tag-green-icon h-8 w-1 rounded-full" }),
45406
- /* @__PURE__ */ jsxs("div", { children: [
45407
- /* @__PURE__ */ jsx(Text, { weight: "plus", size: "small", className: "text-ui-fg-subtle", children: "Current Balance" }),
45408
- /* @__PURE__ */ jsx(
45409
- Text,
45410
- {
45411
- weight: "plus",
45412
- size: "xlarge",
45413
- className: "tabular-nums text-ui-fg-base",
45414
- children: formatAmount(
45415
- storeCreditAccount.balance,
45416
- storeCreditAccount.currency_code
45417
- )
45418
- }
45419
- )
45420
- ] })
45421
- ] }) });
45422
- };
45423
- const StoreCreditAccountDetailsSection = ({
45424
- storeCreditAccount
45425
- }) => {
45426
- if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
45427
- return;
45428
- }
45429
- return /* @__PURE__ */ jsxs(Container$1, { className: "flex justify-between gap-x-2 px-6 py-6", children: [
45430
- /* @__PURE__ */ jsxs(
45431
- Text,
45432
- {
45433
- weight: "plus",
45434
- size: "xlarge",
45435
- className: "text-ui-fg-base flex gap-x-4",
45436
- children: [
45437
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
45438
- /* @__PURE__ */ jsx(CreditCardIcon, { className: "inline" }),
45439
- " "
45440
- ] }),
45441
- /* @__PURE__ */ jsxs("div", { children: [
45442
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle", children: [
45443
- storeCreditAccount.currency_code.toUpperCase(),
45444
- " Account"
45445
- ] }),
45446
- /* @__PURE__ */ jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsx(
45447
- Text,
45448
- {
45449
- weight: "regular",
45450
- size: "small",
45451
- className: "text-ui-fg-base flex gap-x-4",
45452
- children: /* @__PURE__ */ jsx(DisplayId, { id: storeCreditAccount.id })
45453
- }
45454
- ) })
45455
- ] })
45456
- ]
45457
- }
45458
- ),
45459
- /* @__PURE__ */ jsx("div", { className: "flex items-center gap-x-4", children: /* @__PURE__ */ jsx(
45460
- ActionMenu,
45461
- {
45462
- groups: [
45463
- {
45464
- actions: [
45465
- {
45466
- icon: /* @__PURE__ */ jsx(CreditCard, {}),
45467
- label: "Credit the account",
45468
- to: "credit"
45469
- },
45470
- {
45471
- icon: /* @__PURE__ */ jsx(MinusMini, {}),
45472
- label: "Debit the account",
45473
- to: "debit",
45474
- disabled: !Number(storeCreditAccount.balance)
45475
- }
45476
- ]
45477
- }
45478
- ]
45479
- }
45480
- ) })
45481
- ] });
45482
- };
45483
- function StoreCreditAccountCustomerSection({
45484
- customerId
45485
- }) {
45486
- const { customer, isPending } = useCustomer(customerId, void 0, {
45487
- enabled: !!customerId
45488
- });
45489
- if (isPending || !customer) {
45490
- return null;
45491
- }
45492
- return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
45493
- /* @__PURE__ */ jsx(Header$5, { title: "Customer" }),
45494
- /* @__PURE__ */ jsx(
45495
- SidebarLink,
45496
- {
45497
- icon: /* @__PURE__ */ jsx(User, {}),
45498
- labelKey: customer.email || "N/A",
45499
- descriptionKey: !customer.first_name && !customer.last_name ? "N/A" : `${customer.first_name} ${customer.last_name}`,
45500
- to: `/customers/${customer.id}`
45501
- },
45502
- customer.id
45503
- )
45504
- ] });
45505
- }
45506
- function StoreCreditAccountCodeSection({ code }) {
45507
- if (!code) {
45508
- return null;
45509
- }
45510
- return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
45511
- /* @__PURE__ */ jsx(Header$5, { title: "Account Code" }),
45512
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-4 px-6 mb-2", children: [
45513
- /* @__PURE__ */ jsx(Share, { className: "inline" }),
45514
- /* @__PURE__ */ jsx("div", { className: "text-ui-fg-subtle text-sm", children: code })
45515
- ] })
45516
- ] });
45517
- }
45518
- const StoreCreditAccountPage = () => {
45519
- const { id } = useParams();
45520
- const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
45521
- id
45522
- );
45523
- if (!storeCreditAccount) {
45524
- return;
45525
- }
45526
- return /* @__PURE__ */ jsx(
45527
- LayoutComposer,
45528
- {
45529
- widgetsZonePrefix: "store_credit_account.details",
45530
- preferredLayoutId: "core:two-column",
45531
- data: storeCreditAccount,
45532
- sections: {
45533
- main: /* @__PURE__ */ jsxs(Fragment, { children: [
45534
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountDetailsSection", children: /* @__PURE__ */ jsx(
45535
- StoreCreditAccountDetailsSection,
45536
- {
45537
- storeCreditAccount
45538
- }
45539
- ) }),
45540
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "TransactionsTable", children: /* @__PURE__ */ jsx(TransactionsTable, { id: storeCreditAccount.id }) })
45541
- ] }),
45542
- side: /* @__PURE__ */ jsxs(Fragment, { children: [
45543
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountBalanceSection", children: /* @__PURE__ */ jsx(
45544
- StoreCreditAccountBalanceSection,
45545
- {
45546
- storeCreditAccount
45547
- }
45548
- ) }),
45549
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountCodeSection", children: /* @__PURE__ */ jsx(StoreCreditAccountCodeSection, { code: storeCreditAccount.code }) }),
45550
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountCustomerSection", children: /* @__PURE__ */ jsx(
45551
- StoreCreditAccountCustomerSection,
45552
- {
45553
- customerId: storeCreditAccount.customer_id
45554
- }
45555
- ) })
45556
- ] })
45557
- }
45558
- }
45559
- );
45560
- };
45561
- const Note = () => {
45562
- const { id } = useParams();
45563
- const {
45564
- store_credit_account: storeCreditAccount,
45565
- isPending,
45566
- isError,
45567
- error: error2
45568
- } = useStoreCreditAccount(id, {});
45569
- if (isError) {
45570
- throw error2;
45571
- }
45572
- const isReady = !isPending && !!storeCreditAccount;
45573
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
45574
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
45575
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Credit store credit account" }) }),
45576
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Credit the store credit account" }) })
45577
- ] }),
45578
- isReady && /* @__PURE__ */ jsx(StoreCreditAccountCreditForm, { storeCreditAccount })
45579
- ] });
45580
- };
45581
- const StoreCreditAccountCreditForm = ({
45582
- storeCreditAccount
45583
- }) => {
45584
- const form = useForm({
45585
- defaultValues: {
45586
- amount: {
45587
- float: 0,
45588
- value: ""
45589
- },
45590
- note: ""
45591
- },
45592
- resolver: u(schema$1)
45593
- });
45594
- const { mutateAsync, isPending } = useCreditStoreCreditAccount(
45595
- storeCreditAccount.id
45596
- );
45597
- const { handleSuccess } = useRouteModal();
45598
- const onSubmit = form.handleSubmit(async (data) => {
45599
- if (data.amount.float <= 0) {
45600
- form.setError("amount", { message: "Amount must be greater than 0" });
45601
- return;
45602
- }
45603
- await mutateAsync(
45604
- { amount: data.amount.float, note: data.note },
45605
- {
45606
- onSuccess: () => handleSuccess(),
45607
- onError: (error2) => toast.error(error2.message)
45608
- }
45609
- );
45610
- });
45611
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
45612
- KeyboundForm,
45613
- {
45614
- className: "flex flex-1 flex-col overflow-hidden",
45615
- onSubmit,
45616
- children: [
45617
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
45618
- /* @__PURE__ */ jsx(
45619
- Form$2.Field,
45620
- {
45621
- control: form.control,
45622
- name: "amount",
45623
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
45624
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Amount" }),
45625
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
45626
- CurrencyInput,
45627
- {
45628
- min: 0,
45629
- placeholder: "0",
45630
- value: field.value.value,
45631
- onValueChange: (_value, _name, values) => {
45632
- field.onChange({
45633
- value: values?.value,
45634
- float: values?.float || null
45635
- });
45636
- },
45637
- symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
45638
- code: storeCreditAccount.currency_code.toUpperCase()
45639
- }
45640
- ) }),
45641
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
45642
- ] })
45643
- }
45644
- ),
45645
- /* @__PURE__ */ jsx(
45646
- Form$2.Field,
45647
- {
45648
- control: form.control,
45649
- name: "note",
45650
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
45651
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
45652
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
45653
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
45654
- ] })
45655
- }
45656
- )
45657
- ] }),
45658
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
45659
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
45660
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
45661
- ] }) })
45662
- ]
45663
- }
45664
- ) });
45665
- };
45666
- const schema$1 = z.object({
45667
- note: z.string(),
45668
- amount: z.object({
45669
- float: z.number(),
45670
- value: z.string()
45671
- })
45672
- });
45673
- const Debit = () => {
45674
- const { id } = useParams();
45675
- const {
45676
- store_credit_account: storeCreditAccount,
45677
- isPending,
45678
- isError,
45679
- error: error2
45680
- } = useStoreCreditAccount(id, {});
45681
- if (isError) {
45682
- throw error2;
45683
- }
45684
- const isReady = !isPending && !!storeCreditAccount;
45685
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
45686
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
45687
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Debit store credit account" }) }),
45688
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Debit the store credit account" }) })
45689
- ] }),
45690
- isReady && /* @__PURE__ */ jsx(StoreCreditAccountDebitForm, { storeCreditAccount })
45691
- ] });
45692
- };
45693
- const StoreCreditAccountDebitForm = ({
45694
- storeCreditAccount
45695
- }) => {
45696
- const form = useForm({
45697
- defaultValues: {
45698
- amount: {
45699
- float: 0,
45700
- value: ""
45701
- },
45702
- note: ""
45703
- },
45704
- resolver: u(schema)
45705
- });
45706
- const { mutateAsync, isPending } = useDebitStoreCreditAccount(
45707
- storeCreditAccount.id
45708
- );
45709
- const { handleSuccess } = useRouteModal();
45710
- const balance = storeCreditAccount.balance ?? 0;
45711
- const onSubmit = form.handleSubmit(async (data) => {
45712
- if (data.amount.float <= 0) {
45713
- form.setError("amount", { message: "Amount must be greater than 0" });
45714
- return;
45715
- }
45716
- if (data.amount.float > balance) {
45717
- form.setError("amount", {
45718
- message: "Amount can't be greater than the current balance"
45719
- });
45720
- return;
45721
- }
45722
- await mutateAsync(
45723
- { amount: data.amount.float, note: data.note },
45724
- {
45725
- onSuccess: () => handleSuccess(),
45726
- onError: (error2) => toast.error(error2.message)
45727
- }
45728
- );
45729
- });
45730
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
45731
- KeyboundForm,
45732
- {
45733
- className: "flex flex-1 flex-col overflow-hidden",
45734
- onSubmit,
45735
- children: [
45736
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
45737
- /* @__PURE__ */ jsx(
45738
- Form$2.Field,
45739
- {
45740
- control: form.control,
45741
- name: "amount",
45742
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
45743
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Amount" }),
45744
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
45745
- CurrencyInput,
45746
- {
45747
- min: 0,
45748
- placeholder: "0",
45749
- value: field.value.value,
45750
- onValueChange: (_value, _name, values) => {
45751
- field.onChange({
45752
- value: values?.value,
45753
- float: values?.float || null
45754
- });
45755
- },
45756
- symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
45757
- code: storeCreditAccount.currency_code.toUpperCase()
45758
- }
45759
- ) }),
45760
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
45761
- ] })
45762
- }
45763
- ),
45764
- /* @__PURE__ */ jsx(
45765
- Form$2.Field,
45766
- {
45767
- control: form.control,
45768
- name: "note",
45769
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
45770
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
45771
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
45772
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
45773
- ] })
45774
- }
45775
- )
45776
- ] }),
45777
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
45778
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
45779
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
45780
- ] }) })
45781
- ]
45782
- }
45783
- ) });
45784
- };
45785
- const schema = z.object({
45786
- note: z.string(),
45787
- amount: z.object({
45788
- float: z.number(),
45789
- value: z.string()
45790
- })
45791
- });
45792
45792
  const productStatusColor = (status) => {
45793
45793
  switch (status) {
45794
45794
  case "draft":
@@ -47222,7 +47222,7 @@ const ProductMedia = () => {
47222
47222
  ] });
47223
47223
  };
47224
47224
  const VariantPricingForm = ({ form }) => {
47225
- const { store } = useStore$2();
47225
+ const { store } = useStore$1();
47226
47226
  const { regions } = useRegions({ limit: 9999 });
47227
47227
  const { price_preferences: pricePreferences } = usePricePreferences({});
47228
47228
  const { setCloseOnEscape } = useRouteModal();
@@ -47497,10 +47497,21 @@ const widgetModule = { widgets: [
47497
47497
  ] };
47498
47498
  const routeModule = {
47499
47499
  routes: [
47500
+ {
47501
+ Component: StoreCreditAccountsPage,
47502
+ path: "/store-credit-accounts",
47503
+ handle: { label: config$3.label, translationNs: config$3.translationNs },
47504
+ children: [
47505
+ {
47506
+ Component: StoreCreditAccountCreate,
47507
+ path: "/store-credit-accounts/create"
47508
+ }
47509
+ ]
47510
+ },
47500
47511
  {
47501
47512
  Component: GiftCardsPage,
47502
47513
  path: "/gift-cards",
47503
- handle: { label: config$3.label, translationNs: config$3.translationNs },
47514
+ handle: { label: config$2.label, translationNs: config$2.translationNs },
47504
47515
  children: [
47505
47516
  {
47506
47517
  Component: GiftCardCreate,
@@ -47509,13 +47520,16 @@ const routeModule = {
47509
47520
  ]
47510
47521
  },
47511
47522
  {
47512
- Component: StoreCreditAccountsPage,
47513
- path: "/store-credit-accounts",
47514
- handle: { label: config$1.label, translationNs: config$1.translationNs },
47523
+ Component: StoreCreditAccountPage,
47524
+ path: "/store-credit-accounts/:id",
47515
47525
  children: [
47516
47526
  {
47517
- Component: StoreCreditAccountCreate,
47518
- path: "/store-credit-accounts/create"
47527
+ Component: Note$1,
47528
+ path: "/store-credit-accounts/:id/credit"
47529
+ },
47530
+ {
47531
+ Component: Debit,
47532
+ path: "/store-credit-accounts/:id/debit"
47519
47533
  }
47520
47534
  ]
47521
47535
  },
@@ -47528,7 +47542,7 @@ const routeModule = {
47528
47542
  path: "/gift-cards/:id/expiration"
47529
47543
  },
47530
47544
  {
47531
- Component: Note$1,
47545
+ Component: Note,
47532
47546
  path: "/gift-cards/:id/note"
47533
47547
  }
47534
47548
  ]
@@ -47544,20 +47558,6 @@ const routeModule = {
47544
47558
  }
47545
47559
  ]
47546
47560
  },
47547
- {
47548
- Component: StoreCreditAccountPage,
47549
- path: "/store-credit-accounts/:id",
47550
- children: [
47551
- {
47552
- Component: Note,
47553
- path: "/store-credit-accounts/:id/credit"
47554
- },
47555
- {
47556
- Component: Debit,
47557
- path: "/store-credit-accounts/:id/debit"
47558
- }
47559
- ]
47560
- },
47561
47561
  {
47562
47562
  Component: ProductDetail,
47563
47563
  path: "/gift-cards/gift-card-products/:id",
@@ -47591,15 +47591,15 @@ const menuItemModule = {
47591
47591
  {
47592
47592
  label: config$3.label,
47593
47593
  icon: config$3.icon,
47594
- path: "/gift-cards",
47594
+ path: "/store-credit-accounts",
47595
47595
  nested: void 0,
47596
47596
  rank: void 0,
47597
47597
  translationNs: void 0
47598
47598
  },
47599
47599
  {
47600
- label: config$1.label,
47601
- icon: config$1.icon,
47602
- path: "/store-credit-accounts",
47600
+ label: config$2.label,
47601
+ icon: config$2.icon,
47602
+ path: "/gift-cards",
47603
47603
  nested: void 0,
47604
47604
  rank: void 0,
47605
47605
  translationNs: void 0