@medusajs/loyalty-plugin 2.20.1 → 2.20.2-preview-20260904113944

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 as CurrencyInput$1, 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 as CurrencyInput$1, 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, useId as useId$1, useContext, useEffect, isValidElement as isValidElement$1, useLayoutEffect, useRef, useReducer, useTransition, useImperativeHandle, useDeferredValue, Suspense, memo as memo$2, 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, User, Share, XCircleSolid, TriangleLeftMini } from "@medusajs/icons";
7
+ import { EllipsisHorizontal, InformationCircleSolid, ExclamationCircle, PlusMini, TriangleRightMini, Gift, Photo, PencilSquare, Trash, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, Tag, CreditCard, 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, {}) }) }),
@@ -5728,7 +5728,7 @@ defineWidgetConfig({
5728
5728
  zone: "sales_channel.details.after",
5729
5729
  id: "medusa:sales-channel-gift-cards-widget"
5730
5730
  });
5731
- const GiftCardIcon = (props) => {
5731
+ const StoreCreditIcon = (props) => {
5732
5732
  return /* @__PURE__ */ jsxs(
5733
5733
  "svg",
5734
5734
  {
@@ -5739,197 +5739,49 @@ const GiftCardIcon = (props) => {
5739
5739
  xmlns: "http://www.w3.org/2000/svg",
5740
5740
  ...props,
5741
5741
  children: [
5742
- /* @__PURE__ */ jsx("rect", { width: "15", height: "15", fill: "#F97316" }),
5742
+ /* @__PURE__ */ jsx("rect", { width: "15", height: "15", fill: "#8B5CF6" }),
5743
5743
  /* @__PURE__ */ jsx(
5744
5744
  "rect",
5745
5745
  {
5746
5746
  width: "15",
5747
5747
  height: "15",
5748
- fill: "url(#paint0_linear_28788_25808)",
5748
+ fill: "url(#paint0_linear_29181_44790)",
5749
5749
  fillOpacity: "0.2"
5750
5750
  }
5751
5751
  ),
5752
- /* @__PURE__ */ jsxs("g", { clipPath: "url(#clip0_28788_25808)", children: [
5753
- /* @__PURE__ */ jsx(
5754
- "path",
5755
- {
5756
- 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",
5757
- fill: "white"
5758
- }
5759
- ),
5760
- /* @__PURE__ */ jsx(
5761
- "path",
5762
- {
5763
- 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",
5764
- fill: "white"
5765
- }
5766
- ),
5767
- /* @__PURE__ */ jsx(
5768
- "path",
5769
- {
5770
- 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",
5771
- fill: "white"
5772
- }
5773
- ),
5774
- /* @__PURE__ */ jsx(
5775
- "path",
5776
- {
5777
- d: "M6.938 7.5H3.75V9.563C3.75 10.7 4.675 11.625 5.813 11.625H6.938V7.5Z",
5778
- fill: "white"
5779
- }
5780
- ),
5781
- /* @__PURE__ */ jsx(
5782
- "path",
5783
- {
5784
- d: "M8.063 7.5V11.625H9.188C10.325 11.625 11.25 10.7 11.25 9.563V7.5H8.063Z",
5785
- fill: "white"
5786
- }
5787
- )
5788
- ] }),
5789
- /* @__PURE__ */ jsxs("defs", { children: [
5790
- /* @__PURE__ */ jsxs(
5791
- "linearGradient",
5792
- {
5793
- id: "paint0_linear_28788_25808",
5794
- x1: "7.5",
5795
- y1: "0",
5796
- x2: "7.5",
5797
- y2: "15",
5798
- gradientUnits: "userSpaceOnUse",
5799
- children: [
5800
- /* @__PURE__ */ jsx("stop", { stopColor: "white" }),
5801
- /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
5802
- ]
5803
- }
5804
- ),
5805
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_28788_25808", children: /* @__PURE__ */ jsx("rect", { width: "9", height: "9", fill: "white", transform: "translate(3 3)" }) })
5806
- ] })
5752
+ /* @__PURE__ */ jsx(
5753
+ "path",
5754
+ {
5755
+ d: "M12 6V5.813C12 4.675 11.075 3.75 9.938 3.75H5.063C3.925 3.75 3 4.675 3 5.813V6H12Z",
5756
+ fill: "white"
5757
+ }
5758
+ ),
5759
+ /* @__PURE__ */ jsx(
5760
+ "path",
5761
+ {
5762
+ 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",
5763
+ fill: "white"
5764
+ }
5765
+ ),
5766
+ /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
5767
+ "linearGradient",
5768
+ {
5769
+ id: "paint0_linear_29181_44790",
5770
+ x1: "7.5",
5771
+ y1: "0",
5772
+ x2: "7.5",
5773
+ y2: "15",
5774
+ gradientUnits: "userSpaceOnUse",
5775
+ children: [
5776
+ /* @__PURE__ */ jsx("stop", { stopColor: "white" }),
5777
+ /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
5778
+ ]
5779
+ }
5780
+ ) })
5807
5781
  ]
5808
5782
  }
5809
5783
  );
5810
5784
  };
