@medusajs/loyalty-plugin 0.0.3 → 0.0.4

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.
@@ -640,6 +640,147 @@ const OrderGiftCardsWidget = () => {
640
640
  adminSdk.defineWidgetConfig({
641
641
  zone: "order.details.side.after"
642
642
  });
643
+ const TwoColumnLayout = ({
644
+ firstCol,
645
+ secondCol
646
+ }) => {
647
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-x-4 gap-y-3 xl:flex-row xl:items-start", children: [
648
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-col gap-y-3", children: firstCol }),
649
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full max-w-[100%] flex-col gap-y-3 xl:mt-0 xl:max-w-[440px]", children: secondCol })
650
+ ] });
651
+ };
652
+ const PRODUCTS_QUERY_KEY = "products";
653
+ const productsQueryKeys = queryKeysFactory(PRODUCTS_QUERY_KEY);
654
+ const VARIANTS_QUERY_KEY = "product_variants";
655
+ const variantsQueryKeys = queryKeysFactory(VARIANTS_QUERY_KEY);
656
+ const useProducts = (query, options) => {
657
+ const { data, ...rest } = reactQuery.useQuery({
658
+ queryFn: () => sdk.admin.product.list(query),
659
+ queryKey: productsQueryKeys.list(query),
660
+ ...options
661
+ });
662
+ return { ...data, ...rest };
663
+ };
664
+ const useProduct = (id, query, options) => {
665
+ const { data, ...rest } = reactQuery.useQuery({
666
+ queryFn: () => sdk.admin.product.retrieve(id, query),
667
+ queryKey: productsQueryKeys.detail(id, query),
668
+ ...options
669
+ });
670
+ return { ...data, ...rest };
671
+ };
672
+ const useCreateProduct = (options) => {
673
+ const queryClient = reactQuery.useQueryClient();
674
+ return reactQuery.useMutation({
675
+ mutationFn: (payload) => sdk.admin.product.create(payload),
676
+ onSuccess: (data, variables, context) => {
677
+ queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() });
678
+ },
679
+ ...options
680
+ });
681
+ };
682
+ const useDeleteProduct = (id, options) => {
683
+ const queryClient = reactQuery.useQueryClient();
684
+ return reactQuery.useMutation({
685
+ mutationFn: () => sdk.admin.product.delete(id),
686
+ onSuccess: (data, variables, context) => {
687
+ queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() });
688
+ queryClient.invalidateQueries({ queryKey: productsQueryKeys.detail(id) });
689
+ },
690
+ ...options
691
+ });
692
+ };
693
+ const useProductVariants = (productId, query, options) => {
694
+ const { data, ...rest } = reactQuery.useQuery({
695
+ queryFn: () => sdk.admin.product.listVariants(productId, query),
696
+ queryKey: variantsQueryKeys.list({ productId, ...query }),
697
+ ...options
698
+ });
699
+ return { ...data, ...rest };
700
+ };
701
+ const useDeleteVariantLazy = (productId, options) => {
702
+ const queryClient = reactQuery.useQueryClient();
703
+ return reactQuery.useMutation({
704
+ mutationFn: ({ variantId }) => sdk.admin.product.deleteVariant(productId, variantId),
705
+ onSuccess: (data, variables, context) => {
706
+ queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() });
707
+ queryClient.invalidateQueries({
708
+ queryKey: variantsQueryKeys.detail(variables.variantId)
709
+ });
710
+ queryClient.invalidateQueries({
711
+ queryKey: productsQueryKeys.detail(productId)
712
+ });
713
+ },
714
+ ...options
715
+ });
716
+ };
717
+ const useUpdateProduct = (id, options) => {
718
+ const queryClient = reactQuery.useQueryClient();
719
+ return reactQuery.useMutation({
720
+ mutationFn: (payload) => sdk.admin.product.update(id, payload),
721
+ onSuccess: async (data, variables, context) => {
722
+ await queryClient.invalidateQueries({
723
+ queryKey: productsQueryKeys.lists()
724
+ });
725
+ await queryClient.invalidateQueries({
726
+ queryKey: productsQueryKeys.details()
727
+ });
728
+ await queryClient.invalidateQueries({
729
+ queryKey: variantsQueryKeys.lists()
730
+ });
731
+ await queryClient.invalidateQueries({
732
+ queryKey: variantsQueryKeys.details()
733
+ });
734
+ },
735
+ ...options
736
+ });
737
+ };
738
+ const useUpdateProductVariantsBatch = (productId, options) => {
739
+ const queryClient = reactQuery.useQueryClient();
740
+ return reactQuery.useMutation({
741
+ mutationFn: (payload) => sdk.admin.product.batchVariants(productId, {
742
+ update: payload
743
+ }),
744
+ onSuccess: (data, variables, context) => {
745
+ queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() });
746
+ queryClient.invalidateQueries({ queryKey: variantsQueryKeys.details() });
747
+ queryClient.invalidateQueries({
748
+ queryKey: productsQueryKeys.detail(productId)
749
+ });
750
+ },
751
+ ...options
752
+ });
753
+ };
754
+ const GiftCardProductsSection = () => {
755
+ const { products: giftCardProducts } = useProducts({
756
+ is_giftcard: true
757
+ });
758
+ if (!(giftCardProducts == null ? void 0 : giftCardProducts.length)) {
759
+ return;
760
+ }
761
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
762
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
763
+ /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Gift Card Products" }),
764
+ /* @__PURE__ */ jsxRuntime.jsx(
765
+ reactRouterDom.Link,
766
+ {
767
+ to: `/gift-card-products/create`,
768
+ className: "text-ui-fg-muted text-sm px-6",
769
+ children: "Create gift card product"
770
+ }
771
+ )
772
+ ] }),
773
+ giftCardProducts.map((giftCardProduct) => /* @__PURE__ */ jsxRuntime.jsx(
774
+ SidebarLink,
775
+ {
776
+ to: `/gift-card-products/${giftCardProduct.id}`,
777
+ labelKey: giftCardProduct.title,
778
+ descriptionKey: giftCardProduct.title,
779
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Tag, {})
780
+ }
781
+ ))
782
+ ] });
783
+ };
643
784
  function useQueryParams(keys, prefix) {
644
785
  const [params] = reactRouterDom.useSearchParams();
645
786
  const result = {};
@@ -890,108 +1031,282 @@ const DataTableAction = ({
890
1031
  }
891
1032
  return /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { ...buttonProps, onClick: props.onClick, children: label });
892
1033
  };
893
- const PRODUCTS_QUERY_KEY = "products";
894
- const productsQueryKeys = queryKeysFactory(PRODUCTS_QUERY_KEY);
895
- const VARIANTS_QUERY_KEY = "product_variants";
896
- const variantsQueryKeys = queryKeysFactory(VARIANTS_QUERY_KEY);
897
- const useProducts = (query, options) => {
898
- const { data, ...rest } = reactQuery.useQuery({
899
- queryFn: () => sdk.admin.product.list(query),
900
- queryKey: productsQueryKeys.list(query),
901
- ...options
902
- });
903
- return { ...data, ...rest };
904
- };
905
- const useProduct = (id, query, options) => {
906
- const { data, ...rest } = reactQuery.useQuery({
907
- queryFn: () => sdk.admin.product.retrieve(id, query),
908
- queryKey: productsQueryKeys.detail(id, query),
909
- ...options
910
- });
911
- return { ...data, ...rest };
912
- };
913
- const useCreateProduct = (options) => {
914
- const queryClient = reactQuery.useQueryClient();
915
- return reactQuery.useMutation({
916
- mutationFn: (payload) => sdk.admin.product.create(payload),
917
- onSuccess: (data, variables, context) => {
918
- queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() });
919
- },
920
- ...options
921
- });
922
- };
923
- const useDeleteProduct = (id, options) => {
924
- const queryClient = reactQuery.useQueryClient();
925
- return reactQuery.useMutation({
926
- mutationFn: () => sdk.admin.product.delete(id),
927
- onSuccess: (data, variables, context) => {
928
- queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() });
929
- queryClient.invalidateQueries({ queryKey: productsQueryKeys.detail(id) });
930
- },
931
- ...options
1034
+ function getRelativeDate(date) {
1035
+ const now = /* @__PURE__ */ new Date();
1036
+ return dateFns.formatDistance(dateFns.sub(new Date(date), { minutes: 0 }), now, {
1037
+ addSuffix: true,
1038
+ includeSeconds: false
932
1039
  });
1040
+ }
1041
+ function formatDate(date, withTime = true) {
1042
+ if (!date) {
1043
+ return "-";
1044
+ }
1045
+ if (withTime) {
1046
+ return dateFns.format(new Date(date), "dd MMM, yyyy, HH:mm:ss");
1047
+ }
1048
+ return dateFns.format(new Date(date), "dd MMM, yyyy");
1049
+ }
1050
+ const columnHelper$a = ui.createDataTableColumnHelper();
1051
+ const useGiftCardTableColumns = () => {
1052
+ return React.useMemo(() => {
1053
+ return [
1054
+ columnHelper$a.accessor("line_item.product.title", {
1055
+ header: "Product",
1056
+ cell: ({ row }) => {
1057
+ var _a, _b;
1058
+ return ((_b = (_a = row.original.line_item) == null ? void 0 : _a.product) == null ? void 0 : _b.title) || "Custom Gift Card";
1059
+ }
1060
+ }),
1061
+ columnHelper$a.accessor("customer.first_name", {
1062
+ header: "Owner",
1063
+ cell: ({ row }) => {
1064
+ if (!row.original.customer) {
1065
+ return "N/A";
1066
+ }
1067
+ const fullName = [
1068
+ row.original.customer.first_name,
1069
+ row.original.customer.last_name
1070
+ ];
1071
+ if (fullName.join("").length > 0) {
1072
+ return fullName.join(" ");
1073
+ }
1074
+ return row.original.customer.email;
1075
+ }
1076
+ }),
1077
+ columnHelper$a.accessor("created_at", {
1078
+ header: "Date issued",
1079
+ cell: ({ row }) => getRelativeDate(row.original.created_at)
1080
+ }),
1081
+ columnHelper$a.accessor("status", {
1082
+ header: "Status",
1083
+ cell: ({ row }) => {
1084
+ const status = getGiftCardStatus(row.original);
1085
+ const color = getGiftCardStatusColor(status);
1086
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color, children: status });
1087
+ }
1088
+ }),
1089
+ columnHelper$a.accessor("value", {
1090
+ header: "Value",
1091
+ cell: ({ row }) => {
1092
+ return formatAmount(row.original.value, row.original.currency_code);
1093
+ }
1094
+ })
1095
+ ];
1096
+ }, []);
933
1097
  };
