@medusajs/loyalty-plugin 0.0.5 → 0.0.7-preview.0

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.
Files changed (54) hide show
  1. package/.medusa/server/src/admin/index.js +206 -820
  2. package/.medusa/server/src/admin/index.mjs +207 -821
  3. package/.medusa/server/src/api/admin/gift-cards/[id]/redeem/route.js +1 -2
  4. package/.medusa/server/src/api/admin/gift-cards/middlewares.js +1 -9
  5. package/.medusa/server/src/api/admin/gift-cards/query-config.js +1 -3
  6. package/.medusa/server/src/api/admin/gift-cards/validators.js +2 -7
  7. package/.medusa/server/src/api/admin/store-credit-accounts/validators.js +2 -2
  8. package/.medusa/server/src/api/middlewares.js +5 -7
  9. package/.medusa/server/src/api/store/carts/middlewares.js +2 -1
  10. package/.medusa/server/src/api/store/gift-cards/[idOrCode]/redeem/route.js +24 -0
  11. package/.medusa/server/src/api/store/gift-cards/[idOrCode]/route.js +24 -0
  12. package/.medusa/server/src/api/store/gift-cards/middlewares.js +5 -26
  13. package/.medusa/server/src/api/store/gift-cards/query-config.js +1 -4
  14. package/.medusa/server/src/api/store/gift-cards/validators.js +3 -21
  15. package/.medusa/server/src/links/cart-gift-cards-link.js +2 -2
  16. package/.medusa/server/src/links/gift-card-store-credit.js +10 -0
  17. package/.medusa/server/src/links/order-gift-cards-link.js +2 -2
  18. package/.medusa/server/src/modules/loyalty/migrations/Migration20250617080328.js +20 -0
  19. package/.medusa/server/src/modules/loyalty/models/gift-card.js +1 -11
  20. package/.medusa/server/src/modules/loyalty/service.js +1 -3
  21. package/.medusa/server/src/modules/store-credit/migrations/Migration20250520081315.js +16 -0
  22. package/.medusa/server/src/modules/store-credit/models/store-credit-account.js +3 -2
  23. package/.medusa/server/src/subscribers/create-gift-card.js +1 -3
  24. package/.medusa/server/src/types/loyalty/module.js +2 -10
  25. package/.medusa/server/src/types/modules.js +1 -2
  26. package/.medusa/server/src/workflows/carts/workflows/add-gift-card-to-cart.js +24 -35
  27. package/.medusa/server/src/workflows/carts/workflows/add-store-credits-to-cart.js +1 -1
  28. package/.medusa/server/src/workflows/carts/workflows/confirm-cart-credit-lines.js +13 -11
  29. package/.medusa/server/src/workflows/carts/workflows/refresh-cart-gift-cards.js +28 -8
  30. package/.medusa/server/src/workflows/gift-cards/steps/retrieve-gift-card-balance.js +6 -7
  31. package/.medusa/server/src/workflows/gift-cards/workflows/redeem-gift-card.js +53 -32
  32. package/.medusa/server/src/workflows/orders/workflows/refund-credit-lines.js +45 -69
  33. package/.medusa/server/src/workflows/store-credit/workflows/create-store-credit-accounts.js +7 -42
  34. package/package.json +8 -8
  35. package/.medusa/server/src/api/admin/gift-cards/[id]/transfer/route.js +0 -24
  36. package/.medusa/server/src/api/store/gift-card-invitations/[code]/accept/route.js +0 -24
  37. package/.medusa/server/src/api/store/gift-card-invitations/[code]/reject/route.js +0 -24
  38. package/.medusa/server/src/api/store/gift-card-invitations/middlewares.js +0 -30
  39. package/.medusa/server/src/api/store/gift-card-invitations/query-config.js +0 -17
  40. package/.medusa/server/src/api/store/gift-card-invitations/validators.js +0 -14
  41. package/.medusa/server/src/api/store/gift-cards/[id]/invitation/route.js +0 -26
  42. package/.medusa/server/src/api/store/gift-cards/[id]/redeem/route.js +0 -24
  43. package/.medusa/server/src/api/store/gift-cards/[id]/route.js +0 -16
  44. package/.medusa/server/src/api/store/gift-cards/route.js +0 -28
  45. package/.medusa/server/src/links/customer-gift-card-link.js +0 -13
  46. package/.medusa/server/src/modules/loyalty/models/gift-card-invitation.js +0 -20
  47. package/.medusa/server/src/workflows/gift-card-invitation/steps/create-gift-card-invitation.js +0 -17
  48. package/.medusa/server/src/workflows/gift-card-invitation/steps/delete-gift-card-invitation.js +0 -20
  49. package/.medusa/server/src/workflows/gift-card-invitation/steps/update-gift-card-invitation.js +0 -31
  50. package/.medusa/server/src/workflows/gift-card-invitation/workflows/accept-gift-card-invitation.js +0 -79
  51. package/.medusa/server/src/workflows/gift-card-invitation/workflows/create-gift-card-invitation.js +0 -66
  52. package/.medusa/server/src/workflows/gift-card-invitation/workflows/delete-gift-card-invitation.js +0 -10
  53. package/.medusa/server/src/workflows/gift-card-invitation/workflows/reject-gift-card-invitation.js +0 -70
  54. package/.medusa/server/src/workflows/gift-cards/workflows/transfer-gift-card.js +0 -48
@@ -3,11 +3,11 @@ var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, {
3
3
  var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
4
4
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
5
5
  import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
6
- import { EllipsisHorizontal, InformationCircleSolid, ExclamationCircle, PlusMini, TriangleRightMini, Gift, Photo, PencilSquare, Trash, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, Tag, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Calendar, ShoppingCart, UserMini, AdjustmentsDone, Adjustments, TaxInclusive, TaxExclusive, XMark, ArrowDownTray, DotsSix, ThumbnailBadge, StackPerspective, MinusMini, TriangleLeftMini } from "@medusajs/icons";
7
- import { DropdownMenu, IconButton, clx, Heading, Text, Tooltip, Button, Container as Container$1, StatusBadge, useDataTable, DataTable as DataTable$1, createDataTableFilterHelper, usePrompt, Checkbox, toast, createDataTableColumnHelper, Badge, Toaster, Label as Label$1, Hint as Hint$1, Prompt, Drawer, FocusModal, Divider, CurrencyInput as CurrencyInput$1, Textarea, Kbd, Copy, RadioGroup, DatePicker, Input, Select, Skeleton, Alert, ProgressTabs, CommandBar } from "@medusajs/ui";
6
+ import { DropdownMenu, IconButton, clx, Heading, Text, Tooltip, Button, Container as Container$1, StatusBadge, useDataTable, DataTable as DataTable$1, createDataTableFilterHelper, usePrompt, Checkbox, toast, createDataTableColumnHelper, Badge, Toaster, Label as Label$1, Hint as Hint$1, Prompt, Drawer, FocusModal, Divider, CurrencyInput as CurrencyInput$1, Textarea, Kbd, Copy, RadioGroup, DatePicker, Skeleton, Input, Alert, ProgressTabs, CommandBar, Select } from "@medusajs/ui";
8
7
  import { Link, useParams, useSearchParams, useNavigate, Outlet, useBlocker, useLocation } from "react-router-dom";
9
8
  import * as React from "react";
10
9
  import React__default, { createElement as createElement$1, useState, useCallback, useMemo, Fragment as Fragment$1, createContext, forwardRef, useId as useId$1, useContext, useEffect, isValidElement as isValidElement$1, useLayoutEffect, useRef, useReducer, useTransition, useImperativeHandle, useDeferredValue, Suspense, memo as memo$2, cloneElement } from "react";
10
+ import { EllipsisHorizontal, InformationCircleSolid, ExclamationCircle, PlusMini, TriangleRightMini, Gift, Photo, PencilSquare, Trash, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, Tag, User, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Calendar, ShoppingCart, AdjustmentsDone, Adjustments, TaxInclusive, TaxExclusive, XMark, ArrowDownTray, DotsSix, ThumbnailBadge, StackPerspective, XCircleSolid, TriangleLeftMini } from "@medusajs/icons";
11
11
  import { useQuery, useQueryClient, useMutation, useInfiniteQuery, keepPreviousData } from "@tanstack/react-query";
12
12
  import Medusa, { FetchError } from "@medusajs/js-sdk";
13
13
  import { format as format$1, subDays, subMonths, formatDistance, sub } from "date-fns";
@@ -183,198 +183,6 @@ const sdk = new Medusa({
183
183
  type: "session"
184
184
  }
185
185
  });