5811
- const GiftCardProductsSection = () => {
5812
- const { products: giftCardProducts, count: count2 = 0 } = useProducts({
5813
- is_giftcard: true
5814
- });
5815
- const slicedProducts = giftCardProducts?.slice(0, 3) ?? [];
5816
- return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
5817
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
5818
- /* @__PURE__ */ jsx(Header$5, { title: "Gift Card Products" }),
5819
- /* @__PURE__ */ jsx(
5820
- Link,
5821
- {
5822
- to: `/gift-cards/gift-card-products/create`,
5823
- className: "text-ui-fg-muted text-sm px-6",
5824
- children: "Create"
5825
- }
5826
- )
5827
- ] }),
5828
- giftCardProducts?.length === 0 && /* @__PURE__ */ jsx(
5829
- NoRecords,
5830
- {
5831
- className: "px-10 py-4 h-[200px]",
5832
- title: "No gift card products",
5833
- message: "There are no gift card products to show. Create one to get started.",
5834
- action: {
5835
- to: "/gift-cards/gift-card-products/create",
5836
- label: "Create gift card product"
5837
- }
5838
- }
5839
- ),
5840
- slicedProducts.map((giftCardProduct) => /* @__PURE__ */ jsx(
5841
- SidebarLink,
5842
- {
5843
- to: `/gift-cards/gift-card-products/${giftCardProduct.id}`,
5844
- labelKey: giftCardProduct.title,
5845
- descriptionKey: giftCardProduct.title,
5846
- icon: /* @__PURE__ */ jsx(Tag, {})
5847
- }
5848
- )),
5849
- count2 > 3 && /* @__PURE__ */ jsx(
5850
- Link,
5851
- {
5852
- to: "/gift-cards/gift-card-products",
5853
- className: "text-ui-fg-muted text-sm px-6 py-4 flex items-center justify-center",
5854
- children: "View more"
5855
- }
5856
- )
5857
- ] });
5858
- };
5859
- const _giftCardQueryKey = queryKeysFactory("gift-card");
5860
- const giftCardQueryKey = {
5861
- ..._giftCardQueryKey,
5862
- orders: (id) => [..._giftCardQueryKey.detail(id), "orders"]
5863
- };
5864
- const useGiftCards = (query, options) => {
5865
- const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
5866
- query: query2,
5867
- headers
5868
- });
5869
- const { data, ...rest } = useQuery({
5870
- ...options,
5871
- queryFn: () => fetchGiftCards(query),
5872
- queryKey: giftCardQueryKey.list(query)
5873
- });
5874
- return { ...data, ...rest };
5875
- };
5876
- const useGiftCard = (id, query, options) => {
5877
- const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
5878
- query: query2,
5879
- headers
5880
- });
5881
- const { data, ...rest } = useQuery({
5882
- queryFn: () => fetchGiftCard(id, query),
5883
- queryKey: giftCardQueryKey.detail(id, query),
5884
- ...options
5885
- });
5886
- return { ...data, ...rest };
5887
- };
5888
- const useGiftCardOrders = (id, options) => {
5889
- const fetchGiftCardOrders = (id2, query, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}/orders`, {
5890
- query,
5891
- headers
5892
- });
5893
- const { data, ...rest } = useQuery({
5894
- queryFn: () => fetchGiftCardOrders(id),
5895
- queryKey: giftCardQueryKey.orders(id),
5896
- ...options
5897
- });
5898
- return { ...data, ...rest };
5899
- };
5900
- const useUpdateGiftCard = (id, options) => {
5901
- const queryClient = useQueryClient();
5902
- const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
5903
- body,
5904
- method: "POST"
5905
- });
5906
- return useMutation({
5907
- mutationFn: async (payload) => updateGiftCard(id, payload),
5908
- onSuccess: (data, variables, context) => {
5909
- queryClient.invalidateQueries({
5910
- queryKey: giftCardQueryKey.detail(id)
5911
- });
5912
- queryClient.invalidateQueries({
5913
- queryKey: giftCardQueryKey.lists()
5914
- });
5915
- },
5916
- ...options
5917
- });
5918
- };
5919
- const useCreateGiftCard = (options) => {
5920
- const queryClient = useQueryClient();
5921
- const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
5922
- body,
5923
- method: "POST"
5924
- });
5925
- return useMutation({
5926
- mutationFn: (body) => createGiftCard(body),
5927
- onSuccess: (data, variables, context) => {
5928
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
5929
- },
5930
- ...options
5931
- });
5932
- };
5933
5785
  function getRelativeDate(date2) {
5934
5786
  const now = /* @__PURE__ */ new Date();
5935
5787
  return formatDistance(sub(new Date(date2), { minutes: 0 }), now, {
@@ -5947,30 +5799,51 @@ function formatDate(date2, withTime = true) {
5947
5799
  return format(new Date(date2), "dd MMM, yyyy");
5948
5800
  }
5949
5801
  const columnHelper$a = createDataTableColumnHelper();
5950
- const useGiftCardTableColumns = () => {
5802
+ const useStoreCreditAccountTableColumns = () => {
5951
5803
  return useMemo(() => {
5952
5804
  return [
5953
- columnHelper$a.accessor("code", {
5954
- header: "Code",
5805
+ columnHelper$a.accessor("currency_code", {
5806
+ header: "Currency",
5955
5807
  cell: ({ row }) => {
5956
- return row.original.code;
5808
+ return /* @__PURE__ */ jsx(Badge, { size: "2xsmall", children: row.original.currency_code.toUpperCase() });
5957
5809
  }
5958
5810
  }),
5959
- columnHelper$a.accessor("line_item.product.title", {
5960
- header: "Product",
5811
+ columnHelper$a.accessor("customer.email", {
5812
+ header: "Customer",
5961
5813
  cell: ({ row }) => {
5962
- return row.original.line_item?.product?.title || "Custom Gift Card";
5814
+ return row.original.customer?.email ?? "N/A";
5963
5815
  }
5964
5816
  }),
5965
- columnHelper$a.accessor("created_at", {
5966
- header: "Date issued",
5967
- cell: ({ row }) => getRelativeDate(row.original.created_at)
5817
+ columnHelper$a.accessor("balance", {
5818
+ header: "Balance",
5819
+ cell: ({ row }) => {
5820
+ return formatAmount(
5821
+ row.original.balance,
5822
+ row.original.currency_code
5823
+ );
5824
+ }
5968
5825
  }),
5969
- columnHelper$a.accessor("value", {
5970
- header: "Value",
5826
+ columnHelper$a.accessor("credits", {
5827
+ header: "Credits",
5971
5828
  cell: ({ row }) => {
5972
- return formatAmount(row.original.value, row.original.currency_code);
5829
+ return formatAmount(
5830
+ row.original.credits,
5831
+ row.original.currency_code
5832
+ );
5833
+ }
5834
+ }),
5835
+ columnHelper$a.accessor("debits", {
5836
+ header: "Debits",
5837
+ cell: ({ row }) => {
5838
+ return formatAmount(
5839
+ row.original.debits,
5840
+ row.original.currency_code
5841
+ );
5973
5842
  }
5843
+ }),
5844
+ columnHelper$a.accessor("created_at", {
5845
+ header: "Created at",
5846
+ cell: ({ row }) => getRelativeDate(row.original.created_at)
5974
5847
  })
5975
5848
  ];
5976
5849
  }, []);
@@ -6017,75 +5890,83 @@ const useCustomerFilters = () => {
6017
5890
  ];
6018
5891
  }, [customerFilterOptions]);
6019
5892
  };
6020
- const useGiftCardFilters = () => {
5893
+ const useStoreCreditAccountFilters = () => {
6021
5894
  const dateFilterOptions = useDataTableDateFilters$1();
6022
5895
  const customerFilterOptions = useCustomerFilters();
6023
5896
  return useMemo(() => {
6024
5897
  return [...dateFilterOptions, ...customerFilterOptions];
6025
5898
  }, [dateFilterOptions, customerFilterOptions]);
6026
5899
  };
6027
- const useGiftCardTableQuery = ({
5900
+ const useStoreCreditAccountsTableQuery = ({
6028
5901
  prefix,
6029
5902
  pageSize = 20
6030
5903
  }) => {
6031
5904
  const queryObject = useQueryParams(
6032
- ["q", "offset", "customer_id", "created_at", "updated_at"],
5905
+ ["offset", "customer_id", "currency_code", "created_at", "updated_at"],
6033
5906
  prefix
6034
5907
  );
6035
- const { offset: offset2, created_at, updated_at, customer_id, ...rest } = queryObject;
5908
+ const {
5909
+ offset: offset2,
5910
+ created_at,
5911
+ updated_at,
5912
+ customer_id,
5913
+ currency_code,
5914
+ ...rest
5915
+ } = queryObject;
6036
5916
  const searchParams = {
6037
5917
  limit: pageSize,
6038
5918
  offset: offset2 ? Number(offset2) : 0,
6039
5919
  created_at: created_at ? JSON.parse(created_at) : void 0,
6040
5920
  updated_at: updated_at ? JSON.parse(updated_at) : void 0,
6041
5921
  customer_id: customer_id ? JSON.parse(customer_id) : void 0,
5922
+ currency_code: currency_code ? JSON.parse(currency_code) : void 0,
6042
5923
  ...rest
6043
5924
  };
6044
5925
  return searchParams;
6045
5926
  };
6046
5927
  const PAGE_SIZE$6 = 10;
6047
- function GiftCardsTable() {
6048
- const queryParams = useGiftCardTableQuery({
5928
+ function StoreCreditAccountsTable() {
5929
+ const queryParams = useStoreCreditAccountsTableQuery({
6049
5930
  pageSize: PAGE_SIZE$6
6050
5931
  });
6051
5932
  const {
6052
- gift_cards: giftCards,
5933
+ store_credit_accounts: storeCreditAccounts,
6053
5934
  isPending,
6054
5935
  count: count2
6055
- } = useGiftCards({
5936
+ } = useStoreCreditAccounts({
6056
5937
  ...queryParams,
6057
- order: queryParams.order ?? "-created_at",
6058
- fields: "+line_item.product.title"
5938
+ order: queryParams.order ?? "-created_at"
6059
5939
  });
6060
- const columns = useGiftCardTableColumns();
6061
- const filters = useGiftCardFilters();
5940
+ const columns = useStoreCreditAccountTableColumns();
5941
+ const filters = useStoreCreditAccountFilters();
6062
5942
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
6063
5943
  /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
6064
5944
  DataTable,
6065
5945
  {
6066
- data: giftCards,
5946
+ data: storeCreditAccounts ?? [],
6067
5947
  getRowId: (row) => row.id,
6068
5948
  columns,
6069
5949
  filters,
6070
5950
  isLoading: isPending,
6071
5951
  pageSize: PAGE_SIZE$6,
6072
5952
  rowCount: count2,
6073
- heading: "Gift Cards",
5953
+ enableSearch: false,
5954
+ heading: "Store Credit Accounts",
6074
5955
  rowHref: (row) => `${row.id}`,
6075
5956
  emptyState: {
6076
5957
  empty: {
6077
- heading: "No gift cards found",
6078
- description: "Create a gift card to get started."
5958
+ heading: "No store credit accounts found",
5959
+ description: "Create a new store credit account to get started."
6079
5960
  },
6080
5961
  filtered: {
6081
5962
  heading: "No results found",
6082
- description: "No gift cards match your filter criteria."
5963
+ description: "No store credit accounts match your filter criteria."
6083
5964
  }
6084
5965
  },
6085
5966
  actions: [
6086
5967
  {
6087
5968
  label: "Create",
6088
- to: "create"
5969
+ to: "/store-credit-accounts/create"
6089
5970
  }
6090
5971
  ]
6091
5972
  }
@@ -6093,16 +5974,15 @@ function GiftCardsTable() {
6093
5974
  /* @__PURE__ */ jsx(Outlet, {})
6094
5975
  ] });
6095
5976
  }
6096
- const GiftCardsPage = () => {
5977
+ const StoreCreditAccountsPage = () => {
6097
5978
  return /* @__PURE__ */ jsxs(Fragment, { children: [
6098
5979
  /* @__PURE__ */ jsx(
6099
5980
  LayoutComposer,
6100
5981
  {
6101
- widgetsZonePrefix: "gift_card.list",
6102
- preferredLayoutId: "core:two-column",
5982
+ widgetsZonePrefix: "store_credit_account.list",
5983
+ preferredLayoutId: "core:single-column",
6103
5984
  sections: {
6104
- main: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "GiftCardsTable", children: /* @__PURE__ */ jsx(GiftCardsTable, {}) }),
6105
- side: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "GiftCardProductsSection", children: /* @__PURE__ */ jsx(GiftCardProductsSection, {}) })
5985
+ main: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountsTable", children: /* @__PURE__ */ jsx(StoreCreditAccountsTable, {}) })
6106
5986
  }
6107
5987
  }
6108
5988
  ),
@@ -6110,8 +5990,8 @@ const GiftCardsPage = () => {
6110
5990
  ] });
6111
5991
  };
6112
5992
  const config$3 = defineRouteConfig({
6113
- label: "Gift Cards",
6114
- icon: GiftCardIcon
5993
+ label: "Store Credits",
5994
+ icon: StoreCreditIcon
6115
5995
  });
6116
5996
  function setRef$2(ref, value) {
6117
5997
  if (typeof ref === "function") {
@@ -10806,27 +10686,6 @@ const StackedFocusModal = Object.assign(Root, {
10806
10686
  Description,
10807
10687
  Title
10808
10688
  });
10809
- const STORE_QUERY_KEY = "store";
10810
- const storeQueryKeys = queryKeysFactory(STORE_QUERY_KEY);
10811
- async function retrieveActiveStore(query) {
10812
- const response = await sdk.admin.store.list(query);
10813
- const activeStore = response.stores?.[0];
10814
- if (!activeStore) {
10815
- throw new FetchError("No active store found", "Not Found", 404);
10816
- }
10817
- return { store: activeStore };
10818
- }
10819
- const useStore$2 = (query, options) => {
10820
- const { data, ...rest } = useQuery({
10821
- queryFn: () => retrieveActiveStore(query),
10822
- queryKey: storeQueryKeys.details(),
10823
- ...options
10824
- });
10825
- return {
10826
- ...data,
10827
- ...rest
10828
- };
10829
- };
10830
10689
  const t$1 = (r, t2, s2) => {
10831
10690
  if (r && "reportValidity" in r) {
10832
10691
  const o2 = get$2(s2, t2);
@@ -12726,7 +12585,7 @@ function useStoreProps(store, props, key2, setKey) {
12726
12585
  });
12727
12586
  });
12728
12587
  }
12729
- function useStore$1(createStore2, props) {
12588
+ function useStore$2(createStore2, props) {
12730
12589
  const [store, setStore] = React.useState(() => createStore2(props));
12731
12590
  useSafeLayoutEffect(() => init(store), [store]);
12732
12591
  const useState2 = React.useCallback(
@@ -13548,7 +13407,7 @@ function useDisclosureStoreProps(store, update, props) {
13548
13407
  return Object.assign(store, { disclosure: props.disclosure });
13549
13408
  }
13550
13409
  function useDisclosureStore(props = {}) {
13551
- const [store, update] = useStore$1(createDisclosureStore, props);
13410
+ const [store, update] = useStore$2(createDisclosureStore, props);
13552
13411
  return useDisclosureStoreProps(store, update, props);
13553
13412
  }
13554
13413
  var ctx$2 = createStoreContext(
@@ -14937,7 +14796,7 @@ function useDialogStoreProps(store, update, props) {
14937
14796
  return useDisclosureStoreProps(store, update, props);
14938
14797
  }
14939
14798
  function useDialogStore(props = {}) {
14940
- const [store, update] = useStore$1(createDialogStore, props);
14799
+ const [store, update] = useStore$2(createDialogStore, props);
14941
14800
  return useDialogStoreProps(store, update, props);
14942
14801
  }
14943
14802
  var TagName$e = "div";
@@ -16983,7 +16842,7 @@ function useComboboxStoreProps(store, update, props) {
16983
16842
  }
16984
16843
  function useComboboxStore(props = {}) {
16985
16844
  props = useComboboxStoreOptions(props);
16986
- const [store, update] = useStore$1(createComboboxStore, props);
16845
+ const [store, update] = useStore$2(createComboboxStore, props);
16987
16846
  return useComboboxStoreProps(store, update, props);
16988
16847
  }
16989
16848
  function ComboboxProvider(props = {}) {
@@ -18088,6 +17947,369 @@ const ComboboxImpl = ({
18088
17947
  );
18089
17948
  };
18090
17949
  const Combobox = genericForwardRef(ComboboxImpl);
17950
+ var isObject_1;
17951
+ var hasRequiredIsObject;
17952
+ function requireIsObject() {
17953
+ if (hasRequiredIsObject) return isObject_1;
17954
+ hasRequiredIsObject = 1;
17955
+ function isObject2(value) {
17956
+ var type = typeof value;
17957
+ return value != null && (type == "object" || type == "function");
17958
+ }
17959
+ isObject_1 = isObject2;
17960
+ return isObject_1;
17961
+ }
17962
+ var _freeGlobal;
17963
+ var hasRequired_freeGlobal;
17964
+ function require_freeGlobal() {
17965
+ if (hasRequired_freeGlobal) return _freeGlobal;
17966
+ hasRequired_freeGlobal = 1;
17967
+ var freeGlobal = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
17968
+ _freeGlobal = freeGlobal;
17969
+ return _freeGlobal;
17970
+ }
17971
+ var _root;
17972
+ var hasRequired_root;
17973
+ function require_root() {
17974
+ if (hasRequired_root) return _root;
17975
+ hasRequired_root = 1;
17976
+ var freeGlobal = require_freeGlobal();
17977
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
17978
+ var root = freeGlobal || freeSelf || Function("return this")();
17979
+ _root = root;
17980
+ return _root;
17981
+ }
17982
+ var now_1;
17983
+ var hasRequiredNow;
17984
+ function requireNow() {
17985
+ if (hasRequiredNow) return now_1;
17986
+ hasRequiredNow = 1;
17987
+ var root = require_root();
17988
+ var now = function() {
17989
+ return root.Date.now();
17990
+ };
17991
+ now_1 = now;
17992
+ return now_1;
17993
+ }
17994
+ var _trimmedEndIndex;
17995
+ var hasRequired_trimmedEndIndex;
17996
+ function require_trimmedEndIndex() {
17997
+ if (hasRequired_trimmedEndIndex) return _trimmedEndIndex;
17998
+ hasRequired_trimmedEndIndex = 1;
17999
+ var reWhitespace = /\s/;
18000
+ function trimmedEndIndex(string2) {
18001
+ var index = string2.length;
18002
+ while (index-- && reWhitespace.test(string2.charAt(index))) {
18003
+ }
18004
+ return index;
18005
+ }
18006
+ _trimmedEndIndex = trimmedEndIndex;
18007
+ return _trimmedEndIndex;
18008
+ }
18009
+ var _baseTrim;
18010
+ var hasRequired_baseTrim;
18011
+ function require_baseTrim() {
18012
+ if (hasRequired_baseTrim) return _baseTrim;
18013
+ hasRequired_baseTrim = 1;
18014
+ var trimmedEndIndex = require_trimmedEndIndex();
18015
+ var reTrimStart = /^\s+/;
18016
+ function baseTrim(string2) {
18017
+ return string2 ? string2.slice(0, trimmedEndIndex(string2) + 1).replace(reTrimStart, "") : string2;
18018
+ }
18019
+ _baseTrim = baseTrim;
18020
+ return _baseTrim;
18021
+ }
18022
+ var _Symbol;
18023
+ var hasRequired_Symbol;
18024
+ function require_Symbol() {
18025
+ if (hasRequired_Symbol) return _Symbol;
18026
+ hasRequired_Symbol = 1;
18027
+ var root = require_root();
18028
+ var Symbol2 = root.Symbol;
18029
+ _Symbol = Symbol2;
18030
+ return _Symbol;
18031
+ }
18032
+ var _getRawTag;
18033
+ var hasRequired_getRawTag;
18034
+ function require_getRawTag() {
18035
+ if (hasRequired_getRawTag) return _getRawTag;
18036
+ hasRequired_getRawTag = 1;
18037
+ var Symbol2 = require_Symbol();
18038
+ var objectProto = Object.prototype;
18039
+ var hasOwnProperty2 = objectProto.hasOwnProperty;
18040
+ var nativeObjectToString = objectProto.toString;
18041
+ var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
18042
+ function getRawTag(value) {
18043
+ var isOwn = hasOwnProperty2.call(value, symToStringTag), tag = value[symToStringTag];
18044
+ try {
18045
+ value[symToStringTag] = void 0;
18046
+ var unmasked = true;
18047
+ } catch (e) {
18048
+ }
18049
+ var result = nativeObjectToString.call(value);
18050
+ if (unmasked) {
18051
+ if (isOwn) {
18052
+ value[symToStringTag] = tag;
18053
+ } else {
18054
+ delete value[symToStringTag];
18055
+ }
18056
+ }
18057
+ return result;
18058
+ }
18059
+ _getRawTag = getRawTag;
18060
+ return _getRawTag;
18061
+ }
18062
+ var _objectToString;
18063
+ var hasRequired_objectToString;
18064
+ function require_objectToString() {
18065
+ if (hasRequired_objectToString) return _objectToString;
18066
+ hasRequired_objectToString = 1;
18067
+ var objectProto = Object.prototype;
18068
+ var nativeObjectToString = objectProto.toString;
18069
+ function objectToString(value) {
18070
+ return nativeObjectToString.call(value);
18071
+ }
18072
+ _objectToString = objectToString;
18073
+ return _objectToString;
18074
+ }
18075
+ var _baseGetTag;
18076
+ var hasRequired_baseGetTag;
18077
+ function require_baseGetTag() {
18078
+ if (hasRequired_baseGetTag) return _baseGetTag;
18079
+ hasRequired_baseGetTag = 1;
18080
+ var Symbol2 = require_Symbol(), getRawTag = require_getRawTag(), objectToString = require_objectToString();
18081
+ var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
18082
+ var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
18083
+ function baseGetTag(value) {
18084
+ if (value == null) {
18085
+ return value === void 0 ? undefinedTag : nullTag;
18086
+ }
18087
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
18088
+ }
18089
+ _baseGetTag = baseGetTag;
18090
+ return _baseGetTag;
18091
+ }
18092
+ var isObjectLike_1;
18093
+ var hasRequiredIsObjectLike;
18094
+ function requireIsObjectLike() {
18095
+ if (hasRequiredIsObjectLike) return isObjectLike_1;
18096
+ hasRequiredIsObjectLike = 1;
18097
+ function isObjectLike(value) {
18098
+ return value != null && typeof value == "object";
18099
+ }
18100
+ isObjectLike_1 = isObjectLike;
18101
+ return isObjectLike_1;
18102
+ }
18103
+ var isSymbol_1;
18104
+ var hasRequiredIsSymbol;
18105
+ function requireIsSymbol() {
18106
+ if (hasRequiredIsSymbol) return isSymbol_1;
18107
+ hasRequiredIsSymbol = 1;
18108
+ var baseGetTag = require_baseGetTag(), isObjectLike = requireIsObjectLike();
18109
+ var symbolTag = "[object Symbol]";
18110
+ function isSymbol(value) {
18111
+ return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
18112
+ }
18113
+ isSymbol_1 = isSymbol;
18114
+ return isSymbol_1;
18115
+ }
18116
+ var toNumber_1;
18117
+ var hasRequiredToNumber;
18118
+ function requireToNumber() {
18119
+ if (hasRequiredToNumber) return toNumber_1;
18120
+ hasRequiredToNumber = 1;
18121
+ var baseTrim = require_baseTrim(), isObject2 = requireIsObject(), isSymbol = requireIsSymbol();
18122
+ var NAN = 0 / 0;
18123
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
18124
+ var reIsBinary = /^0b[01]+$/i;
18125
+ var reIsOctal = /^0o[0-7]+$/i;
18126
+ var freeParseInt = parseInt;
18127
+ function toNumber(value) {
18128
+ if (typeof value == "number") {
18129
+ return value;
18130
+ }
18131
+ if (isSymbol(value)) {
18132
+ return NAN;
18133
+ }
18134
+ if (isObject2(value)) {
18135
+ var other = typeof value.valueOf == "function" ? value.valueOf() : value;
18136
+ value = isObject2(other) ? other + "" : other;
18137
+ }
18138
+ if (typeof value != "string") {
18139
+ return value === 0 ? value : +value;
18140
+ }
18141
+ value = baseTrim(value);
18142
+ var isBinary = reIsBinary.test(value);
18143
+ return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
18144
+ }
18145
+ toNumber_1 = toNumber;
18146
+ return toNumber_1;
18147
+ }
18148
+ var debounce_1;
18149
+ var hasRequiredDebounce;
18150
+ function requireDebounce() {
18151
+ if (hasRequiredDebounce) return debounce_1;
18152
+ hasRequiredDebounce = 1;
18153
+ var isObject2 = requireIsObject(), now = requireNow(), toNumber = requireToNumber();
18154
+ var FUNC_ERROR_TEXT = "Expected a function";
18155
+ var nativeMax = Math.max, nativeMin = Math.min;
18156
+ function debounce2(func, wait, options) {
18157
+ var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
18158
+ if (typeof func != "function") {
18159
+ throw new TypeError(FUNC_ERROR_TEXT);
18160
+ }
18161
+ wait = toNumber(wait) || 0;
18162
+ if (isObject2(options)) {
18163
+ leading = !!options.leading;
18164
+ maxing = "maxWait" in options;
18165
+ maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
18166
+ trailing = "trailing" in options ? !!options.trailing : trailing;
18167
+ }
18168
+ function invokeFunc(time2) {
18169
+ var args = lastArgs, thisArg = lastThis;
18170
+ lastArgs = lastThis = void 0;
18171
+ lastInvokeTime = time2;
18172
+ result = func.apply(thisArg, args);
18173
+ return result;
18174
+ }
18175
+ function leadingEdge(time2) {
18176
+ lastInvokeTime = time2;
18177
+ timerId = setTimeout(timerExpired, wait);
18178
+ return leading ? invokeFunc(time2) : result;
18179
+ }
18180
+ function remainingWait(time2) {
18181
+ var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
18182
+ return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
18183
+ }
18184
+ function shouldInvoke(time2) {
18185
+ var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime;
18186
+ return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
18187
+ }
18188
+ function timerExpired() {
18189
+ var time2 = now();
18190
+ if (shouldInvoke(time2)) {
18191
+ return trailingEdge(time2);
18192
+ }
18193
+ timerId = setTimeout(timerExpired, remainingWait(time2));
18194
+ }
18195
+ function trailingEdge(time2) {
18196
+ timerId = void 0;
18197
+ if (trailing && lastArgs) {
18198
+ return invokeFunc(time2);
18199
+ }
18200
+ lastArgs = lastThis = void 0;
18201
+ return result;
18202
+ }
18203
+ function cancel() {
18204
+ if (timerId !== void 0) {
18205
+ clearTimeout(timerId);
18206
+ }
18207
+ lastInvokeTime = 0;
18208
+ lastArgs = lastCallTime = lastThis = timerId = void 0;
18209
+ }
18210
+ function flush() {
18211
+ return timerId === void 0 ? result : trailingEdge(now());
18212
+ }
18213
+ function debounced() {
18214
+ var time2 = now(), isInvoking = shouldInvoke(time2);
18215
+ lastArgs = arguments;
18216
+ lastThis = this;
18217
+ lastCallTime = time2;
18218
+ if (isInvoking) {
18219
+ if (timerId === void 0) {
18220
+ return leadingEdge(lastCallTime);
18221
+ }
18222
+ if (maxing) {
18223
+ clearTimeout(timerId);
18224
+ timerId = setTimeout(timerExpired, wait);
18225
+ return invokeFunc(lastCallTime);
18226
+ }
18227
+ }
18228
+ if (timerId === void 0) {
18229
+ timerId = setTimeout(timerExpired, wait);
18230
+ }
18231
+ return result;
18232
+ }
18233
+ debounced.cancel = cancel;
18234
+ debounced.flush = flush;
18235
+ return debounced;
18236
+ }
18237
+ debounce_1 = debounce2;
18238
+ return debounce_1;
18239
+ }
18240
+ var debounceExports = requireDebounce();
18241
+ const debounce$1 = /* @__PURE__ */ getDefaultExportFromCjs(debounceExports);
18242
+ const useDebouncedSearch = () => {
18243
+ const [searchValue, onSearchValueChange] = useState("");
18244
+ const [debouncedQuery, setDebouncedQuery] = useState("");
18245
+ const debouncedUpdate = useCallback(
18246
+ debounce$1((query) => setDebouncedQuery(query), 300),
18247
+ []
18248
+ );
18249
+ useEffect(() => {
18250
+ debouncedUpdate(searchValue);
18251
+ return () => debouncedUpdate.cancel();
18252
+ }, [searchValue, debouncedUpdate]);
18253
+ return {
18254
+ searchValue,
18255
+ onSearchValueChange,
18256
+ query: debouncedQuery || void 0
18257
+ };
18258
+ };
18259
+ const useComboboxData = ({
18260
+ queryKey,
18261
+ queryFn,
18262
+ getOptions,
18263
+ defaultValue: defaultValue2,
18264
+ defaultValueKey,
18265
+ pageSize = 10
18266
+ }) => {
18267
+ const { searchValue, onSearchValueChange, query } = useDebouncedSearch();
18268
+ const queryInitialDataBy = defaultValueKey || "id";
18269
+ const { data: initialData } = useQuery({
18270
+ queryKey,
18271
+ queryFn: async () => {
18272
+ return queryFn({
18273
+ [queryInitialDataBy]: defaultValue2,
18274
+ limit: Array.isArray(defaultValue2) ? defaultValue2.length : 1
18275
+ });
18276
+ },
18277
+ enabled: !!defaultValue2
18278
+ });
18279
+ const { data, ...rest } = useInfiniteQuery({
18280
+ queryKey: [...queryKey, query],
18281
+ queryFn: async ({ pageParam = 0 }) => {
18282
+ return await queryFn({
18283
+ q: query,
18284
+ limit: pageSize,
18285
+ offset: pageParam
18286
+ });
18287
+ },
18288
+ initialPageParam: 0,
18289
+ getNextPageParam: (lastPage) => {
18290
+ const moreItemsExist = lastPage.count > lastPage.offset + lastPage.limit;
18291
+ return moreItemsExist ? lastPage.offset + lastPage.limit : void 0;
18292
+ },
18293
+ placeholderData: keepPreviousData
18294
+ });
18295
+ const options = data?.pages.flatMap((page) => getOptions(page)) ?? [];
18296
+ const defaultOptions2 = initialData ? getOptions(initialData) : [];
18297
+ const disabled = !rest.isPending && !options.length && !searchValue;
18298
+ if (defaultValue2 && defaultOptions2.length && !searchValue) {
18299
+ defaultOptions2.forEach((option) => {
18300
+ if (!options.find((o2) => o2.value === option.value)) {
18301
+ options.unshift(option);
18302
+ }
18303
+ });
18304
+ }
18305
+ return {
18306
+ options,
18307
+ searchValue,
18308
+ onSearchValueChange,
18309
+ disabled,
18310
+ ...rest
18311
+ };
18312
+ };
18091
18313
  const currencies = {
18092
18314
  USD: {
18093
18315
  code: "USD",
@@ -18828,6 +19050,501 @@ const currencies = {
18828
19050
  decimal_digits: 0
18829
19051
  }
18830
19052
  };
19053
+ const formSchema = z.object({
19054
+ currency_code: z.string().min(1, "Please select a currency"),
19055
+ customer_id: z.string().optional()
19056
+ });
19057
+ const StoreCreditAccountCreateForm = () => {
19058
+ const { handleSuccess } = useRouteModal();
19059
+ const form = useForm({
19060
+ defaultValues: {
19061
+ currency_code: "",
19062
+ customer_id: ""
19063
+ },
19064
+ resolver: u(formSchema)
19065
+ });
19066
+ const { mutateAsync: createStoreCreditAccount, isPending } = useCreateStoreCreditAccount();
19067
+ const handleSubmit = form.handleSubmit(async (data) => {
19068
+ if (!data.customer_id) {
19069
+ delete data.customer_id;
19070
+ }
19071
+ await createStoreCreditAccount(data, {
19072
+ onSuccess: (data2) => {
19073
+ toast.success(`Store credit account was successfully created.`);
19074
+ handleSuccess(`../${data2.store_credit_account.id}`);
19075
+ },
19076
+ onError: (error) => {
19077
+ toast.error(error.message);
19078
+ }
19079
+ });
19080
+ });
19081
+ const [currencySearchValue, setCurrencySearchValue] = useState("");
19082
+ const currencyOptions = useMemo(() => {
19083
+ const options = Object.values(currencies).map((currency) => ({
19084
+ label: `${currency.code} - ${currency.name} (${currency.symbol_native})`,
19085
+ value: currency.code.toLowerCase()
19086
+ }));
19087
+ if (!currencySearchValue) {
19088
+ return options;
19089
+ }
19090
+ return options.filter(
19091
+ (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
19092
+ );
19093
+ }, [currencySearchValue]);
19094
+ const {
19095
+ options: customerOptions,
19096
+ fetchNextPage,
19097
+ isFetchingNextPage,
19098
+ searchValue,
19099
+ onSearchValueChange,
19100
+ isLoading
19101
+ } = useComboboxData({
19102
+ queryKey: customersQueryKeys.list(),
19103
+ queryFn: async (params) => {
19104
+ return sdk.admin.customer.list(params);
19105
+ },
19106
+ getOptions: (data) => {
19107
+ return data.customers?.map((customer) => {
19108
+ const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
19109
+ const label = fullName ? `${customer.email} (${fullName})` : customer.email;
19110
+ return {
19111
+ label,
19112
+ value: customer.id
19113
+ };
19114
+ }) || [];
19115
+ }
19116
+ });
19117
+ return /* @__PURE__ */ jsxs(RouteFocusModal.Form, { form, children: [
19118
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsx("div", { className: "-my-2 w-full border-l" }) }),
19119
+ /* @__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: [
19120
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
19121
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Create Store Credit Account" }),
19122
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new store credit account for a customer" })
19123
+ ] }),
19124
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-x-4", children: [
19125
+ /* @__PURE__ */ jsx(
19126
+ Form$2.Field,
19127
+ {
19128
+ control: form.control,
19129
+ name: "currency_code",
19130
+ render: ({ field }) => {
19131
+ return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
19132
+ /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Currency" }),
19133
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
19134
+ Combobox,
19135
+ {
19136
+ value: field.value,
19137
+ onChange: field.onChange,
19138
+ searchValue: currencySearchValue,
19139
+ onSearchValueChange: setCurrencySearchValue,
19140
+ options: currencyOptions,
19141
+ placeholder: "Search for a currency..."
19142
+ }
19143
+ ) }),
19144
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
19145
+ ] });
19146
+ }
19147
+ }
19148
+ ),
19149
+ /* @__PURE__ */ jsx(
19150
+ Form$2.Field,
19151
+ {
19152
+ control: form.control,
19153
+ name: "customer_id",
19154
+ render: ({ field }) => {
19155
+ return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
19156
+ /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Customer" }),
19157
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
19158
+ Combobox,
19159
+ {
19160
+ value: field.value,
19161
+ onChange: field.onChange,
19162
+ searchValue,
19163
+ onSearchValueChange,
19164
+ options: customerOptions,
19165
+ placeholder: "Search for a customer...",
19166
+ fetchNextPage,
19167
+ isFetchingNextPage,
19168
+ noResultsPlaceholder: isLoading ? "Loading customers..." : "No customers found"
19169
+ }
19170
+ ) }),
19171
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
19172
+ ] });
19173
+ }
19174
+ }
19175
+ )
19176
+ ] })
19177
+ ] }) }) }),
19178
+ /* @__PURE__ */ jsxs(RouteFocusModal.Footer, { children: [
19179
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, disabled: isPending, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", disabled: isPending, children: "Cancel" }) }),
19180
+ /* @__PURE__ */ jsx(
19181
+ Button,
19182
+ {
19183
+ variant: "primary",
19184
+ size: "small",
19185
+ onClick: handleSubmit,
19186
+ disabled: isPending,
19187
+ children: "Create"
19188
+ }
19189
+ )
19190
+ ] })
19191
+ ] });
19192
+ };
19193
+ const StoreCreditAccountCreate = () => {
19194
+ return /* @__PURE__ */ jsxs(RouteFocusModal, { children: [
19195
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create Store Credit Account" }) }),
19196
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create a new store credit account" }) }),
19197
+ /* @__PURE__ */ jsx(StoreCreditAccountCreateForm, {})
19198
+ ] });
19199
+ };
19200
+ const GiftCardIcon = (props) => {
19201
+ return /* @__PURE__ */ jsxs(
19202
+ "svg",
19203
+ {
19204
+ width: "15",
19205
+ height: "15",
19206
+ viewBox: "0 0 15 15",
19207
+ fill: "none",
19208
+ xmlns: "http://www.w3.org/2000/svg",
19209
+ ...props,
19210
+ children: [
19211
+ /* @__PURE__ */ jsx("rect", { width: "15", height: "15", fill: "#F97316" }),
19212
+ /* @__PURE__ */ jsx(
19213
+ "rect",
19214
+ {
19215
+ width: "15",
19216
+ height: "15",
19217
+ fill: "url(#paint0_linear_28788_25808)",
19218
+ fillOpacity: "0.2"
19219
+ }
19220
+ ),
19221
+ /* @__PURE__ */ jsxs("g", { clipPath: "url(#clip0_28788_25808)", children: [
19222
+ /* @__PURE__ */ jsx(
19223
+ "path",
19224
+ {
19225
+ 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",
19226
+ fill: "white"
19227
+ }
19228
+ ),
19229
+ /* @__PURE__ */ jsx(
19230
+ "path",
19231
+ {
19232
+ 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",
19233
+ fill: "white"
19234
+ }
19235
+ ),
19236
+ /* @__PURE__ */ jsx(
19237
+ "path",
19238
+ {
19239
+ 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",
19240
+ fill: "white"
19241
+ }
19242
+ ),
19243
+ /* @__PURE__ */ jsx(
19244
+ "path",
19245
+ {
19246
+ d: "M6.938 7.5H3.75V9.563C3.75 10.7 4.675 11.625 5.813 11.625H6.938V7.5Z",
19247
+ fill: "white"
19248
+ }
19249
+ ),
19250
+ /* @__PURE__ */ jsx(
19251
+ "path",
19252
+ {
19253
+ d: "M8.063 7.5V11.625H9.188C10.325 11.625 11.25 10.7 11.25 9.563V7.5H8.063Z",
19254
+ fill: "white"
19255
+ }
19256
+ )
19257
+ ] }),
19258
+ /* @__PURE__ */ jsxs("defs", { children: [
19259
+ /* @__PURE__ */ jsxs(
19260
+ "linearGradient",
19261
+ {
19262
+ id: "paint0_linear_28788_25808",
19263
+ x1: "7.5",
19264
+ y1: "0",
19265
+ x2: "7.5",
19266
+ y2: "15",
19267
+ gradientUnits: "userSpaceOnUse",
19268
+ children: [
19269
+ /* @__PURE__ */ jsx("stop", { stopColor: "white" }),
19270
+ /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
19271
+ ]
19272
+ }
19273
+ ),
19274
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_28788_25808", children: /* @__PURE__ */ jsx("rect", { width: "9", height: "9", fill: "white", transform: "translate(3 3)" }) })
19275
+ ] })
19276
+ ]
19277
+ }
19278
+ );
19279
+ };
19280
+ const GiftCardProductsSection = () => {
19281
+ const { products: giftCardProducts, count: count2 = 0 } = useProducts({
19282
+ is_giftcard: true
19283
+ });
19284
+ const slicedProducts = giftCardProducts?.slice(0, 3) ?? [];
19285
+ return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
19286
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
19287
+ /* @__PURE__ */ jsx(Header$5, { title: "Gift Card Products" }),
19288
+ /* @__PURE__ */ jsx(
19289
+ Link,
19290
+ {
19291
+ to: `/gift-cards/gift-card-products/create`,
19292
+ className: "text-ui-fg-muted text-sm px-6",
19293
+ children: "Create"
19294
+ }
19295
+ )
19296
+ ] }),
19297
+ giftCardProducts?.length === 0 && /* @__PURE__ */ jsx(
19298
+ NoRecords,
19299
+ {
19300
+ className: "px-10 py-4 h-[200px]",
19301
+ title: "No gift card products",
19302
+ message: "There are no gift card products to show. Create one to get started.",
19303
+ action: {
19304
+ to: "/gift-cards/gift-card-products/create",
19305
+ label: "Create gift card product"
19306
+ }
19307
+ }
19308
+ ),
19309
+ slicedProducts.map((giftCardProduct) => /* @__PURE__ */ jsx(
19310
+ SidebarLink,
19311
+ {
19312
+ to: `/gift-cards/gift-card-products/${giftCardProduct.id}`,
19313
+ labelKey: giftCardProduct.title,
19314
+ descriptionKey: giftCardProduct.title,
19315
+ icon: /* @__PURE__ */ jsx(Tag, {})
19316
+ }
19317
+ )),
19318
+ count2 > 3 && /* @__PURE__ */ jsx(
19319
+ Link,
19320
+ {
19321
+ to: "/gift-cards/gift-card-products",
19322
+ className: "text-ui-fg-muted text-sm px-6 py-4 flex items-center justify-center",
19323
+ children: "View more"
19324
+ }
19325
+ )
19326
+ ] });
19327
+ };
19328
+ const _giftCardQueryKey = queryKeysFactory("gift-card");
19329
+ const giftCardQueryKey = {
19330
+ ..._giftCardQueryKey,
19331
+ orders: (id) => [..._giftCardQueryKey.detail(id), "orders"]
19332
+ };
19333
+ const useGiftCards = (query, options) => {
19334
+ const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
19335
+ query: query2,
19336
+ headers
19337
+ });
19338
+ const { data, ...rest } = useQuery({
19339
+ ...options,
19340
+ queryFn: () => fetchGiftCards(query),
19341
+ queryKey: giftCardQueryKey.list(query)
19342
+ });
19343
+ return { ...data, ...rest };
19344
+ };
19345
+ const useGiftCard = (id, query, options) => {
19346
+ const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
19347
+ query: query2,
19348
+ headers
19349
+ });
19350
+ const { data, ...rest } = useQuery({
19351
+ queryFn: () => fetchGiftCard(id, query),
19352
+ queryKey: giftCardQueryKey.detail(id, query),
19353
+ ...options
19354
+ });
19355
+ return { ...data, ...rest };
19356
+ };
19357
+ const useGiftCardOrders = (id, options) => {
19358
+ const fetchGiftCardOrders = (id2, query, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}/orders`, {
19359
+ query,
19360
+ headers
19361
+ });
19362
+ const { data, ...rest } = useQuery({
19363
+ queryFn: () => fetchGiftCardOrders(id),
19364
+ queryKey: giftCardQueryKey.orders(id),
19365
+ ...options
19366
+ });
19367
+ return { ...data, ...rest };
19368
+ };
19369
+ const useUpdateGiftCard = (id, options) => {
19370
+ const queryClient = useQueryClient();
19371
+ const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
19372
+ body,
19373
+ method: "POST"
19374
+ });
19375
+ return useMutation({
19376
+ mutationFn: async (payload) => updateGiftCard(id, payload),
19377
+ onSuccess: (data, variables, context) => {
19378
+ queryClient.invalidateQueries({
19379
+ queryKey: giftCardQueryKey.detail(id)
19380
+ });
19381
+ queryClient.invalidateQueries({
19382
+ queryKey: giftCardQueryKey.lists()
19383
+ });
19384
+ },
19385
+ ...options
19386
+ });
19387
+ };
19388
+ const useCreateGiftCard = (options) => {
19389
+ const queryClient = useQueryClient();
19390
+ const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
19391
+ body,
19392
+ method: "POST"
19393
+ });
19394
+ return useMutation({
19395
+ mutationFn: (body) => createGiftCard(body),
19396
+ onSuccess: (data, variables, context) => {
19397
+ queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
19398
+ },
19399
+ ...options
19400
+ });
19401
+ };
19402
+ const columnHelper$9 = createDataTableColumnHelper();
19403
+ const useGiftCardTableColumns = () => {
19404
+ return useMemo(() => {
19405
+ return [
19406
+ columnHelper$9.accessor("code", {
19407
+ header: "Code",
19408
+ cell: ({ row }) => {
19409
+ return row.original.code;
19410
+ }
19411
+ }),
19412
+ columnHelper$9.accessor("line_item.product.title", {
19413
+ header: "Product",
19414
+ cell: ({ row }) => {
19415
+ return row.original.line_item?.product?.title || "Custom Gift Card";
19416
+ }
19417
+ }),
19418
+ columnHelper$9.accessor("created_at", {
19419
+ header: "Date issued",
19420
+ cell: ({ row }) => getRelativeDate(row.original.created_at)
19421
+ }),
19422
+ columnHelper$9.accessor("value", {
19423
+ header: "Value",
19424
+ cell: ({ row }) => {
19425
+ return formatAmount(row.original.value, row.original.currency_code);
19426
+ }
19427
+ })
19428
+ ];
19429
+ }, []);
19430
+ };
19431
+ const useGiftCardFilters = () => {
19432
+ const dateFilterOptions = useDataTableDateFilters$1();
19433
+ const customerFilterOptions = useCustomerFilters();
19434
+ return useMemo(() => {
19435
+ return [...dateFilterOptions, ...customerFilterOptions];
19436
+ }, [dateFilterOptions, customerFilterOptions]);
19437
+ };
19438
+ const useGiftCardTableQuery = ({
19439
+ prefix,
19440
+ pageSize = 20
19441
+ }) => {
19442
+ const queryObject = useQueryParams(
19443
+ ["q", "offset", "customer_id", "created_at", "updated_at"],
19444
+ prefix
19445
+ );
19446
+ const { offset: offset2, created_at, updated_at, customer_id, ...rest } = queryObject;
19447
+ const searchParams = {
19448
+ limit: pageSize,
19449
+ offset: offset2 ? Number(offset2) : 0,
19450
+ created_at: created_at ? JSON.parse(created_at) : void 0,
19451
+ updated_at: updated_at ? JSON.parse(updated_at) : void 0,
19452
+ customer_id: customer_id ? JSON.parse(customer_id) : void 0,
19453
+ ...rest
19454
+ };
19455
+ return searchParams;
19456
+ };
19457
+ const PAGE_SIZE$5 = 10;
19458
+ function GiftCardsTable() {
19459
+ const queryParams = useGiftCardTableQuery({
19460
+ pageSize: PAGE_SIZE$5
19461
+ });
19462
+ const {
19463
+ gift_cards: giftCards,
19464
+ isPending,
19465
+ count: count2
19466
+ } = useGiftCards({
19467
+ ...queryParams,
19468
+ order: queryParams.order ?? "-created_at",
19469
+ fields: "+line_item.product.title"
19470
+ });
19471
+ const columns = useGiftCardTableColumns();
19472
+ const filters = useGiftCardFilters();
19473
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
19474
+ /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
19475
+ DataTable,
19476
+ {
19477
+ data: giftCards,
19478
+ getRowId: (row) => row.id,
19479
+ columns,
19480
+ filters,
19481
+ isLoading: isPending,
19482
+ pageSize: PAGE_SIZE$5,
19483
+ rowCount: count2,
19484
+ heading: "Gift Cards",
19485
+ rowHref: (row) => `${row.id}`,
19486
+ emptyState: {
19487
+ empty: {
19488
+ heading: "No gift cards found",
19489
+ description: "Create a gift card to get started."
19490
+ },
19491
+ filtered: {
19492
+ heading: "No results found",
19493
+ description: "No gift cards match your filter criteria."
19494
+ }
19495
+ },
19496
+ actions: [
19497
+ {
19498
+ label: "Create",
19499
+ to: "create"
19500
+ }
19501
+ ]
19502
+ }
19503
+ ) }),
19504
+ /* @__PURE__ */ jsx(Outlet, {})
19505
+ ] });
19506
+ }
19507
+ const GiftCardsPage = () => {
19508
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
19509
+ /* @__PURE__ */ jsx(
19510
+ LayoutComposer,
19511
+ {
19512
+ widgetsZonePrefix: "gift_card.list",
19513
+ preferredLayoutId: "core:two-column",
19514
+ sections: {
19515
+ main: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "GiftCardsTable", children: /* @__PURE__ */ jsx(GiftCardsTable, {}) }),
19516
+ side: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "GiftCardProductsSection", children: /* @__PURE__ */ jsx(GiftCardProductsSection, {}) })
19517
+ }
19518
+ }
19519
+ ),
19520
+ /* @__PURE__ */ jsx(Toaster, {})
19521
+ ] });
19522
+ };
19523
+ const config$2 = defineRouteConfig({
19524
+ label: "Gift Cards",
19525
+ icon: GiftCardIcon
19526
+ });
19527
+ const STORE_QUERY_KEY = "store";
19528
+ const storeQueryKeys = queryKeysFactory(STORE_QUERY_KEY);
19529
+ async function retrieveActiveStore(query) {
19530
+ const response = await sdk.admin.store.list(query);
19531
+ const activeStore = response.stores?.[0];
19532
+ if (!activeStore) {
19533
+ throw new FetchError("No active store found", "Not Found", 404);
19534
+ }
19535
+ return { store: activeStore };
19536
+ }
19537
+ const useStore$1 = (query, options) => {
19538
+ const { data, ...rest } = useQuery({
19539
+ queryFn: () => retrieveActiveStore(query),
19540
+ queryKey: storeQueryKeys.details(),
19541
+ ...options
19542
+ });
19543
+ return {
19544
+ ...data,
19545
+ ...rest
19546
+ };
19547
+ };
18831
19548
  function $constructor(name, initializer2, params) {
18832
19549
  function init2(inst, def) {
18833
19550
  if (!inst._zod) {
@@ -18891,7 +19608,7 @@ class $ZodEncodeError extends Error {
18891
19608
  }
18892
19609
  }
18893
19610
  const globalConfig = {};
18894
- function config$2(newConfig) {
19611
+ function config$1(newConfig) {
18895
19612
  return globalConfig;
18896
19613
  }
18897
19614
  function getEnumValues(entries) {
@@ -19338,7 +20055,7 @@ const _parse = (_Err) => (schema2, value, _ctx, _params) => {
19338
20055
  throw new $ZodAsyncError();
19339
20056
  }
19340
20057
  if (result.issues.length) {
19341
- const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
20058
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
19342
20059
  captureStackTrace(e, _params?.callee);
19343
20060
  throw e;
19344
20061
  }
@@ -19350,7 +20067,7 @@ const _parseAsync = (_Err) => async (schema2, value, _ctx, params) => {
19350
20067
  if (result instanceof Promise)
19351
20068
  result = await result;
19352
20069
  if (result.issues.length) {
19353
- const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())));
20070
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())));
19354
20071
  captureStackTrace(e, params?.callee);