934
- const useProductVariants = (productId, query, options) => {
935
- const { data, ...rest } = reactQuery.useQuery({
936
- queryFn: () => sdk.admin.product.listVariants(productId, query),
937
- queryKey: variantsQueryKeys.list({ productId, ...query }),
938
- ...options
1098
+ const LOCALE = locale.enUS;
1099
+ const getFullDate = ({
1100
+ date,
1101
+ includeTime = false
1102
+ }) => {
1103
+ const ensuredDate = new Date(date);
1104
+ if (isNaN(ensuredDate.getTime())) {
1105
+ return "";
1106
+ }
1107
+ const timeFormat = includeTime ? "p" : "";
1108
+ return dateFns.format(ensuredDate, `PP ${timeFormat}`, {
1109
+ locale: LOCALE
939
1110
  });
940
- return { ...data, ...rest };
941
1111
  };
942
- const useDeleteVariantLazy = (productId, options) => {
943
- const queryClient = reactQuery.useQueryClient();
944
- return reactQuery.useMutation({
945
- mutationFn: ({ variantId }) => sdk.admin.product.deleteVariant(productId, variantId),
946
- onSuccess: (data, variables, context) => {
947
- queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() });
948
- queryClient.invalidateQueries({
949
- queryKey: variantsQueryKeys.detail(variables.variantId)
950
- });
951
- queryClient.invalidateQueries({
952
- queryKey: productsQueryKeys.detail(productId)
953
- });
954
- },
955
- ...options
956
- });
1112
+ const filterHelper$4 = ui.createDataTableFilterHelper();
1113
+ const useDateFilterOptions$1 = () => {
1114
+ const today = React.useMemo(() => {
1115
+ const date = /* @__PURE__ */ new Date();
1116
+ date.setHours(0, 0, 0, 0);
1117
+ return date;
1118
+ }, []);
1119
+ return React.useMemo(() => {
1120
+ return [
1121
+ {
1122
+ label: "Today",
1123
+ value: {
1124
+ $gte: today.toISOString()
1125
+ }
1126
+ },
1127
+ {
1128
+ label: "Last 7 days",
1129
+ value: {
1130
+ $gte: dateFns.subDays(today, 7).toISOString()
1131
+ // 7 days ago
1132
+ }
1133
+ },
1134
+ {
1135
+ label: "Last 30 days",
1136
+ value: {
1137
+ $gte: dateFns.subDays(today, 30).toISOString()
1138
+ // 30 days ago
1139
+ }
1140
+ },
1141
+ {
1142
+ label: "Last 90 days",
1143
+ value: {
1144
+ $gte: dateFns.subDays(today, 90).toISOString()
1145
+ // 90 days ago
1146
+ }
1147
+ },
1148
+ {
1149
+ label: "Last 12 months",
1150
+ value: {
1151
+ $gte: dateFns.subMonths(today, 12).toISOString()
1152
+ // 12 months ago
1153
+ }
1154
+ }
1155
+ ];
1156
+ }, [today]);
957
1157
  };
958
- const useUpdateProduct = (id, options) => {
959
- const queryClient = reactQuery.useQueryClient();
960
- return reactQuery.useMutation({
961
- mutationFn: (payload) => sdk.admin.product.update(id, payload),
962
- onSuccess: async (data, variables, context) => {
963
- await queryClient.invalidateQueries({
964
- queryKey: productsQueryKeys.lists()
965
- });
966
- await queryClient.invalidateQueries({
967
- queryKey: productsQueryKeys.details()
968
- });
969
- await queryClient.invalidateQueries({
970
- queryKey: variantsQueryKeys.lists()
971
- });
972
- await queryClient.invalidateQueries({
973
- queryKey: variantsQueryKeys.details()
974
- });
975
- },
1158
+ const useDataTableDateFilters$1 = (disableRangeOption) => {
1159
+ const dateFilterOptions = useDateFilterOptions$1();
1160
+ const rangeOptions = React.useMemo(() => {
1161
+ return {
1162
+ rangeOptionStartLabel: "Starting",
1163
+ rangeOptionEndLabel: "Ending",
1164
+ rangeOptionLabel: "Custom",
1165
+ options: dateFilterOptions
1166
+ };
1167
+ }, [disableRangeOption, dateFilterOptions]);
1168
+ return React.useMemo(() => {
1169
+ return [
1170
+ filterHelper$4.accessor("created_at", {
1171
+ type: "date",
1172
+ label: "Created at",
1173
+ format: "date",
1174
+ formatDateValue: (date) => getFullDate({ date }),
1175
+ options: dateFilterOptions,
1176
+ ...rangeOptions
1177
+ }),
1178
+ filterHelper$4.accessor("updated_at", {
1179
+ type: "date",
1180
+ label: "Updated at",
1181
+ format: "date",
1182
+ formatDateValue: (date) => getFullDate({ date }),
1183
+ options: dateFilterOptions,
1184
+ ...rangeOptions
1185
+ })
1186
+ ];
1187
+ }, [dateFilterOptions, getFullDate, rangeOptions]);
1188
+ };
1189
+ const CUSTOMERS_QUERY_KEY = "customers";
1190
+ const customersQueryKeys = queryKeysFactory(CUSTOMERS_QUERY_KEY);
1191
+ const useCustomers = (query, options) => {
1192
+ const { data, ...rest } = reactQuery.useQuery({
1193
+ queryFn: () => sdk.admin.customer.list(query),
1194
+ queryKey: customersQueryKeys.list(query),
976
1195
  ...options
977
1196
  });
1197
+ return { ...data, ...rest };
978
1198
  };
979
- const useUpdateProductVariantsBatch = (productId, options) => {
980
- const queryClient = reactQuery.useQueryClient();
981
- return reactQuery.useMutation({
982
- mutationFn: (payload) => sdk.admin.product.batchVariants(productId, {
983
- update: payload
984
- }),
985
- onSuccess: (data, variables, context) => {
986
- queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() });
987
- queryClient.invalidateQueries({ queryKey: variantsQueryKeys.details() });
988
- queryClient.invalidateQueries({
989
- queryKey: productsQueryKeys.detail(productId)
990
- });
991
- },
992
- ...options
1199
+ const filterHelper$3 = ui.createDataTableFilterHelper();
1200
+ const useCustomerFilterOptions = () => {
1201
+ const { customers } = useCustomers({ limit: 1e3 });
1202
+ return React.useMemo(() => {
1203
+ return customers == null ? void 0 : customers.map((customer) => {
1204
+ return {
1205
+ label: customer.email,
1206
+ value: customer.id
1207
+ };
1208
+ });
1209
+ }, [customers]);
1210
+ };
1211
+ const useCustomerFilters = () => {
1212
+ const customerFilterOptions = useCustomerFilterOptions();
1213
+ return React.useMemo(() => {
1214
+ return [
1215
+ filterHelper$3.accessor("customer_id", {
1216
+ type: "select",
1217
+ label: "Owner",
1218
+ options: customerFilterOptions ?? []
1219
+ })
1220
+ ];
1221
+ }, [customerFilterOptions]);
1222
+ };
1223
+ const useGiftCardFilters = () => {
1224
+ const dateFilterOptions = useDataTableDateFilters$1();
1225
+ const customerFilterOptions = useCustomerFilters();
1226
+ return React.useMemo(() => {
1227
+ return [...dateFilterOptions, ...customerFilterOptions];
1228
+ }, [dateFilterOptions, customerFilterOptions]);
1229
+ };
1230
+ const useGiftCardTableQuery = ({
1231
+ prefix,
1232
+ pageSize = 20
1233
+ }) => {
1234
+ const queryObject = useQueryParams(
1235
+ ["offset", "customer_id", "created_at", "updated_at"],
1236
+ prefix
1237
+ );
1238
+ const { offset, created_at, updated_at, customer_id, ...rest } = queryObject;
1239
+ const searchParams = {
1240
+ limit: pageSize,
1241
+ offset: offset ? Number(offset) : 0,
1242
+ created_at: created_at ? JSON.parse(created_at) : void 0,
1243
+ updated_at: updated_at ? JSON.parse(updated_at) : void 0,
1244
+ customer_id: customer_id ? JSON.parse(customer_id) : void 0,
1245
+ ...rest
1246
+ };
1247
+ return searchParams;
1248
+ };
1249
+ const PAGE_SIZE$6 = 10;
1250
+ function GiftCardsTable() {
1251
+ const queryParams = useGiftCardTableQuery({
1252
+ pageSize: PAGE_SIZE$6
1253
+ });
1254
+ const {
1255
+ gift_cards: giftCards,
1256
+ isPending,
1257
+ count: count2
1258
+ } = useGiftCards({
1259
+ ...queryParams,
1260
+ order: queryParams.order ?? "-created_at",
1261
+ fields: "+line_item.product.title"
993
1262
  });
1263
+ const columns = useGiftCardTableColumns();
1264
+ const filters = useGiftCardFilters();
1265
+ return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
1266
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
1267
+ DataTable,
1268
+ {
1269
+ data: giftCards,
1270
+ getRowId: (row) => row.id,
1271
+ columns,
1272
+ filters,
1273
+ isLoading: isPending,
1274
+ pageSize: PAGE_SIZE$6,
1275
+ rowCount: count2,
1276
+ enableSearch: false,
1277
+ heading: "Gift Cards",
1278
+ rowHref: (row) => `${row.id}`,
1279
+ emptyState: {
1280
+ empty: {
1281
+ heading: "No gift cards found",
1282
+ description: "Create a new gift card to get started."
1283
+ },
1284
+ filtered: {
1285
+ heading: "No results found",
1286
+ description: "No gift cards match your filter criteria."
1287
+ }
1288
+ }
1289
+ }
1290
+ ) }),
1291
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
1292
+ ] });
1293
+ }
1294
+ const GiftCardsPage = () => {
1295
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1296
+ /* @__PURE__ */ jsxRuntime.jsx(
1297
+ TwoColumnLayout,
1298
+ {
1299
+ firstCol: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(GiftCardsTable, {}) }),
1300
+ secondCol: /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductsSection, {})
1301
+ }
1302
+ ),
1303
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Toaster, {})
1304
+ ] });
994
1305
  };
1306
+ const config$2 = adminSdk.defineRouteConfig({
1307
+ label: "Gift Cards",
1308
+ icon: icons.Gift
1309
+ });
995
1310
  /**
996
1311
  * table-core
997
1312
  *
@@ -3767,24 +4082,24 @@ const VariantCell = ({ variants }) => {
3767
4082
  const VariantHeader = () => {
3768
4083
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-full w-full items-center", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Denominations" }) });
3769
4084
  };
3770
- const columnHelper$a = createColumnHelper();
4085
+ const columnHelper$9 = createColumnHelper();
3771
4086
  const useGiftCardProductsTableColumns = () => {
3772
4087
  return React.useMemo(
3773
4088
  () => [
3774
- columnHelper$a.display({
4089
+ columnHelper$9.display({
3775
4090
  id: "product",
3776
4091
  header: () => /* @__PURE__ */ jsxRuntime.jsx(ProductHeader, {}),
3777
4092
  cell: ({ row }) => /* @__PURE__ */ jsxRuntime.jsx(ProductCell, { product: row.original })
3778
4093
  }),