186
- const giftCardQueryKey = queryKeysFactory("gift-card");
187
- const useGiftCards = (query, options) => {
188
- const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
189
- query: query2,
190
- headers
191
- });
192
- const { data, ...rest } = useQuery({
193
- ...options,
194
- queryFn: () => fetchGiftCards(query),
195
- queryKey: giftCardQueryKey.list(query)
196
- });
197
- return { ...data, ...rest };
198
- };
199
- const useGiftCard = (id, query, options) => {
200
- const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
201
- query: query2,
202
- headers
203
- });
204
- const { data, ...rest } = useQuery({
205
- queryFn: () => fetchGiftCard(id, query),
206
- queryKey: giftCardQueryKey.detail(id),
207
- ...options
208
- });
209
- return { ...data, ...rest };
210
- };
211
- const useRedeemGiftCard = (id, options) => {
212
- const queryClient = useQueryClient();
213
- const redeemGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}/redeem`, {
214
- body,
215
- method: "POST"
216
- });
217
- return useMutation({
218
- mutationFn: (body) => redeemGiftCard(id, body),
219
- onSuccess: (data, variables, context) => {
220
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
221
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.detail(id) });
222
- }
223
- });
224
- };
225
- const useTransferGiftCard = (id, options) => {
226
- const queryClient = useQueryClient();
227
- const transferGiftCard = async (id2, body) => sdk.client.fetch(
228
- `/admin/gift-cards/${id2}/transfer`,
229
- {
230
- body,
231
- method: "POST"
232
- }
233
- );
234
- return useMutation({
235
- mutationFn: (body) => transferGiftCard(id, body),
236
- onSuccess: (data, variables, context) => {
237
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
238
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.detail(id) });
239
- }
240
- });
241
- };
242
- const useUpdateGiftCard = (id, options) => {
243
- const queryClient = useQueryClient();
244
- const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
245
- body,
246
- method: "POST"
247
- });
248
- return useMutation({
249
- mutationFn: async (payload) => updateGiftCard(id, payload),
250
- onSuccess: (data, variables, context) => {
251
- queryClient.invalidateQueries({
252
- queryKey: giftCardQueryKey.detail(id)
253
- });
254
- queryClient.invalidateQueries({
255
- queryKey: giftCardQueryKey.lists()
256
- });
257
- },
258
- ...options
259
- });
260
- };
261
- const useDeleteGiftCard = (id, options) => {
262
- const queryClient = useQueryClient();
263
- const deleteGiftCard = async (id2) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
264
- method: "DELETE"
265
- });
266
- return useMutation({
267
- mutationFn: () => deleteGiftCard(id),
268
- onSuccess: (data, variables, context) => {
269
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
270
- }
271
- });
272
- };
273
- const useCreateGiftCard = (options) => {
274
- const queryClient = useQueryClient();
275
- const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
276
- body,
277
- method: "POST"
278
- });
279
- return useMutation({
280
- mutationFn: (body) => createGiftCard(body),
281
- onSuccess: (data, variables, context) => {
282
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
283
- },
284
- ...options
285
- });
286
- };
287
- const formatAmount = (amount, currency_code) => {
288
- return new Intl.NumberFormat("en-US", {
289
- style: "currency",
290
- currency: currency_code
291
- }).format(amount);
292
- };
293
- var GiftCardStatus = /* @__PURE__ */ ((GiftCardStatus2) => {
294
- GiftCardStatus2["PENDING"] = "pending";
295
- GiftCardStatus2["REDEEMED"] = "redeemed";
296
- return GiftCardStatus2;
297
- })(GiftCardStatus || {});
298
- function getGiftCardStatus(giftCard) {
299
- if (giftCard.expires_at && new Date(giftCard.expires_at) < /* @__PURE__ */ new Date()) {
300
- return "deactivated";
301
- } else if (giftCard.status === GiftCardStatus.PENDING) {
302
- return "pending";
303
- } else {
304
- return "active";
305
- }
306
- }
307
- function getGiftCardStatusColor(status) {
308
- if (status === "deactivated") {
309
- return "red";
310
- } else if (status === "pending") {
311
- return "orange";
312
- } else {
313
- return "green";
314
- }
315
- }
316
- const MAX_GIFT_CARDS = 3;
317
- const CustomerStoreCreditWidget$1 = () => {
318
- const params = useParams();
319
- const {
320
- gift_cards: giftCards,
321
- isPending,
322
- count: count2
323
- } = useGiftCards({
324
- customer_id: params.id,
325
- limit: MAX_GIFT_CARDS,
326
- order: "-created_at",
327
- fields: "+line_item.product.title"
328
- });
329
- if (isPending) {
330
- return null;
331
- }
332
- return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
333
- /* @__PURE__ */ jsx(Header$5, { title: "Gift Cards" }),
334
- (giftCards == null ? void 0 : giftCards.length) === 0 && /* @__PURE__ */ jsx(
335
- NoRecords,
336
- {
337
- className: "border-t",
338
- title: "No gift cards",
339
- message: "There are no gift cards to show",
340
- icon: null
341
- }
342
- ),
343
- giftCards == null ? void 0 : giftCards.map((giftCard) => {
344
- const giftCardStatus = getGiftCardStatus(giftCard);
345
- const giftCardStatusColor = getGiftCardStatusColor(giftCardStatus);
346
- return /* @__PURE__ */ jsx(
347
- SidebarLink,
348
- {
349
- icon: /* @__PURE__ */ jsx(Gift, {}),
350
- labelKey: giftCard.code,
351
- descriptionKey: formatAmount(
352
- giftCard.value ?? 0,
353
- giftCard.currency_code
354
- ),
355
- to: `/gift-cards/${giftCard.id}`,
356
- children: /* @__PURE__ */ jsx(StatusBadge, { color: giftCardStatusColor, className: "capitalize", children: giftCardStatus })
357
- },
358
- giftCard.id
359
- );
360
- }),
361
- typeof count2 === "number" && count2 > MAX_GIFT_CARDS && /* @__PURE__ */ jsx(
362
- Link,
363
- {
364
- to: `/gift-cards?customer_id="${params.id}"`,
365
- className: "flex flex-col px-2 pb-2",
366
- children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-2 txt-compact-small rounded-md p-2 shadow-elevation-card-rest font-medium", children: [
367
- "+ ",
368
- count2 - MAX_GIFT_CARDS,
369
- " more"
370
- ] })
371
- }
372
- )
373
- ] });
374
- };
375
- defineWidgetConfig({
376
- zone: "customer.details.side.after"
377
- });
378
186
  const storeCreditAccountQueryKey = queryKeysFactory(
379
187
  "store-credit-account"
380
188
  );
@@ -403,7 +211,7 @@ const useStoreCreditAccount = (id, query, options) => {
403
211
  );
404
212
  const { data, ...rest } = useQuery({
405
213
  queryFn: () => fetchStoreCreditAccount(query),
406
- queryKey: storeCreditAccountQueryKey.list(query),
214
+ queryKey: storeCreditAccountQueryKey.detail(id),
407
215
  ...options
408
216
  });
409
217
  return { ...data, ...rest };
@@ -545,13 +353,18 @@ const CreditCardIcon = ({ className }) => {
545
353
  }
546
354
  );
547
355
  };
356
+ const formatAmount = (amount, currency_code) => {
357
+ return new Intl.NumberFormat("en-US", {
358
+ style: "currency",
359
+ currency: currency_code
360
+ }).format(amount);
361
+ };
548
362
  const CustomerStoreCreditWidget = () => {
549
363
  const params = useParams();
550
364
  const { store_credit_accounts: storeCreditAccounts, isPending } = useStoreCreditAccounts({
551
- customer_id: params.id,
552
- currency_code: "eur"
365
+ customer_id: params.id
553
366
  });
554
- if (isPending) {
367
+ if (isPending || !(storeCreditAccounts == null ? void 0 : storeCreditAccounts.length)) {
555
368
  return null;
556
369
  }
557
370
  return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
@@ -593,6 +406,29 @@ const useOrder = (id, query, options) => {
593
406
  });
594
407
  return { ...data, ...rest };
595
408
  };
409
+ var GiftCardStatus = /* @__PURE__ */ ((GiftCardStatus2) => {
410
+ GiftCardStatus2["PENDING"] = "pending";
411
+ GiftCardStatus2["REDEEMED"] = "redeemed";
412
+ return GiftCardStatus2;
413
+ })(GiftCardStatus || {});
414
+ function getGiftCardStatus(giftCard) {
415
+ if (giftCard.expires_at && new Date(giftCard.expires_at) < /* @__PURE__ */ new Date()) {
416
+ return "deactivated";
417
+ } else if (giftCard.status === GiftCardStatus.PENDING) {
418
+ return "pending";
419
+ } else {
420
+ return "active";
421
+ }
422
+ }
423
+ function getGiftCardStatusColor(status) {
424
+ if (status === "deactivated") {
425
+ return "red";
426
+ } else if (status === "pending") {
427
+ return "orange";
428
+ } else {
429
+ return "green";
430
+ }
431
+ }
596
432
  const OrderGiftCardsWidget = () => {
597
433
  var _a, _b, _c;
598
434
  const params = useParams();
@@ -608,7 +444,7 @@ const OrderGiftCardsWidget = () => {
608
444
  {
609
445
  title: "Gift Cards",
610
446
  subtitle: "Gift cards that have been applied to this order",
611
- tooltip: `A credit line “refund” will always attempt to apply the credit to gift card balance first. However, if the initial balance is covered, an remaining credit will be applied to the order.`
447
+ tooltip: `A credit line “refund” will always attempt to apply the credit to the customers store credit account first. If the customers doesn't have a store credit account, a new one will be created.`
612
448
  }