19355
20072
  throw e;
19356
20073
  }
@@ -19364,7 +20081,7 @@ const _safeParse = (_Err) => (schema2, value, _ctx) => {
19364
20081
  }
19365
20082
  return result.issues.length ? {
19366
20083
  success: false,
19367
- error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())))
20084
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())))
19368
20085
  } : { success: true, data: result.value };
19369
20086
  };
19370
20087
  const safeParse$1 = /* @__PURE__ */ _safeParse($ZodRealError);
@@ -19375,7 +20092,7 @@ const _safeParseAsync = (_Err) => async (schema2, value, _ctx) => {
19375
20092
  result = await result;
19376
20093
  return result.issues.length ? {
19377
20094
  success: false,
19378
- error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())))
20095
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())))
19379
20096
  } : { success: true, data: result.value };
19380
20097
  };
19381
20098
  const safeParseAsync$1 = /* @__PURE__ */ _safeParseAsync($ZodRealError);
@@ -20631,7 +21348,7 @@ function handleUnionResults(results, final, inst, ctx2) {
20631
21348
  code: "invalid_union",
20632
21349
  input: final.value,
20633
21350
  inst,
20634
- errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())))
21351
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())))
20635
21352
  });
20636
21353
  return final;
20637
21354
  }
@@ -20824,7 +21541,7 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
20824
21541
  payload.issues.push({
20825
21542
  code: "invalid_key",
20826
21543
  origin: "record",
20827
- issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$2())),
21544
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx2, config$1())),
20828
21545
  input: key2,