3779
- columnHelper$a.accessor("sales_channels", {
4094
+ columnHelper$9.accessor("sales_channels", {
3780
4095
  header: () => /* @__PURE__ */ jsxRuntime.jsx(SalesChannelHeader, {}),
3781
4096
  cell: ({ row }) => /* @__PURE__ */ jsxRuntime.jsx(SalesChannelsCell, { salesChannels: row.original.sales_channels })
3782
4097
  }),
3783
- columnHelper$a.accessor("variants", {
4098
+ columnHelper$9.accessor("variants", {
3784
4099
  header: () => /* @__PURE__ */ jsxRuntime.jsx(VariantHeader, {}),
3785
4100
  cell: ({ row }) => /* @__PURE__ */ jsxRuntime.jsx(VariantCell, { variants: row.original.variants })
3786
4101
  }),
3787
- columnHelper$a.accessor("status", {
4102
+ columnHelper$9.accessor("status", {
3788
4103
  header: () => /* @__PURE__ */ jsxRuntime.jsx(ProductStatusHeader, {}),
3789
4104
  cell: ({ row }) => /* @__PURE__ */ jsxRuntime.jsx(ProductStatusCell, { status: row.original.status })
3790
4105
  })
@@ -3792,102 +4107,11 @@ const useGiftCardProductsTableColumns = () => {
3792
4107
  []
3793
4108
  );
3794
4109
  };
3795
- const LOCALE = locale.enUS;
3796
- const getFullDate = ({
3797
- date,
3798
- includeTime = false
3799
- }) => {
3800
- const ensuredDate = new Date(date);
3801
- if (isNaN(ensuredDate.getTime())) {
3802
- return "";
3803
- }
3804
- const timeFormat = includeTime ? "p" : "";
3805
- return dateFns.format(ensuredDate, `PP ${timeFormat}`, {
3806
- locale: LOCALE
3807
- });
3808
- };
3809
- const filterHelper$4 = ui.createDataTableFilterHelper();
3810
- const useDateFilterOptions$1 = () => {
3811
- const today = React.useMemo(() => {
3812
- const date = /* @__PURE__ */ new Date();
3813
- date.setHours(0, 0, 0, 0);
3814
- return date;
3815
- }, []);
3816
- return React.useMemo(() => {
3817
- return [
3818
- {
3819
- label: "Today",
3820
- value: {
3821
- $gte: today.toISOString()
3822
- }
3823
- },
3824
- {
3825
- label: "Last 7 days",
3826
- value: {
3827
- $gte: dateFns.subDays(today, 7).toISOString()
3828
- // 7 days ago
3829
- }
3830
- },
3831
- {
3832
- label: "Last 30 days",
3833
- value: {
3834
- $gte: dateFns.subDays(today, 30).toISOString()
3835
- // 30 days ago
3836
- }
3837
- },
3838
- {
3839
- label: "Last 90 days",
3840
- value: {
3841
- $gte: dateFns.subDays(today, 90).toISOString()
3842
- // 90 days ago
3843
- }
3844
- },
3845
- {
3846
- label: "Last 12 months",
3847
- value: {
3848
- $gte: dateFns.subMonths(today, 12).toISOString()
3849
- // 12 months ago
3850
- }
3851
- }
3852
- ];
3853
- }, [today]);
3854
- };
3855
- const useDataTableDateFilters$1 = (disableRangeOption) => {
3856
- const dateFilterOptions = useDateFilterOptions$1();
3857
- const rangeOptions = React.useMemo(() => {
3858
- return {
3859
- rangeOptionStartLabel: "Starting",
3860
- rangeOptionEndLabel: "Ending",
3861
- rangeOptionLabel: "Custom",
3862
- options: dateFilterOptions
3863
- };
3864
- }, [disableRangeOption, dateFilterOptions]);
3865
- return React.useMemo(() => {
3866
- return [
3867
- filterHelper$4.accessor("created_at", {
3868
- type: "date",
3869
- label: "Created at",
3870
- format: "date",
3871
- formatDateValue: (date) => getFullDate({ date }),
3872
- options: dateFilterOptions,
3873
- ...rangeOptions
3874
- }),
3875
- filterHelper$4.accessor("updated_at", {
3876
- type: "date",
3877
- label: "Updated at",
3878
- format: "date",
3879
- formatDateValue: (date) => getFullDate({ date }),
3880
- options: dateFilterOptions,
3881
- ...rangeOptions
3882
- })
3883
- ];
3884
- }, [dateFilterOptions, getFullDate, rangeOptions]);
3885
- };
3886
- const useGiftCardProductsFilters = () => {
3887
- const dateFilterOptions = useDataTableDateFilters$1();
3888
- return React.useMemo(() => {
3889
- return [...dateFilterOptions];
3890
- }, [dateFilterOptions]);
4110
+ const useGiftCardProductsFilters = () => {
4111
+ const dateFilterOptions = useDataTableDateFilters$1();
4112
+ return React.useMemo(() => {
4113
+ return [...dateFilterOptions];
4114
+ }, [dateFilterOptions]);
3891
4115
  };
3892
4116
  const useGiftCardProductsTableQuery = ({
3893
4117
  prefix,
@@ -3908,10 +4132,10 @@ const useGiftCardProductsTableQuery = ({
3908
4132
  };
3909
4133
  return searchParams;
3910
4134
  };
3911
- const PAGE_SIZE$6 = 10;
4135
+ const PAGE_SIZE$5 = 10;
3912
4136
  function GiftCardProductsTable() {
3913
4137
  const queryParams = useGiftCardProductsTableQuery({
3914
- pageSize: PAGE_SIZE$6
4138
+ pageSize: PAGE_SIZE$5
3915
4139
  });
3916
4140
  const {
3917
4141
  products: giftCardProducts,
@@ -3933,7 +4157,7 @@ function GiftCardProductsTable() {
3933
4157
  columns,
3934
4158
  filters,
3935
4159
  isLoading: isPending,
3936
- pageSize: PAGE_SIZE$6,
4160
+ pageSize: PAGE_SIZE$5,
3937
4161
  rowCount: count2,
3938
4162
  enableSearch: false,
3939
4163
  heading: "Gift Card Products",
@@ -3963,7 +4187,7 @@ const GiftCardProductsPage = () => {
3963
4187
  /* @__PURE__ */ jsxRuntime.jsx(ui.Toaster, {})
3964
4188
  ] });
3965
4189
  };
3966
- const config$2 = adminSdk.defineRouteConfig({
4190
+ const config$1 = adminSdk.defineRouteConfig({
3967
4191
  label: "Gift Cards",
3968
4192
  nested: "/products"
3969
4193
  });
@@ -17829,7 +18053,7 @@ const GiftCardProductCreateDenominationsForm = ({
17829
18053
  }
17830
18054
  ) });
17831
18055
  };
17832
- const columnHelper$9 = createDataGridHelper();
18056
+ const columnHelper$8 = createDataGridHelper();
17833
18057
  const useColumns$3 = ({
17834
18058
  denominations = [],
17835
18059
  currencies: currencies2 = [],
@@ -17838,7 +18062,7 @@ const useColumns$3 = ({
17838
18062
  }) => {
17839
18063
  return React.useMemo(
17840
18064
  () => [
17841
- columnHelper$9.column({
18065
+ columnHelper$8.column({
17842
18066
  id: "denominations",
17843
18067
  header: () => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-full items-center overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: "Denomination" }) }),
17844
18068
  cell: (context) => {
@@ -17846,7 +18070,7 @@ const useColumns$3 = ({
17846
18070
  },
17847
18071
  disableHiding: true
17848
18072
  }),
17849
- columnHelper$9.column({
18073
+ columnHelper$8.column({
17850
18074
  id: "sku",
17851
18075
  name: "SKU",
17852
18076
  header: "SKU",
@@ -23484,12 +23708,12 @@ const useDate = () => {
23484
23708
  getRelativeDate: getRelativeDate2
23485
23709
  };
23486
23710
  };
23487
- const columnHelper$8 = ui.createDataTableColumnHelper();
23711
+ const columnHelper$7 = ui.createDataTableColumnHelper();
23488
23712
  const useDataTableDateColumns = () => {
23489
23713
  const { getFullDate: getFullDate2 } = useDate();
23490
23714
  return React.useMemo(() => {
23491
23715
  return [
23492
- columnHelper$8.accessor("created_at", {
23716
+ columnHelper$7.accessor("created_at", {
23493
23717
  header: "Created at",
23494
23718
  cell: ({ row }) => {
23495
23719
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -23507,7 +23731,7 @@ const useDataTableDateColumns = () => {
23507
23731
  sortAscLabel: "Asc",
23508
23732
  sortDescLabel: "Desc"
23509
23733
  }),
23510
- columnHelper$8.accessor("updated_at", {
23734
+ columnHelper$7.accessor("updated_at", {
23511
23735
  header: "Updated at",
23512
23736
  cell: ({ row }) => {
23513
23737
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -23528,19 +23752,19 @@ const useDataTableDateColumns = () => {
23528
23752
  ];
23529
23753
  }, [getFullDate2]);
23530
23754
  };
23531
- const columnHelper$7 = ui.createDataTableColumnHelper();
23755
+ const columnHelper$6 = ui.createDataTableColumnHelper();
23532
23756
  const useSalesChannelTableColumns = () => {
23533
23757
  const dateColumns = useDataTableDateColumns();
23534
23758
  return React.useMemo(
23535
23759
  () => [
23536
- columnHelper$7.accessor("name", {
23760
+ columnHelper$6.accessor("name", {
23537
23761
  header: () => "Name",
23538
23762
  enableSorting: true,
23539
23763
  sortLabel: "Name",
23540
23764
  sortAscLabel: "Asc",
23541
23765
  sortDescLabel: "Desc"
23542
23766
  }),
23543
- columnHelper$7.accessor("description", {
23767
+ columnHelper$6.accessor("description", {
23544
23768
  header: () => "Description",
23545
23769
  cell: ({ getValue }) => {
23546
23770
  return /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: getValue(), children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-full w-full items-center overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: getValue() }) }) });
@@ -23552,7 +23776,7 @@ const useSalesChannelTableColumns = () => {
23552
23776
  maxSize: 250,
23553
23777
  minSize: 100
23554
23778
  }),
23555
- columnHelper$7.accessor("is_disabled", {
23779
+ columnHelper$6.accessor("is_disabled", {
23556
23780
  header: () => "Status",
23557
23781
  enableSorting: true,
23558
23782
  sortLabel: "Status",
@@ -23583,7 +23807,7 @@ const useSalesChannelTableEmptyState = () => {
23583
23807
  return content;
23584
23808
  }, []);
23585
23809
  };
23586
- const filterHelper$3 = ui.createDataTableFilterHelper();
23810
+ const filterHelper$2 = ui.createDataTableFilterHelper();
23587
23811
  const useDateFilterOptions = () => {
23588
23812
  const today = React.useMemo(() => {
23589
23813
  const date = /* @__PURE__ */ new Date();
@@ -23642,7 +23866,7 @@ const useDataTableDateFilters = (disableRangeOption) => {
23642
23866
  }, [disableRangeOption, dateFilterOptions]);
23643
23867
  return React.useMemo(() => {
23644
23868
  return [
23645
- filterHelper$3.accessor("created_at", {
23869
+ filterHelper$2.accessor("created_at", {
23646
23870
  type: "date",
23647
23871
  label: "Created At",
23648
23872
  format: "date",
@@ -23650,7 +23874,7 @@ const useDataTableDateFilters = (disableRangeOption) => {
23650
23874
  options: dateFilterOptions,
23651
23875
  ...rangeOptions
23652
23876
  }),
23653
- filterHelper$3.accessor("updated_at", {
23877
+ filterHelper$2.accessor("updated_at", {
23654
23878
  type: "date",
23655
23879
  label: "Updated At",
23656
23880
  format: "date",
@@ -23661,12 +23885,12 @@ const useDataTableDateFilters = (disableRangeOption) => {
23661
23885
  ];
23662
23886
  }, [dateFilterOptions, getFullDate2, rangeOptions]);
23663
23887
  };
23664
- const filterHelper$2 = ui.createDataTableFilterHelper();
23888
+ const filterHelper$1 = ui.createDataTableFilterHelper();
23665
23889
  const useSalesChannelTableFilters = () => {
23666
23890
  const dateFilters = useDataTableDateFilters();
23667
23891
  return React.useMemo(
23668
23892
  () => [
23669
- filterHelper$2.accessor("is_disabled", {
23893
+ filterHelper$1.accessor("is_disabled", {
23670
23894
  label: "Status",
23671
23895
  type: "radio",
23672
23896
  options: [
@@ -23807,7 +24031,7 @@ const PRODUCT_CREATE_FORM_DEFAULTS = {
23807
24031
  weight: "",
23808
24032
  width: ""
23809
24033
  };
23810
- const PAGE_SIZE$5 = 50;
24034
+ const PAGE_SIZE$4 = 50;
23811
24035
  const GiftCardProductSalesChannelStackedModal = ({
23812
24036
  form
23813
24037
  }) => {
@@ -23818,7 +24042,7 @@ const GiftCardProductSalesChannelStackedModal = ({
23818
24042
  );
23819
24043
  const [state, setState] = React.useState([]);
23820
24044
  const searchParams = useSalesChannelTableQuery({
23821
- pageSize: PAGE_SIZE$5,
24045
+ pageSize: PAGE_SIZE$4,
23822
24046
  prefix: SC_STACKED_MODAL_ID
23823
24047
  });
23824
24048
  const { sales_channels, count: count2, isLoading, isError, error } = useSalesChannels(
@@ -23887,7 +24111,7 @@ const GiftCardProductSalesChannelStackedModal = ({
23887
24111
  filters,
23888
24112
  emptyState,
23889
24113
  rowCount: count2,
23890
- pageSize: PAGE_SIZE$5,
24114
+ pageSize: PAGE_SIZE$4,
23891
24115
  getRowId: (row) => row.id,
23892
24116
  rowSelection: {
23893
24117
  state: rowSelection,
@@ -23904,10 +24128,10 @@ const GiftCardProductSalesChannelStackedModal = ({
23904
24128
  ] }) })
23905
24129
  ] });
23906
24130
  };
23907
- const columnHelper$6 = ui.createDataTableColumnHelper();
24131
+ const columnHelper$5 = ui.createDataTableColumnHelper();
23908
24132
  const useColumns$2 = () => {
23909
24133
  const base = useSalesChannelTableColumns();
23910
- return React.useMemo(() => [columnHelper$6.select(), ...base], [base]);
24134
+ return React.useMemo(() => [columnHelper$5.select(), ...base], [base]);
23911
24135
  };
23912
24136
  const GiftCardProductCreateOrganizeForm = ({
23913
24137
  form
@@ -24256,39 +24480,23 @@ const GiftCardProductCreate = () => {
24256
24480
  )
24257
24481
  ] });
24258
24482
  };
24259
- function getRelativeDate(date) {
24260
- const now = /* @__PURE__ */ new Date();
24261
- return dateFns.formatDistance(dateFns.sub(new Date(date), { minutes: 0 }), now, {
24262
- addSuffix: true,
24263
- includeSeconds: false
24264
- });
24265
- }
24266
- function formatDate(date, withTime = true) {
24267
- if (!date) {
24268
- return "-";
24269
- }
24270
- if (withTime) {
24271
- return dateFns.format(new Date(date), "dd MMM, yyyy, HH:mm:ss");
24272
- }
24273
- return dateFns.format(new Date(date), "dd MMM, yyyy");
24274
- }
24275
- const columnHelper$5 = ui.createDataTableColumnHelper();
24483
+ const columnHelper$4 = ui.createDataTableColumnHelper();
24276
24484
  const useStoreCreditAccountTableColumns = () => {
24277
24485
  return React.useMemo(() => {
24278
24486
  return [
24279
- columnHelper$5.accessor("currency_code", {
24487
+ columnHelper$4.accessor("currency_code", {
24280
24488
  header: "Currency",
24281
24489
  cell: ({ row }) => {
24282
24490
  return /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", children: row.original.currency_code.toUpperCase() });
24283
24491
  }
24284
24492
  }),
24285
- columnHelper$5.accessor("customer.email", {
24493
+ columnHelper$4.accessor("customer.email", {
24286
24494
  header: "Customer",
24287
24495
  cell: ({ row }) => {
24288
24496
  return row.original.customer.email;
24289
24497
  }
24290
24498
  }),
24291
- columnHelper$5.accessor("balance", {
24499
+ columnHelper$4.accessor("balance", {
24292
24500
  header: "Balance",
24293
24501
  cell: ({ row }) => {
24294
24502
  return formatAmount(
@@ -24297,7 +24505,7 @@ const useStoreCreditAccountTableColumns = () => {
24297
24505
  );
24298
24506
  }
24299
24507
  }),
24300
- columnHelper$5.accessor("credits", {
24508
+ columnHelper$4.accessor("credits", {
24301
24509
  header: "Credits",
24302
24510
  cell: ({ row }) => {
24303
24511
  return formatAmount(
@@ -24306,7 +24514,7 @@ const useStoreCreditAccountTableColumns = () => {
24306
24514
  );
24307
24515
  }
24308
24516
  }),
24309
- columnHelper$5.accessor("debits", {
24517
+ columnHelper$4.accessor("debits", {
24310
24518
  header: "Debits",
24311
24519
  cell: ({ row }) => {
24312
24520
  return formatAmount(
@@ -24315,47 +24523,13 @@ const useStoreCreditAccountTableColumns = () => {
24315
24523
  );
24316
24524
  }
24317
24525
  }),
24318
- columnHelper$5.accessor("created_at", {
24526
+ columnHelper$4.accessor("created_at", {
24319
24527
  header: "Created at",
24320
24528
  cell: ({ row }) => getRelativeDate(row.original.created_at)
24321
24529
  })
24322
24530
  ];
24323
24531
  }, []);
24324
24532
  };
24325
- const CUSTOMERS_QUERY_KEY = "customers";
24326
- const customersQueryKeys = queryKeysFactory(CUSTOMERS_QUERY_KEY);
24327
- const useCustomers = (query, options) => {
24328
- const { data, ...rest } = reactQuery.useQuery({
24329
- queryFn: () => sdk.admin.customer.list(query),
24330
- queryKey: customersQueryKeys.list(query),
24331
- ...options
24332
- });
24333
- return { ...data, ...rest };
24334
- };
24335
- const filterHelper$1 = ui.createDataTableFilterHelper();
24336
- const useCustomerFilterOptions = () => {
24337
- const { customers } = useCustomers({ limit: 1e3 });
24338
- return React.useMemo(() => {
24339
- return customers == null ? void 0 : customers.map((customer) => {
24340
- return {
24341
- label: customer.email,
24342
- value: customer.id
24343
- };
24344
- });
24345
- }, [customers]);
24346
- };
24347
- const useCustomerFilters = () => {
24348
- const customerFilterOptions = useCustomerFilterOptions();
24349
- return React.useMemo(() => {
24350
- return [
24351
- filterHelper$1.accessor("customer_id", {
24352
- type: "select",
24353
- label: "Owner",
24354
- options: customerFilterOptions ?? []
24355
- })
24356
- ];
24357
- }, [customerFilterOptions]);
24358
- };
24359
24533
  const useStoreCreditAccountFilters = () => {
24360
24534
  const dateFilterOptions = useDataTableDateFilters$1();
24361
24535
  const customerFilterOptions = useCustomerFilters();
@@ -24390,10 +24564,10 @@ const useStoreCreditAccountsTableQuery = ({
24390
24564
  };
24391
24565
  return searchParams;
24392
24566
  };
24393
- const PAGE_SIZE$4 = 10;
24567
+ const PAGE_SIZE$3 = 10;
24394
24568
  function StoreCreditAccountsTable() {
24395
24569
  const queryParams = useStoreCreditAccountsTableQuery({
24396
- pageSize: PAGE_SIZE$4
24570
+ pageSize: PAGE_SIZE$3
24397
24571
  });
24398
24572
  const {
24399
24573
  store_credit_accounts: storeCreditAccounts,
@@ -24414,7 +24588,7 @@ function StoreCreditAccountsTable() {
24414
24588
  columns,
24415
24589
  filters,
24416
24590
  isLoading: isPending,
24417
- pageSize: PAGE_SIZE$4,
24591
+ pageSize: PAGE_SIZE$3,
24418
24592
  rowCount: count2,
24419
24593
  enableSearch: false,
24420
24594
  heading: "Store Credit Accounts",
@@ -24440,630 +24614,46 @@ const StoreCreditAccountsPage = () => {
24440
24614
  /* @__PURE__ */ jsxRuntime.jsx(ui.Toaster, {})
24441
24615
  ] });
24442
24616
  };
24443
- const config$1 = adminSdk.defineRouteConfig({
24617
+ const config = adminSdk.defineRouteConfig({
24444
24618
  label: "Store Credits",
24445
24619
  icon: icons.CreditCard
24446
24620
  });
24447
- const TwoColumnLayout = ({
24448
- firstCol,
24449
- secondCol
24450
- }) => {
24451
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-x-4 gap-y-3 xl:flex-row xl:items-start", children: [
24452
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-col gap-y-3", children: firstCol }),
24453
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full max-w-[100%] flex-col gap-y-3 xl:mt-0 xl:max-w-[440px]", children: secondCol })
24454
- ] });
24621
+ function _objectWithoutPropertiesLoose(r2, e2) {
24622
+ if (null == r2) return {};
24623
+ var t2 = {};
24624
+ for (var n2 in r2) if ({}.hasOwnProperty.call(r2, n2)) {
24625
+ if (-1 !== e2.indexOf(n2)) continue;
24626
+ t2[n2] = r2[n2];
24627
+ }
24628
+ return t2;
24629
+ }
24630
+ var initialState$5 = {};
24631
+ var Context$5 = /* @__PURE__ */ React.createContext(initialState$5);
24632
+ var reducer$5 = (state, action) => _extends({}, state, action);
24633
+ var useShowToolsStore = () => {
24634
+ return React.useContext(Context$5);
24455
24635
  };
24456
- const GiftCardProductsSection = () => {
24457
- const { products: giftCardProducts } = useProducts({
24458
- is_giftcard: true
24459
- });
24460
- if (!(giftCardProducts == null ? void 0 : giftCardProducts.length)) {
24461
- return;
24462
- }
24463
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
24464
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
24465
- /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Gift Card Products" }),
24466
- /* @__PURE__ */ jsxRuntime.jsx(
24467
- reactRouterDom.Link,
24468
- {
24469
- to: `/gift-card-products/create`,
24470
- className: "text-ui-fg-muted text-sm px-6",
24471
- children: "Create gift card product"
24472
- }
24473
- )
24474
- ] }),
24475
- giftCardProducts.map((giftCardProduct) => /* @__PURE__ */ jsxRuntime.jsx(
24476
- SidebarLink,
24477
- {
24478
- to: `/gift-card-products/${giftCardProduct.id}`,
24479
- labelKey: giftCardProduct.title,
24480
- descriptionKey: giftCardProduct.title,
24481
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Tag, {})
24482
- }
24483
- ))
24484
- ] });
24485
- };
24486
- const columnHelper$4 = ui.createDataTableColumnHelper();
24487
- const useGiftCardTableColumns = () => {
24488
- return React.useMemo(() => {
24489
- return [
24490
- columnHelper$4.accessor("line_item.product.title", {
24491
- header: "Product",
24492
- cell: ({ row }) => {
24493
- var _a, _b;
24494
- return ((_b = (_a = row.original.line_item) == null ? void 0 : _a.product) == null ? void 0 : _b.title) || "Custom Gift Card";
24495
- }
24496
- }),
24497
- columnHelper$4.accessor("customer.first_name", {
24498
- header: "Owner",
24499
- cell: ({ row }) => {
24500
- if (!row.original.customer) {
24501
- return "N/A";
24502
- }
24503
- const fullName = [
24504
- row.original.customer.first_name,
24505
- row.original.customer.last_name
24506
- ];
24507
- if (fullName.join("").length > 0) {
24508
- return fullName.join(" ");
24509
- }
24510
- return row.original.customer.email;
24511
- }
24512
- }),
24513
- columnHelper$4.accessor("created_at", {
24514
- header: "Date issued",
24515
- cell: ({ row }) => getRelativeDate(row.original.created_at)
24516
- }),
24517
- columnHelper$4.accessor("status", {
24518
- header: "Status",
24519
- cell: ({ row }) => {
24520
- const status = getGiftCardStatus(row.original);
24521
- const color = getGiftCardStatusColor(status);
24522
- return /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color, children: status });
24523
- }
24524
- }),
24525
- columnHelper$4.accessor("value", {
24526
- header: "Value",
24527
- cell: ({ row }) => {
24528
- return formatAmount(row.original.value, row.original.currency_code);
24529
- }
24530
- })
24531
- ];
24532
- }, []);
24533
- };
24534
- const useGiftCardFilters = () => {
24535
- const dateFilterOptions = useDataTableDateFilters$1();
24536
- const customerFilterOptions = useCustomerFilters();
24537
- return React.useMemo(() => {
24538
- return [...dateFilterOptions, ...customerFilterOptions];
24539
- }, [dateFilterOptions, customerFilterOptions]);
24540
- };
24541
- const useGiftCardTableQuery = ({
24542
- prefix,
24543
- pageSize = 20
24544
- }) => {
24545
- const queryObject = useQueryParams(
24546
- ["offset", "customer_id", "created_at", "updated_at"],
24547
- prefix
24548
- );
24549
- const { offset, created_at, updated_at, customer_id, ...rest } = queryObject;
24550
- const searchParams = {
24551
- limit: pageSize,
24552
- offset: offset ? Number(offset) : 0,
24553
- created_at: created_at ? JSON.parse(created_at) : void 0,
24554
- updated_at: updated_at ? JSON.parse(updated_at) : void 0,
24555
- customer_id: customer_id ? JSON.parse(customer_id) : void 0,
24556
- ...rest
24557
- };
24558
- return searchParams;
24559
- };
24560
- const PAGE_SIZE$3 = 10;
24561
- function GiftCardsTable() {
24562
- const queryParams = useGiftCardTableQuery({
24563
- pageSize: PAGE_SIZE$3
24564
- });
24565
- const {
24566
- gift_cards: giftCards,
24567
- isPending,
24568
- count: count2
24569
- } = useGiftCards({
24570
- ...queryParams,
24571
- order: queryParams.order ?? "-created_at",
24572
- fields: "+line_item.product.title"
24573
- });
24574
- const columns = useGiftCardTableColumns();
24575
- const filters = useGiftCardFilters();
24576
- return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
24577
- /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
24578
- DataTable,
24579
- {
24580
- data: giftCards,
24581
- getRowId: (row) => row.id,
24582
- columns,
24583
- filters,
24584
- isLoading: isPending,
24585
- pageSize: PAGE_SIZE$3,
24586
- rowCount: count2,
24587
- enableSearch: false,
24588
- heading: "Gift Cards",
24589
- rowHref: (row) => `${row.id}`,
24590
- emptyState: {
24591
- empty: {
24592
- heading: "No gift cards found",
24593
- description: "Create a new gift card to get started."
24594
- },
24595
- filtered: {
24596
- heading: "No results found",
24597
- description: "No gift cards match your filter criteria."
24598
- }
24599
- }
24600
- }
24601
- ) }),
24602
- /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
24603
- ] });
24604
- }
24605
- const GiftCardsPage = () => {
24606
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
24607
- /* @__PURE__ */ jsxRuntime.jsx(
24608
- TwoColumnLayout,
24609
- {
24610
- firstCol: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(GiftCardsTable, {}) }),
24611
- secondCol: /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductsSection, {})
24612
- }
24613
- ),
24614
- /* @__PURE__ */ jsxRuntime.jsx(ui.Toaster, {})
24615
- ] });
24616
- };
24617
- const config = adminSdk.defineRouteConfig({
24618
- label: "Gift Cards",
24619
- icon: icons.Gift
24620
- });
24621
- const StoreCreditAccountBalanceSection = ({
24622
- storeCreditAccount
24623
- }) => {
24624
- if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
24625
- return;
24626
- }
24627
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "grid grid-cols-2 gap-x-2 px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-x-3", children: [
24628
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-tag-green-icon h-8 w-1 rounded-full" }),
24629
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
24630
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", size: "small", className: "text-ui-fg-subtle", children: "Current Balance" }),
24631
- /* @__PURE__ */ jsxRuntime.jsx(
24632
- ui.Text,
24633
- {
24634
- weight: "plus",
24635
- size: "xlarge",
24636
- className: "tabular-nums text-ui-fg-base",
24637
- children: formatAmount(
24638
- storeCreditAccount.balance,
24639
- storeCreditAccount.currency_code
24640
- )
24641
- }
24642
- )
24643
- ] })
24644
- ] }) });
24645
- };
24646
- var toggleSelection = function() {
24647
- var selection = document.getSelection();
24648
- if (!selection.rangeCount) {
24649
- return function() {
24650
- };
24651
- }
24652
- var active = document.activeElement;
24653
- var ranges = [];
24654
- for (var i2 = 0; i2 < selection.rangeCount; i2++) {
24655
- ranges.push(selection.getRangeAt(i2));
24656
- }
24657
- switch (active.tagName.toUpperCase()) {
24658
- case "INPUT":
24659
- case "TEXTAREA":
24660
- active.blur();
24661
- break;
24662
- default:
24663
- active = null;
24664
- break;
24665
- }
24666
- selection.removeAllRanges();
24667
- return function() {
24668
- selection.type === "Caret" && selection.removeAllRanges();
24669
- if (!selection.rangeCount) {
24670
- ranges.forEach(function(range) {
24671
- selection.addRange(range);
24672
- });
24673
- }
24674
- active && active.focus();
24675
- };
24676
- };
24677
- var deselectCurrent = toggleSelection;
24678
- var clipboardToIE11Formatting = {
24679
- "text/plain": "Text",
24680
- "text/html": "Url",
24681
- "default": "Text"
24682
- };
24683
- var defaultMessage = "Copy to clipboard: #{key}, Enter";
24684
- function format(message) {
24685
- var copyKey = (/mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl") + "+C";
24686
- return message.replace(/#{\s*key\s*}/g, copyKey);
24687
- }
24688
- function copy(text2, options) {
24689
- var debug2, message, reselectPrevious, range, selection, mark, success = false;
24690
- if (!options) {
24691
- options = {};
24692
- }
24693
- debug2 = options.debug || false;
24694
- try {
24695
- reselectPrevious = deselectCurrent();
24696
- range = document.createRange();
24697
- selection = document.getSelection();
24698
- mark = document.createElement("span");
24699
- mark.textContent = text2;
24700
- mark.ariaHidden = "true";
24701
- mark.style.all = "unset";
24702
- mark.style.position = "fixed";
24703
- mark.style.top = 0;
24704
- mark.style.clip = "rect(0, 0, 0, 0)";
24705
- mark.style.whiteSpace = "pre";
24706
- mark.style.webkitUserSelect = "text";
24707
- mark.style.MozUserSelect = "text";
24708
- mark.style.msUserSelect = "text";
24709
- mark.style.userSelect = "text";
24710
- mark.addEventListener("copy", function(e2) {
24711
- e2.stopPropagation();
24712
- if (options.format) {
24713
- e2.preventDefault();
24714
- if (typeof e2.clipboardData === "undefined") {
24715
- debug2 && console.warn("unable to use e.clipboardData");
24716
- debug2 && console.warn("trying IE specific stuff");
24717
- window.clipboardData.clearData();
24718
- var format2 = clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting["default"];
24719
- window.clipboardData.setData(format2, text2);
24720
- } else {
24721
- e2.clipboardData.clearData();
24722
- e2.clipboardData.setData(options.format, text2);
24723
- }
24724
- }
24725
- if (options.onCopy) {
24726
- e2.preventDefault();
24727
- options.onCopy(e2.clipboardData);
24728
- }
24729
- });
24730
- document.body.appendChild(mark);
24731
- range.selectNodeContents(mark);
24732
- selection.addRange(range);
24733
- var successful = document.execCommand("copy");
24734
- if (!successful) {
24735
- throw new Error("copy command was unsuccessful");
24736
- }
24737
- success = true;
24738
- } catch (err) {
24739
- debug2 && console.error("unable to copy using execCommand: ", err);
24740
- debug2 && console.warn("trying IE specific stuff");
24741
- try {
24742
- window.clipboardData.setData(options.format || "text", text2);
24743
- options.onCopy && options.onCopy(window.clipboardData);
24744
- success = true;
24745
- } catch (err2) {
24746
- debug2 && console.error("unable to copy using clipboardData: ", err2);
24747
- debug2 && console.error("falling back to prompt");
24748
- message = format("message" in options ? options.message : defaultMessage);
24749
- window.prompt(message, text2);
24750
- }
24751
- } finally {
24752
- if (selection) {
24753
- if (typeof selection.removeRange == "function") {
24754
- selection.removeRange(range);
24755
- } else {
24756
- selection.removeAllRanges();
24757
- }
24758
- }
24759
- if (mark) {
24760
- document.body.removeChild(mark);
24761
- }
24762
- reselectPrevious();
24763
- }
24764
- return success;
24765
- }
24766
- var copyToClipboard = copy;
24767
- const copy$1 = /* @__PURE__ */ getDefaultExportFromCjs(copyToClipboard);
24768
- function DisplayId({ id, className }) {
24769
- const [open, setOpen] = React.useState(false);
24770
- const onClick = () => {
24771
- copy$1(id);
24772
- ui.toast.success("Copied to clipboard");
24773
- };
24774
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { maxWidth: 260, content: id, open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { onClick, className: ui.clx("cursor-pointer", className), children: [
24775
- "#",
24776
- id.slice(-7)
24777
- ] }) });
24778
- }
24779
- const StoreCreditAccountDetailsSection = ({
24780
- storeCreditAccount
24781
- }) => {
24782
- if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
24783
- return;
24784
- }
24785
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "grid grid-cols-2 gap-x-2 px-6 py-6", children: /* @__PURE__ */ jsxRuntime.jsxs(
24786
- ui.Text,
24787
- {
24788
- weight: "plus",
24789
- size: "xlarge",
24790
- className: "text-ui-fg-base flex gap-x-4",
24791
- children: [
24792
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
24793
- /* @__PURE__ */ jsxRuntime.jsx(CreditCardIcon, { className: "inline" }),
24794
- " "
24795
- ] }),
24796
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
24797
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle", children: [
24798
- storeCreditAccount.currency_code.toUpperCase(),
24799
- " Account"
24800
- ] }),
24801
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx(
24802
- ui.Text,
24803
- {
24804
- weight: "regular",
24805
- size: "small",
24806
- className: "text-ui-fg-base flex gap-x-4",
24807
- children: /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: storeCreditAccount.id })
24808
- }
24809
- ) })
24810
- ] })
24811
- ]
24812
- }
24813
- ) });
24814
- };
24815
- const transactionQueryKey = queryKeysFactory("transaction");
24816
- const useStoreCreditAccountTransactions = (id, query, options) => {
24817
- const fetchStoreCreditAccountTransactions = (query2, headers) => sdk.client.fetch(
24818
- `/admin/store-credit-accounts/${id}/transactions`,
24819
- {
24820
- query: query2,
24821
- headers
24822
- }
24823
- );
24824
- const { data, ...rest } = reactQuery.useQuery({
24825
- queryFn: () => fetchStoreCreditAccountTransactions(query),
24826
- queryKey: transactionQueryKey.list(query),
24827
- ...options
24828
- });
24829
- return { ...data, ...rest };
24830
- };
24831
- const columnHelper$3 = ui.createDataTableColumnHelper();
24832
- const useTransactionsTableColumns = () => {
24833
- return React.useMemo(() => {
24834
- return [
24835
- columnHelper$3.accessor("id", {
24836
- header: "ID",
24837
- cell: ({ row }) => {
24838
- return /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: row.original.id });
24839
- }
24840
- }),
24841
- columnHelper$3.accessor("created_at", {
24842
- header: "Created At",
24843
- cell: ({ row }) => formatDate(row.original.created_at, false)
24844
- }),
24845
- columnHelper$3.accessor("reference", {
24846
- header: "Reference",
24847
- cell: ({ row }) => {
24848
- var _a;
24849
- const prettyReference = (_a = row.original.reference) == null ? void 0 : _a.split("_").join(" ").split("-").join(" ");
24850
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "capitalize", children: prettyReference });
24851
- }
24852
- }),
24853
- columnHelper$3.accessor("reference_id", {
24854
- header: "Reference ID",
24855
- cell: ({ row }) => {
24856
- return /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: row.original.reference_id });
24857
- }
24858
- }),
24859
- columnHelper$3.accessor("amount", {
24860
- header: "Amount",
24861
- cell: ({ row }) => {
24862
- return row.original.account.currency_code && formatAmount(
24863
- row.original.amount,
24864
- row.original.account.currency_code
24865
- );
24866
- }
24867
- })
24868
- ];
24869
- }, []);
24870
- };
24871
- const transactionGroupQueryKey = queryKeysFactory("transaction-group");
24872
- const useTransactionGroups = (query, options) => {
24873
- const fetchTransactionGroups = (query2, headers) => sdk.client.fetch(
24874
- `/admin/transaction-groups`,
24875
- {
24876
- query: query2,
24877
- headers
24878
- }
24879
- );
24880
- const { data, ...rest } = reactQuery.useQuery({
24881
- queryFn: () => fetchTransactionGroups(query),
24882
- queryKey: transactionGroupQueryKey.list(query),
24883
- ...options
24884
- });
24885
- return { ...data, ...rest };
24886
- };
24887
- const filterHelper = ui.createDataTableFilterHelper();
24888
- const useTransactionGroupFilterOptions = () => {
24889
- const { transaction_groups } = useTransactionGroups({ limit: 1e3 });
24890
- return React.useMemo(() => {
24891
- return transaction_groups == null ? void 0 : transaction_groups.map((transactionGroup) => {
24892
- return {
24893
- label: transactionGroup.code,
24894
- value: transactionGroup.id
24895
- };
24896
- });
24897
- }, [transaction_groups]);
24898
- };
24899
- const useTransactionGroupFilters = () => {
24900
- const transactionGroupFilterOptions = useTransactionGroupFilterOptions();
24901
- return React.useMemo(() => {
24902
- return [
24903
- filterHelper.accessor("transaction_group_id", {
24904
- type: "select",
24905
- label: "Transaction Group",
24906
- options: transactionGroupFilterOptions ?? []
24907
- })
24908
- ];
24909
- }, [transactionGroupFilterOptions]);
24910
- };
24911
- const useTransactionsTableFilters = ({
24912
- transactionGroup
24913
- }) => {
24914
- const dateFilterOptions = useDataTableDateFilters$1();
24915
- const transactionGroupFilters = useTransactionGroupFilters();
24916
- return React.useMemo(() => {
24917
- if (transactionGroup) {
24918
- return [...dateFilterOptions];
24919
- }
24920
- return [...dateFilterOptions, ...transactionGroupFilters];
24921
- }, [dateFilterOptions, transactionGroupFilters, transactionGroup]);
24922
- };
24923
- const useTransactionsTableQuery = ({
24924
- prefix,
24925
- pageSize = 20
24926
- }) => {
24927
- const queryObject = useQueryParams(
24928
- [
24929
- "offset",
24930
- "limit",
24931
- "transaction_group_id",
24932
- "currency_code",
24933
- "created_at",
24934
- "updated_at"
24935
- ],
24936
- prefix
24937
- );
24938
- const {
24939
- offset,
24940
- limit,
24941
- created_at,
24942
- updated_at,
24943
- transaction_group_id,
24944
- ...rest
24945
- } = queryObject;
24946
- const searchParams = {
24947
- limit: limit ? Number(limit) : pageSize,
24948
- offset: offset ? Number(offset) : 0,
24949
- created_at: created_at ? JSON.parse(created_at) : void 0,
24950
- updated_at: updated_at ? JSON.parse(updated_at) : void 0,
24951
- transaction_group_id: transaction_group_id ? JSON.parse(transaction_group_id) : void 0,
24952
- ...rest
24953
- };
24954
- return searchParams;
24955
- };
24956
- const PAGE_SIZE$2 = 10;
24957
- function TransactionsTable({
24958
- id,
24959
- transactionGroup
24960
- }) {
24961
- const queryParams = useTransactionsTableQuery({
24962
- pageSize: PAGE_SIZE$2
24963
- });
24964
- const { transactions, isLoading, count: count2 } = useStoreCreditAccountTransactions(
24965
- id,
24966
- {
24967
- ...queryParams,
24968
- transaction_group_id: transactionGroup == null ? void 0 : transactionGroup.id,
24969
- order: queryParams.order ?? "-created_at",
24970
- fields: "*account,*transaction_group"
24971
- }
24972
- );
24973
- const columns = useTransactionsTableColumns();
24974
- const filters = useTransactionsTableFilters({ transactionGroup });
24975
- return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
24976
- /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
24977
- DataTable,
24978
- {
24979
- data: transactions ?? [],
24980
- getRowId: (row) => row.id,
24981
- columns,
24982
- filters,
24983
- isLoading,
24984
- pageSize: PAGE_SIZE$2,
24985
- rowCount: count2,
24986
- enableSearch: false,
24987
- heading: "Transactions",
24988
- emptyState: {
24989
- empty: {
24990
- heading: "No transactions found"
24991
- },
24992
- filtered: {
24993
- heading: "No results found",
24994
- description: "No transactions match your filter criteria."
24995
- }
24996
- }
24997
- }
24998
- ) }),
24999
- /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
25000
- ] });
25001
- }
25002
- const StoreCreditAccountPage = () => {
25003
- const { id } = reactRouterDom.useParams();
25004
- const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
25005
- id
25006
- );
25007
- if (!storeCreditAccount) {
25008
- return;
25009
- }
25010
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
25011
- TwoColumnLayout,
25012
- {
25013
- firstCol: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
25014
- /* @__PURE__ */ jsxRuntime.jsx(
25015
- StoreCreditAccountDetailsSection,
25016
- {
25017
- storeCreditAccount
25018
- }
25019
- ),
25020
- /* @__PURE__ */ jsxRuntime.jsx(TransactionsTable, { id: storeCreditAccount.id })
25021
- ] }),
25022
- secondCol: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
25023
- StoreCreditAccountBalanceSection,
25024
- {
25025
- storeCreditAccount
25026
- }
25027
- ) })
25028
- }
25029
- ) });
25030
- };
25031
- function _objectWithoutPropertiesLoose(r2, e2) {
25032
- if (null == r2) return {};
25033
- var t2 = {};
25034
- for (var n2 in r2) if ({}.hasOwnProperty.call(r2, n2)) {
25035
- if (-1 !== e2.indexOf(n2)) continue;
25036
- t2[n2] = r2[n2];
25037
- }
25038
- return t2;
25039
- }
25040
- var initialState$5 = {};
25041
- var Context$5 = /* @__PURE__ */ React.createContext(initialState$5);
25042
- var reducer$5 = (state, action) => _extends({}, state, action);
25043
- var useShowToolsStore = () => {
25044
- return React.useContext(Context$5);
25045
- };
25046
- var DispatchShowTools = /* @__PURE__ */ React.createContext(() => {
25047
- });
25048
- DispatchShowTools.displayName = "JVR.DispatchShowTools";
25049
- function useShowTools() {
25050
- return React.useReducer(reducer$5, initialState$5);
25051
- }
25052
- function useShowToolsDispatch() {
25053
- return React.useContext(DispatchShowTools);
25054
- }
25055
- var ShowTools = (_ref) => {
25056
- var {
25057
- initial,
25058
- dispatch,
25059
- children
25060
- } = _ref;
25061
- return /* @__PURE__ */ jsxRuntime.jsx(Context$5.Provider, {
25062
- value: initial,
25063
- children: /* @__PURE__ */ jsxRuntime.jsx(DispatchShowTools.Provider, {
25064
- value: dispatch,
25065
- children
25066
- })
24636
+ var DispatchShowTools = /* @__PURE__ */ React.createContext(() => {
24637
+ });
24638
+ DispatchShowTools.displayName = "JVR.DispatchShowTools";
24639
+ function useShowTools() {
24640
+ return React.useReducer(reducer$5, initialState$5);
24641
+ }
24642
+ function useShowToolsDispatch() {
24643
+ return React.useContext(DispatchShowTools);
24644
+ }
24645
+ var ShowTools = (_ref) => {
24646
+ var {
24647
+ initial,
24648
+ dispatch,
24649
+ children
24650
+ } = _ref;
24651
+ return /* @__PURE__ */ jsxRuntime.jsx(Context$5.Provider, {
24652
+ value: initial,
24653
+ children: /* @__PURE__ */ jsxRuntime.jsx(DispatchShowTools.Provider, {
24654
+ value: dispatch,
24655
+ children
24656
+ })
25067
24657
  });
25068
24658
  };
25069
24659
  ShowTools.displayName = "JVR.ShowTools";
@@ -27413,6 +27003,22 @@ const Copied = ({ style, value }) => {
27413
27003
  }
27414
27004
  return /* @__PURE__ */ jsxRuntime.jsx("span", { style: { ...style, ...styl }, onClick: handler, children: /* @__PURE__ */ jsxRuntime.jsx(icons.SquareTwoStack, { className: "text-ui-contrast-fg-secondary" }) });
27415
27005
  };
27006
+ const transactionGroupQueryKey = queryKeysFactory("transaction-group");
27007
+ const useTransactionGroups = (query, options) => {
27008
+ const fetchTransactionGroups = (query2, headers) => sdk.client.fetch(
27009
+ `/admin/transaction-groups`,
27010
+ {
27011
+ query: query2,
27012
+ headers
27013
+ }
27014
+ );
27015
+ const { data, ...rest } = reactQuery.useQuery({
27016
+ queryFn: () => fetchTransactionGroups(query),
27017
+ queryKey: transactionGroupQueryKey.list(query),
27018
+ ...options
27019
+ });
27020
+ return { ...data, ...rest };
27021
+ };
27416
27022
  const GiftCardBalanceSection = ({
27417
27023
  storeCreditAccount,
27418
27024
  giftCard
@@ -27637,81 +27243,385 @@ const GiftCardGeneralSection = ({ giftCard }) => {
27637
27243
  }
27638
27244
  ),
27639
27245
  /* @__PURE__ */ jsxRuntime.jsx(
27640
- SectionRow,
27246
+ SectionRow,
27247
+ {
27248
+ title: "Creation Date",
27249
+ value: getRelativeDate(giftCard.created_at)
27250
+ }
27251
+ )
27252
+ ] });
27253
+ };
27254
+ const GiftCardNoteSection = ({ giftCard }) => {
27255
+ if (!giftCard) {
27256
+ return;
27257
+ }
27258
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
27259
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
27260
+ /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Note" }),
27261
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: "note", className: "text-ui-fg-muted text-sm px-6", children: "Edit note" })
27262
+ ] }),
27263
+ giftCard.note && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2 px-2 pb-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shadow-elevation-card-rest bg-ui-bg-component transition-fg hover:bg-ui-bg-component-hover active:bg-ui-bg-component-pressed group-focus-visible:shadow-borders-interactive-with-active rounded-md px-4 py-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col", children: /* @__PURE__ */ jsxRuntime.jsx(
27264
+ ui.Text,
27265
+ {
27266
+ size: "small",
27267
+ leading: "compact",
27268
+ className: "text-ui-fg-subtle",
27269
+ children: giftCard.note ?? ""
27270
+ }
27271
+ ) }) }) }) })
27272
+ ] });
27273
+ };
27274
+ const GiftCardOrderSection = ({ giftCard }) => {
27275
+ if (!giftCard || giftCard.reference !== "order") {
27276
+ return;
27277
+ }
27278
+ const { order, isLoading, isError, error } = useOrder(giftCard.reference_id);
27279
+ if (isError) {
27280
+ throw error;
27281
+ }
27282
+ if (isLoading) {
27283
+ return null;
27284
+ }
27285
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
27286
+ /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Order" }),
27287
+ /* @__PURE__ */ jsxRuntime.jsx(
27288
+ SidebarLink,
27641
27289
  {
27642
- title: "Creation Date",
27643
- value: getRelativeDate(giftCard.created_at)
27290
+ to: `/orders/${order.id}`,
27291
+ labelKey: `#${order.display_id}`,
27292
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ShoppingCart, {}),
27293
+ descriptionKey: `Order #${order.display_id}`
27644
27294
  }
27645
27295
  )