613
449
  ),
614
450
  ((_b = order == null ? void 0 : order.gift_cards) == null ? void 0 : _b.length) === 0 && /* @__PURE__ */ jsx(
@@ -3756,7 +3592,7 @@ const getFullDate = ({
3756
3592
  locale: LOCALE
3757
3593
  });
3758
3594
  };
3759
- const filterHelper$4 = createDataTableFilterHelper();
3595
+ const filterHelper$3 = createDataTableFilterHelper();
3760
3596
  const useDateFilterOptions$1 = () => {
3761
3597
  const today = useMemo(() => {
3762
3598
  const date = /* @__PURE__ */ new Date();
@@ -3814,7 +3650,7 @@ const useDataTableDateFilters$1 = (disableRangeOption) => {
3814
3650
  }, [disableRangeOption, dateFilterOptions]);
3815
3651
  return useMemo(() => {
3816
3652
  return [
3817
- filterHelper$4.accessor("created_at", {
3653
+ filterHelper$3.accessor("created_at", {
3818
3654
  type: "date",
3819
3655
  label: "Created at",
3820
3656
  format: "date",
@@ -3822,7 +3658,7 @@ const useDataTableDateFilters$1 = (disableRangeOption) => {
3822
3658
  options: dateFilterOptions,
3823
3659
  ...rangeOptions
3824
3660
  }),
3825
- filterHelper$4.accessor("updated_at", {
3661
+ filterHelper$3.accessor("updated_at", {
3826
3662
  type: "date",
3827
3663
  label: "Updated at",
3828
3664
  format: "date",
@@ -4276,7 +4112,8 @@ const useStoreCreditAccountTableColumns = () => {
4276
4112
  columnHelper$a.accessor("customer.email", {
4277
4113
  header: "Customer",
4278
4114
  cell: ({ row }) => {
4279
- return row.original.customer.email;
4115
+ var _a;
4116
+ return ((_a = row.original.customer) == null ? void 0 : _a.email) ?? "N/A";
4280
4117
  }
4281
4118
  }),
4282
4119
  columnHelper$a.accessor("balance", {
@@ -4315,6 +4152,14 @@ const useStoreCreditAccountTableColumns = () => {
4315
4152
  };
4316
4153
  const CUSTOMERS_QUERY_KEY = "customers";
4317
4154
  const customersQueryKeys = queryKeysFactory(CUSTOMERS_QUERY_KEY);
4155
+ const useCustomer = (id, query, options) => {
4156
+ const { data, ...rest } = useQuery({
4157
+ queryKey: customersQueryKeys.detail(id),
4158
+ queryFn: async () => sdk.admin.customer.retrieve(id, query),
4159
+ ...options
4160
+ });
4161
+ return { ...data, ...rest };
4162
+ };
4318
4163
  const useCustomers = (query, options) => {
4319
4164
  const { data, ...rest } = useQuery({
4320
4165
  queryFn: () => sdk.admin.customer.list(query),
@@ -4323,7 +4168,7 @@ const useCustomers = (query, options) => {
4323
4168
  });
4324
4169
  return { ...data, ...rest };
4325
4170
  };
4326
- const filterHelper$3 = createDataTableFilterHelper();
4171
+ const filterHelper$2 = createDataTableFilterHelper();
4327
4172
  const useCustomerFilterOptions = () => {
4328
4173
  const { customers } = useCustomers({ limit: 1e3 });
4329
4174
  return useMemo(() => {
@@ -4339,7 +4184,7 @@ const useCustomerFilters = () => {
4339
4184
  const customerFilterOptions = useCustomerFilterOptions();
4340
4185
  return useMemo(() => {
4341
4186
  return [
4342
- filterHelper$3.accessor("customer_id", {
4187
+ filterHelper$2.accessor("customer_id", {
4343
4188
  type: "select",
4344
4189
  label: "Customer",
4345
4190
  options: customerFilterOptions ?? []
@@ -20489,7 +20334,7 @@ const GiftCardProductsSection = () => {
20489
20334
  slicedProducts.map((giftCardProduct) => /* @__PURE__ */ jsx(
20490
20335
  SidebarLink,
20491
20336
  {
20492
- to: `/gift-card-products/${giftCardProduct.id}`,
20337
+ to: `/gift-cards/gift-card-products/${giftCardProduct.id}`,
20493
20338
  labelKey: giftCardProduct.title,
20494
20339
  descriptionKey: giftCardProduct.title,
20495
20340
  icon: /* @__PURE__ */ jsx(Tag, {})
@@ -20505,6 +20350,90 @@ const GiftCardProductsSection = () => {
20505
20350
  )
20506
20351
  ] });
20507
20352
  };
20353
+ const giftCardQueryKey = queryKeysFactory("gift-card");
20354
+ const useGiftCards = (query, options) => {
20355
+ const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
20356
+ query: query2,
20357
+ headers
20358
+ });
20359
+ const { data, ...rest } = useQuery({
20360
+ ...options,
20361
+ queryFn: () => fetchGiftCards(query),
20362
+ queryKey: giftCardQueryKey.list(query)
20363
+ });
20364
+ return { ...data, ...rest };
20365
+ };
20366
+ const useGiftCard = (id, query, options) => {
20367
+ const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
20368
+ query: query2,
20369
+ headers
20370
+ });
20371
+ const { data, ...rest } = useQuery({
20372
+ queryFn: () => fetchGiftCard(id, query),
20373
+ queryKey: giftCardQueryKey.detail(id),
20374
+ ...options
20375
+ });
20376
+ return { ...data, ...rest };
20377
+ };
20378
+ const useRedeemGiftCard = (id, options) => {
20379
+ const queryClient = useQueryClient();
20380
+ const redeemGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}/redeem`, {
20381
+ body,
20382
+ method: "POST"
20383
+ });
20384
+ return useMutation({
20385
+ mutationFn: (body) => redeemGiftCard(id, body),
20386
+ onSuccess: (data, variables, context) => {
20387
+ queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
20388
+ queryClient.invalidateQueries({ queryKey: giftCardQueryKey.detail(id) });
20389
+ }
20390
+ });
20391
+ };
20392
+ const useUpdateGiftCard = (id, options) => {
20393
+ const queryClient = useQueryClient();
20394
+ const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
20395
+ body,
20396
+ method: "POST"
20397
+ });
20398
+ return useMutation({
20399
+ mutationFn: async (payload) => updateGiftCard(id, payload),
20400
+ onSuccess: (data, variables, context) => {
20401
+ queryClient.invalidateQueries({
20402
+ queryKey: giftCardQueryKey.detail(id)
20403
+ });
20404
+ queryClient.invalidateQueries({
20405
+ queryKey: giftCardQueryKey.lists()
20406
+ });
20407
+ },
20408
+ ...options
20409
+ });
20410
+ };
20411
+ const useDeleteGiftCard = (id, options) => {
20412
+ const queryClient = useQueryClient();
20413
+ const deleteGiftCard = async (id2) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
20414
+ method: "DELETE"
20415
+ });
20416
+ return useMutation({
20417
+ mutationFn: () => deleteGiftCard(id),
20418
+ onSuccess: (data, variables, context) => {
20419
+ queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
20420
+ }
20421
+ });
20422
+ };
20423
+ const useCreateGiftCard = (options) => {
20424
+ const queryClient = useQueryClient();
20425
+ const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
20426
+ body,
20427
+ method: "POST"
20428
+ });
20429
+ return useMutation({
20430
+ mutationFn: (body) => createGiftCard(body),
20431
+ onSuccess: (data, variables, context) => {
20432
+ queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
20433
+ },
20434
+ ...options
20435
+ });
20436
+ };
20508
20437
  const columnHelper$9 = createDataTableColumnHelper();
20509
20438
  const useGiftCardTableColumns = () => {
20510
20439
  return useMemo(() => {
@@ -20565,7 +20494,7 @@ const useGiftCardTableQuery = ({
20565
20494
  pageSize = 20
20566
20495
  }) => {
20567
20496
  const queryObject = useQueryParams(
20568
- ["offset", "customer_id", "created_at", "updated_at"],
20497
+ ["q", "offset", "customer_id", "created_at", "updated_at"],
20569
20498
  prefix
20570
20499
  );
20571
20500
  const { offset: offset2, created_at, updated_at, customer_id, ...rest } = queryObject;
@@ -20606,7 +20535,6 @@ function GiftCardsTable() {
20606
20535
  isLoading: isPending,
20607
20536
  pageSize: PAGE_SIZE$5,
20608
20537
  rowCount: count2,
20609
- enableSearch: false,
20610
20538
  heading: "Gift Cards",
20611
20539
  rowHref: (row) => `${row.id}`,
20612
20540
  emptyState: {
@@ -21094,6 +21022,27 @@ const StoreCreditAccountDetailsSection = ({
21094
21022
  }
21095
21023
  ) });
21096
21024
  };
21025
+ function StoreCreditAccountCustomerSection({
21026
+ customerId
21027
+ }) {
21028
+ const { customer, isPending } = useCustomer(customerId);
21029
+ if (isPending || !customer) {
21030
+ return null;
21031
+ }
21032
+ return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
21033
+ /* @__PURE__ */ jsx(Header$5, { title: "Customer" }),
21034
+ /* @__PURE__ */ jsx(
21035
+ SidebarLink,
21036
+ {
21037
+ icon: /* @__PURE__ */ jsx(User, {}),
21038
+ labelKey: customer.email || "N/A",
21039
+ descriptionKey: !customer.first_name && !customer.last_name ? "N/A" : `${customer.first_name} ${customer.last_name}`,
21040
+ to: `/customers/${customer.id}`
21041
+ },
21042
+ customer.id
21043
+ )
21044
+ ] });
21045
+ }
21097
21046
  const transactionQueryKey = queryKeysFactory("transaction");
21098
21047
  const useStoreCreditAccountTransactions = (id, query, options) => {
21099
21048
  const fetchStoreCreditAccountTransactions = (query2, headers) => sdk.client.fetch(
@@ -21105,7 +21054,7 @@ const useStoreCreditAccountTransactions = (id, query, options) => {
21105
21054
  );
21106
21055
  const { data, ...rest } = useQuery({
21107
21056
  queryFn: () => fetchStoreCreditAccountTransactions(query),
21108
- queryKey: transactionQueryKey.list(query),
21057
+ queryKey: transactionQueryKey.list({ sca_id: id, query }),
21109
21058
  ...options
21110
21059
  });
21111
21060
  return { ...data, ...rest };
@@ -21141,8 +21090,9 @@ const useTransactionsTableColumns = () => {
21141
21090
  columnHelper$8.accessor("amount", {
21142
21091
  header: "Amount",
21143
21092
  cell: ({ row }) => {
21093
+ const isDebit = row.original.type === "debit";
21144
21094
  return row.original.account.currency_code && formatAmount(
21145
- row.original.amount,
21095
+ row.original.amount * (isDebit ? -1 : 1),
21146
21096
  row.original.account.currency_code
21147
21097
  );
21148
21098
  }
@@ -21150,57 +21100,16 @@ const useTransactionsTableColumns = () => {
21150
21100
  ];
21151
21101
  }, []);
21152
21102
  };
21153
- const transactionGroupQueryKey = queryKeysFactory("transaction-group");
21154
- const useTransactionGroups = (query, options) => {
21155
- const fetchTransactionGroups = (query2, headers) => sdk.client.fetch(
21156
- `/admin/transaction-groups`,
21157
- {
21158
- query: query2,
21159
- headers
21160
- }
21161
- );
21162
- const { data, ...rest } = useQuery({
21163
- queryFn: () => fetchTransactionGroups(query),
21164
- queryKey: transactionGroupQueryKey.list(query),
21165
- ...options
21166
- });
21167
- return { ...data, ...rest };
21168
- };
21169
- const filterHelper$2 = createDataTableFilterHelper();
21170
- const useTransactionGroupFilterOptions = () => {
21171
- const { transaction_groups } = useTransactionGroups({ limit: 1e3 });
21172
- return useMemo(() => {
21173
- return transaction_groups == null ? void 0 : transaction_groups.map((transactionGroup) => {
21174
- return {
21175
- label: transactionGroup.code,
21176
- value: transactionGroup.id
21177
- };
21178
- });
21179
- }, [transaction_groups]);
21180
- };
21181
- const useTransactionGroupFilters = () => {
21182
- const transactionGroupFilterOptions = useTransactionGroupFilterOptions();
21183
- return useMemo(() => {
21184
- return [
21185
- filterHelper$2.accessor("transaction_group_id", {
21186
- type: "select",
21187
- label: "Transaction Group",
21188
- options: transactionGroupFilterOptions ?? []
21189
- })
21190
- ];
21191
- }, [transactionGroupFilterOptions]);
21192
- };
21193
21103
  const useTransactionsTableFilters = ({
21194
21104
  transactionGroup
21195
21105
  }) => {
21196
21106
  const dateFilterOptions = useDataTableDateFilters$1();
21197
- const transactionGroupFilters = useTransactionGroupFilters();
21198
21107
  return useMemo(() => {
21199
21108
  if (transactionGroup) {
21200
21109
  return [...dateFilterOptions];
21201
21110
  }
21202
- return [...dateFilterOptions, ...transactionGroupFilters];
21203
- }, [dateFilterOptions, transactionGroupFilters, transactionGroup]);
21111
+ return [...dateFilterOptions];
21112
+ }, [dateFilterOptions, , transactionGroup]);
21204
21113
  };
21205
21114
  const useTransactionsTableQuery = ({
21206
21115
  prefix,
@@ -21301,12 +21210,20 @@ const StoreCreditAccountPage = () => {
21301
21210
  ),
21302
21211
  /* @__PURE__ */ jsx(TransactionsTable, { id: storeCreditAccount.id })
21303
21212
  ] }),
21304
- secondCol: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
21305
- StoreCreditAccountBalanceSection,
21306
- {
21307
- storeCreditAccount
21308
- }
21309
- ) })
21213
+ secondCol: /* @__PURE__ */ jsxs(Fragment, { children: [
21214
+ /* @__PURE__ */ jsx(
21215
+ StoreCreditAccountBalanceSection,
21216
+ {
21217
+ storeCreditAccount
21218
+ }
21219
+ ),
21220
+ /* @__PURE__ */ jsx(
21221
+ StoreCreditAccountCustomerSection,
21222
+ {
21223
+ customerId: storeCreditAccount.customer_id
21224
+ }
21225
+ )
21226
+ ] })
21310
21227
  }
21311
21228
  ) });
21312
21229
  };
@@ -23777,34 +23694,11 @@ const SectionRow = ({ title, value, actions }) => {
23777
23694
  const GiftCardGeneralSection = ({ giftCard }) => {
23778
23695
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
23779
23696
  const prompt = usePrompt();
23780
- const navigate = useNavigate();
23697
+ useNavigate();
23781
23698
  const { mutateAsync: redeemGiftCard, isPending } = useRedeemGiftCard(
23782
23699
  giftCard.id
23783
23700
  );
23784
23701
  const { mutateAsync: deleteGiftCard, isPending: isDeleting } = useDeleteGiftCard(giftCard.id);
23785
- const handleRedeem = async () => {
23786
- const res = await prompt({
23787
- title: "Redeem gift card",
23788
- description: `Are you sure? This cannot be undone. Once you confirm the gift card value will be added to the customers store credit account.`,
23789
- confirmText: "Redeem",
23790
- cancelText: "Cancel"
23791
- });
23792
- if (!res) {
23793
- return;
23794
- }
23795
- await redeemGiftCard(
23796
- { customer_id: giftCard == null ? void 0 : giftCard.customer_id },
23797
- {
23798
- onSuccess: () => {
23799
- toast.success("Successfully redeemed gift card");
23800
- navigate("..", { replace: true });
23801
- },
23802
- onError: (err) => {
23803
- toast.error(err.message);
23804
- }
23805
- }
23806
- );
23807
- };
23808
23702
  const handleDelete = async () => {
23809
23703
  const res = await prompt({
23810
23704
  title: "Delete gift card",
@@ -23847,12 +23741,13 @@ const GiftCardGeneralSection = ({ giftCard }) => {
23847
23741
  groups: [
23848
23742
  {
23849
23743
  actions: [
23850
- {
23851
- icon: /* @__PURE__ */ jsx(Gift, {}),
23852
- label: "Redeem gift card",
23853
- onClick: () => handleRedeem(),
23854
- disabled: isPending
23855
- },
23744
+ // TODO: revisit this - now GC doesn't have owner so redeeming would result in an anonymous account
23745
+ // {
23746
+ // icon: <Gift />,
23747
+ // label: "Redeem gift card",
23748
+ // onClick: () => handleRedeem(),
23749
+ // disabled: isPending || giftCard.status === "redeemed",
23750
+ // },
23856
23751
  {
23857
23752
  icon: /* @__PURE__ */ jsx(Calendar, {}),
23858
23753
  label: "Edit expiration date",
@@ -23980,91 +23875,33 @@ const GiftCardOrderSection = ({ giftCard }) => {
23980
23875
  )
23981
23876
  ] });
23982
23877
  };
23983
- const GiftCardOwnerSection = ({ giftCard }) => {
23984
- var _a, _b;
23985
- if (!giftCard) {
23986
- return;
23987
- }
23988
- return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
23989
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
23990
- /* @__PURE__ */ jsx(Header$5, { title: "Owner" }),
23991
- giftCard.status !== GiftCardStatus.REDEEMED && /* @__PURE__ */ jsx(Link, { to: `owner`, className: "text-ui-fg-muted text-sm px-6", children: "Transfer ownership" })
23992
- ] }),
23993
- !((_a = giftCard.customer) == null ? void 0 : _a.id) && /* @__PURE__ */ jsx(
23994
- NoRecords,
23995
- {
23996
- title: "No customer assigned",
23997
- message: "Transfer gift card ownership to a customer to assign an owner",
23998
- icon: null
23999
- }
24000
- ),
24001
- ((_b = giftCard.customer) == null ? void 0 : _b.id) && /* @__PURE__ */ jsx(
24002
- SidebarLink,
24003
- {
24004
- to: `/customers/${giftCard.customer.id}`,
24005
- labelKey: `${[
24006
- giftCard.customer.first_name,
24007
- giftCard.customer.last_name
24008
- ].join(" ")}`,
24009
- descriptionKey: giftCard.customer.email,
24010
- icon: /* @__PURE__ */ jsx(UserMini, {})
24011
- }
24012
- )
24013
- ] });
24014
- };
24015
23878
  const GiftCardTransactionsSection = ({
24016
- storeCreditAccount,
24017
- transactionGroup
23879
+ storeCreditAccount
24018
23880
  }) => {
24019
- return /* @__PURE__ */ jsx(Container$1, { className: "divide-y p-0", children: /* @__PURE__ */ jsx(
24020
- TransactionsTable,
24021
- {
24022
- id: storeCreditAccount.id,
24023
- transactionGroup
24024
- }
24025
- ) }, storeCreditAccount.id);
23881
+ return /* @__PURE__ */ jsx(Container$1, { className: "divide-y p-0", children: /* @__PURE__ */ jsx(TransactionsTable, { id: storeCreditAccount.id }) }, storeCreditAccount.id);
24026
23882
  };
24027
23883
  const GiftCardDetailsPage = () => {
24028
- var _a;
24029
23884
  const { id } = useParams();
24030
23885
  const { gift_card: giftCard, isLoading } = useGiftCard(id, {
24031
- fields: "*line_item.product"
23886
+ fields: "*line_item.product,*store_credit_account"
24032
23887
  });
24033
- const { store_credit_accounts: storeCreditAccounts } = useStoreCreditAccounts(
24034
- {
24035
- customer_id: giftCard == null ? void 0 : giftCard.customer_id,
24036
- currency_code: giftCard == null ? void 0 : giftCard.currency_code
24037
- },
24038
- { enabled: !isLoading && !!(giftCard == null ? void 0 : giftCard.customer_id) }
24039
- );
24040
- const { transaction_groups: transactionGroups } = useTransactionGroups(
24041
- { code: giftCard == null ? void 0 : giftCard.code },
24042
- { enabled: !isLoading && !!(giftCard == null ? void 0 : giftCard.code) }
24043
- );
24044
- const transactionGroup = transactionGroups == null ? void 0 : transactionGroups[0];
24045
- const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
24046
- (_a = storeCreditAccounts == null ? void 0 : storeCreditAccounts[0]) == null ? void 0 : _a.id,
24047
- {
24048
- transaction_group_id: transactionGroup == null ? void 0 : transactionGroup.id
24049
- },
24050
- {
24051
- enabled: !isLoading && !!(giftCard == null ? void 0 : giftCard.customer_id) && !!(transactionGroup == null ? void 0 : transactionGroup.id) && !!(storeCreditAccounts == null ? void 0 : storeCreditAccounts.length)
24052
- }
24053
- );
24054
- if (!giftCard) {
23888
+ if (isLoading) {
24055
23889
  return /* @__PURE__ */ jsx(Fragment, { children: "Loading" });
24056
23890
  }
23891
+ if (!isLoading && !giftCard) {
23892
+ return /* @__PURE__ */ jsx(Fragment, { children: "Gift card not found" });
23893
+ }
23894
+ const storeCreditAccount = giftCard == null ? void 0 : giftCard.store_credit_account;
24057
23895
  return /* @__PURE__ */ jsxs(Fragment, { children: [
24058
23896
  /* @__PURE__ */ jsx(
24059
23897
  TwoColumnLayout,
24060
23898
  {
24061
23899
  firstCol: /* @__PURE__ */ jsxs(Fragment, { children: [
24062
23900
  /* @__PURE__ */ jsx(GiftCardGeneralSection, { giftCard }),
24063
- storeCreditAccount && transactionGroup && /* @__PURE__ */ jsx(
23901
+ storeCreditAccount && /* @__PURE__ */ jsx(
24064
23902
  GiftCardTransactionsSection,
24065
23903
  {
24066
- storeCreditAccount,
24067
- transactionGroup
23904
+ storeCreditAccount
24068
23905
  }
24069
23906
  ),
24070
23907
  /* @__PURE__ */ jsx(JsonViewSection, { data: giftCard })
@@ -24077,7 +23914,6 @@ const GiftCardDetailsPage = () => {
24077
23914
  giftCard
24078
23915
  }
24079
23916
  ),
24080
- /* @__PURE__ */ jsx(GiftCardOwnerSection, { giftCard }),
24081
23917
  /* @__PURE__ */ jsx(GiftCardNoteSection, { giftCard }),
24082
23918
  /* @__PURE__ */ jsx(GiftCardOrderSection, { giftCard })
24083
23919
  ] })
@@ -24113,7 +23949,7 @@ const KeyboundForm = React__default.forwardRef(({ onSubmit, onKeyDown, ...rest }
24113
23949
  );
24114
23950
  });
24115
23951
  KeyboundForm.displayName = "KeyboundForm";
24116
- const Note$1 = () => {
23952
+ const Note = () => {
24117
23953
  const { id } = useParams();
24118
23954
  const {
24119
23955
  gift_card: giftCard,
@@ -24130,15 +23966,15 @@ const Note$1 = () => {
24130
23966
  /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit note" }) }),
24131
23967
  /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the note for the gift card" }) })
24132
23968
  ] }),
24133
- isReady && /* @__PURE__ */ jsx(GiftCardNoteForm$1, { giftCard })
23969
+ isReady && /* @__PURE__ */ jsx(GiftCardNoteForm, { giftCard })
24134
23970
  ] });
24135
23971
  };
24136
- const GiftCardNoteForm$1 = ({ giftCard }) => {
23972
+ const GiftCardNoteForm = ({ giftCard }) => {
24137
23973
  const form = useForm({
24138
23974
  defaultValues: {
24139
23975
  note: giftCard.note ?? ""
24140
23976
  },
24141
- resolver: t(schema$2)
23977
+ resolver: t(schema$1)
24142
23978
  });
24143
23979
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
24144
23980
  const { handleSuccess } = useRouteModal();
@@ -24177,7 +24013,7 @@ const GiftCardNoteForm$1 = ({ giftCard }) => {
24177
24013
  }
24178
24014
  ) });
24179
24015
  };
24180
- const schema$2 = z.object({
24016
+ const schema$1 = z.object({
24181
24017
  note: z.string().optional()
24182
24018
  });
24183
24019
  const GiftCardExpiration = () => {
@@ -24205,7 +24041,7 @@ const GiftCardExpirationForm = ({ giftCard }) => {
24205
24041
  defaultValues: {
24206
24042
  expires_at: giftCard.expires_at ? new Date(giftCard.expires_at) : null
24207
24043
  },
24208
- resolver: t(schema$1)
24044
+ resolver: t(schema)
24209
24045
  });
24210
24046
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
24211
24047
  const { handleSuccess } = useRouteModal();
@@ -24294,450 +24130,8 @@ const GiftCardExpirationForm = ({ giftCard }) => {
24294
24130
  }
24295
24131
  ) });
24296
24132
  };
24297
- const schema$1 = z.object({
24298
- expires_at: z.date().nullish()
24299
- });
24300
- const TransferIcon = () => /* @__PURE__ */ jsxs(
24301
- "svg",
24302
- {
24303
- width: "514",
24304
- height: "182",
24305
- viewBox: "0 0 514 182",
24306
- fill: "none",
24307
- xmlns: "http://www.w3.org/2000/svg",
24308
- children: [
24309
- /* @__PURE__ */ jsx("rect", { x: "0.5", y: "0.5", width: "513", height: "181", rx: "6.5", fill: "#FAFAFA" }),
24310
- /* @__PURE__ */ jsx("rect", { x: "0.5", y: "0.5", width: "513", height: "181", rx: "6.5", stroke: "#E4E4E7" }),
24311
- /* @__PURE__ */ jsx(
24312
- "rect",
24313
- {
24314
- x: "0.00428286",
24315
- y: "-0.742904",
24316
- width: "33.5",
24317
- height: "65.5",
24318
- rx: "6.75",
24319
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 306.755 89.438)",
24320
- fill: "#D4D4D8",
24321
- stroke: "#52525B",
24322
- "stroke-width": "1.5"
24323
- }
24324
- ),
24325
- /* @__PURE__ */ jsx(
24326
- "rect",
24327
- {
24328
- x: "0.00428286",
24329
- y: "-0.742904",
24330
- width: "33.5",
24331
- height: "65.5",
24332
- rx: "6.75",
24333
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 306.755 86.438)",
24334
- fill: "white",
24335
- stroke: "#52525B",
24336
- "stroke-width": "1.5"
24337
- }
24338
- ),
24339
- /* @__PURE__ */ jsx(
24340
- "path",
24341
- {
24342
- d: "M297.579 108.142L296.126 108.959",
24343
- stroke: "#52525B",
24344
- "stroke-width": "1.5",
24345
- "stroke-linecap": "round",
24346
- "stroke-linejoin": "round"
24347
- }
24348
- ),
24349
- /* @__PURE__ */ jsx(
24350
- "path",
24351
- {
24352
- opacity: "0.88",
24353
- d: "M299.305 110.546L297.257 110.534",
24354
- stroke: "#52525B",
24355
- "stroke-width": "1.5",
24356
- "stroke-linecap": "round",
24357
- "stroke-linejoin": "round"
24358
- }
24359
- ),
24360
- /* @__PURE__ */ jsx(
24361
- "path",
24362
- {
24363
- opacity: "0.75",
24364
- d: "M297.552 112.929L296.108 112.096",
24365
- stroke: "#52525B",
24366
- "stroke-width": "1.5",
24367
- "stroke-linecap": "round",
24368
- "stroke-linejoin": "round"
24369
- }
24370
- ),
24371
- /* @__PURE__ */ jsx(
24372
- "path",
24373
- {
24374
- opacity: "0.63",
24375
- d: "M293.347 113.897L293.354 112.73",
24376
- stroke: "#52525B",
24377
- "stroke-width": "1.5",
24378
- "stroke-linecap": "round",
24379
- "stroke-linejoin": "round"
24380
- }
24381
- ),
24382
- /* @__PURE__ */ jsx(
24383
- "path",
24384
- {
24385
- opacity: "0.5",
24386
- d: "M289.154 112.881L290.606 112.064",
24387
- stroke: "#52525B",
24388
- "stroke-width": "1.5",
24389
- "stroke-linecap": "round",
24390
- "stroke-linejoin": "round"
24391
- }
24392
- ),
24393
- /* @__PURE__ */ jsx(
24394
- "path",
24395
- {
24396
- opacity: "0.38",
24397
- d: "M287.428 110.477L289.476 110.489",
24398
- stroke: "#52525B",
24399
- "stroke-width": "1.5",
24400
- "stroke-linecap": "round",
24401
- "stroke-linejoin": "round"
24402
- }
24403
- ),
24404
- /* @__PURE__ */ jsx(
24405
- "path",
24406
- {
24407
- opacity: "0.25",
24408
- d: "M289.181 108.094L290.624 108.928",
24409
- stroke: "#52525B",
24410
- "stroke-width": "1.5",
24411
- "stroke-linecap": "round",
24412
- "stroke-linejoin": "round"
24413
- }
24414
- ),
24415
- /* @__PURE__ */ jsx(
24416
- "path",
24417
- {
24418
- opacity: "0.13",
24419
- d: "M293.386 107.126L293.379 108.293",
24420
- stroke: "#52525B",
24421
- "stroke-width": "1.5",
24422
- "stroke-linecap": "round",
24423
- "stroke-linejoin": "round"
24424
- }
24425
- ),
24426
- /* @__PURE__ */ jsx(
24427
- "rect",
24428
- {
24429
- width: "12",
24430
- height: "3",
24431
- rx: "1.5",
24432
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 313.446 93.2925)",
24433
- fill: "#D4D4D8"
24434
- }
24435
- ),
24436
- /* @__PURE__ */ jsx(
24437
- "rect",
24438
- {
24439
- x: "0.00428286",
24440
- y: "-0.742904",
24441
- width: "33.5",
24442
- height: "65.5",
24443
- rx: "6.75",
24444
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 234.023 47.4146)",
24445
- fill: "#D4D4D8",
24446
- stroke: "#52525B",
24447
- "stroke-width": "1.5"
24448
- }
24449
- ),
24450
- /* @__PURE__ */ jsx(
24451
- "rect",
24452
- {
24453
- x: "0.00428286",
24454
- y: "-0.742904",
24455
- width: "33.5",
24456
- height: "65.5",
24457
- rx: "6.75",
24458
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 234.023 44.4146)",
24459
- fill: "white",
24460
- stroke: "#52525B",
24461
- "stroke-width": "1.5"
24462
- }
24463
- ),
24464
- /* @__PURE__ */ jsx(
24465
- "rect",
24466
- {
24467
- width: "12",
24468
- height: "3",
24469
- rx: "1.5",
24470
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 240.714 51.269)",
24471
- fill: "#D4D4D8"
24472
- }
24473
- ),
24474
- /* @__PURE__ */ jsx(
24475
- "rect",
24476
- {
24477
- width: "17",
24478
- height: "3",
24479
- rx: "1.5",
24480
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 214.556 67.958)",
24481
- fill: "#D4D4D8"
24482
- }
24483
- ),
24484
- /* @__PURE__ */ jsx(
24485
- "rect",
24486
- {
24487
- width: "12",
24488
- height: "3",
24489
- rx: "1.5",
24490
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 210.197 70.4092)",
24491
- fill: "#D4D4D8"
24492
- }
24493
- ),
24494
- /* @__PURE__ */ jsx(
24495
- "path",
24496
- {
24497
- d: "M209.36 64.9564C207.928 64.1287 205.59 64.1152 204.148 64.9264C202.706 65.7375 202.698 67.0703 204.131 67.898C205.563 68.7257 207.901 68.7392 209.343 67.928C210.785 67.1169 210.793 65.7841 209.36 64.9564ZM205.438 67.1626C204.722 66.7488 204.726 66.0822 205.447 65.6768C206.168 65.2713 207.337 65.2781 208.053 65.6918C208.769 66.1055 208.765 66.7722 208.044 67.1776C207.324 67.583 206.154 67.5763 205.438 67.1626Z",
24498
- fill: "#A1A1AA"
24499
- }
24500
- ),
24501
- /* @__PURE__ */ jsx(
24502
- "rect",
24503
- {
24504
- width: "17",
24505
- height: "3",
24506
- rx: "1.5",
24507
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 226.758 61.0942)",
24508
- fill: "#A1A1AA"
24509
- }
24510
- ),
24511
- /* @__PURE__ */ jsx(
24512
- "rect",
24513
- {
24514
- width: "12",
24515
- height: "3",
24516
- rx: "1.5",
24517
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 222.399 63.5454)",
24518
- fill: "#A1A1AA"
24519
- }
24520
- ),
24521
- /* @__PURE__ */ jsx(
24522
- "path",
24523
- {
24524
- d: "M221.562 58.0926C220.13 57.2649 217.792 57.2514 216.35 58.0626C214.908 58.8737 214.9 60.2065 216.333 61.0342C217.766 61.8619 220.103 61.8754 221.545 61.0642C222.987 60.2531 222.995 58.9203 221.562 58.0926ZM220.858 59.8971L217.815 60.1265C217.683 60.1366 217.55 60.1133 217.449 60.0629C217.44 60.0584 217.432 60.0544 217.425 60.0499C217.339 60.0004 217.29 59.9335 217.291 59.8637L217.294 59.12C217.294 58.9751 217.501 58.8585 217.756 58.8599C218.01 58.8614 218.217 58.98 218.216 59.1256L218.214 59.5669L220.732 59.3768C220.984 59.3577 221.217 59.4584 221.251 59.6029C221.286 59.7468 221.11 59.8787 220.858 59.8976L220.858 59.8971Z",
24525
- fill: "#52525B"
24526
- }
24527
- ),
24528
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_28788_23850)", children: /* @__PURE__ */ jsx(
24529
- "path",
24530
- {
24531
- d: "M250.105 82.8025L257.489 82.845L257.514 78.6353",
24532
- stroke: "#A1A1AA",
24533
- "stroke-width": "1.5",
24534
- "stroke-linecap": "round",
24535
- "stroke-linejoin": "round"
24536
- }
24537
- ) }),
24538
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_28788_23850)", children: /* @__PURE__ */ jsx(
24539
- "path",
24540
- {
24541
- d: "M260.496 88.8059L267.88 88.8485L267.904 84.6387",
24542
- stroke: "#A1A1AA",
24543
- "stroke-width": "1.5",
24544
- "stroke-linecap": "round",
24545
- "stroke-linejoin": "round"
24546
- }
24547
- ) }),
24548
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_28788_23850)", children: /* @__PURE__ */ jsx(
24549
- "path",
24550
- {
24551
- d: "M270.886 94.8093L278.27 94.8519L278.294 90.6421",
24552
- stroke: "#A1A1AA",
24553
- "stroke-width": "1.5",
24554
- "stroke-linecap": "round",
24555
- "stroke-linejoin": "round"
24556
- }
24557
- ) }),
24558
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_28788_23850)", children: /* @__PURE__ */ jsx(
24559
- "path",
24560
- {
24561
- d: "M243.113 90.1911L235.728 90.1486L235.704 94.3583",
24562
- stroke: "#A1A1AA",
24563
- "stroke-width": "1.5",
24564
- "stroke-linecap": "round",
24565
- "stroke-linejoin": "round"
24566
- }
24567
- ) }),
24568
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_28788_23850)", children: /* @__PURE__ */ jsx(
24569
- "path",
24570
- {
24571
- d: "M253.503 96.1945L246.119 96.152L246.095 100.362",
24572
- stroke: "#A1A1AA",
24573
- "stroke-width": "1.5",
24574
- "stroke-linecap": "round",
24575
- "stroke-linejoin": "round"
24576
- }
24577
- ) }),
24578
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_28788_23850)", children: /* @__PURE__ */ jsx(
24579
- "path",
24580
- {
24581
- d: "M263.893 102.198L256.509 102.155L256.484 106.365",
24582
- stroke: "#A1A1AA",
24583
- "stroke-width": "1.5",
24584
- "stroke-linecap": "round",
24585
- "stroke-linejoin": "round"
24586
- }
24587
- ) }),
24588
- /* @__PURE__ */ jsxs("defs", { children: [
24589
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_28788_23850", children: /* @__PURE__ */ jsx(
24590
- "rect",
24591
- {
24592
- width: "12",
24593
- height: "12",
24594
- fill: "white",
24595
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 255.359 75.6509)"
24596
- }
24597
- ) }),
24598
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_28788_23850", children: /* @__PURE__ */ jsx(
24599
- "rect",
24600
- {
24601
- width: "12",
24602
- height: "12",
24603
- fill: "white",
24604
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 265.75 81.6543)"
24605
- }
24606
- ) }),
24607
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_28788_23850", children: /* @__PURE__ */ jsx(
24608
- "rect",
24609
- {
24610
- width: "12",
24611
- height: "12",
24612
- fill: "white",
24613
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 276.14 87.6577)"
24614
- }
24615
- ) }),
24616
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_28788_23850", children: /* @__PURE__ */ jsx(
24617
- "rect",
24618
- {
24619
- width: "12",
24620
- height: "12",
24621
- fill: "white",
24622
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 237.928 85.4561)"
24623
- }
24624
- ) }),
24625
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_28788_23850", children: /* @__PURE__ */ jsx(
24626
- "rect",
24627
- {
24628
- width: "12",
24629
- height: "12",
24630
- fill: "white",
24631
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 248.318 91.4595)"
24632
- }
24633
- ) }),
24634
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_28788_23850", children: /* @__PURE__ */ jsx(
24635
- "rect",
24636
- {
24637
- width: "12",
24638
- height: "12",
24639
- fill: "white",
24640
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 258.708 97.4629)"
24641
- }
24642
- ) })
24643
- ] })
24644
- ]
24645
- }
24646
- );
24647
- const Note = () => {
24648
- const { id } = useParams();
24649
- const {
24650
- gift_card: giftCard,
24651
- isPending,
24652
- isError,
24653
- error
24654
- } = useGiftCard(id, {});
24655
- if (isError) {
24656
- throw error;
24657
- }
24658
- const isReady = !isPending && !!giftCard;
24659
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
24660
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
24661
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Gift Card" }) }),
24662
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the gift card to a new owner" }) })
24663
- ] }),
24664
- isReady && /* @__PURE__ */ jsx(GiftCardNoteForm, { giftCard })
24665
- ] });
24666
- };
24667
- const GiftCardNoteForm = ({ giftCard }) => {
24668
- var _a, _b;
24669
- const { customers } = useCustomers();
24670
- const form = useForm({
24671
- defaultValues: {
24672
- customer_id: (_a = giftCard.customer) == null ? void 0 : _a.id
24673
- },
24674
- resolver: t(schema)
24675
- });
24676
- const { mutateAsync, isPending } = useTransferGiftCard(giftCard.id);
24677
- const { handleSuccess } = useRouteModal();
24678
- const onSubmit = form.handleSubmit(async (data) => {
24679
- await mutateAsync(
24680
- { customer_id: data.customer_id },
24681
- {
24682
- onSuccess: () => {
24683
- toast.success("Gift card transferred successfully");
24684
- handleSuccess();
24685
- },
24686
- onError: (error) => toast.error(error.message)
24687
- }
24688
- );
24689
- });
24690
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
24691
- KeyboundForm,
24692
- {
24693
- className: "flex flex-1 flex-col overflow-hidden",
24694
- onSubmit,
24695
- children: [
24696
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
24697
- /* @__PURE__ */ jsx(TransferIcon, {}),
24698
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-6", children: /* @__PURE__ */ jsxs(Form$2.Item, { children: [
24699
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Current Owner" }),
24700
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { value: (_b = giftCard.customer) == null ? void 0 : _b.email, readOnly: true, disabled: true }) }),
24701
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
24702
- ] }) }),
24703
- /* @__PURE__ */ jsx(
24704
- Form$2.Field,
24705
- {
24706
- control: form.control,
24707
- name: "customer_id",
24708
- render: ({ field: { onChange, ref, ...field } }) => {
24709
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
24710
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New Owner" }),
24711
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsxs(Select, { ...field, onValueChange: onChange, children: [
24712
- /* @__PURE__ */ jsx(Select.Trigger, { ref, children: /* @__PURE__ */ jsx(Select.Value, {}) }),
24713
- /* @__PURE__ */ jsx(Select.Content, { children: customers == null ? void 0 : customers.map((customer) => {
24714
- const customerName = [
24715
- customer.first_name,
24716
- customer.last_name
24717
- ];
24718
- return /* @__PURE__ */ jsxs(Select.Item, { value: customer.id, children: [
24719
- customer.email,
24720
- " ",
24721
- customerName.join("").length ? `(${customerName.join(" ")})` : ""
24722
- ] }, customer.id);
24723
- }) })
24724
- ] }) }),
24725
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
24726
- ] });
24727
- }
24728
- }
24729
- )
24730
- ] }),
24731
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
24732
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
24733
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
24734
- ] }) })
24735
- ]
24736
- }
24737
- ) });
24738
- };
24739
24133
  const schema = z.object({
24740
- customer_id: z.string()
24134
+ expires_at: z.date().nullish()
24741
24135
  });
24742
24136
  const columnHelper$7 = createColumnHelper();
24743
24137
  const useGiftCardProductsTableColumns = () => {
@@ -37874,7 +37268,7 @@ const ProductVariantSection = ({
37874
37268
  },
37875
37269
  actions: [
37876
37270
  {
37877
- label: "Edit denomination",
37271
+ label: "Edit denominations",
37878
37272
  to: `denominations`
37879
37273
  },
37880
37274
  {
@@ -38291,11 +37685,11 @@ const GiftCardProductEditDenominationsForm = ({
38291
37685
  size: "small",
38292
37686
  variant: "secondary",
38293
37687
  type: "button",
38294
- className: "rounded-full bg-red-500 text-white p-0 ml-4 hover:bg-red-600",
37688
+ className: "rounded-full p-0 ml-4",
38295
37689
  onClick: () => {
38296
37690
  removeDenomination(index);
38297
37691
  },
38298
- children: /* @__PURE__ */ jsx(MinusMini, { className: "rounded-full" })
37692
+ children: /* @__PURE__ */ jsx(XCircleSolid, { className: "rounded-full" })
38299
37693
  }
38300
37694
  ) })
38301
37695
  ]
@@ -38334,8 +37728,8 @@ const GiftCardProductEdit = () => {
38334
37728
  }
38335
37729
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
38336
37730
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
38337
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit gift card product" }) }),
38338
- /* @__PURE__ */ jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card product" })
37731
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit gift cards denominations" }) }),
37732
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card denominations" })
38339
37733
  ] }),
38340
37734
  !isLoading && product && /* @__PURE__ */ jsx(GiftCardProductEditDenominationsForm, { product })
38341
37735
  ] });
@@ -39218,10 +38612,6 @@ const ProductSalesChannels = () => {
39218
38612
  return /* @__PURE__ */ jsx(RouteFocusModal, { children: !isLoading && product && /* @__PURE__ */ jsx(EditSalesChannelsForm, { product }) });
39219
38613
  };
39220
38614
  const widgetModule = { widgets: [
39221
- {
39222
- Component: CustomerStoreCreditWidget$1,
39223
- zone: ["customer.details.side.after"]
39224
- },
39225
38615
  {
39226
38616
  Component: CustomerStoreCreditWidget,
39227
38617
  zone: ["customer.details.side.after"]
@@ -39266,16 +38656,12 @@ const routeModule = {
39266
38656
  path: "/gift-cards/:id",
39267
38657
  children: [
39268
38658
  {
39269
- Component: Note$1,
38659
+ Component: Note,
39270
38660
  path: "/gift-cards/:id/note"
39271
38661
  },
39272
38662
  {
39273
38663
  Component: GiftCardExpiration,
39274
38664
  path: "/gift-cards/:id/expiration"
39275
- },
39276
- {
39277
- Component: Note,
39278
- path: "/gift-cards/:id/owner"
39279
38665
  }
39280
38666
  ]
39281
38667
  },