20829
21546
  path: [key2],
20830
21547
  inst
@@ -21023,7 +21740,7 @@ const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
21023
21740
  payload.value = def.catchValue({
21024
21741
  ...payload,
21025
21742
  error: {
21026
- issues: result2.issues.map((iss) => finalizeIssue(iss, ctx2, config$2()))
21743
+ issues: result2.issues.map((iss) => finalizeIssue(iss, ctx2, config$1()))
21027
21744
  },
21028
21745
  input: payload.value
21029
21746
  });
@@ -21037,7 +21754,7 @@ const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
21037
21754
  payload.value = def.catchValue({
21038
21755
  ...payload,
21039
21756
  error: {
21040
- issues: result.issues.map((iss) => finalizeIssue(iss, ctx2, config$2()))
21757
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx2, config$1()))
21041
21758
  },
21042
21759
  input: payload.value
21043
21760
  });
@@ -23085,730 +23802,561 @@ const GiftCardCreateForm = ({
23085
23802
  ] });
23086
23803
  };
23087
23804
  const GiftCardCreate = () => {
23088
- const { store, isLoading } = useStore$2({});
23805
+ const { store, isLoading } = useStore$1({});
23089
23806
  return /* @__PURE__ */ jsxs(RouteFocusModal, { children: [
23090
23807
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create Gift Card" }) }),
23091
23808
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create a new gift card" }) }),
23092
23809
  !isLoading && /* @__PURE__ */ jsx(GiftCardCreateForm, { store })
23093
23810
  ] });
23094
23811
  };
23095
- const StoreCreditIcon = (props) => {
23096
- return /* @__PURE__ */ jsxs(
23097
- "svg",
23098
- {
23099
- width: "15",
23100
- height: "15",
23101
- viewBox: "0 0 15 15",
23102
- fill: "none",
23103
- xmlns: "http://www.w3.org/2000/svg",
23104
- ...props,
23105
- children: [
23106
- /* @__PURE__ */ jsx("rect", { width: "15", height: "15", fill: "#8B5CF6" }),
23107
- /* @__PURE__ */ jsx(
23108
- "rect",
23109
- {
23110
- width: "15",
23111
- height: "15",
23112
- fill: "url(#paint0_linear_29181_44790)",
23113
- fillOpacity: "0.2"
23114
- }
23115
- ),
23116
- /* @__PURE__ */ jsx(
23117
- "path",
23118
- {
23119
- d: "M12 6V5.813C12 4.675 11.075 3.75 9.938 3.75H5.063C3.925 3.75 3 4.675 3 5.813V6H12Z",
23120
- fill: "white"
23121
- }
23122
- ),
23123
- /* @__PURE__ */ jsx(
23124
- "path",
23125
- {
23126
- 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",
23127
- fill: "white"
23812
+ const StoreCreditAccountBalanceSection = ({
23813
+ storeCreditAccount
23814
+ }) => {
23815
+ if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
23816
+ return;
23817
+ }
23818
+ 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: [
23819
+ /* @__PURE__ */ jsx("div", { className: "bg-ui-tag-green-icon h-8 w-1 rounded-full" }),
23820
+ /* @__PURE__ */ jsxs("div", { children: [
23821
+ /* @__PURE__ */ jsx(Text, { weight: "plus", size: "small", className: "text-ui-fg-subtle", children: "Current Balance" }),
23822
+ /* @__PURE__ */ jsx(
23823
+ Text,
23824
+ {
23825
+ weight: "plus",
23826
+ size: "xlarge",
23827
+ className: "tabular-nums text-ui-fg-base",
23828
+ children: formatAmount(
23829
+ storeCreditAccount.balance,
23830
+ storeCreditAccount.currency_code
23831
+ )
23832
+ }
23833
+ )
23834
+ ] })
23835
+ ] }) });
23836
+ };
23837
+ var toggleSelection;
23838
+ var hasRequiredToggleSelection;
23839
+ function requireToggleSelection() {
23840
+ if (hasRequiredToggleSelection) return toggleSelection;
23841
+ hasRequiredToggleSelection = 1;
23842
+ toggleSelection = function() {
23843
+ var selection = document.getSelection();
23844
+ if (!selection.rangeCount) {
23845
+ return function() {
23846
+ };
23847
+ }
23848
+ var active = document.activeElement;
23849
+ var ranges = [];
23850
+ for (var i2 = 0; i2 < selection.rangeCount; i2++) {
23851
+ ranges.push(selection.getRangeAt(i2));
23852
+ }
23853
+ switch (active.tagName.toUpperCase()) {
23854
+ // .toUpperCase handles XHTML
23855
+ case "INPUT":
23856
+ case "TEXTAREA":
23857
+ active.blur();
23858
+ break;
23859
+ default:
23860
+ active = null;
23861
+ break;
23862
+ }
23863
+ selection.removeAllRanges();
23864
+ return function() {
23865
+ selection.type === "Caret" && selection.removeAllRanges();
23866
+ if (!selection.rangeCount) {
23867
+ ranges.forEach(function(range) {
23868
+ selection.addRange(range);
23869
+ });
23870
+ }
23871
+ active && active.focus();
23872
+ };
23873
+ };
23874
+ return toggleSelection;
23875
+ }
23876
+ var copyToClipboard;
23877
+ var hasRequiredCopyToClipboard;
23878
+ function requireCopyToClipboard() {
23879
+ if (hasRequiredCopyToClipboard) return copyToClipboard;
23880
+ hasRequiredCopyToClipboard = 1;
23881
+ var deselectCurrent = requireToggleSelection();
23882
+ var clipboardToIE11Formatting = {
23883
+ "text/plain": "Text",
23884
+ "text/html": "Url",
23885
+ "default": "Text"
23886
+ };
23887
+ var defaultMessage = "Copy to clipboard: #{key}, Enter";
23888
+ function format2(message2) {
23889
+ var copyKey = (/mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl") + "+C";
23890
+ return message2.replace(/#{\s*key\s*}/g, copyKey);
23891
+ }
23892
+ function copy2(text2, options) {
23893
+ var debug2, message2, reselectPrevious, range, selection, mark, success = false;
23894
+ if (!options) {
23895
+ options = {};
23896
+ }
23897
+ debug2 = options.debug || false;
23898
+ try {
23899
+ reselectPrevious = deselectCurrent();
23900
+ range = document.createRange();
23901
+ selection = document.getSelection();
23902
+ mark = document.createElement("span");
23903
+ mark.textContent = text2;
23904
+ mark.ariaHidden = "true";
23905
+ mark.style.all = "unset";
23906
+ mark.style.position = "fixed";
23907
+ mark.style.top = 0;
23908
+ mark.style.clip = "rect(0, 0, 0, 0)";
23909
+ mark.style.whiteSpace = "pre";
23910
+ mark.style.webkitUserSelect = "text";
23911
+ mark.style.MozUserSelect = "text";
23912
+ mark.style.msUserSelect = "text";
23913
+ mark.style.userSelect = "text";
23914
+ mark.addEventListener("copy", function(e) {
23915
+ e.stopPropagation();
23916
+ if (options.format) {
23917
+ e.preventDefault();
23918
+ if (typeof e.clipboardData === "undefined") {
23919
+ debug2 && console.warn("unable to use e.clipboardData");
23920
+ debug2 && console.warn("trying IE specific stuff");
23921
+ window.clipboardData.clearData();
23922
+ var format3 = clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting["default"];
23923
+ window.clipboardData.setData(format3, text2);
23924
+ } else {
23925
+ e.clipboardData.clearData();
23926
+ e.clipboardData.setData(options.format, text2);
23128
23927
  }
23129
- ),
23130
- /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
23131
- "linearGradient",
23928
+ }
23929
+ if (options.onCopy) {
23930
+ e.preventDefault();
23931
+ options.onCopy(e.clipboardData);
23932
+ }
23933
+ });
23934
+ document.body.appendChild(mark);
23935
+ range.selectNodeContents(mark);
23936
+ selection.addRange(range);
23937
+ var successful = document.execCommand("copy");
23938
+ if (!successful) {
23939
+ throw new Error("copy command was unsuccessful");
23940
+ }
23941
+ success = true;
23942
+ } catch (err) {
23943
+ debug2 && console.error("unable to copy using execCommand: ", err);
23944
+ debug2 && console.warn("trying IE specific stuff");
23945
+ try {
23946
+ window.clipboardData.setData(options.format || "text", text2);
23947
+ options.onCopy && options.onCopy(window.clipboardData);
23948
+ success = true;
23949
+ } catch (err2) {
23950
+ debug2 && console.error("unable to copy using clipboardData: ", err2);
23951
+ debug2 && console.error("falling back to prompt");
23952
+ message2 = format2("message" in options ? options.message : defaultMessage);
23953
+ window.prompt(message2, text2);
23954
+ }
23955
+ } finally {
23956
+ if (selection) {
23957
+ if (typeof selection.removeRange == "function") {
23958
+ selection.removeRange(range);
23959
+ } else {
23960
+ selection.removeAllRanges();
23961
+ }
23962
+ }
23963
+ if (mark) {
23964
+ document.body.removeChild(mark);
23965
+ }
23966
+ reselectPrevious();
23967
+ }
23968
+ return success;
23969
+ }
23970
+ copyToClipboard = copy2;
23971
+ return copyToClipboard;
23972
+ }
23973
+ var copyToClipboardExports = requireCopyToClipboard();
23974
+ const copy$1 = /* @__PURE__ */ getDefaultExportFromCjs(copyToClipboardExports);
23975
+ function DisplayId({ id, className }) {
23976
+ const [open, setOpen] = useState(false);
23977
+ const onClick = () => {
23978
+ copy$1(id);
23979
+ toast.success("Copied to clipboard");
23980
+ };
23981
+ return /* @__PURE__ */ jsx(Tooltip, { maxWidth: 260, content: id, open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs("span", { onClick, className: clx("cursor-pointer", className), children: [
23982
+ "#",
23983
+ id.slice(-7)
23984
+ ] }) });
23985
+ }
23986
+ const StoreCreditAccountDetailsSection = ({
23987
+ storeCreditAccount
23988
+ }) => {
23989
+ if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
23990
+ return;
23991
+ }
23992
+ return /* @__PURE__ */ jsxs(Container$1, { className: "flex justify-between gap-x-2 px-6 py-6", children: [
23993
+ /* @__PURE__ */ jsxs(
23994
+ Text,
23995
+ {
23996
+ weight: "plus",
23997
+ size: "xlarge",
23998
+ className: "text-ui-fg-base flex gap-x-4",
23999
+ children: [
24000
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
24001
+ /* @__PURE__ */ jsx(CreditCardIcon, { className: "inline" }),
24002
+ " "
24003
+ ] }),
24004
+ /* @__PURE__ */ jsxs("div", { children: [
24005
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle", children: [
24006
+ storeCreditAccount.currency_code.toUpperCase(),
24007
+ " Account"
24008
+ ] }),
24009
+ /* @__PURE__ */ jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsx(
24010
+ Text,
24011
+ {
24012
+ weight: "regular",
24013
+ size: "small",
24014
+ className: "text-ui-fg-base flex gap-x-4",
24015
+ children: /* @__PURE__ */ jsx(DisplayId, { id: storeCreditAccount.id })
24016
+ }
24017
+ ) })
24018
+ ] })
24019
+ ]
24020
+ }
24021
+ ),
24022
+ /* @__PURE__ */ jsx("div", { className: "flex items-center gap-x-4", children: /* @__PURE__ */ jsx(
24023
+ ActionMenu,
24024
+ {
24025
+ groups: [
23132
24026
  {
23133
- id: "paint0_linear_29181_44790",
23134
- x1: "7.5",
23135
- y1: "0",
23136
- x2: "7.5",
23137
- y2: "15",
23138
- gradientUnits: "userSpaceOnUse",
23139
- children: [
23140
- /* @__PURE__ */ jsx("stop", { stopColor: "white" }),
23141
- /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "white", stopOpacity: "0" })
24027
+ actions: [
24028
+ {
24029
+ icon: /* @__PURE__ */ jsx(CreditCard, {}),
24030
+ label: "Credit the account",
24031
+ to: "credit"
24032
+ }
23142
24033
  ]
23143
24034
  }
23144
- ) })
23145
- ]
23146
- }
23147
- );
24035
+ ]
24036
+ }
24037
+ ) })
24038
+ ] });
23148
24039
  };