27646
27296
  ] });
27647
27297
  };
27648
- const GiftCardNoteSection = ({ giftCard }) => {
27298
+ const GiftCardOwnerSection = ({ giftCard }) => {
27649
27299
  if (!giftCard) {
27650
27300
  return;
27651
27301
  }
27652
27302
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
27653
27303
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
27654
- /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Note" }),
27655
- /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: "note", className: "text-ui-fg-muted text-sm px-6", children: "Edit note" })
27304
+ /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Owner" }),
27305
+ giftCard.status !== GiftCardStatus.REDEEMED && /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: `owner`, className: "text-ui-fg-muted text-sm px-6", children: "Transfer ownership" })
27656
27306
  ] }),
27657
- giftCard.note && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2 px-2 pb-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shadow-elevation-card-rest bg-ui-bg-component transition-fg hover:bg-ui-bg-component-hover active:bg-ui-bg-component-pressed group-focus-visible:shadow-borders-interactive-with-active rounded-md px-4 py-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col", children: /* @__PURE__ */ jsxRuntime.jsx(
27658
- ui.Text,
27307
+ /* @__PURE__ */ jsxRuntime.jsx(
27308
+ SidebarLink,
27659
27309
  {
27660
- size: "small",
27661
- leading: "compact",
27662
- className: "text-ui-fg-subtle",
27663
- children: giftCard.note ?? ""
27310
+ to: `/customers/${giftCard.customer.id}`,
27311
+ labelKey: `${[
27312
+ giftCard.customer.first_name,
27313
+ giftCard.customer.last_name
27314
+ ].join(" ")}`,
27315
+ descriptionKey: giftCard.customer.email,
27316
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.UserMini, {})
27664
27317
  }