23149
- const columnHelper$9 = createDataTableColumnHelper();
23150
- const useStoreCreditAccountTableColumns = () => {
24040
+ function StoreCreditAccountCustomerSection({
24041
+ customerId
24042
+ }) {
24043
+ const { customer, isPending } = useCustomer(customerId, void 0, {
24044
+ enabled: !!customerId
24045
+ });
24046
+ if (isPending || !customer) {
24047
+ return null;
24048
+ }
24049
+ return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
24050
+ /* @__PURE__ */ jsx(Header$5, { title: "Customer" }),
24051
+ /* @__PURE__ */ jsx(
24052
+ SidebarLink,
24053
+ {
24054
+ icon: /* @__PURE__ */ jsx(User, {}),
24055
+ labelKey: customer.email || "N/A",
24056
+ descriptionKey: !customer.first_name && !customer.last_name ? "N/A" : `${customer.first_name} ${customer.last_name}`,
24057
+ to: `/customers/${customer.id}`
24058
+ },
24059
+ customer.id
24060
+ )
24061
+ ] });
24062
+ }
24063
+ const columnHelper$8 = createDataTableColumnHelper();
24064
+ const useTransactionsTableColumns = () => {
23151
24065
  return useMemo(() => {
23152
24066
  return [
23153
- columnHelper$9.accessor("currency_code", {
23154
- header: "Currency",
24067
+ columnHelper$8.accessor("id", {
24068
+ header: "ID",
23155
24069
  cell: ({ row }) => {
23156
- return /* @__PURE__ */ jsx(Badge, { size: "2xsmall", children: row.original.currency_code.toUpperCase() });
24070
+ return /* @__PURE__ */ jsx(DisplayId, { id: row.original.id });
23157
24071
  }
23158
24072
  }),
23159
- columnHelper$9.accessor("customer.email", {
23160
- header: "Customer",
23161
- cell: ({ row }) => {
23162
- return row.original.customer?.email ?? "N/A";
23163
- }
24073
+ columnHelper$8.accessor("created_at", {
24074
+ header: "Created At",
24075
+ cell: ({ row }) => formatDate(row.original.created_at, false)
23164
24076
  }),
23165
- columnHelper$9.accessor("balance", {
23166
- header: "Balance",
23167
- cell: ({ row }) => {
23168
- return formatAmount(
23169
- row.original.balance,
23170
- row.original.currency_code
23171
- );
23172
- }
24077
+ columnHelper$8.accessor("note", {
24078
+ header: "Description",
24079
+ cell: ({ row }) => row.original.note
23173
24080
  }),
23174
- columnHelper$9.accessor("credits", {
23175
- header: "Credits",
24081
+ columnHelper$8.accessor("note", {
24082
+ header: "Note",
23176
24083
  cell: ({ row }) => {
23177
- return formatAmount(
23178
- row.original.credits,
23179
- row.original.currency_code
23180
- );
24084
+ return /* @__PURE__ */ jsx(Text, { title: row.original.note, className: "max-w-[300px] truncate", children: row.original.note || "-" });
23181
24085
  }
23182
24086
  }),
23183
- columnHelper$9.accessor("debits", {
23184
- header: "Debits",
24087
+ columnHelper$8.accessor("amount", {
24088
+ header: "Amount",
23185
24089
  cell: ({ row }) => {
23186
- return formatAmount(
23187
- row.original.debits,
23188
- row.original.currency_code
24090
+ const isDebit = row.original.type === "debit";
24091
+ return row.original.account.currency_code && formatAmount(
24092
+ row.original.amount * (isDebit ? -1 : 1),
24093
+ row.original.account.currency_code
23189
24094
  );
23190
24095
  }
23191
- }),
23192
- columnHelper$9.accessor("created_at", {
23193
- header: "Created at",
23194
- cell: ({ row }) => getRelativeDate(row.original.created_at)
23195
24096
  })
23196
24097
  ];
23197
24098
  }, []);
23198
24099
  };
23199
- const useStoreCreditAccountFilters = () => {
24100
+ const useTransactionsTableFilters = ({}) => {
23200
24101
  const dateFilterOptions = useDataTableDateFilters$1();
23201
- const customerFilterOptions = useCustomerFilters();
23202
24102
  return useMemo(() => {
23203
- return [...dateFilterOptions, ...customerFilterOptions];
23204
- }, [dateFilterOptions, customerFilterOptions]);
24103
+ return [...dateFilterOptions];
24104
+ }, [dateFilterOptions]);
23205
24105
  };
23206
- const useStoreCreditAccountsTableQuery = ({
24106
+ const useTransactionsTableQuery = ({
23207
24107
  prefix,
23208
24108
  pageSize = 20
23209
24109
  }) => {
23210
24110
  const queryObject = useQueryParams(
23211
- ["offset", "customer_id", "currency_code", "created_at", "updated_at"],
24111
+ ["offset", "limit", "currency_code", "created_at", "updated_at"],
23212
24112
  prefix
23213
24113
  );
23214
- const {
23215
- offset: offset2,
23216
- created_at,
23217
- updated_at,
23218
- customer_id,
23219
- currency_code,
23220
- ...rest
23221
- } = queryObject;
24114
+ const { offset: offset2, limit, created_at, updated_at, ...rest } = queryObject;
23222
24115
  const searchParams = {
23223
- limit: pageSize,
24116
+ limit: limit ? Number(limit) : pageSize,
23224
24117
  offset: offset2 ? Number(offset2) : 0,
23225
24118
  created_at: created_at ? JSON.parse(created_at) : void 0,
23226
24119
  updated_at: updated_at ? JSON.parse(updated_at) : void 0,
23227
- customer_id: customer_id ? JSON.parse(customer_id) : void 0,
23228
- currency_code: currency_code ? JSON.parse(currency_code) : void 0,
23229
24120
  ...rest
23230
24121
  };
23231
24122
  return searchParams;
23232
24123
  };
23233
- const PAGE_SIZE$5 = 10;
23234
- function StoreCreditAccountsTable() {
23235
- const queryParams = useStoreCreditAccountsTableQuery({
23236
- pageSize: PAGE_SIZE$5
23237
- });
23238
- const {
23239
- store_credit_accounts: storeCreditAccounts,
23240
- isPending,
23241
- count: count2
23242
- } = useStoreCreditAccounts({
23243
- ...queryParams,
23244
- order: queryParams.order ?? "-created_at"
24124
+ const PAGE_SIZE$4 = 10;
24125
+ function TransactionsTable({ id }) {
24126
+ const queryParams = useTransactionsTableQuery({
24127
+ pageSize: PAGE_SIZE$4
23245
24128
  });
23246
- const columns = useStoreCreditAccountTableColumns();
23247
- const filters = useStoreCreditAccountFilters();
24129
+ const { transactions, isLoading, count: count2 } = useStoreCreditAccountTransactions(
24130
+ id,
24131
+ {
24132
+ ...queryParams,
24133
+ order: queryParams.order ?? "-created_at",
24134
+ fields: "*account"
24135
+ }
24136
+ );
24137
+ const columns = useTransactionsTableColumns();
24138
+ const filters = useTransactionsTableFilters({});
23248
24139
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
23249
24140
  /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
23250
24141
  DataTable,
23251
24142
  {
23252
- data: storeCreditAccounts ?? [],
24143
+ data: transactions ?? [],
23253
24144
  getRowId: (row) => row.id,
23254
24145
  columns,
23255
24146
  filters,
23256
- isLoading: isPending,
23257
- pageSize: PAGE_SIZE$5,
24147
+ isLoading,
24148
+ pageSize: PAGE_SIZE$4,
23258
24149
  rowCount: count2,
23259
24150
  enableSearch: false,
23260
- heading: "Store Credit Accounts",
23261
- rowHref: (row) => `${row.id}`,
24151
+ heading: "Transactions",
23262
24152
  emptyState: {
23263
24153
  empty: {
23264
- heading: "No store credit accounts found",
23265
- description: "Create a new store credit account to get started."
24154
+ heading: "No transactions found"
23266
24155
  },
23267
24156
  filtered: {
23268
24157
  heading: "No results found",
23269
- description: "No store credit accounts match your filter criteria."
23270
- }
23271
- },
23272
- actions: [
23273
- {
23274
- label: "Create",
23275
- to: "/store-credit-accounts/create"
24158
+ description: "No transactions match your filter criteria."
23276
24159
  }
23277
- ]
24160
+ }
23278
24161
  }
23279
24162
  ) }),
23280
24163
  /* @__PURE__ */ jsx(Outlet, {})
23281
24164
  ] });
23282
24165
  }
23283
- const StoreCreditAccountsPage = () => {
23284
- return /* @__PURE__ */ jsxs(Fragment, { children: [
23285
- /* @__PURE__ */ jsx(
23286
- LayoutComposer,
23287
- {
23288
- widgetsZonePrefix: "store_credit_account.list",
23289
- preferredLayoutId: "core:single-column",
23290
- sections: {
23291
- main: /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountsTable", children: /* @__PURE__ */ jsx(StoreCreditAccountsTable, {}) })
23292
- }
23293
- }
23294
- ),
23295
- /* @__PURE__ */ jsx(Toaster, {})
23296
- ] });
23297
- };
23298
- const config$1 = defineRouteConfig({
23299
- label: "Store Credits",
23300
- icon: StoreCreditIcon
23301
- });
23302
- var isObject_1;
23303
- var hasRequiredIsObject;
23304
- function requireIsObject() {
23305
- if (hasRequiredIsObject) return isObject_1;
23306
- hasRequiredIsObject = 1;
23307
- function isObject2(value) {
23308
- var type = typeof value;
23309
- return value != null && (type == "object" || type == "function");
24166
+ function StoreCreditAccountCodeSection({ code }) {
24167
+ if (!code) {
24168
+ return null;
23310
24169
  }
23311
- isObject_1 = isObject2;
23312
- return isObject_1;
23313
- }
23314
- var _freeGlobal;
23315
- var hasRequired_freeGlobal;
23316
- function require_freeGlobal() {
23317
- if (hasRequired_freeGlobal) return _freeGlobal;
23318
- hasRequired_freeGlobal = 1;
23319
- var freeGlobal = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
23320
- _freeGlobal = freeGlobal;
23321
- return _freeGlobal;
23322
- }
23323
- var _root;
23324
- var hasRequired_root;
23325
- function require_root() {
23326
- if (hasRequired_root) return _root;
23327
- hasRequired_root = 1;
23328
- var freeGlobal = require_freeGlobal();
23329
- var freeSelf = typeof self == "object" && self && self.Object === Object && self;
23330
- var root = freeGlobal || freeSelf || Function("return this")();
23331
- _root = root;
23332
- return _root;
23333
- }
23334
- var now_1;
23335
- var hasRequiredNow;
23336
- function requireNow() {
23337
- if (hasRequiredNow) return now_1;
23338
- hasRequiredNow = 1;
23339
- var root = require_root();
23340
- var now = function() {
23341
- return root.Date.now();
23342
- };
23343
- now_1 = now;
23344
- return now_1;
24170
+ return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
24171
+ /* @__PURE__ */ jsx(Header$5, { title: "Account Code" }),
24172
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-4 px-6 mb-2", children: [
24173
+ /* @__PURE__ */ jsx(Share, { className: "inline" }),
24174
+ /* @__PURE__ */ jsx("div", { className: "text-ui-fg-subtle text-sm", children: code })
24175
+ ] })
24176
+ ] });
23345
24177
  }
23346
- var _trimmedEndIndex;
23347
- var hasRequired_trimmedEndIndex;
23348
- function require_trimmedEndIndex() {
23349
- if (hasRequired_trimmedEndIndex) return _trimmedEndIndex;
23350
- hasRequired_trimmedEndIndex = 1;
23351
- var reWhitespace = /\s/;
23352
- function trimmedEndIndex(string2) {
23353
- var index = string2.length;
23354
- while (index-- && reWhitespace.test(string2.charAt(index))) {
23355
- }
23356
- return index;
24178
+ const StoreCreditAccountPage = () => {
24179
+ const { id } = useParams();
24180
+ const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
24181
+ id
24182
+ );
24183
+ if (!storeCreditAccount) {
24184
+ return;
23357
24185
  }
23358
- _trimmedEndIndex = trimmedEndIndex;
23359
- return _trimmedEndIndex;
23360
- }
23361
- var _baseTrim;
23362
- var hasRequired_baseTrim;
23363
- function require_baseTrim() {
23364
- if (hasRequired_baseTrim) return _baseTrim;
23365
- hasRequired_baseTrim = 1;
23366
- var trimmedEndIndex = require_trimmedEndIndex();
23367
- var reTrimStart = /^\s+/;
23368
- function baseTrim(string2) {
23369
- return string2 ? string2.slice(0, trimmedEndIndex(string2) + 1).replace(reTrimStart, "") : string2;
23370
- }
23371
- _baseTrim = baseTrim;
23372
- return _baseTrim;
23373
- }
23374
- var _Symbol;
23375
- var hasRequired_Symbol;
23376
- function require_Symbol() {
23377
- if (hasRequired_Symbol) return _Symbol;
23378
- hasRequired_Symbol = 1;
23379
- var root = require_root();
23380
- var Symbol2 = root.Symbol;
23381
- _Symbol = Symbol2;
23382
- return _Symbol;
23383
- }
23384
- var _getRawTag;
23385
- var hasRequired_getRawTag;
23386
- function require_getRawTag() {
23387
- if (hasRequired_getRawTag) return _getRawTag;
23388
- hasRequired_getRawTag = 1;
23389
- var Symbol2 = require_Symbol();
23390
- var objectProto = Object.prototype;
23391
- var hasOwnProperty2 = objectProto.hasOwnProperty;
23392
- var nativeObjectToString = objectProto.toString;
23393
- var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
23394
- function getRawTag(value) {
23395
- var isOwn = hasOwnProperty2.call(value, symToStringTag), tag = value[symToStringTag];
23396
- try {
23397
- value[symToStringTag] = void 0;
23398
- var unmasked = true;
23399
- } catch (e) {
23400
- }
23401
- var result = nativeObjectToString.call(value);
23402
- if (unmasked) {
23403
- if (isOwn) {
23404
- value[symToStringTag] = tag;
23405
- } else {
23406
- delete value[symToStringTag];
23407
- }
23408
- }
23409
- return result;
23410
- }
23411
- _getRawTag = getRawTag;
23412
- return _getRawTag;
23413
- }
23414
- var _objectToString;
23415
- var hasRequired_objectToString;
23416
- function require_objectToString() {
23417
- if (hasRequired_objectToString) return _objectToString;
23418
- hasRequired_objectToString = 1;
23419
- var objectProto = Object.prototype;
23420
- var nativeObjectToString = objectProto.toString;
23421
- function objectToString(value) {
23422
- return nativeObjectToString.call(value);
23423
- }
23424
- _objectToString = objectToString;
23425
- return _objectToString;
23426
- }
23427
- var _baseGetTag;
23428
- var hasRequired_baseGetTag;
23429
- function require_baseGetTag() {
23430
- if (hasRequired_baseGetTag) return _baseGetTag;
23431
- hasRequired_baseGetTag = 1;
23432
- var Symbol2 = require_Symbol(), getRawTag = require_getRawTag(), objectToString = require_objectToString();
23433
- var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
23434
- var symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
23435
- function baseGetTag(value) {
23436
- if (value == null) {
23437
- return value === void 0 ? undefinedTag : nullTag;
23438
- }
23439
- return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
23440
- }
23441
- _baseGetTag = baseGetTag;
23442
- return _baseGetTag;
23443
- }
23444
- var isObjectLike_1;
23445
- var hasRequiredIsObjectLike;
23446
- function requireIsObjectLike() {
23447
- if (hasRequiredIsObjectLike) return isObjectLike_1;
23448
- hasRequiredIsObjectLike = 1;
23449
- function isObjectLike(value) {
23450
- return value != null && typeof value == "object";
23451
- }
23452
- isObjectLike_1 = isObjectLike;
23453
- return isObjectLike_1;
23454
- }
23455
- var isSymbol_1;
23456
- var hasRequiredIsSymbol;
23457
- function requireIsSymbol() {
23458
- if (hasRequiredIsSymbol) return isSymbol_1;
23459
- hasRequiredIsSymbol = 1;
23460
- var baseGetTag = require_baseGetTag(), isObjectLike = requireIsObjectLike();
23461
- var symbolTag = "[object Symbol]";
23462
- function isSymbol(value) {
23463
- return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
23464
- }
23465
- isSymbol_1 = isSymbol;
23466
- return isSymbol_1;
23467
- }
23468
- var toNumber_1;
23469
- var hasRequiredToNumber;
23470
- function requireToNumber() {
23471
- if (hasRequiredToNumber) return toNumber_1;
23472
- hasRequiredToNumber = 1;
23473
- var baseTrim = require_baseTrim(), isObject2 = requireIsObject(), isSymbol = requireIsSymbol();
23474
- var NAN = 0 / 0;
23475
- var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
23476
- var reIsBinary = /^0b[01]+$/i;
23477
- var reIsOctal = /^0o[0-7]+$/i;
23478
- var freeParseInt = parseInt;
23479
- function toNumber(value) {
23480
- if (typeof value == "number") {
23481
- return value;
23482
- }
23483
- if (isSymbol(value)) {
23484
- return NAN;
23485
- }
23486
- if (isObject2(value)) {
23487
- var other = typeof value.valueOf == "function" ? value.valueOf() : value;
23488
- value = isObject2(other) ? other + "" : other;
23489
- }
23490
- if (typeof value != "string") {
23491
- return value === 0 ? value : +value;
23492
- }
23493
- value = baseTrim(value);
23494
- var isBinary = reIsBinary.test(value);
23495
- return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
23496
- }
23497
- toNumber_1 = toNumber;
23498
- return toNumber_1;
23499
- }
23500
- var debounce_1;
23501
- var hasRequiredDebounce;
23502
- function requireDebounce() {
23503
- if (hasRequiredDebounce) return debounce_1;
23504
- hasRequiredDebounce = 1;
23505
- var isObject2 = requireIsObject(), now = requireNow(), toNumber = requireToNumber();
23506
- var FUNC_ERROR_TEXT = "Expected a function";
23507
- var nativeMax = Math.max, nativeMin = Math.min;
23508
- function debounce2(func, wait, options) {
23509
- var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
23510
- if (typeof func != "function") {
23511
- throw new TypeError(FUNC_ERROR_TEXT);
23512
- }
23513
- wait = toNumber(wait) || 0;
23514
- if (isObject2(options)) {
23515
- leading = !!options.leading;
23516
- maxing = "maxWait" in options;
23517
- maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
23518
- trailing = "trailing" in options ? !!options.trailing : trailing;
23519
- }
23520
- function invokeFunc(time2) {
23521
- var args = lastArgs, thisArg = lastThis;
23522
- lastArgs = lastThis = void 0;
23523
- lastInvokeTime = time2;
23524
- result = func.apply(thisArg, args);
23525
- return result;
23526
- }
23527
- function leadingEdge(time2) {
23528
- lastInvokeTime = time2;
23529
- timerId = setTimeout(timerExpired, wait);
23530
- return leading ? invokeFunc(time2) : result;
23531
- }
23532
- function remainingWait(time2) {
23533
- var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
23534
- return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
23535
- }
23536
- function shouldInvoke(time2) {
23537
- var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime;
23538
- return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
23539
- }
23540
- function timerExpired() {
23541
- var time2 = now();
23542
- if (shouldInvoke(time2)) {
23543
- return trailingEdge(time2);
24186
+ return /* @__PURE__ */ jsx(
24187
+ LayoutComposer,
24188
+ {
24189
+ widgetsZonePrefix: "store_credit_account.details",
24190
+ preferredLayoutId: "core:two-column",
24191
+ data: storeCreditAccount,
24192
+ sections: {
24193
+ main: /* @__PURE__ */ jsxs(Fragment, { children: [
24194
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountDetailsSection", children: /* @__PURE__ */ jsx(
24195
+ StoreCreditAccountDetailsSection,
24196
+ {
24197
+ storeCreditAccount
24198
+ }
24199
+ ) }),
24200
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "TransactionsTable", children: /* @__PURE__ */ jsx(TransactionsTable, { id: storeCreditAccount.id }) })
24201
+ ] }),
24202
+ side: /* @__PURE__ */ jsxs(Fragment, { children: [
24203
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountBalanceSection", children: /* @__PURE__ */ jsx(
24204
+ StoreCreditAccountBalanceSection,
24205
+ {
24206
+ storeCreditAccount
24207
+ }
24208
+ ) }),
24209
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountCodeSection", children: /* @__PURE__ */ jsx(StoreCreditAccountCodeSection, { code: storeCreditAccount.code }) }),
24210
+ /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountCustomerSection", children: /* @__PURE__ */ jsx(
24211
+ StoreCreditAccountCustomerSection,
24212
+ {
24213
+ customerId: storeCreditAccount.customer_id
24214
+ }
24215
+ ) })
24216
+ ] })
23544
24217
  }
23545
- timerId = setTimeout(timerExpired, remainingWait(time2));
23546
24218
  }
23547
- function trailingEdge(time2) {
23548
- timerId = void 0;
23549
- if (trailing && lastArgs) {
23550
- return invokeFunc(time2);
24219
+ );
24220
+ };
24221
+ const KeyboundForm = React__default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
24222
+ const handleSubmit = (event) => {
24223
+ event.preventDefault();
24224
+ onSubmit?.(event);
24225
+ };
24226
+ const handleKeyDown = (event) => {
24227
+ if (event.key === "Enter") {
24228
+ if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
24229
+ return;
23551
24230
  }
23552
- lastArgs = lastThis = void 0;
23553
- return result;
23554
- }
23555
- function cancel() {
23556
- if (timerId !== void 0) {
23557
- clearTimeout(timerId);
24231
+ event.preventDefault();
24232
+ if (event.metaKey || event.ctrlKey) {
24233
+ handleSubmit(event);
23558
24234
  }
23559
- lastInvokeTime = 0;
23560
- lastArgs = lastCallTime = lastThis = timerId = void 0;
23561
24235
  }
23562
- function flush() {
23563
- return timerId === void 0 ? result : trailingEdge(now());
23564
- }
23565
- function debounced() {
23566
- var time2 = now(), isInvoking = shouldInvoke(time2);
23567
- lastArgs = arguments;
23568
- lastThis = this;
23569
- lastCallTime = time2;
23570
- if (isInvoking) {
23571
- if (timerId === void 0) {
23572
- return leadingEdge(lastCallTime);
23573
- }
23574
- if (maxing) {
23575
- clearTimeout(timerId);
23576
- timerId = setTimeout(timerExpired, wait);
23577
- return invokeFunc(lastCallTime);
23578
- }
23579
- }
23580
- if (timerId === void 0) {
23581
- timerId = setTimeout(timerExpired, wait);
23582
- }
23583
- return result;
24236
+ };
24237
+ return /* @__PURE__ */ jsx(
24238
+ "form",
24239
+ {
24240
+ ...rest,
24241
+ onSubmit: handleSubmit,
24242
+ onKeyDown: onKeyDown ?? handleKeyDown,
24243
+ ref
23584
24244
  }
23585
- debounced.cancel = cancel;
23586
- debounced.flush = flush;
23587
- return debounced;
23588
- }
23589
- debounce_1 = debounce2;
23590
- return debounce_1;
23591
- }
23592
- var debounceExports = requireDebounce();
23593
- const debounce$1 = /* @__PURE__ */ getDefaultExportFromCjs(debounceExports);
23594
- const useDebouncedSearch = () => {
23595
- const [searchValue, onSearchValueChange] = useState("");
23596
- const [debouncedQuery, setDebouncedQuery] = useState("");
23597
- const debouncedUpdate = useCallback(
23598
- debounce$1((query) => setDebouncedQuery(query), 300),
23599
- []
23600
24245
  );
23601
- useEffect(() => {
23602
- debouncedUpdate(searchValue);
23603
- return () => debouncedUpdate.cancel();
23604
- }, [searchValue, debouncedUpdate]);
23605
- return {
23606
- searchValue,
23607
- onSearchValueChange,
23608
- query: debouncedQuery || void 0
23609
- };
23610
- };
23611
- const useComboboxData = ({
23612
- queryKey,
23613
- queryFn,
23614
- getOptions,
23615
- defaultValue: defaultValue2,
23616
- defaultValueKey,
23617
- pageSize = 10
23618
- }) => {
23619
- const { searchValue, onSearchValueChange, query } = useDebouncedSearch();
23620
- const queryInitialDataBy = defaultValueKey || "id";
23621
- const { data: initialData } = useQuery({
23622
- queryKey,
23623
- queryFn: async () => {
23624
- return queryFn({
23625
- [queryInitialDataBy]: defaultValue2,
23626
- limit: Array.isArray(defaultValue2) ? defaultValue2.length : 1
23627
- });
23628
- },
23629
- enabled: !!defaultValue2
23630
- });
23631
- const { data, ...rest } = useInfiniteQuery({
23632
- queryKey: [...queryKey, query],
23633
- queryFn: async ({ pageParam = 0 }) => {
23634
- return await queryFn({
23635
- q: query,
23636
- limit: pageSize,
23637
- offset: pageParam
23638
- });
23639
- },
23640
- initialPageParam: 0,
23641
- getNextPageParam: (lastPage) => {
23642
- const moreItemsExist = lastPage.count > lastPage.offset + lastPage.limit;
23643
- return moreItemsExist ? lastPage.offset + lastPage.limit : void 0;
23644
- },
23645
- placeholderData: keepPreviousData
23646
- });
23647
- const options = data?.pages.flatMap((page) => getOptions(page)) ?? [];
23648
- const defaultOptions2 = initialData ? getOptions(initialData) : [];
23649
- const disabled = !rest.isPending && !options.length && !searchValue;
23650
- if (defaultValue2 && defaultOptions2.length && !searchValue) {
23651
- defaultOptions2.forEach((option) => {
23652
- if (!options.find((o2) => o2.value === option.value)) {
23653
- options.unshift(option);
23654
- }
23655
- });
24246
+ });
24247
+ KeyboundForm.displayName = "KeyboundForm";
24248
+ const Note$1 = () => {
24249
+ const { id } = useParams();
24250
+ const {
24251
+ store_credit_account: storeCreditAccount,
24252
+ isPending,
24253
+ isError,
24254
+ error
24255
+ } = useStoreCreditAccount(id, {});
24256
+ if (isError) {
24257
+ throw error;
23656
24258
  }
23657
- return {
23658
- options,
23659
- searchValue,
23660
- onSearchValueChange,
23661
- disabled,
23662
- ...rest
23663
- };
24259
+ const isReady = !isPending && !!storeCreditAccount;
24260
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
24261
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
24262
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Credit store credit account" }) }),
24263
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Credit the store credit account" }) })
24264
+ ] }),
24265
+ isReady && /* @__PURE__ */ jsx(StoreCreditAccountCreditForm, { storeCreditAccount })
24266
+ ] });
23664
24267
  };