27665
- ) }) }) }) })
27318
+ )
27666
27319
  ] });
27667
27320
  };
27668
- const GiftCardOrderSection = ({ giftCard }) => {
27669
- if (!giftCard || giftCard.reference !== "order") {
27670
- return;
27671
- }
27672
- const { order, isLoading, isError, error } = useOrder(giftCard.reference_id);
27673
- if (isError) {
27674
- throw error;
27675
- }
27676
- if (isLoading) {
27677
- return null;
27678
- }
27679
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
27680
- /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Order" }),
27681
- /* @__PURE__ */ jsxRuntime.jsx(
27682
- SidebarLink,
27683
- {
27684
- to: `/orders/${order.id}`,
27685
- labelKey: `#${order.display_id}`,
27686
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ShoppingCart, {}),
27687
- descriptionKey: `Order #${order.display_id}`
27688
- }
27689
- )
27690
- ] });
27321
+ const transactionQueryKey = queryKeysFactory("transaction");
27322
+ const useStoreCreditAccountTransactions = (id, query, options) => {
27323
+ const fetchStoreCreditAccountTransactions = (query2, headers) => sdk.client.fetch(
27324
+ `/admin/store-credit-accounts/${id}/transactions`,
27325
+ {
27326
+ query: query2,
27327
+ headers
27328
+ }
27329
+ );
27330
+ const { data, ...rest } = reactQuery.useQuery({
27331
+ queryFn: () => fetchStoreCreditAccountTransactions(query),
27332
+ queryKey: transactionQueryKey.list(query),
27333
+ ...options
27334
+ });
27335
+ return { ...data, ...rest };
27336
+ };
27337
+ var toggleSelection = function() {
27338
+ var selection = document.getSelection();
27339
+ if (!selection.rangeCount) {
27340
+ return function() {
27341
+ };
27342
+ }
27343
+ var active = document.activeElement;
27344
+ var ranges = [];
27345
+ for (var i2 = 0; i2 < selection.rangeCount; i2++) {
27346
+ ranges.push(selection.getRangeAt(i2));
27347
+ }
27348
+ switch (active.tagName.toUpperCase()) {
27349
+ case "INPUT":
27350
+ case "TEXTAREA":
27351
+ active.blur();
27352
+ break;
27353
+ default:
27354
+ active = null;
27355
+ break;
27356
+ }
27357
+ selection.removeAllRanges();
27358
+ return function() {
27359
+ selection.type === "Caret" && selection.removeAllRanges();
27360
+ if (!selection.rangeCount) {
27361
+ ranges.forEach(function(range) {
27362
+ selection.addRange(range);
27363
+ });
27364
+ }
27365
+ active && active.focus();
27366
+ };
27367
+ };
27368
+ var deselectCurrent = toggleSelection;
27369
+ var clipboardToIE11Formatting = {
27370
+ "text/plain": "Text",
27371
+ "text/html": "Url",
27372
+ "default": "Text"
27373
+ };
27374
+ var defaultMessage = "Copy to clipboard: #{key}, Enter";
27375
+ function format(message) {
27376
+ var copyKey = (/mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl") + "+C";
27377
+ return message.replace(/#{\s*key\s*}/g, copyKey);
27378
+ }
27379
+ function copy(text2, options) {
27380
+ var debug2, message, reselectPrevious, range, selection, mark, success = false;
27381
+ if (!options) {
27382
+ options = {};
27383
+ }
27384
+ debug2 = options.debug || false;
27385
+ try {
27386
+ reselectPrevious = deselectCurrent();
27387
+ range = document.createRange();
27388
+ selection = document.getSelection();
27389
+ mark = document.createElement("span");
27390
+ mark.textContent = text2;
27391
+ mark.ariaHidden = "true";
27392
+ mark.style.all = "unset";
27393
+ mark.style.position = "fixed";
27394
+ mark.style.top = 0;
27395
+ mark.style.clip = "rect(0, 0, 0, 0)";
27396
+ mark.style.whiteSpace = "pre";
27397
+ mark.style.webkitUserSelect = "text";
27398
+ mark.style.MozUserSelect = "text";
27399
+ mark.style.msUserSelect = "text";
27400
+ mark.style.userSelect = "text";
27401
+ mark.addEventListener("copy", function(e2) {
27402
+ e2.stopPropagation();
27403
+ if (options.format) {
27404
+ e2.preventDefault();
27405
+ if (typeof e2.clipboardData === "undefined") {
27406
+ debug2 && console.warn("unable to use e.clipboardData");
27407
+ debug2 && console.warn("trying IE specific stuff");
27408
+ window.clipboardData.clearData();
27409
+ var format2 = clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting["default"];
27410
+ window.clipboardData.setData(format2, text2);
27411
+ } else {
27412
+ e2.clipboardData.clearData();
27413
+ e2.clipboardData.setData(options.format, text2);
27414
+ }
27415
+ }
27416
+ if (options.onCopy) {
27417
+ e2.preventDefault();
27418
+ options.onCopy(e2.clipboardData);
27419
+ }
27420
+ });
27421
+ document.body.appendChild(mark);
27422
+ range.selectNodeContents(mark);
27423
+ selection.addRange(range);
27424
+ var successful = document.execCommand("copy");
27425
+ if (!successful) {
27426
+ throw new Error("copy command was unsuccessful");
27427
+ }
27428
+ success = true;
27429
+ } catch (err) {
27430
+ debug2 && console.error("unable to copy using execCommand: ", err);
27431
+ debug2 && console.warn("trying IE specific stuff");
27432
+ try {
27433
+ window.clipboardData.setData(options.format || "text", text2);
27434
+ options.onCopy && options.onCopy(window.clipboardData);
27435
+ success = true;
27436
+ } catch (err2) {
27437
+ debug2 && console.error("unable to copy using clipboardData: ", err2);
27438
+ debug2 && console.error("falling back to prompt");
27439
+ message = format("message" in options ? options.message : defaultMessage);
27440
+ window.prompt(message, text2);
27441
+ }
27442
+ } finally {
27443
+ if (selection) {
27444
+ if (typeof selection.removeRange == "function") {
27445
+ selection.removeRange(range);
27446
+ } else {
27447
+ selection.removeAllRanges();
27448
+ }
27449
+ }
27450
+ if (mark) {
27451
+ document.body.removeChild(mark);
27452
+ }
27453
+ reselectPrevious();
27454
+ }
27455
+ return success;
27456
+ }
27457
+ var copyToClipboard = copy;
27458
+ const copy$1 = /* @__PURE__ */ getDefaultExportFromCjs(copyToClipboard);
27459
+ function DisplayId({ id, className }) {
27460
+ const [open, setOpen] = React.useState(false);
27461
+ const onClick = () => {
27462
+ copy$1(id);
27463
+ ui.toast.success("Copied to clipboard");
27464
+ };
27465
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { maxWidth: 260, content: id, open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { onClick, className: ui.clx("cursor-pointer", className), children: [
27466
+ "#",
27467
+ id.slice(-7)
27468
+ ] }) });
27469
+ }
27470
+ const columnHelper$3 = ui.createDataTableColumnHelper();
27471
+ const useTransactionsTableColumns = () => {
27472
+ return React.useMemo(() => {
27473
+ return [
27474
+ columnHelper$3.accessor("id", {
27475
+ header: "ID",
27476
+ cell: ({ row }) => {
27477
+ return /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: row.original.id });
27478
+ }
27479
+ }),
27480
+ columnHelper$3.accessor("created_at", {
27481
+ header: "Created At",
27482
+ cell: ({ row }) => formatDate(row.original.created_at, false)
27483
+ }),
27484
+ columnHelper$3.accessor("reference", {
27485
+ header: "Reference",
27486
+ cell: ({ row }) => {
27487
+ var _a;
27488
+ const prettyReference = (_a = row.original.reference) == null ? void 0 : _a.split("_").join(" ").split("-").join(" ");
27489
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "capitalize", children: prettyReference });
27490
+ }
27491
+ }),
27492
+ columnHelper$3.accessor("reference_id", {
27493
+ header: "Reference ID",
27494
+ cell: ({ row }) => {
27495
+ return /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: row.original.reference_id });
27496
+ }
27497
+ }),
27498
+ columnHelper$3.accessor("amount", {
27499
+ header: "Amount",
27500
+ cell: ({ row }) => {
27501
+ return row.original.account.currency_code && formatAmount(
27502
+ row.original.amount,
27503
+ row.original.account.currency_code
27504
+ );
27505
+ }
27506
+ })
27507
+ ];
27508
+ }, []);
27509
+ };
27510
+ const filterHelper = ui.createDataTableFilterHelper();
27511
+ const useTransactionGroupFilterOptions = () => {
27512
+ const { transaction_groups } = useTransactionGroups({ limit: 1e3 });
27513
+ return React.useMemo(() => {
27514
+ return transaction_groups == null ? void 0 : transaction_groups.map((transactionGroup) => {
27515
+ return {
27516
+ label: transactionGroup.code,
27517
+ value: transactionGroup.id
27518
+ };
27519
+ });
27520
+ }, [transaction_groups]);
27521
+ };
27522
+ const useTransactionGroupFilters = () => {
27523
+ const transactionGroupFilterOptions = useTransactionGroupFilterOptions();
27524
+ return React.useMemo(() => {
27525
+ return [
27526
+ filterHelper.accessor("transaction_group_id", {
27527
+ type: "select",
27528
+ label: "Transaction Group",
27529
+ options: transactionGroupFilterOptions ?? []
27530
+ })
27531
+ ];
27532
+ }, [transactionGroupFilterOptions]);
27533
+ };
27534
+ const useTransactionsTableFilters = ({
27535
+ transactionGroup
27536
+ }) => {
27537
+ const dateFilterOptions = useDataTableDateFilters$1();
27538
+ const transactionGroupFilters = useTransactionGroupFilters();
27539
+ return React.useMemo(() => {
27540
+ if (transactionGroup) {
27541
+ return [...dateFilterOptions];
27542
+ }
27543
+ return [...dateFilterOptions, ...transactionGroupFilters];
27544
+ }, [dateFilterOptions, transactionGroupFilters, transactionGroup]);
27545
+ };
27546
+ const useTransactionsTableQuery = ({
27547
+ prefix,
27548
+ pageSize = 20
27549
+ }) => {
27550
+ const queryObject = useQueryParams(
27551
+ [
27552
+ "offset",
27553
+ "limit",
27554
+ "transaction_group_id",
27555
+ "currency_code",
27556
+ "created_at",
27557
+ "updated_at"
27558
+ ],
27559
+ prefix
27560
+ );
27561
+ const {
27562
+ offset,
27563
+ limit,
27564
+ created_at,
27565
+ updated_at,
27566
+ transaction_group_id,
27567
+ ...rest
27568
+ } = queryObject;
27569
+ const searchParams = {
27570
+ limit: limit ? Number(limit) : pageSize,
27571
+ offset: offset ? Number(offset) : 0,
27572
+ created_at: created_at ? JSON.parse(created_at) : void 0,
27573
+ updated_at: updated_at ? JSON.parse(updated_at) : void 0,
27574
+ transaction_group_id: transaction_group_id ? JSON.parse(transaction_group_id) : void 0,
27575
+ ...rest
27576
+ };
27577
+ return searchParams;
27691
27578
  };
27692
- const GiftCardOwnerSection = ({ giftCard }) => {
27693
- if (!giftCard) {
27694
- return;
27695
- }
27696
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
27697
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
27698
- /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Owner" }),
27699
- giftCard.status !== GiftCardStatus.REDEEMED && /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: `owner`, className: "text-ui-fg-muted text-sm px-6", children: "Transfer ownership" })
27700
- ] }),
27701
- /* @__PURE__ */ jsxRuntime.jsx(
27702
- SidebarLink,
27579
+ const PAGE_SIZE$2 = 10;
27580
+ function TransactionsTable({
27581
+ id,
27582
+ transactionGroup
27583
+ }) {
27584
+ const queryParams = useTransactionsTableQuery({
27585
+ pageSize: PAGE_SIZE$2
27586
+ });
27587
+ const { transactions, isLoading, count: count2 } = useStoreCreditAccountTransactions(
27588
+ id,
27589
+ {
27590
+ ...queryParams,
27591
+ transaction_group_id: transactionGroup == null ? void 0 : transactionGroup.id,
27592
+ order: queryParams.order ?? "-created_at",
27593
+ fields: "*account,*transaction_group"
27594
+ }
27595
+ );
27596
+ const columns = useTransactionsTableColumns();
27597
+ const filters = useTransactionsTableFilters({ transactionGroup });
27598
+ return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
27599
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
27600
+ DataTable,
27703
27601
  {
27704
- to: `/customers/${giftCard.customer.id}`,
27705
- labelKey: `${[
27706
- giftCard.customer.first_name,
27707
- giftCard.customer.last_name
27708
- ].join(" ")}`,
27709
- descriptionKey: giftCard.customer.email,
27710
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.UserMini, {})
27602
+ data: transactions ?? [],
27603
+ getRowId: (row) => row.id,
27604
+ columns,
27605
+ filters,
27606
+ isLoading,
27607
+ pageSize: PAGE_SIZE$2,
27608
+ rowCount: count2,
27609
+ enableSearch: false,
27610
+ heading: "Transactions",
27611
+ emptyState: {
27612
+ empty: {
27613
+ heading: "No transactions found"
27614
+ },
27615
+ filtered: {
27616
+ heading: "No results found",
27617
+ description: "No transactions match your filter criteria."
27618
+ }
27619
+ }
27711
27620
  }
27712
- )
27621
+ ) }),
27622
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
27713
27623
  ] });