23665
- const formSchema = z.object({
23666
- currency_code: z.string().min(1, "Please select a currency"),
23667
- customer_id: z.string().optional()
23668
- });
23669
- const StoreCreditAccountCreateForm = () => {
23670
- const { handleSuccess } = useRouteModal();
24268
+ const StoreCreditAccountCreditForm = ({
24269
+ storeCreditAccount
24270
+ }) => {
23671
24271
  const form = useForm({
23672
24272
  defaultValues: {
23673
- currency_code: "",
23674
- customer_id: ""
24273
+ amount: {
24274
+ float: 0,
24275
+ value: ""
24276
+ },
24277
+ note: ""
23675
24278
  },
23676
- resolver: u(formSchema)
24279
+ resolver: u(schema$2)
23677
24280
  });
23678
- const { mutateAsync: createStoreCreditAccount, isPending } = useCreateStoreCreditAccount();
23679
- const handleSubmit = form.handleSubmit(async (data) => {
23680
- if (!data.customer_id) {
23681
- delete data.customer_id;
24281
+ const { mutateAsync, isPending } = useCreditStoreCreditAccount(
24282
+ storeCreditAccount.id
24283
+ );
24284
+ const { handleSuccess } = useRouteModal();
24285
+ const onSubmit = form.handleSubmit(async (data) => {
24286
+ if (data.amount.float <= 0) {
24287
+ form.setError("amount", { message: "Amount must be greater than 0" });
24288
+ return;
23682
24289
  }
23683
- await createStoreCreditAccount(data, {
23684
- onSuccess: (data2) => {
23685
- toast.success(`Store credit account was successfully created.`);
23686
- handleSuccess(`../${data2.store_credit_account.id}`);
23687
- },
23688
- onError: (error) => {
23689
- toast.error(error.message);
24290
+ await mutateAsync(
24291
+ { amount: data.amount.float, note: data.note },
24292
+ {
24293
+ onSuccess: () => handleSuccess(),
24294
+ onError: (error) => toast.error(error.message)
23690
24295
  }
23691
- });
23692
- });
23693
- const [currencySearchValue, setCurrencySearchValue] = useState("");
23694
- const currencyOptions = useMemo(() => {
23695
- const options = Object.values(currencies).map((currency) => ({
23696
- label: `${currency.code} - ${currency.name} (${currency.symbol_native})`,
23697
- value: currency.code.toLowerCase()
23698
- }));
23699
- if (!currencySearchValue) {
23700
- return options;
23701
- }
23702
- return options.filter(
23703
- (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
23704
24296
  );
23705
- }, [currencySearchValue]);
23706
- const {
23707
- options: customerOptions,
23708
- fetchNextPage,
23709
- isFetchingNextPage,
23710
- searchValue,
23711
- onSearchValueChange,
23712
- isLoading
23713
- } = useComboboxData({
23714
- queryKey: customersQueryKeys.list(),
23715
- queryFn: async (params) => {
23716
- return sdk.admin.customer.list(params);
23717
- },
23718
- getOptions: (data) => {
23719
- return data.customers?.map((customer) => {
23720
- const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
23721
- const label = fullName ? `${customer.email} (${fullName})` : customer.email;
23722
- return {
23723
- label,
23724
- value: customer.id
23725
- };
23726
- }) || [];
23727
- }
23728
24297
  });
23729
- return /* @__PURE__ */ jsxs(RouteFocusModal.Form, { form, children: [
23730
- /* @__PURE__ */ jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsx("div", { className: "-my-2 w-full border-l" }) }),
23731
- /* @__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: [
23732
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
23733
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Create Store Credit Account" }),
23734
- /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new store credit account for a customer" })
23735
- ] }),
23736
- /* @__PURE__ */ jsxs("div", { className: "flex gap-x-4", children: [
23737
- /* @__PURE__ */ jsx(
23738
- Form$2.Field,
23739
- {
23740
- control: form.control,
23741
- name: "currency_code",
23742
- render: ({ field }) => {
23743
- return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
23744
- /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Currency" }),
24298
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
24299
+ KeyboundForm,
24300
+ {
24301
+ className: "flex flex-1 flex-col overflow-hidden",
24302
+ onSubmit,
24303
+ children: [
24304
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
24305
+ /* @__PURE__ */ jsx(
24306
+ Form$2.Field,
24307
+ {
24308
+ control: form.control,
24309
+ name: "amount",
24310
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
24311
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Amount" }),
23745
24312
  /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
23746
- Combobox,
24313
+ CurrencyInput$1,
23747
24314
  {
23748
- value: field.value,
23749
- onChange: field.onChange,
23750
- searchValue: currencySearchValue,
23751
- onSearchValueChange: setCurrencySearchValue,
23752
- options: currencyOptions,
23753
- placeholder: "Search for a currency..."
24315
+ min: 0,
24316
+ placeholder: "0",
24317
+ value: field.value.value,
24318
+ onValueChange: (_value, _name, values) => {
24319
+ field.onChange({
24320
+ value: values?.value,
24321
+ float: values?.float || null
24322
+ });
24323
+ },
24324
+ symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
24325
+ code: storeCreditAccount.currency_code.toUpperCase()
23754
24326
  }
23755
24327
  ) }),
23756
24328
  /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
23757
- ] });
24329
+ ] })
23758
24330
  }
23759
- }
23760
- ),
23761
- /* @__PURE__ */ jsx(
23762
- Form$2.Field,
23763
- {
23764
- control: form.control,
23765
- name: "customer_id",
23766
- render: ({ field }) => {
23767
- return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
23768
- /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Customer" }),
23769
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
23770
- Combobox,
23771
- {
23772
- value: field.value,
23773
- onChange: field.onChange,
23774
- searchValue,
23775
- onSearchValueChange,
23776
- options: customerOptions,
23777
- placeholder: "Search for a customer...",
23778
- fetchNextPage,
23779
- isFetchingNextPage,
23780
- noResultsPlaceholder: isLoading ? "Loading customers..." : "No customers found"
23781
- }
23782
- ) }),
24331
+ ),
24332
+ /* @__PURE__ */ jsx(
24333
+ Form$2.Field,
24334
+ {
24335
+ control: form.control,
24336
+ name: "note",
24337
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
24338
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
24339
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
23783
24340
  /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
23784
- ] });
24341
+ ] })
23785
24342
  }
23786
- }
23787
- )
23788
- ] })
23789
- ] }) }) }),
23790
- /* @__PURE__ */ jsxs(RouteFocusModal.Footer, { children: [
23791
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, disabled: isPending, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", disabled: isPending, children: "Cancel" }) }),
23792
- /* @__PURE__ */ jsx(
23793
- Button,
23794
- {
23795
- variant: "primary",
23796
- size: "small",
23797
- onClick: handleSubmit,
23798
- disabled: isPending,
23799
- children: "Create"
23800
- }
23801
- )
23802
- ] })
23803
- ] });
23804
- };
23805
- const StoreCreditAccountCreate = () => {
23806
- return /* @__PURE__ */ jsxs(RouteFocusModal, { children: [
23807
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create Store Credit Account" }) }),
23808
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Create a new store credit account" }) }),
23809
- /* @__PURE__ */ jsx(StoreCreditAccountCreateForm, {})
23810
- ] });
24343
+ )
24344
+ ] }),
24345
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
24346
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
24347
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
24348
+ ] }) })
24349
+ ]
24350
+ }
24351
+ ) });
23811
24352
  };
24353
+ const schema$2 = z.object({
24354
+ note: z.string(),
24355
+ amount: z.object({
24356
+ float: z.number(),
24357
+ value: z.string()
24358
+ })
24359
+ });
23812
24360
  function _extends() {
23813
24361
  return _extends = Object.assign ? Object.assign.bind() : function(n2) {
23814
24362
  for (var e = 1; e < arguments.length; e++) {
@@ -26488,258 +27036,6 @@ const GiftCardOrderSection = ({ giftCard }) => {
26488
27036
  ))
26489
27037
  ] });
26490
27038
  };
26491
- var toggleSelection;
26492
- var hasRequiredToggleSelection;
26493
- function requireToggleSelection() {
26494
- if (hasRequiredToggleSelection) return toggleSelection;
26495
- hasRequiredToggleSelection = 1;
26496
- toggleSelection = function() {
26497
- var selection = document.getSelection();
26498
- if (!selection.rangeCount) {
26499
- return function() {
26500
- };
26501
- }
26502
- var active = document.activeElement;
26503
- var ranges = [];
26504
- for (var i2 = 0; i2 < selection.rangeCount; i2++) {
26505
- ranges.push(selection.getRangeAt(i2));
26506
- }
26507
- switch (active.tagName.toUpperCase()) {
26508
- // .toUpperCase handles XHTML
26509
- case "INPUT":
26510
- case "TEXTAREA":
26511
- active.blur();
26512
- break;
26513
- default:
26514
- active = null;
26515
- break;
26516
- }
26517
- selection.removeAllRanges();
26518
- return function() {
26519
- selection.type === "Caret" && selection.removeAllRanges();
26520
- if (!selection.rangeCount) {
26521
- ranges.forEach(function(range) {
26522
- selection.addRange(range);
26523
- });
26524
- }
26525
- active && active.focus();
26526
- };
26527
- };
26528
- return toggleSelection;
26529
- }
26530
- var copyToClipboard;
26531
- var hasRequiredCopyToClipboard;
26532
- function requireCopyToClipboard() {
26533
- if (hasRequiredCopyToClipboard) return copyToClipboard;
26534
- hasRequiredCopyToClipboard = 1;
26535
- var deselectCurrent = requireToggleSelection();
26536
- var clipboardToIE11Formatting = {
26537
- "text/plain": "Text",
26538
- "text/html": "Url",
26539
- "default": "Text"
26540
- };
26541
- var defaultMessage = "Copy to clipboard: #{key}, Enter";
26542
- function format2(message2) {
26543
- var copyKey = (/mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl") + "+C";
26544
- return message2.replace(/#{\s*key\s*}/g, copyKey);
26545
- }
26546
- function copy2(text2, options) {
26547
- var debug2, message2, reselectPrevious, range, selection, mark, success = false;
26548
- if (!options) {
26549
- options = {};
26550
- }
26551
- debug2 = options.debug || false;
26552
- try {
26553
- reselectPrevious = deselectCurrent();
26554
- range = document.createRange();
26555
- selection = document.getSelection();
26556
- mark = document.createElement("span");
26557
- mark.textContent = text2;
26558
- mark.ariaHidden = "true";
26559
- mark.style.all = "unset";
26560
- mark.style.position = "fixed";
26561
- mark.style.top = 0;
26562
- mark.style.clip = "rect(0, 0, 0, 0)";
26563
- mark.style.whiteSpace = "pre";
26564
- mark.style.webkitUserSelect = "text";
26565
- mark.style.MozUserSelect = "text";
26566
- mark.style.msUserSelect = "text";
26567
- mark.style.userSelect = "text";
26568
- mark.addEventListener("copy", function(e) {
26569
- e.stopPropagation();
26570
- if (options.format) {
26571
- e.preventDefault();
26572
- if (typeof e.clipboardData === "undefined") {
26573
- debug2 && console.warn("unable to use e.clipboardData");
26574
- debug2 && console.warn("trying IE specific stuff");
26575
- window.clipboardData.clearData();
26576
- var format3 = clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting["default"];
26577
- window.clipboardData.setData(format3, text2);
26578
- } else {
26579
- e.clipboardData.clearData();
26580
- e.clipboardData.setData(options.format, text2);
26581
- }
26582
- }
26583
- if (options.onCopy) {
26584
- e.preventDefault();
26585
- options.onCopy(e.clipboardData);
26586
- }
26587
- });
26588
- document.body.appendChild(mark);
26589
- range.selectNodeContents(mark);
26590
- selection.addRange(range);
26591
- var successful = document.execCommand("copy");
26592
- if (!successful) {
26593
- throw new Error("copy command was unsuccessful");
26594
- }
26595
- success = true;
26596
- } catch (err) {
26597
- debug2 && console.error("unable to copy using execCommand: ", err);
26598
- debug2 && console.warn("trying IE specific stuff");
26599
- try {
26600
- window.clipboardData.setData(options.format || "text", text2);
26601
- options.onCopy && options.onCopy(window.clipboardData);
26602
- success = true;
26603
- } catch (err2) {
26604
- debug2 && console.error("unable to copy using clipboardData: ", err2);
26605
- debug2 && console.error("falling back to prompt");
26606
- message2 = format2("message" in options ? options.message : defaultMessage);
26607
- window.prompt(message2, text2);
26608
- }
26609
- } finally {
26610
- if (selection) {
26611
- if (typeof selection.removeRange == "function") {
26612
- selection.removeRange(range);
26613
- } else {
26614
- selection.removeAllRanges();
26615
- }
26616
- }
26617
- if (mark) {
26618
- document.body.removeChild(mark);
26619
- }
26620
- reselectPrevious();
26621
- }
26622
- return success;
26623
- }
26624
- copyToClipboard = copy2;
26625
- return copyToClipboard;
26626
- }
26627
- var copyToClipboardExports = requireCopyToClipboard();
26628
- const copy$1 = /* @__PURE__ */ getDefaultExportFromCjs(copyToClipboardExports);
26629
- function DisplayId({ id, className }) {
26630
- const [open, setOpen] = useState(false);
26631
- const onClick = () => {
26632
- copy$1(id);
26633
- toast.success("Copied to clipboard");
26634
- };
26635
- return /* @__PURE__ */ jsx(Tooltip, { maxWidth: 260, content: id, open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs("span", { onClick, className: clx("cursor-pointer", className), children: [
26636
- "#",
26637
- id.slice(-7)
26638
- ] }) });
26639
- }
26640
- const columnHelper$8 = createDataTableColumnHelper();
26641
- const useTransactionsTableColumns = () => {
26642
- return useMemo(() => {
26643
- return [
26644
- columnHelper$8.accessor("id", {
26645
- header: "ID",
26646
- cell: ({ row }) => {
26647
- return /* @__PURE__ */ jsx(DisplayId, { id: row.original.id });
26648
- }
26649
- }),
26650
- columnHelper$8.accessor("created_at", {
26651
- header: "Created At",
26652
- cell: ({ row }) => formatDate(row.original.created_at, false)
26653
- }),
26654
- columnHelper$8.accessor("note", {
26655
- header: "Description",
26656
- cell: ({ row }) => row.original.note
26657
- }),
26658
- columnHelper$8.accessor("note", {
26659
- header: "Note",
26660
- cell: ({ row }) => {
26661
- return /* @__PURE__ */ jsx(Text, { title: row.original.note, className: "max-w-[300px] truncate", children: row.original.note || "-" });
26662
- }
26663
- }),
26664
- columnHelper$8.accessor("amount", {
26665
- header: "Amount",
26666
- cell: ({ row }) => {
26667
- const isDebit = row.original.type === "debit";
26668
- return row.original.account.currency_code && formatAmount(
26669
- row.original.amount * (isDebit ? -1 : 1),
26670
- row.original.account.currency_code
26671
- );
26672
- }
26673
- })
26674
- ];
26675
- }, []);
26676
- };
26677
- const useTransactionsTableFilters = ({}) => {
26678
- const dateFilterOptions = useDataTableDateFilters$1();
26679
- return useMemo(() => {
26680
- return [...dateFilterOptions];
26681
- }, [dateFilterOptions]);
26682
- };
26683
- const useTransactionsTableQuery = ({
26684
- prefix,
26685
- pageSize = 20
26686
- }) => {
26687
- const queryObject = useQueryParams(
26688
- ["offset", "limit", "currency_code", "created_at", "updated_at"],
26689
- prefix
26690
- );
26691
- const { offset: offset2, limit, created_at, updated_at, ...rest } = queryObject;
26692
- const searchParams = {
26693
- limit: limit ? Number(limit) : pageSize,
26694
- offset: offset2 ? Number(offset2) : 0,
26695
- created_at: created_at ? JSON.parse(created_at) : void 0,
26696
- updated_at: updated_at ? JSON.parse(updated_at) : void 0,
26697
- ...rest
26698
- };
26699
- return searchParams;
26700
- };
26701
- const PAGE_SIZE$4 = 10;
26702
- function TransactionsTable({ id }) {
26703
- const queryParams = useTransactionsTableQuery({
26704
- pageSize: PAGE_SIZE$4
26705
- });
26706
- const { transactions, isLoading, count: count2 } = useStoreCreditAccountTransactions(
26707
- id,
26708
- {
26709
- ...queryParams,
26710
- order: queryParams.order ?? "-created_at",
26711
- fields: "*account"
26712
- }
26713
- );
26714
- const columns = useTransactionsTableColumns();
26715
- const filters = useTransactionsTableFilters({});
26716
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [
26717
- /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
26718
- DataTable,
26719
- {
26720
- data: transactions ?? [],
26721
- getRowId: (row) => row.id,
26722
- columns,
26723
- filters,
26724
- isLoading,
26725
- pageSize: PAGE_SIZE$4,
26726
- rowCount: count2,
26727
- enableSearch: false,
26728
- heading: "Transactions",
26729
- emptyState: {
26730
- empty: {
26731
- heading: "No transactions found"
26732
- },
26733
- filtered: {
26734
- heading: "No results found",
26735
- description: "No transactions match your filter criteria."
26736
- }
26737
- }
26738
- }
26739
- ) }),
26740
- /* @__PURE__ */ jsx(Outlet, {})
26741
- ] });
26742
- }
26743
27039
  const GiftCardTransactionsSection = ({
26744
27040
  storeCreditAccount
26745
27041
  }) => {
@@ -26789,33 +27085,6 @@ const GiftCardDetailsPage = () => {
26789
27085
  }
26790
27086
  );