27714
- };
27624
+ }
27715
27625
  const GiftCardTransactionsSection = ({
27716
27626
  storeCreditAccount,
27717
27627
  transactionGroup
@@ -27903,73 +27813,6 @@ const GiftCardExpirationForm = ({ giftCard }) => {
27903
27813
  const schema$2 = z.object({
27904
27814
  expires_at: z.date().nullish()
27905
27815
  });
27906
- const Note$1 = () => {
27907
- const { id } = reactRouterDom.useParams();
27908
- const {
27909
- gift_card: giftCard,
27910
- isPending,
27911
- isError,
27912
- error
27913
- } = useGiftCard(id, {});
27914
- if (isError) {
27915
- throw error;
27916
- }
27917
- const isReady = !isPending && !!giftCard;
27918
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
27919
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
27920
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit note" }) }),
27921
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the note for the gift card" }) })
27922
- ] }),
27923
- isReady && /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteForm$1, { giftCard })
27924
- ] });
27925
- };
27926
- const GiftCardNoteForm$1 = ({ giftCard }) => {
27927
- const form = useForm({
27928
- defaultValues: {
27929
- note: giftCard.note ?? ""
27930
- },
27931
- resolver: t$1(schema$1)
27932
- });
27933
- const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
27934
- const { handleSuccess } = useRouteModal();
27935
- const onSubmit = form.handleSubmit(async (data) => {
27936
- await mutateAsync(
27937
- { note: data.note },
27938
- {
27939
- onSuccess: () => handleSuccess(),
27940
- onError: (error) => ui.toast.error(error.message)
27941
- }
27942
- );
27943
- });
27944
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
27945
- KeyboundForm,
27946
- {
27947
- className: "flex flex-1 flex-col overflow-hidden",
27948
- onSubmit,
27949
- children: [
27950
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
27951
- Form$2.Field,
27952
- {
27953
- control: form.control,
27954
- name: "note",
27955
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
27956
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
27957
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
27958
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
27959
- ] })
27960
- }
27961
- ) }),
27962
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
27963
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
27964
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
27965
- ] }) })
27966
- ]
27967
- }
27968
- ) });
27969
- };
27970
- const schema$1 = z.object({
27971
- note: z.string().optional()
27972
- });
27973
27816
  const TransferIcon = () => /* @__PURE__ */ jsxRuntime.jsxs(
27974
27817
  "svg",
27975
27818
  {
@@ -28317,7 +28160,7 @@ const TransferIcon = () => /* @__PURE__ */ jsxRuntime.jsxs(
28317
28160
  ]
28318
28161
  }
28319
28162
  );
28320
- const Note = () => {
28163
+ const Note$1 = () => {
28321
28164
  const { id } = reactRouterDom.useParams();
28322
28165
  const {
28323
28166
  gift_card: giftCard,
@@ -28334,16 +28177,16 @@ const Note = () => {
28334
28177
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Gift Card" }) }),
28335
28178
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the gift card to a new owner" }) })
28336
28179
  ] }),
28337
- isReady && /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteForm, { giftCard })
28180
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteForm$1, { giftCard })
28338
28181
  ] });
28339
28182
  };
28340
- const GiftCardNoteForm = ({ giftCard }) => {
28183
+ const GiftCardNoteForm$1 = ({ giftCard }) => {
28341
28184
  const { customers } = useCustomers();
28342
28185
  const form = useForm({
28343
28186
  defaultValues: {
28344
28187
  customer_id: giftCard.customer.id
28345
28188
  },
28346
- resolver: t$1(schema)
28189
+ resolver: t$1(schema$1)
28347
28190
  });
28348
28191
  const { mutateAsync, isPending } = useTransferGiftCard(giftCard.id);
28349
28192
  const { handleSuccess } = useRouteModal();
@@ -28408,8 +28251,75 @@ const GiftCardNoteForm = ({ giftCard }) => {
28408
28251
  }
28409
28252
  ) });
28410
28253
  };
28254
+ const schema$1 = z.object({
28255
+ customer_id: z.string()
28256
+ });
28257
+ const Note = () => {
28258
+ const { id } = reactRouterDom.useParams();
28259
+ const {
28260
+ gift_card: giftCard,
28261
+ isPending,
28262
+ isError,
28263
+ error
28264
+ } = useGiftCard(id, {});
28265
+ if (isError) {
28266
+ throw error;
28267
+ }
28268
+ const isReady = !isPending && !!giftCard;
28269
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
28270
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
28271
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit note" }) }),
28272
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the note for the gift card" }) })
28273
+ ] }),
28274
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteForm, { giftCard })
28275
+ ] });
28276
+ };
28277
+ const GiftCardNoteForm = ({ giftCard }) => {
28278
+ const form = useForm({
28279
+ defaultValues: {
28280
+ note: giftCard.note ?? ""
28281
+ },
28282
+ resolver: t$1(schema)
28283
+ });
28284
+ const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
28285
+ const { handleSuccess } = useRouteModal();
28286
+ const onSubmit = form.handleSubmit(async (data) => {
28287
+ await mutateAsync(
28288
+ { note: data.note },
28289
+ {
28290
+ onSuccess: () => handleSuccess(),
28291
+ onError: (error) => ui.toast.error(error.message)
28292
+ }
28293
+ );
28294
+ });
28295
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
28296
+ KeyboundForm,
28297
+ {
28298
+ className: "flex flex-1 flex-col overflow-hidden",
28299
+ onSubmit,
28300
+ children: [
28301
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
28302
+ Form$2.Field,
28303
+ {
28304
+ control: form.control,
28305
+ name: "note",
28306
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
28307
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
28308
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
28309
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
28310
+ ] })
28311
+ }
28312
+ ) }),
28313
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
28314
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
28315
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
28316
+ ] }) })
28317
+ ]
28318
+ }
28319
+ ) });
28320
+ };
28411
28321
  const schema = z.object({
28412
- customer_id: z.string()
28322
+ note: z.string().optional()
28413
28323
  });
28414
28324
  const productStatusColor = (status) => {
28415
28325
  switch (status) {
@@ -28943,180 +28853,6 @@ const ProductDetail = () => {
28943
28853
  ] });
28944
28854
  };
28945
28855
  const EditProductSchema$1 = z.object({
28946
- status: z.enum(["draft", "published", "proposed", "rejected"]),
28947
- title: z.string().min(1),
28948
- subtitle: z.string().optional(),
28949
- handle: z.string().min(1),
28950
- description: z.string().optional()
28951
- });
28952
- const GiftCardProductEditForm = ({
28953
- product
28954
- }) => {
28955
- const { handleSuccess } = useRouteModal();
28956
- const form = useForm({
28957
- defaultValues: {
28958
- status: product.status,
28959
- title: product.title,
28960
- subtitle: product.subtitle || "",
28961
- handle: product.handle || "",
28962
- description: product.description || ""
28963
- },
28964
- resolver: t$1(EditProductSchema$1)
28965
- });
28966
- const { mutateAsync, isPending } = useUpdateProduct(product.id);
28967
- const handleSubmit = form.handleSubmit(async (data) => {
28968
- const { title, handle, status, ...optional } = data;
28969
- await mutateAsync(
28970
- {
28971
- ...optional,
28972
- title,
28973
- handle,
28974
- status
28975
- },
28976
- {
28977
- onSuccess: ({ product: product2 }) => {
28978
- ui.toast.success(
28979
- `Gift card product ${product2.title} updated successfully`
28980
- );
28981
- handleSuccess();
28982
- },
28983
- onError: (e2) => {
28984
- ui.toast.error(e2.message);
28985
- }
28986
- }
28987
- );
28988
- });
28989
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
28990
- KeyboundForm,
28991
- {
28992
- onSubmit: handleSubmit,
28993
- className: "flex flex-1 flex-col overflow-hidden",
28994
- children: [
28995
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-8", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
28996
- /* @__PURE__ */ jsxRuntime.jsx(
28997
- Form$2.Field,
28998
- {
28999
- control: form.control,
29000
- name: "status",
29001
- render: ({ field: { onChange, ref, ...field } }) => {
29002
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
29003
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Status" }),
29004
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { ...field, onValueChange: onChange, children: [
29005
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { ref, className: "capitalize", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
29006
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: [
29007
- "draft",
29008
- "published",
29009
- "proposed",
29010
- "rejected"
29011
- ].map((status) => {
29012
- return /* @__PURE__ */ jsxRuntime.jsx(
29013
- ui.Select.Item,
29014
- {
29015
- value: status,
29016
- className: "capitalize",
29017
- children: status
29018
- },
29019
- status
29020
- );
29021
- }) })
29022
- ] }) }),
29023
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
29024
- ] });
29025
- }
29026
- }
29027
- ),
29028
- /* @__PURE__ */ jsxRuntime.jsx(
29029
- Form$2.Field,
29030
- {
29031
- control: form.control,
29032
- name: "title",
29033
- render: ({ field }) => {
29034
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
29035
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
29036
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
29037
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
29038
- ] });
29039
- }
29040
- }
29041
- ),
29042
- /* @__PURE__ */ jsxRuntime.jsx(
29043
- Form$2.Field,
29044
- {
29045
- control: form.control,
29046
- name: "subtitle",
29047
- render: ({ field }) => {
29048
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
29049
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Subtitle" }),
29050
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
29051
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
29052
- ] });
29053
- }
29054
- }
29055
- ),
29056
- /* @__PURE__ */ jsxRuntime.jsx(
29057
- Form$2.Field,
29058
- {
29059
- control: form.control,
29060
- name: "handle",
29061
- render: ({ field }) => {
29062
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
29063
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Handle" }),
29064
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
29065
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-y-0 left-0 z-10 flex w-8 items-center justify-center border-r", children: /* @__PURE__ */ jsxRuntime.jsx(
29066
- ui.Text,
29067
- {
29068
- className: "text-ui-fg-muted",
29069
- size: "small",
29070
- leading: "compact",
29071
- weight: "plus",
29072
- children: "/"
29073
- }
29074
- ) }),
29075
- /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, className: "pl-10" })
29076
- ] }) }),
29077
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
29078
- ] });
29079
- }
29080
- }
29081
- ),
29082
- /* @__PURE__ */ jsxRuntime.jsx(
29083
- Form$2.Field,
29084
- {
29085
- control: form.control,
29086
- name: "description",
29087
- render: ({ field }) => {
29088
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
29089
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Description" }),
29090
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
29091
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
29092
- ] });
29093
- }
29094
- }
29095
- )
29096
- ] }) }) }),
29097
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
29098
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
29099
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
29100
- ] }) })
29101
- ]
29102
- }
29103
- ) });
29104
- };
29105
- const GiftCardProductEdit$1 = () => {
29106
- const { id } = reactRouterDom.useParams();
29107
- const { product, isLoading, isError, error } = useProduct(id, {});
29108
- if (isError) {
29109
- throw error;
29110
- }
29111
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
29112
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
29113
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit gift card product" }) }),
29114
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card product" })
29115
- ] }),
29116
- !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditForm, { product })
29117
- ] });
29118
- };
29119
- const EditProductSchema = z.object({
29120
28856
  denominations: z.array(
29121
28857
  z.object({
29122
28858
  id: z.string().optional(),
@@ -29142,7 +28878,7 @@ const GiftCardProductEditDenominationsForm = ({
29142
28878
  };
29143
28879
  })
29144
28880
  },
29145
- resolver: t$1(EditProductSchema)
28881
+ resolver: t$1(EditProductSchema$1)
29146
28882
  });
29147
28883
  const { mutateAsync, isPending } = useUpdateProduct(product.id);
29148
28884
  const handleSubmit = form.handleSubmit(async (data) => {
@@ -29244,20 +28980,194 @@ const GiftCardProductEditDenominationsForm = ({
29244
28980
  );
29245
28981
  }),
29246
28982
  /* @__PURE__ */ jsxRuntime.jsx(
29247
- ui.Button,
28983
+ ui.Button,
28984
+ {
28985
+ size: "small",
28986
+ variant: "secondary",
28987
+ type: "button",
28988
+ className: "w-full",
28989
+ onClick: () => {
28990
+ addDenomination({ value: "", sku: "", prices: {} });
28991
+ },
28992
+ children: "Add denomination"
28993
+ }
28994
+ ),
28995
+ form.formState.errors.denominations && /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", children: "Please add at least one denomination." })
28996
+ ] }) }) }) }),
28997
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
28998
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
28999
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
29000
+ ] }) })
29001
+ ]
29002
+ }
29003
+ ) });
29004
+ };
29005
+ const GiftCardProductEdit$1 = () => {
29006
+ const { id } = reactRouterDom.useParams();
29007
+ const { product, isLoading, isError, error } = useProduct(id, {});
29008
+ if (isError) {
29009
+ throw error;
29010
+ }
29011
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
29012
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
29013
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit gift card product" }) }),
29014
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card product" })
29015
+ ] }),
29016
+ !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditDenominationsForm, { product })
29017
+ ] });
29018
+ };
29019
+ const EditProductSchema = z.object({
29020
+ status: z.enum(["draft", "published", "proposed", "rejected"]),
29021
+ title: z.string().min(1),
29022
+ subtitle: z.string().optional(),
29023
+ handle: z.string().min(1),
29024
+ description: z.string().optional()
29025
+ });
29026
+ const GiftCardProductEditForm = ({
29027
+ product
29028
+ }) => {
29029
+ const { handleSuccess } = useRouteModal();
29030
+ const form = useForm({
29031
+ defaultValues: {
29032
+ status: product.status,
29033
+ title: product.title,
29034
+ subtitle: product.subtitle || "",
29035
+ handle: product.handle || "",
29036
+ description: product.description || ""
29037
+ },
29038
+ resolver: t$1(EditProductSchema)
29039
+ });
29040
+ const { mutateAsync, isPending } = useUpdateProduct(product.id);
29041
+ const handleSubmit = form.handleSubmit(async (data) => {
29042
+ const { title, handle, status, ...optional } = data;
29043
+ await mutateAsync(
29044
+ {
29045
+ ...optional,
29046
+ title,
29047
+ handle,
29048
+ status
29049
+ },
29050
+ {
29051
+ onSuccess: ({ product: product2 }) => {
29052
+ ui.toast.success(
29053
+ `Gift card product ${product2.title} updated successfully`
29054
+ );
29055
+ handleSuccess();
29056
+ },
29057
+ onError: (e2) => {
29058
+ ui.toast.error(e2.message);
29059
+ }
29060
+ }
29061
+ );
29062
+ });
29063
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
29064
+ KeyboundForm,
29065
+ {
29066
+ onSubmit: handleSubmit,
29067
+ className: "flex flex-1 flex-col overflow-hidden",
29068
+ children: [
29069
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-8", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
29070
+ /* @__PURE__ */ jsxRuntime.jsx(
29071
+ Form$2.Field,
29248
29072
  {
29249
- size: "small",
29250
- variant: "secondary",
29251
- type: "button",
29252
- className: "w-full",
29253
- onClick: () => {
29254
- addDenomination({ value: "", sku: "", prices: {} });
29255
- },
29256
- children: "Add denomination"
29073
+ control: form.control,
29074
+ name: "status",
29075
+ render: ({ field: { onChange, ref, ...field } }) => {
29076
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
29077
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Status" }),
29078
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { ...field, onValueChange: onChange, children: [
29079
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { ref, className: "capitalize", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
29080
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: [
29081
+ "draft",
29082
+ "published",
29083
+ "proposed",
29084
+ "rejected"
29085
+ ].map((status) => {
29086
+ return /* @__PURE__ */ jsxRuntime.jsx(
29087
+ ui.Select.Item,
29088
+ {
29089
+ value: status,
29090
+ className: "capitalize",
29091
+ children: status
29092
+ },
29093
+ status
29094
+ );
29095
+ }) })
29096
+ ] }) }),
29097
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
29098
+ ] });
29099
+ }
29257
29100
  }
29258
29101
  ),
29259
- form.formState.errors.denominations && /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", children: "Please add at least one denomination." })
29260
- ] }) }) }) }),
29102
+ /* @__PURE__ */ jsxRuntime.jsx(
29103
+ Form$2.Field,
29104
+ {
29105
+ control: form.control,
29106
+ name: "title",
29107
+ render: ({ field }) => {
29108
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
29109
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
29110
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
29111
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
29112
+ ] });
29113
+ }
29114
+ }
29115
+ ),
29116
+ /* @__PURE__ */ jsxRuntime.jsx(
29117
+ Form$2.Field,
29118
+ {
29119
+ control: form.control,
29120
+ name: "subtitle",
29121
+ render: ({ field }) => {
29122
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
29123
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Subtitle" }),
29124
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
29125
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
29126
+ ] });
29127
+ }
29128
+ }
29129
+ ),
29130
+ /* @__PURE__ */ jsxRuntime.jsx(
29131
+ Form$2.Field,
29132
+ {
29133
+ control: form.control,
29134
+ name: "handle",
29135
+ render: ({ field }) => {
29136
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
29137
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Handle" }),
29138
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
29139
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-y-0 left-0 z-10 flex w-8 items-center justify-center border-r", children: /* @__PURE__ */ jsxRuntime.jsx(
29140
+ ui.Text,
29141
+ {
29142
+ className: "text-ui-fg-muted",
29143
+ size: "small",
29144
+ leading: "compact",
29145
+ weight: "plus",
29146
+ children: "/"
29147
+ }
29148
+ ) }),
29149
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, className: "pl-10" })
29150
+ ] }) }),
29151
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
29152
+ ] });
29153
+ }
29154
+ }
29155
+ ),
29156
+ /* @__PURE__ */ jsxRuntime.jsx(
29157
+ Form$2.Field,
29158
+ {
29159
+ control: form.control,
29160
+ name: "description",
29161
+ render: ({ field }) => {
29162
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
29163
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Description" }),
29164
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
29165
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
29166
+ ] });
29167
+ }
29168
+ }
29169
+ )
29170
+ ] }) }) }),
29261
29171
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
29262
29172
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
29263
29173
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -29277,9 +29187,99 @@ const GiftCardProductEdit = () => {
29277
29187
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit gift card product" }) }),
29278
29188
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card product" })
29279
29189
  ] }),
29280
- !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditDenominationsForm, { product })
29190
+ !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditForm, { product })
29281
29191
  ] });
29282
29192
  };
29193
+ const StoreCreditAccountBalanceSection = ({
29194
+ storeCreditAccount
29195
+ }) => {
29196
+ if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
29197
+ return;
29198
+ }
29199
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "grid grid-cols-2 gap-x-2 px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-x-3", children: [
29200
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-tag-green-icon h-8 w-1 rounded-full" }),
29201
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
29202
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", size: "small", className: "text-ui-fg-subtle", children: "Current Balance" }),
29203
+ /* @__PURE__ */ jsxRuntime.jsx(
29204
+ ui.Text,
29205
+ {
29206
+ weight: "plus",
29207
+ size: "xlarge",
29208
+ className: "tabular-nums text-ui-fg-base",
29209
+ children: formatAmount(
29210
+ storeCreditAccount.balance,
29211
+ storeCreditAccount.currency_code
29212
+ )
29213
+ }
29214
+ )
29215
+ ] })
29216
+ ] }) });
29217
+ };
29218
+ const StoreCreditAccountDetailsSection = ({
29219
+ storeCreditAccount
29220
+ }) => {
29221
+ if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
29222
+ return;
29223
+ }
29224
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "grid grid-cols-2 gap-x-2 px-6 py-6", children: /* @__PURE__ */ jsxRuntime.jsxs(
29225
+ ui.Text,
29226
+ {
29227
+ weight: "plus",
29228
+ size: "xlarge",
29229
+ className: "text-ui-fg-base flex gap-x-4",
29230
+ children: [
29231
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
29232
+ /* @__PURE__ */ jsxRuntime.jsx(CreditCardIcon, { className: "inline" }),
29233
+ " "
29234
+ ] }),
29235
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
29236
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle", children: [
29237
+ storeCreditAccount.currency_code.toUpperCase(),
29238
+ " Account"
29239
+ ] }),
29240
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx(
29241
+ ui.Text,
29242
+ {
29243
+ weight: "regular",
29244
+ size: "small",
29245
+ className: "text-ui-fg-base flex gap-x-4",
29246
+ children: /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: storeCreditAccount.id })
29247
+ }
29248
+ ) })
29249
+ ] })
29250
+ ]
29251
+ }
29252
+ ) });
29253
+ };
29254
+ const StoreCreditAccountPage = () => {
29255
+ const { id } = reactRouterDom.useParams();
29256
+ const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
29257
+ id
29258
+ );
29259
+ if (!storeCreditAccount) {
29260
+ return;
29261
+ }
29262
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
29263
+ TwoColumnLayout,
29264
+ {
29265
+ firstCol: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
29266
+ /* @__PURE__ */ jsxRuntime.jsx(
29267
+ StoreCreditAccountDetailsSection,
29268
+ {
29269
+ storeCreditAccount
29270
+ }
29271
+ ),
29272
+ /* @__PURE__ */ jsxRuntime.jsx(TransactionsTable, { id: storeCreditAccount.id })
29273
+ ] }),
29274
+ secondCol: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
29275
+ StoreCreditAccountBalanceSection,
29276
+ {
29277
+ storeCreditAccount
29278
+ }
29279
+ ) })
29280
+ }
29281
+ ) });
29282
+ };
29283
29283
  const EditProductMediaForm = ({ product }) => {
29284
29284
  const [selection, setSelection] = React.useState({});
29285
29285
  const { handleSuccess } = useRouteModal();
@@ -30173,6 +30173,10 @@ const widgetModule = { widgets: [
30173
30173
  ] };
30174
30174
  const routeModule = {
30175
30175
  routes: [
30176
+ {
30177
+ Component: GiftCardsPage,
30178
+ path: "/gift-cards"
30179
+ },
30176
30180
  {
30177
30181
  Component: GiftCardProductsPage,
30178
30182
  path: "/gift-card-products",
@@ -30187,14 +30191,6 @@ const routeModule = {
30187
30191
  Component: StoreCreditAccountsPage,
30188
30192
  path: "/store-credit-accounts"
30189
30193
  },
30190
- {
30191
- Component: GiftCardsPage,
30192
- path: "/gift-cards"
30193
- },
30194
- {
30195
- Component: StoreCreditAccountPage,
30196
- path: "/store-credit-accounts/:id"
30197
- },
30198
30194
  {
30199
30195
  Component: GiftCardDetailsPage,
30200
30196
  path: "/gift-cards/:id",
@@ -30205,11 +30201,11 @@ const routeModule = {
30205
30201
  },
30206
30202
  {
30207
30203
  Component: Note$1,
30208
- path: "/gift-cards/:id/note"
30204
+ path: "/gift-cards/:id/owner"
30209
30205
  },
30210
30206
  {
30211
30207
  Component: Note,
30212
- path: "/gift-cards/:id/owner"
30208
+ path: "/gift-cards/:id/note"
30213
30209
  }
30214
30210
  ]
30215
30211
  },
@@ -30219,14 +30215,18 @@ const routeModule = {
30219
30215
  children: [
30220
30216
  {
30221
30217
  Component: GiftCardProductEdit$1,
30222
- path: "/gift-card-products/:id/edit"
30218
+ path: "/gift-card-products/:id/denominations"
30223
30219
  },
30224
30220
  {
30225
30221
  Component: GiftCardProductEdit,
30226
- path: "/gift-card-products/:id/denominations"
30222
+ path: "/gift-card-products/:id/edit"
30227
30223
  }
30228
30224
  ]
30229
30225
  },
30226
+ {
30227
+ Component: StoreCreditAccountPage,
30228
+ path: "/store-credit-accounts/:id"
30229
+ },
30230
30230
  {
30231
30231
  Component: ProductMedia,
30232
30232
  path: "/gift-card-products/:id/media"
@@ -30244,22 +30244,22 @@ const routeModule = {
30244
30244
  const menuItemModule = {
30245
30245
  menuItems: [
30246
30246
  {
30247
- label: config$1.label,
30248
- icon: config$1.icon,
30249
- path: "/store-credit-accounts",
30250
- nested: void 0
30251
- },
30252
- {
30253
- label: config.label,
30254
- icon: config.icon,
30247
+ label: config$2.label,
30248
+ icon: config$2.icon,
30255
30249
  path: "/gift-cards",
30256
30250
  nested: void 0
30257
30251
  },
30258
30252
  {
30259
- label: config$2.label,
30253
+ label: config$1.label,
30260
30254
  icon: void 0,
30261
30255
  path: "/gift-card-products",
30262
30256
  nested: "/products"
30257
+ },
30258
+ {
30259
+ label: config.label,
30260
+ icon: config.icon,
30261
+ path: "/store-credit-accounts",
30262
+ nested: void 0
30263
30263
  }
30264
30264
  ]
30265
30265
  };