26791
27087
  };
26792
- const KeyboundForm = React__default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
26793
- const handleSubmit = (event) => {
26794
- event.preventDefault();
26795
- onSubmit?.(event);
26796
- };
26797
- const handleKeyDown = (event) => {
26798
- if (event.key === "Enter") {
26799
- if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
26800
- return;
26801
- }
26802
- event.preventDefault();
26803
- if (event.metaKey || event.ctrlKey) {
26804
- handleSubmit(event);
26805
- }
26806
- }
26807
- };
26808
- return /* @__PURE__ */ jsx(
26809
- "form",
26810
- {
26811
- ...rest,
26812
- onSubmit: handleSubmit,
26813
- onKeyDown: onKeyDown ?? handleKeyDown,
26814
- ref
26815
- }
26816
- );
26817
- });
26818
- KeyboundForm.displayName = "KeyboundForm";
26819
27088
  const GiftCardExpiration = () => {
26820
27089
  const { id } = useParams();
26821
27090
  const { gift_card: giftCard, isPending, isError, error } = useGiftCard(id);
@@ -26836,7 +27105,7 @@ const GiftCardExpirationForm = ({ giftCard }) => {
26836
27105
  defaultValues: {
26837
27106
  expires_at: giftCard.expires_at ? new Date(giftCard.expires_at) : null
26838
27107
  },
26839
- resolver: u(schema$2)
27108
+ resolver: u(schema$1)
26840
27109
  });
26841
27110
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
26842
27111
  const { handleSuccess } = useRouteModal();
@@ -26931,10 +27200,10 @@ const GiftCardExpirationForm = ({ giftCard }) => {
26931
27200
  }
26932
27201
  ) });
26933
27202
  };
26934
- const schema$2 = z.object({
27203
+ const schema$1 = z.object({
26935
27204
  expires_at: z.date().nullish()
26936
27205
  });
26937
- const Note$1 = () => {
27206
+ const Note = () => {
26938
27207
  const { id } = useParams();
26939
27208
  const {
26940
27209
  gift_card: giftCard,
@@ -26959,7 +27228,7 @@ const GiftCardNoteForm = ({ giftCard }) => {
26959
27228
  defaultValues: {
26960
27229
  note: giftCard.note ?? ""
26961
27230
  },
26962
- resolver: u(schema$1)
27231
+ resolver: u(schema)
26963
27232
  });
26964
27233
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
26965
27234
  const { handleSuccess } = useRouteModal();
@@ -26998,7 +27267,7 @@ const GiftCardNoteForm = ({ giftCard }) => {
26998
27267
  }
26999
27268
  ) });
27000
27269
  };
27001
- const schema$1 = z.object({
27270
+ const schema = z.object({
27002
27271
  note: z.string().optional()
27003
27272
  });
27004
27273
  const columnHelper$7 = createColumnHelper();
@@ -40658,7 +40927,7 @@ const GiftCardProductCreate = () => {
40658
40927
  isPending: isStorePending,
40659
40928
  isError: isStoreError,
40660
40929
  error: storeError
40661
- } = useStore$2({
40930
+ } = useStore$1({
40662
40931
  fields: "+default_sales_channel"
40663
40932
  });
40664
40933
  const {
@@ -40710,275 +40979,6 @@ const GiftCardProductCreate = () => {
40710
40979
  )
40711
40980
  ] });
40712
40981
  };
40713
- const StoreCreditAccountBalanceSection = ({
40714
- storeCreditAccount
40715
- }) => {
40716
- if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
40717
- return;
40718
- }
40719
- 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: [
40720
- /* @__PURE__ */ jsx("div", { className: "bg-ui-tag-green-icon h-8 w-1 rounded-full" }),
40721
- /* @__PURE__ */ jsxs("div", { children: [
40722
- /* @__PURE__ */ jsx(Text, { weight: "plus", size: "small", className: "text-ui-fg-subtle", children: "Current Balance" }),
40723
- /* @__PURE__ */ jsx(
40724
- Text,
40725
- {
40726
- weight: "plus",
40727
- size: "xlarge",
40728
- className: "tabular-nums text-ui-fg-base",
40729
- children: formatAmount(
40730
- storeCreditAccount.balance,
40731
- storeCreditAccount.currency_code
40732
- )
40733
- }
40734
- )
40735
- ] })
40736
- ] }) });
40737
- };
40738
- const StoreCreditAccountDetailsSection = ({
40739
- storeCreditAccount
40740
- }) => {
40741
- if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
40742
- return;
40743
- }
40744
- return /* @__PURE__ */ jsxs(Container$1, { className: "flex justify-between gap-x-2 px-6 py-6", children: [
40745
- /* @__PURE__ */ jsxs(
40746
- Text,
40747
- {
40748
- weight: "plus",
40749
- size: "xlarge",
40750
- className: "text-ui-fg-base flex gap-x-4",
40751
- children: [
40752
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
40753
- /* @__PURE__ */ jsx(CreditCardIcon, { className: "inline" }),
40754
- " "
40755
- ] }),
40756
- /* @__PURE__ */ jsxs("div", { children: [
40757
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle", children: [
40758
- storeCreditAccount.currency_code.toUpperCase(),
40759
- " Account"
40760
- ] }),
40761
- /* @__PURE__ */ jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsx(
40762
- Text,
40763
- {
40764
- weight: "regular",
40765
- size: "small",
40766
- className: "text-ui-fg-base flex gap-x-4",
40767
- children: /* @__PURE__ */ jsx(DisplayId, { id: storeCreditAccount.id })
40768
- }
40769
- ) })
40770
- ] })
40771
- ]
40772
- }
40773
- ),
40774
- /* @__PURE__ */ jsx("div", { className: "flex items-center gap-x-4", children: /* @__PURE__ */ jsx(
40775
- ActionMenu,
40776
- {
40777
- groups: [
40778
- {
40779
- actions: [
40780
- {
40781
- icon: /* @__PURE__ */ jsx(CreditCard, {}),
40782
- label: "Credit the account",
40783
- to: "credit"
40784
- }
40785
- ]
40786
- }
40787
- ]
40788
- }
40789
- ) })
40790
- ] });
40791
- };
40792
- function StoreCreditAccountCustomerSection({
40793
- customerId
40794
- }) {
40795
- const { customer, isPending } = useCustomer(customerId, void 0, {
40796
- enabled: !!customerId
40797
- });
40798
- if (isPending || !customer) {
40799
- return null;
40800
- }
40801
- return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
40802
- /* @__PURE__ */ jsx(Header$5, { title: "Customer" }),
40803
- /* @__PURE__ */ jsx(
40804
- SidebarLink,
40805
- {
40806
- icon: /* @__PURE__ */ jsx(User, {}),
40807
- labelKey: customer.email || "N/A",
40808
- descriptionKey: !customer.first_name && !customer.last_name ? "N/A" : `${customer.first_name} ${customer.last_name}`,
40809
- to: `/customers/${customer.id}`
40810
- },
40811
- customer.id
40812
- )
40813
- ] });
40814
- }
40815
- function StoreCreditAccountCodeSection({ code }) {
40816
- if (!code) {
40817
- return null;
40818
- }
40819
- return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
40820
- /* @__PURE__ */ jsx(Header$5, { title: "Account Code" }),
40821
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-4 px-6 mb-2", children: [
40822
- /* @__PURE__ */ jsx(Share, { className: "inline" }),
40823
- /* @__PURE__ */ jsx("div", { className: "text-ui-fg-subtle text-sm", children: code })
40824
- ] })
40825
- ] });
40826
- }
40827
- const StoreCreditAccountPage = () => {
40828
- const { id } = useParams();
40829
- const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
40830
- id
40831
- );
40832
- if (!storeCreditAccount) {
40833
- return;
40834
- }
40835
- return /* @__PURE__ */ jsx(
40836
- LayoutComposer,
40837
- {
40838
- widgetsZonePrefix: "store_credit_account.details",
40839
- preferredLayoutId: "core:two-column",
40840
- data: storeCreditAccount,
40841
- sections: {
40842
- main: /* @__PURE__ */ jsxs(Fragment, { children: [
40843
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountDetailsSection", children: /* @__PURE__ */ jsx(
40844
- StoreCreditAccountDetailsSection,
40845
- {
40846
- storeCreditAccount
40847
- }
40848
- ) }),
40849
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "TransactionsTable", children: /* @__PURE__ */ jsx(TransactionsTable, { id: storeCreditAccount.id }) })
40850
- ] }),
40851
- side: /* @__PURE__ */ jsxs(Fragment, { children: [
40852
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountBalanceSection", children: /* @__PURE__ */ jsx(
40853
- StoreCreditAccountBalanceSection,
40854
- {
40855
- storeCreditAccount
40856
- }
40857
- ) }),
40858
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountCodeSection", children: /* @__PURE__ */ jsx(StoreCreditAccountCodeSection, { code: storeCreditAccount.code }) }),
40859
- /* @__PURE__ */ jsx(LayoutComposer.Entry, { id: "StoreCreditAccountCustomerSection", children: /* @__PURE__ */ jsx(
40860
- StoreCreditAccountCustomerSection,
40861
- {
40862
- customerId: storeCreditAccount.customer_id
40863
- }
40864
- ) })
40865
- ] })
40866
- }
40867
- }
40868
- );
40869
- };
40870
- const Note = () => {
40871
- const { id } = useParams();
40872
- const {
40873
- store_credit_account: storeCreditAccount,
40874
- isPending,
40875
- isError,
40876
- error
40877
- } = useStoreCreditAccount(id, {});
40878
- if (isError) {
40879
- throw error;
40880
- }
40881
- const isReady = !isPending && !!storeCreditAccount;
40882
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
40883
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
40884
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Credit store credit account" }) }),
40885
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Credit the store credit account" }) })
40886
- ] }),
40887
- isReady && /* @__PURE__ */ jsx(StoreCreditAccountCreditForm, { storeCreditAccount })
40888
- ] });
40889
- };
40890
- const StoreCreditAccountCreditForm = ({
40891
- storeCreditAccount
40892
- }) => {
40893
- const form = useForm({
40894
- defaultValues: {
40895
- amount: {
40896
- float: 0,
40897
- value: ""
40898
- },
40899
- note: ""
40900
- },
40901
- resolver: u(schema)
40902
- });
40903
- const { mutateAsync, isPending } = useCreditStoreCreditAccount(
40904
- storeCreditAccount.id
40905
- );
40906
- const { handleSuccess } = useRouteModal();
40907
- const onSubmit = form.handleSubmit(async (data) => {
40908
- if (data.amount.float <= 0) {
40909
- form.setError("amount", { message: "Amount must be greater than 0" });
40910
- return;
40911
- }
40912
- await mutateAsync(
40913
- { amount: data.amount.float, note: data.note },
40914
- {
40915
- onSuccess: () => handleSuccess(),
40916
- onError: (error) => toast.error(error.message)
40917
- }
40918
- );
40919
- });
40920
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
40921
- KeyboundForm,
40922
- {
40923
- className: "flex flex-1 flex-col overflow-hidden",
40924
- onSubmit,
40925
- children: [
40926
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
40927
- /* @__PURE__ */ jsx(
40928
- Form$2.Field,
40929
- {
40930
- control: form.control,
40931
- name: "amount",
40932
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
40933
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Amount" }),
40934
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
40935
- CurrencyInput$1,
40936
- {
40937
- min: 0,
40938
- placeholder: "0",
40939
- value: field.value.value,
40940
- onValueChange: (_value, _name, values) => {
40941
- field.onChange({
40942
- value: values?.value,
40943
- float: values?.float || null
40944
- });
40945
- },
40946
- symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
40947
- code: storeCreditAccount.currency_code.toUpperCase()
40948
- }
40949
- ) }),
40950
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
40951
- ] })
40952
- }
40953
- ),
40954
- /* @__PURE__ */ jsx(
40955
- Form$2.Field,
40956
- {
40957
- control: form.control,
40958
- name: "note",
40959
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
40960
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
40961
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
40962
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
40963
- ] })
40964
- }
40965
- )
40966
- ] }),
40967
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
40968
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
40969
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
40970
- ] }) })
40971
- ]
40972
- }
40973
- ) });
40974
- };
40975
- const schema = z.object({
40976
- note: z.string(),
40977
- amount: z.object({
40978
- float: z.number(),
40979
- value: z.string()
40980
- })
40981
- });
40982
40982
  const productStatusColor = (status) => {
40983
40983
  switch (status) {
40984
40984
  case "draft":
@@ -42412,7 +42412,7 @@ const ProductMedia = () => {
42412
42412
  ] });
42413
42413
  };
42414
42414
  const VariantPricingForm = ({ form }) => {
42415
- const { store } = useStore$2();
42415
+ const { store } = useStore$1();
42416
42416
  const { regions } = useRegions({ limit: 9999 });
42417
42417
  const { price_preferences: pricePreferences } = usePricePreferences({});
42418
42418
  const { setCloseOnEscape } = useRouteModal();
@@ -42687,10 +42687,21 @@ const widgetModule = { widgets: [
42687
42687
  ] };
42688
42688
  const routeModule = {
42689
42689
  routes: [
42690
+ {
42691
+ Component: StoreCreditAccountsPage,
42692
+ path: "/store-credit-accounts",
42693
+ handle: { label: config$3.label, translationNs: config$3.translationNs },
42694
+ children: [
42695
+ {
42696
+ Component: StoreCreditAccountCreate,
42697
+ path: "/store-credit-accounts/create"
42698
+ }
42699
+ ]
42700
+ },
42690
42701
  {
42691
42702
  Component: GiftCardsPage,
42692
42703
  path: "/gift-cards",
42693
- handle: { label: config$3.label, translationNs: config$3.translationNs },
42704
+ handle: { label: config$2.label, translationNs: config$2.translationNs },
42694
42705
  children: [
42695
42706
  {
42696
42707
  Component: GiftCardCreate,
@@ -42699,13 +42710,12 @@ const routeModule = {
42699
42710
  ]
42700
42711
  },
42701
42712
  {
42702
- Component: StoreCreditAccountsPage,
42703
- path: "/store-credit-accounts",
42704
- handle: { label: config$1.label, translationNs: config$1.translationNs },
42713
+ Component: StoreCreditAccountPage,
42714
+ path: "/store-credit-accounts/:id",
42705
42715
  children: [
42706
42716
  {
42707
- Component: StoreCreditAccountCreate,
42708
- path: "/store-credit-accounts/create"
42717
+ Component: Note$1,
42718
+ path: "/store-credit-accounts/:id/credit"
42709
42719
  }
42710
42720
  ]
42711
42721
  },
@@ -42718,7 +42728,7 @@ const routeModule = {
42718
42728
  path: "/gift-cards/:id/expiration"
42719
42729
  },
42720
42730
  {
42721
- Component: Note$1,
42731
+ Component: Note,
42722
42732
  path: "/gift-cards/:id/note"
42723
42733
  }
42724
42734
  ]
@@ -42734,16 +42744,6 @@ const routeModule = {
42734
42744
  }
42735
42745
  ]
42736
42746
  },
42737
- {
42738
- Component: StoreCreditAccountPage,
42739
- path: "/store-credit-accounts/:id",
42740
- children: [
42741
- {
42742
- Component: Note,
42743
- path: "/store-credit-accounts/:id/credit"
42744
- }
42745
- ]
42746
- },
42747
42747
  {
42748
42748
  Component: ProductDetail,
42749
42749
  path: "/gift-cards/gift-card-products/:id",
@@ -42775,16 +42775,16 @@ const routeModule = {
42775
42775
  const menuItemModule = {
42776
42776
  menuItems: [
42777
42777
  {
42778
- label: config$3.label,
42779
- icon: config$3.icon,
42778
+ label: config$2.label,
42779
+ icon: config$2.icon,
42780
42780
  path: "/gift-cards",
42781
42781
  nested: void 0,
42782
42782
  rank: void 0,
42783
42783
  translationNs: void 0
42784
42784
  },
42785
42785
  {
42786
- label: config$1.label,
42787
- icon: config$1.icon,
42786
+ label: config$3.label,
42787
+ icon: config$3.icon,
42788
42788
  path: "/store-credit-accounts",
42789
42789
  nested: void 0,
42790
42790
  rank: void 0,