@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
@@ -4,10 +4,10 @@ var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, {
4
4
  var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
5
5
  const jsxRuntime = require("react/jsx-runtime");
6
6
  const adminSdk = require("@medusajs/admin-sdk");
7
- const icons = require("@medusajs/icons");
8
7
  const ui = require("@medusajs/ui");
9
8
  const reactRouterDom = require("react-router-dom");
10
9
  const React = require("react");
10
+ const icons = require("@medusajs/icons");
11
11
  const reactQuery = require("@tanstack/react-query");
12
12
  const Medusa = require("@medusajs/js-sdk");
13
13
  const dateFns = require("date-fns");
@@ -206,198 +206,6 @@ const sdk = new Medusa__default.default({
206
206
  type: "session"
207
207
  }
208
208
  });
209
- const giftCardQueryKey = queryKeysFactory("gift-card");
210
- const useGiftCards = (query, options) => {
211
- const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
212
- query: query2,
213
- headers
214
- });
215
- const { data, ...rest } = reactQuery.useQuery({
216
- ...options,
217
- queryFn: () => fetchGiftCards(query),
218
- queryKey: giftCardQueryKey.list(query)
219
- });
220
- return { ...data, ...rest };
221
- };
222
- const useGiftCard = (id, query, options) => {
223
- const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
224
- query: query2,
225
- headers
226
- });
227
- const { data, ...rest } = reactQuery.useQuery({
228
- queryFn: () => fetchGiftCard(id, query),
229
- queryKey: giftCardQueryKey.detail(id),
230
- ...options
231
- });
232
- return { ...data, ...rest };
233
- };
234
- const useRedeemGiftCard = (id, options) => {
235
- const queryClient = reactQuery.useQueryClient();
236
- const redeemGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}/redeem`, {
237
- body,
238
- method: "POST"
239
- });
240
- return reactQuery.useMutation({
241
- mutationFn: (body) => redeemGiftCard(id, body),
242
- onSuccess: (data, variables, context) => {
243
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
244
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.detail(id) });
245
- }
246
- });
247
- };
248
- const useTransferGiftCard = (id, options) => {
249
- const queryClient = reactQuery.useQueryClient();
250
- const transferGiftCard = async (id2, body) => sdk.client.fetch(
251
- `/admin/gift-cards/${id2}/transfer`,
252
- {
253
- body,
254
- method: "POST"
255
- }
256
- );
257
- return reactQuery.useMutation({
258
- mutationFn: (body) => transferGiftCard(id, body),
259
- onSuccess: (data, variables, context) => {
260
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
261
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.detail(id) });
262
- }
263
- });
264
- };
265
- const useUpdateGiftCard = (id, options) => {
266
- const queryClient = reactQuery.useQueryClient();
267
- const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
268
- body,
269
- method: "POST"
270
- });
271
- return reactQuery.useMutation({
272
- mutationFn: async (payload) => updateGiftCard(id, payload),
273
- onSuccess: (data, variables, context) => {
274
- queryClient.invalidateQueries({
275
- queryKey: giftCardQueryKey.detail(id)
276
- });
277
- queryClient.invalidateQueries({
278
- queryKey: giftCardQueryKey.lists()
279
- });
280
- },
281
- ...options
282
- });
283
- };
284
- const useDeleteGiftCard = (id, options) => {
285
- const queryClient = reactQuery.useQueryClient();
286
- const deleteGiftCard = async (id2) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
287
- method: "DELETE"
288
- });
289
- return reactQuery.useMutation({
290
- mutationFn: () => deleteGiftCard(id),
291
- onSuccess: (data, variables, context) => {
292
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
293
- }
294
- });
295
- };
296
- const useCreateGiftCard = (options) => {
297
- const queryClient = reactQuery.useQueryClient();
298
- const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
299
- body,
300
- method: "POST"
301
- });
302
- return reactQuery.useMutation({
303
- mutationFn: (body) => createGiftCard(body),
304
- onSuccess: (data, variables, context) => {
305
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
306
- },
307
- ...options
308
- });
309
- };
310
- const formatAmount = (amount, currency_code) => {
311
- return new Intl.NumberFormat("en-US", {
312
- style: "currency",
313
- currency: currency_code
314
- }).format(amount);
315
- };
316
- var GiftCardStatus = /* @__PURE__ */ ((GiftCardStatus2) => {
317
- GiftCardStatus2["PENDING"] = "pending";
318
- GiftCardStatus2["REDEEMED"] = "redeemed";
319
- return GiftCardStatus2;
320
- })(GiftCardStatus || {});
321
- function getGiftCardStatus(giftCard) {
322
- if (giftCard.expires_at && new Date(giftCard.expires_at) < /* @__PURE__ */ new Date()) {
323
- return "deactivated";
324
- } else if (giftCard.status === GiftCardStatus.PENDING) {
325
- return "pending";
326
- } else {
327
- return "active";
328
- }
329
- }
330
- function getGiftCardStatusColor(status) {
331
- if (status === "deactivated") {
332
- return "red";
333
- } else if (status === "pending") {
334
- return "orange";
335
- } else {
336
- return "green";
337
- }
338
- }
339
- const MAX_GIFT_CARDS = 3;
340
- const CustomerStoreCreditWidget$1 = () => {
341
- const params = reactRouterDom.useParams();
342
- const {
343
- gift_cards: giftCards,
344
- isPending,
345
- count: count2
346
- } = useGiftCards({
347
- customer_id: params.id,
348
- limit: MAX_GIFT_CARDS,
349
- order: "-created_at",
350
- fields: "+line_item.product.title"
351
- });
352
- if (isPending) {
353
- return null;
354
- }
355
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
356
- /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Gift Cards" }),
357
- (giftCards == null ? void 0 : giftCards.length) === 0 && /* @__PURE__ */ jsxRuntime.jsx(
358
- NoRecords,
359
- {
360
- className: "border-t",
361
- title: "No gift cards",
362
- message: "There are no gift cards to show",
363
- icon: null
364
- }
365
- ),
366
- giftCards == null ? void 0 : giftCards.map((giftCard) => {
367
- const giftCardStatus = getGiftCardStatus(giftCard);
368
- const giftCardStatusColor = getGiftCardStatusColor(giftCardStatus);
369
- return /* @__PURE__ */ jsxRuntime.jsx(
370
- SidebarLink,
371
- {
372
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Gift, {}),
373
- labelKey: giftCard.code,
374
- descriptionKey: formatAmount(
375
- giftCard.value ?? 0,
376
- giftCard.currency_code
377
- ),
378
- to: `/gift-cards/${giftCard.id}`,
379
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: giftCardStatusColor, className: "capitalize", children: giftCardStatus })
380
- },
381
- giftCard.id
382
- );
383
- }),
384
- typeof count2 === "number" && count2 > MAX_GIFT_CARDS && /* @__PURE__ */ jsxRuntime.jsx(
385
- reactRouterDom.Link,
386
- {
387
- to: `/gift-cards?customer_id="${params.id}"`,
388
- className: "flex flex-col px-2 pb-2",
389
- children: /* @__PURE__ */ jsxRuntime.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: [
390
- "+ ",
391
- count2 - MAX_GIFT_CARDS,
392
- " more"
393
- ] })
394
- }
395
- )
396
- ] });
397
- };
398
- adminSdk.defineWidgetConfig({
399
- zone: "customer.details.side.after"
400
- });
401
209
  const storeCreditAccountQueryKey = queryKeysFactory(
402
210
  "store-credit-account"
403
211
  );
@@ -426,7 +234,7 @@ const useStoreCreditAccount = (id, query, options) => {
426
234
  );
427
235
  const { data, ...rest } = reactQuery.useQuery({
428
236
  queryFn: () => fetchStoreCreditAccount(query),
429
- queryKey: storeCreditAccountQueryKey.list(query),
237
+ queryKey: storeCreditAccountQueryKey.detail(id),
430
238
  ...options
431
239
  });
432
240
  return { ...data, ...rest };
@@ -568,13 +376,18 @@ const CreditCardIcon = ({ className }) => {
568
376
  }
569
377
  );
570
378
  };
379
+ const formatAmount = (amount, currency_code) => {
380
+ return new Intl.NumberFormat("en-US", {
381
+ style: "currency",
382
+ currency: currency_code
383
+ }).format(amount);
384
+ };
571
385
  const CustomerStoreCreditWidget = () => {
572
386
  const params = reactRouterDom.useParams();
573
387
  const { store_credit_accounts: storeCreditAccounts, isPending } = useStoreCreditAccounts({
574
- customer_id: params.id,
575
- currency_code: "eur"
388
+ customer_id: params.id
576
389
  });
577
- if (isPending) {
390
+ if (isPending || !(storeCreditAccounts == null ? void 0 : storeCreditAccounts.length)) {
578
391
  return null;
579
392
  }
580
393
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
@@ -616,6 +429,29 @@ const useOrder = (id, query, options) => {
616
429
  });
617
430
  return { ...data, ...rest };
618
431
  };
432
+ var GiftCardStatus = /* @__PURE__ */ ((GiftCardStatus2) => {
433
+ GiftCardStatus2["PENDING"] = "pending";
434
+ GiftCardStatus2["REDEEMED"] = "redeemed";
435
+ return GiftCardStatus2;
436
+ })(GiftCardStatus || {});
437
+ function getGiftCardStatus(giftCard) {
438
+ if (giftCard.expires_at && new Date(giftCard.expires_at) < /* @__PURE__ */ new Date()) {
439
+ return "deactivated";
440
+ } else if (giftCard.status === GiftCardStatus.PENDING) {
441
+ return "pending";
442
+ } else {
443
+ return "active";
444
+ }
445
+ }
446
+ function getGiftCardStatusColor(status) {
447
+ if (status === "deactivated") {
448
+ return "red";
449
+ } else if (status === "pending") {
450
+ return "orange";
451
+ } else {
452
+ return "green";
453
+ }
454
+ }
619
455
  const OrderGiftCardsWidget = () => {
620
456
  var _a, _b, _c;
621
457
  const params = reactRouterDom.useParams();
@@ -631,7 +467,7 @@ const OrderGiftCardsWidget = () => {
631
467
  {
632
468
  title: "Gift Cards",
633
469
  subtitle: "Gift cards that have been applied to this order",
634
- 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.`
470
+ 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.`
635
471
  }
636
472
  ),
637
473
  ((_b = order == null ? void 0 : order.gift_cards) == null ? void 0 : _b.length) === 0 && /* @__PURE__ */ jsxRuntime.jsx(
@@ -3779,7 +3615,7 @@ const getFullDate = ({
3779
3615
  locale: LOCALE
3780
3616
  });
3781
3617
  };
3782
- const filterHelper$4 = ui.createDataTableFilterHelper();
3618
+ const filterHelper$3 = ui.createDataTableFilterHelper();
3783
3619
  const useDateFilterOptions$1 = () => {
3784
3620
  const today = React.useMemo(() => {
3785
3621
  const date = /* @__PURE__ */ new Date();
@@ -3837,7 +3673,7 @@ const useDataTableDateFilters$1 = (disableRangeOption) => {
3837
3673
  }, [disableRangeOption, dateFilterOptions]);
3838
3674
  return React.useMemo(() => {
3839
3675
  return [
3840
- filterHelper$4.accessor("created_at", {
3676
+ filterHelper$3.accessor("created_at", {
3841
3677
  type: "date",
3842
3678
  label: "Created at",
3843
3679
  format: "date",
@@ -3845,7 +3681,7 @@ const useDataTableDateFilters$1 = (disableRangeOption) => {
3845
3681
  options: dateFilterOptions,
3846
3682
  ...rangeOptions
3847
3683
  }),
3848
- filterHelper$4.accessor("updated_at", {
3684
+ filterHelper$3.accessor("updated_at", {
3849
3685
  type: "date",
3850
3686
  label: "Updated at",
3851
3687
  format: "date",
@@ -4299,7 +4135,8 @@ const useStoreCreditAccountTableColumns = () => {
4299
4135
  columnHelper$a.accessor("customer.email", {
4300
4136
  header: "Customer",
4301
4137
  cell: ({ row }) => {
4302
- return row.original.customer.email;
4138
+ var _a;
4139
+ return ((_a = row.original.customer) == null ? void 0 : _a.email) ?? "N/A";
4303
4140
  }
4304
4141
  }),
4305
4142
  columnHelper$a.accessor("balance", {
@@ -4338,6 +4175,14 @@ const useStoreCreditAccountTableColumns = () => {
4338
4175
  };
4339
4176
  const CUSTOMERS_QUERY_KEY = "customers";
4340
4177
  const customersQueryKeys = queryKeysFactory(CUSTOMERS_QUERY_KEY);
4178
+ const useCustomer = (id, query, options) => {
4179
+ const { data, ...rest } = reactQuery.useQuery({
4180
+ queryKey: customersQueryKeys.detail(id),
4181
+ queryFn: async () => sdk.admin.customer.retrieve(id, query),
4182
+ ...options
4183
+ });
4184
+ return { ...data, ...rest };
4185
+ };
4341
4186
  const useCustomers = (query, options) => {
4342
4187
  const { data, ...rest } = reactQuery.useQuery({
4343
4188
  queryFn: () => sdk.admin.customer.list(query),
@@ -4346,7 +4191,7 @@ const useCustomers = (query, options) => {
4346
4191
  });
4347
4192
  return { ...data, ...rest };
4348
4193
  };
4349
- const filterHelper$3 = ui.createDataTableFilterHelper();
4194
+ const filterHelper$2 = ui.createDataTableFilterHelper();
4350
4195
  const useCustomerFilterOptions = () => {
4351
4196
  const { customers } = useCustomers({ limit: 1e3 });
4352
4197
  return React.useMemo(() => {
@@ -4362,7 +4207,7 @@ const useCustomerFilters = () => {
4362
4207
  const customerFilterOptions = useCustomerFilterOptions();
4363
4208
  return React.useMemo(() => {
4364
4209
  return [
4365
- filterHelper$3.accessor("customer_id", {
4210
+ filterHelper$2.accessor("customer_id", {
4366
4211
  type: "select",
4367
4212
  label: "Customer",
4368
4213
  options: customerFilterOptions ?? []
@@ -20512,7 +20357,7 @@ const GiftCardProductsSection = () => {
20512
20357
  slicedProducts.map((giftCardProduct) => /* @__PURE__ */ jsxRuntime.jsx(
20513
20358
  SidebarLink,
20514
20359
  {
20515
- to: `/gift-card-products/${giftCardProduct.id}`,
20360
+ to: `/gift-cards/gift-card-products/${giftCardProduct.id}`,
20516
20361
  labelKey: giftCardProduct.title,
20517
20362
  descriptionKey: giftCardProduct.title,
20518
20363
  icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Tag, {})
@@ -20528,6 +20373,90 @@ const GiftCardProductsSection = () => {
20528
20373
  )
20529
20374
  ] });
20530
20375
  };
20376
+ const giftCardQueryKey = queryKeysFactory("gift-card");
20377
+ const useGiftCards = (query, options) => {
20378
+ const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
20379
+ query: query2,
20380
+ headers
20381
+ });
20382
+ const { data, ...rest } = reactQuery.useQuery({
20383
+ ...options,
20384
+ queryFn: () => fetchGiftCards(query),
20385
+ queryKey: giftCardQueryKey.list(query)
20386
+ });
20387
+ return { ...data, ...rest };
20388
+ };
20389
+ const useGiftCard = (id, query, options) => {
20390
+ const fetchGiftCard = (id2, query2, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
20391
+ query: query2,
20392
+ headers
20393
+ });
20394
+ const { data, ...rest } = reactQuery.useQuery({
20395
+ queryFn: () => fetchGiftCard(id, query),
20396
+ queryKey: giftCardQueryKey.detail(id),
20397
+ ...options
20398
+ });
20399
+ return { ...data, ...rest };
20400
+ };
20401
+ const useRedeemGiftCard = (id, options) => {
20402
+ const queryClient = reactQuery.useQueryClient();
20403
+ const redeemGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}/redeem`, {
20404
+ body,
20405
+ method: "POST"
20406
+ });
20407
+ return reactQuery.useMutation({
20408
+ mutationFn: (body) => redeemGiftCard(id, body),
20409
+ onSuccess: (data, variables, context) => {
20410
+ queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
20411
+ queryClient.invalidateQueries({ queryKey: giftCardQueryKey.detail(id) });
20412
+ }
20413
+ });
20414
+ };
20415
+ const useUpdateGiftCard = (id, options) => {
20416
+ const queryClient = reactQuery.useQueryClient();
20417
+ const updateGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
20418
+ body,
20419
+ method: "POST"
20420
+ });
20421
+ return reactQuery.useMutation({
20422
+ mutationFn: async (payload) => updateGiftCard(id, payload),
20423
+ onSuccess: (data, variables, context) => {
20424
+ queryClient.invalidateQueries({
20425
+ queryKey: giftCardQueryKey.detail(id)
20426
+ });
20427
+ queryClient.invalidateQueries({
20428
+ queryKey: giftCardQueryKey.lists()
20429
+ });
20430
+ },
20431
+ ...options
20432
+ });
20433
+ };
20434
+ const useDeleteGiftCard = (id, options) => {
20435
+ const queryClient = reactQuery.useQueryClient();
20436
+ const deleteGiftCard = async (id2) => sdk.client.fetch(`/admin/gift-cards/${id2}`, {
20437
+ method: "DELETE"
20438
+ });
20439
+ return reactQuery.useMutation({
20440
+ mutationFn: () => deleteGiftCard(id),
20441
+ onSuccess: (data, variables, context) => {
20442
+ queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
20443
+ }
20444
+ });
20445
+ };
20446
+ const useCreateGiftCard = (options) => {
20447
+ const queryClient = reactQuery.useQueryClient();
20448
+ const createGiftCard = async (body) => sdk.client.fetch(`/admin/gift-cards`, {
20449
+ body,
20450
+ method: "POST"
20451
+ });
20452
+ return reactQuery.useMutation({
20453
+ mutationFn: (body) => createGiftCard(body),
20454
+ onSuccess: (data, variables, context) => {
20455
+ queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
20456
+ },
20457
+ ...options
20458
+ });
20459
+ };
20531
20460
  const columnHelper$9 = ui.createDataTableColumnHelper();
20532
20461
  const useGiftCardTableColumns = () => {
20533
20462
  return React.useMemo(() => {
@@ -20588,7 +20517,7 @@ const useGiftCardTableQuery = ({
20588
20517
  pageSize = 20
20589
20518
  }) => {
20590
20519
  const queryObject = useQueryParams(
20591
- ["offset", "customer_id", "created_at", "updated_at"],
20520
+ ["q", "offset", "customer_id", "created_at", "updated_at"],
20592
20521
  prefix
20593
20522
  );
20594
20523
  const { offset: offset2, created_at, updated_at, customer_id, ...rest } = queryObject;
@@ -20629,7 +20558,6 @@ function GiftCardsTable() {
20629
20558
  isLoading: isPending,
20630
20559
  pageSize: PAGE_SIZE$5,
20631
20560
  rowCount: count2,
20632
- enableSearch: false,
20633
20561
  heading: "Gift Cards",
20634
20562
  rowHref: (row) => `${row.id}`,
20635
20563
  emptyState: {
@@ -21117,6 +21045,27 @@ const StoreCreditAccountDetailsSection = ({
21117
21045
  }
21118
21046
  ) });
21119
21047
  };
21048
+ function StoreCreditAccountCustomerSection({
21049
+ customerId
21050
+ }) {
21051
+ const { customer, isPending } = useCustomer(customerId);
21052
+ if (isPending || !customer) {
21053
+ return null;
21054
+ }
21055
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
21056
+ /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Customer" }),
21057
+ /* @__PURE__ */ jsxRuntime.jsx(
21058
+ SidebarLink,
21059
+ {
21060
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.User, {}),
21061
+ labelKey: customer.email || "N/A",
21062
+ descriptionKey: !customer.first_name && !customer.last_name ? "N/A" : `${customer.first_name} ${customer.last_name}`,
21063
+ to: `/customers/${customer.id}`
21064
+ },
21065
+ customer.id
21066
+ )
21067
+ ] });
21068
+ }
21120
21069
  const transactionQueryKey = queryKeysFactory("transaction");
21121
21070
  const useStoreCreditAccountTransactions = (id, query, options) => {
21122
21071
  const fetchStoreCreditAccountTransactions = (query2, headers) => sdk.client.fetch(
@@ -21128,7 +21077,7 @@ const useStoreCreditAccountTransactions = (id, query, options) => {
21128
21077
  );
21129
21078
  const { data, ...rest } = reactQuery.useQuery({
21130
21079
  queryFn: () => fetchStoreCreditAccountTransactions(query),
21131
- queryKey: transactionQueryKey.list(query),
21080
+ queryKey: transactionQueryKey.list({ sca_id: id, query }),
21132
21081
  ...options
21133
21082
  });
21134
21083
  return { ...data, ...rest };
@@ -21164,8 +21113,9 @@ const useTransactionsTableColumns = () => {
21164
21113
  columnHelper$8.accessor("amount", {
21165
21114
  header: "Amount",
21166
21115
  cell: ({ row }) => {
21116
+ const isDebit = row.original.type === "debit";
21167
21117
  return row.original.account.currency_code && formatAmount(
21168
- row.original.amount,
21118
+ row.original.amount * (isDebit ? -1 : 1),
21169
21119
  row.original.account.currency_code
21170
21120
  );
21171
21121
  }
@@ -21173,57 +21123,16 @@ const useTransactionsTableColumns = () => {
21173
21123
  ];
21174
21124
  }, []);
21175
21125
  };
21176
- const transactionGroupQueryKey = queryKeysFactory("transaction-group");
21177
- const useTransactionGroups = (query, options) => {
21178
- const fetchTransactionGroups = (query2, headers) => sdk.client.fetch(
21179
- `/admin/transaction-groups`,
21180
- {
21181
- query: query2,
21182
- headers
21183
- }
21184
- );
21185
- const { data, ...rest } = reactQuery.useQuery({
21186
- queryFn: () => fetchTransactionGroups(query),
21187
- queryKey: transactionGroupQueryKey.list(query),
21188
- ...options
21189
- });
21190
- return { ...data, ...rest };
21191
- };
21192
- const filterHelper$2 = ui.createDataTableFilterHelper();
21193
- const useTransactionGroupFilterOptions = () => {
21194
- const { transaction_groups } = useTransactionGroups({ limit: 1e3 });
21195
- return React.useMemo(() => {
21196
- return transaction_groups == null ? void 0 : transaction_groups.map((transactionGroup) => {
21197
- return {
21198
- label: transactionGroup.code,
21199
- value: transactionGroup.id
21200
- };
21201
- });
21202
- }, [transaction_groups]);
21203
- };
21204
- const useTransactionGroupFilters = () => {
21205
- const transactionGroupFilterOptions = useTransactionGroupFilterOptions();
21206
- return React.useMemo(() => {
21207
- return [
21208
- filterHelper$2.accessor("transaction_group_id", {
21209
- type: "select",
21210
- label: "Transaction Group",
21211
- options: transactionGroupFilterOptions ?? []
21212
- })
21213
- ];
21214
- }, [transactionGroupFilterOptions]);
21215
- };
21216
21126
  const useTransactionsTableFilters = ({
21217
21127
  transactionGroup
21218
21128
  }) => {
21219
21129
  const dateFilterOptions = useDataTableDateFilters$1();
21220
- const transactionGroupFilters = useTransactionGroupFilters();
21221
21130
  return React.useMemo(() => {
21222
21131
  if (transactionGroup) {
21223
21132
  return [...dateFilterOptions];
21224
21133
  }
21225
- return [...dateFilterOptions, ...transactionGroupFilters];
21226
- }, [dateFilterOptions, transactionGroupFilters, transactionGroup]);
21134
+ return [...dateFilterOptions];
21135
+ }, [dateFilterOptions, , transactionGroup]);
21227
21136
  };
21228
21137
  const useTransactionsTableQuery = ({
21229
21138
  prefix,
@@ -21324,12 +21233,20 @@ const StoreCreditAccountPage = () => {
21324
21233
  ),
21325
21234
  /* @__PURE__ */ jsxRuntime.jsx(TransactionsTable, { id: storeCreditAccount.id })
21326
21235
  ] }),
21327
- secondCol: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
21328
- StoreCreditAccountBalanceSection,
21329
- {
21330
- storeCreditAccount
21331
- }
21332
- ) })
21236
+ secondCol: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
21237
+ /* @__PURE__ */ jsxRuntime.jsx(
21238
+ StoreCreditAccountBalanceSection,
21239
+ {
21240
+ storeCreditAccount
21241
+ }
21242
+ ),
21243
+ /* @__PURE__ */ jsxRuntime.jsx(
21244
+ StoreCreditAccountCustomerSection,
21245
+ {
21246
+ customerId: storeCreditAccount.customer_id
21247
+ }
21248
+ )
21249
+ ] })
21333
21250
  }
21334
21251
  ) });
21335
21252
  };
@@ -23800,34 +23717,11 @@ const SectionRow = ({ title, value, actions }) => {
23800
23717
  const GiftCardGeneralSection = ({ giftCard }) => {
23801
23718
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
23802
23719
  const prompt = ui.usePrompt();
23803
- const navigate = reactRouterDom.useNavigate();
23720
+ reactRouterDom.useNavigate();
23804
23721
  const { mutateAsync: redeemGiftCard, isPending } = useRedeemGiftCard(
23805
23722
  giftCard.id
23806
23723
  );
23807
23724
  const { mutateAsync: deleteGiftCard, isPending: isDeleting } = useDeleteGiftCard(giftCard.id);
23808
- const handleRedeem = async () => {
23809
- const res = await prompt({
23810
- title: "Redeem gift card",
23811
- description: `Are you sure? This cannot be undone. Once you confirm the gift card value will be added to the customers store credit account.`,
23812
- confirmText: "Redeem",
23813
- cancelText: "Cancel"
23814
- });
23815
- if (!res) {
23816
- return;
23817
- }
23818
- await redeemGiftCard(
23819
- { customer_id: giftCard == null ? void 0 : giftCard.customer_id },
23820
- {
23821
- onSuccess: () => {
23822
- ui.toast.success("Successfully redeemed gift card");
23823
- navigate("..", { replace: true });
23824
- },
23825
- onError: (err) => {
23826
- ui.toast.error(err.message);
23827
- }
23828
- }
23829
- );
23830
- };
23831
23725
  const handleDelete = async () => {
23832
23726
  const res = await prompt({
23833
23727
  title: "Delete gift card",
@@ -23870,12 +23764,13 @@ const GiftCardGeneralSection = ({ giftCard }) => {
23870
23764
  groups: [
23871
23765
  {
23872
23766
  actions: [
23873
- {
23874
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Gift, {}),
23875
- label: "Redeem gift card",
23876
- onClick: () => handleRedeem(),
23877
- disabled: isPending
23878
- },
23767
+ // TODO: revisit this - now GC doesn't have owner so redeeming would result in an anonymous account
23768
+ // {
23769
+ // icon: <Gift />,
23770
+ // label: "Redeem gift card",
23771
+ // onClick: () => handleRedeem(),
23772
+ // disabled: isPending || giftCard.status === "redeemed",
23773
+ // },
23879
23774
  {
23880
23775
  icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Calendar, {}),
23881
23776
  label: "Edit expiration date",
@@ -24003,91 +23898,33 @@ const GiftCardOrderSection = ({ giftCard }) => {
24003
23898
  )
24004
23899
  ] });
24005
23900
  };
24006
- const GiftCardOwnerSection = ({ giftCard }) => {
24007
- var _a, _b;
24008
- if (!giftCard) {
24009
- return;
24010
- }
24011
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
24012
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
24013
- /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Owner" }),
24014
- giftCard.status !== GiftCardStatus.REDEEMED && /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: `owner`, className: "text-ui-fg-muted text-sm px-6", children: "Transfer ownership" })
24015
- ] }),
24016
- !((_a = giftCard.customer) == null ? void 0 : _a.id) && /* @__PURE__ */ jsxRuntime.jsx(
24017
- NoRecords,
24018
- {
24019
- title: "No customer assigned",
24020
- message: "Transfer gift card ownership to a customer to assign an owner",
24021
- icon: null
24022
- }
24023
- ),
24024
- ((_b = giftCard.customer) == null ? void 0 : _b.id) && /* @__PURE__ */ jsxRuntime.jsx(
24025
- SidebarLink,
24026
- {
24027
- to: `/customers/${giftCard.customer.id}`,
24028
- labelKey: `${[
24029
- giftCard.customer.first_name,
24030
- giftCard.customer.last_name
24031
- ].join(" ")}`,
24032
- descriptionKey: giftCard.customer.email,
24033
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.UserMini, {})
24034
- }
24035
- )
24036
- ] });
24037
- };
24038
23901
  const GiftCardTransactionsSection = ({
24039
- storeCreditAccount,
24040
- transactionGroup
23902
+ storeCreditAccount
24041
23903
  }) => {
24042
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "divide-y p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
24043
- TransactionsTable,
24044
- {
24045
- id: storeCreditAccount.id,
24046
- transactionGroup
24047
- }
24048
- ) }, storeCreditAccount.id);
23904
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "divide-y p-0", children: /* @__PURE__ */ jsxRuntime.jsx(TransactionsTable, { id: storeCreditAccount.id }) }, storeCreditAccount.id);
24049
23905
  };
24050
23906
  const GiftCardDetailsPage = () => {
24051
- var _a;
24052
23907
  const { id } = reactRouterDom.useParams();
24053
23908
  const { gift_card: giftCard, isLoading } = useGiftCard(id, {
24054
- fields: "*line_item.product"
23909
+ fields: "*line_item.product,*store_credit_account"
24055
23910
  });
24056
- const { store_credit_accounts: storeCreditAccounts } = useStoreCreditAccounts(
24057
- {
24058
- customer_id: giftCard == null ? void 0 : giftCard.customer_id,
24059
- currency_code: giftCard == null ? void 0 : giftCard.currency_code
24060
- },
24061
- { enabled: !isLoading && !!(giftCard == null ? void 0 : giftCard.customer_id) }
24062
- );
24063
- const { transaction_groups: transactionGroups } = useTransactionGroups(
24064
- { code: giftCard == null ? void 0 : giftCard.code },
24065
- { enabled: !isLoading && !!(giftCard == null ? void 0 : giftCard.code) }
24066
- );
24067
- const transactionGroup = transactionGroups == null ? void 0 : transactionGroups[0];
24068
- const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
24069
- (_a = storeCreditAccounts == null ? void 0 : storeCreditAccounts[0]) == null ? void 0 : _a.id,
24070
- {
24071
- transaction_group_id: transactionGroup == null ? void 0 : transactionGroup.id
24072
- },
24073
- {
24074
- enabled: !isLoading && !!(giftCard == null ? void 0 : giftCard.customer_id) && !!(transactionGroup == null ? void 0 : transactionGroup.id) && !!(storeCreditAccounts == null ? void 0 : storeCreditAccounts.length)
24075
- }
24076
- );
24077
- if (!giftCard) {
23911
+ if (isLoading) {
24078
23912
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Loading" });
24079
23913
  }
23914
+ if (!isLoading && !giftCard) {
23915
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Gift card not found" });
23916
+ }
23917
+ const storeCreditAccount = giftCard == null ? void 0 : giftCard.store_credit_account;
24080
23918
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
24081
23919
  /* @__PURE__ */ jsxRuntime.jsx(
24082
23920
  TwoColumnLayout,
24083
23921
  {
24084
23922
  firstCol: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
24085
23923
  /* @__PURE__ */ jsxRuntime.jsx(GiftCardGeneralSection, { giftCard }),
24086
- storeCreditAccount && transactionGroup && /* @__PURE__ */ jsxRuntime.jsx(
23924
+ storeCreditAccount && /* @__PURE__ */ jsxRuntime.jsx(
24087
23925
  GiftCardTransactionsSection,
24088
23926
  {
24089
- storeCreditAccount,
24090
- transactionGroup
23927
+ storeCreditAccount
24091
23928
  }
24092
23929
  ),
24093
23930
  /* @__PURE__ */ jsxRuntime.jsx(JsonViewSection, { data: giftCard })
@@ -24100,7 +23937,6 @@ const GiftCardDetailsPage = () => {
24100
23937
  giftCard
24101
23938
  }
24102
23939
  ),
24103
- /* @__PURE__ */ jsxRuntime.jsx(GiftCardOwnerSection, { giftCard }),
24104
23940
  /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteSection, { giftCard }),
24105
23941
  /* @__PURE__ */ jsxRuntime.jsx(GiftCardOrderSection, { giftCard })
24106
23942
  ] })
@@ -24136,7 +23972,7 @@ const KeyboundForm = React__namespace.default.forwardRef(({ onSubmit, onKeyDown,
24136
23972
  );
24137
23973
  });
24138
23974
  KeyboundForm.displayName = "KeyboundForm";
24139
- const Note$1 = () => {
23975
+ const Note = () => {
24140
23976
  const { id } = reactRouterDom.useParams();
24141
23977
  const {
24142
23978
  gift_card: giftCard,
@@ -24153,15 +23989,15 @@ const Note$1 = () => {
24153
23989
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit note" }) }),
24154
23990
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the note for the gift card" }) })
24155
23991
  ] }),
24156
- isReady && /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteForm$1, { giftCard })
23992
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteForm, { giftCard })
24157
23993
  ] });
24158
23994
  };
24159
- const GiftCardNoteForm$1 = ({ giftCard }) => {
23995
+ const GiftCardNoteForm = ({ giftCard }) => {
24160
23996
  const form = useForm({
24161
23997
  defaultValues: {
24162
23998
  note: giftCard.note ?? ""
24163
23999
  },
24164
- resolver: t(schema$2)
24000
+ resolver: t(schema$1)
24165
24001
  });
24166
24002
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
24167
24003
  const { handleSuccess } = useRouteModal();
@@ -24200,7 +24036,7 @@ const GiftCardNoteForm$1 = ({ giftCard }) => {
24200
24036
  }
24201
24037
  ) });
24202
24038
  };
24203
- const schema$2 = z.object({
24039
+ const schema$1 = z.object({
24204
24040
  note: z.string().optional()
24205
24041
  });
24206
24042
  const GiftCardExpiration = () => {
@@ -24228,7 +24064,7 @@ const GiftCardExpirationForm = ({ giftCard }) => {
24228
24064
  defaultValues: {
24229
24065
  expires_at: giftCard.expires_at ? new Date(giftCard.expires_at) : null
24230
24066
  },
24231
- resolver: t(schema$1)
24067
+ resolver: t(schema)
24232
24068
  });
24233
24069
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
24234
24070
  const { handleSuccess } = useRouteModal();
@@ -24317,450 +24153,8 @@ const GiftCardExpirationForm = ({ giftCard }) => {
24317
24153
  }
24318
24154
  ) });
24319
24155
  };
24320
- const schema$1 = z.object({
24321
- expires_at: z.date().nullish()
24322
- });
24323
- const TransferIcon = () => /* @__PURE__ */ jsxRuntime.jsxs(
24324
- "svg",
24325
- {
24326
- width: "514",
24327
- height: "182",
24328
- viewBox: "0 0 514 182",
24329
- fill: "none",
24330
- xmlns: "http://www.w3.org/2000/svg",
24331
- children: [
24332
- /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "0.5", y: "0.5", width: "513", height: "181", rx: "6.5", fill: "#FAFAFA" }),
24333
- /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "0.5", y: "0.5", width: "513", height: "181", rx: "6.5", stroke: "#E4E4E7" }),
24334
- /* @__PURE__ */ jsxRuntime.jsx(
24335
- "rect",
24336
- {
24337
- x: "0.00428286",
24338
- y: "-0.742904",
24339
- width: "33.5",
24340
- height: "65.5",
24341
- rx: "6.75",
24342
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 306.755 89.438)",
24343
- fill: "#D4D4D8",
24344
- stroke: "#52525B",
24345
- "stroke-width": "1.5"
24346
- }
24347
- ),
24348
- /* @__PURE__ */ jsxRuntime.jsx(
24349
- "rect",
24350
- {
24351
- x: "0.00428286",
24352
- y: "-0.742904",
24353
- width: "33.5",
24354
- height: "65.5",
24355
- rx: "6.75",
24356
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 306.755 86.438)",
24357
- fill: "white",
24358
- stroke: "#52525B",
24359
- "stroke-width": "1.5"
24360
- }
24361
- ),
24362
- /* @__PURE__ */ jsxRuntime.jsx(
24363
- "path",
24364
- {
24365
- d: "M297.579 108.142L296.126 108.959",
24366
- stroke: "#52525B",
24367
- "stroke-width": "1.5",
24368
- "stroke-linecap": "round",
24369
- "stroke-linejoin": "round"
24370
- }
24371
- ),
24372
- /* @__PURE__ */ jsxRuntime.jsx(
24373
- "path",
24374
- {
24375
- opacity: "0.88",
24376
- d: "M299.305 110.546L297.257 110.534",
24377
- stroke: "#52525B",
24378
- "stroke-width": "1.5",
24379
- "stroke-linecap": "round",
24380
- "stroke-linejoin": "round"
24381
- }
24382
- ),
24383
- /* @__PURE__ */ jsxRuntime.jsx(
24384
- "path",
24385
- {
24386
- opacity: "0.75",
24387
- d: "M297.552 112.929L296.108 112.096",
24388
- stroke: "#52525B",
24389
- "stroke-width": "1.5",
24390
- "stroke-linecap": "round",
24391
- "stroke-linejoin": "round"
24392
- }
24393
- ),
24394
- /* @__PURE__ */ jsxRuntime.jsx(
24395
- "path",
24396
- {
24397
- opacity: "0.63",
24398
- d: "M293.347 113.897L293.354 112.73",
24399
- stroke: "#52525B",
24400
- "stroke-width": "1.5",
24401
- "stroke-linecap": "round",
24402
- "stroke-linejoin": "round"
24403
- }
24404
- ),
24405
- /* @__PURE__ */ jsxRuntime.jsx(
24406
- "path",
24407
- {
24408
- opacity: "0.5",
24409
- d: "M289.154 112.881L290.606 112.064",
24410
- stroke: "#52525B",
24411
- "stroke-width": "1.5",
24412
- "stroke-linecap": "round",
24413
- "stroke-linejoin": "round"
24414
- }
24415
- ),
24416
- /* @__PURE__ */ jsxRuntime.jsx(
24417
- "path",
24418
- {
24419
- opacity: "0.38",
24420
- d: "M287.428 110.477L289.476 110.489",
24421
- stroke: "#52525B",
24422
- "stroke-width": "1.5",
24423
- "stroke-linecap": "round",
24424
- "stroke-linejoin": "round"
24425
- }
24426
- ),
24427
- /* @__PURE__ */ jsxRuntime.jsx(
24428
- "path",
24429
- {
24430
- opacity: "0.25",
24431
- d: "M289.181 108.094L290.624 108.928",
24432
- stroke: "#52525B",
24433
- "stroke-width": "1.5",
24434
- "stroke-linecap": "round",
24435
- "stroke-linejoin": "round"
24436
- }
24437
- ),
24438
- /* @__PURE__ */ jsxRuntime.jsx(
24439
- "path",
24440
- {
24441
- opacity: "0.13",
24442
- d: "M293.386 107.126L293.379 108.293",
24443
- stroke: "#52525B",
24444
- "stroke-width": "1.5",
24445
- "stroke-linecap": "round",
24446
- "stroke-linejoin": "round"
24447
- }
24448
- ),
24449
- /* @__PURE__ */ jsxRuntime.jsx(
24450
- "rect",
24451
- {
24452
- width: "12",
24453
- height: "3",
24454
- rx: "1.5",
24455
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 313.446 93.2925)",
24456
- fill: "#D4D4D8"
24457
- }
24458
- ),
24459
- /* @__PURE__ */ jsxRuntime.jsx(
24460
- "rect",
24461
- {
24462
- x: "0.00428286",
24463
- y: "-0.742904",
24464
- width: "33.5",
24465
- height: "65.5",
24466
- rx: "6.75",
24467
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 234.023 47.4146)",
24468
- fill: "#D4D4D8",
24469
- stroke: "#52525B",
24470
- "stroke-width": "1.5"
24471
- }
24472
- ),
24473
- /* @__PURE__ */ jsxRuntime.jsx(
24474
- "rect",
24475
- {
24476
- x: "0.00428286",
24477
- y: "-0.742904",
24478
- width: "33.5",
24479
- height: "65.5",
24480
- rx: "6.75",
24481
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 234.023 44.4146)",
24482
- fill: "white",
24483
- stroke: "#52525B",
24484
- "stroke-width": "1.5"
24485
- }
24486
- ),
24487
- /* @__PURE__ */ jsxRuntime.jsx(
24488
- "rect",
24489
- {
24490
- width: "12",
24491
- height: "3",
24492
- rx: "1.5",
24493
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 240.714 51.269)",
24494
- fill: "#D4D4D8"
24495
- }
24496
- ),
24497
- /* @__PURE__ */ jsxRuntime.jsx(
24498
- "rect",
24499
- {
24500
- width: "17",
24501
- height: "3",
24502
- rx: "1.5",
24503
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 214.556 67.958)",
24504
- fill: "#D4D4D8"
24505
- }
24506
- ),
24507
- /* @__PURE__ */ jsxRuntime.jsx(
24508
- "rect",
24509
- {
24510
- width: "12",
24511
- height: "3",
24512
- rx: "1.5",
24513
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 210.197 70.4092)",
24514
- fill: "#D4D4D8"
24515
- }
24516
- ),
24517
- /* @__PURE__ */ jsxRuntime.jsx(
24518
- "path",
24519
- {
24520
- 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",
24521
- fill: "#A1A1AA"
24522
- }
24523
- ),
24524
- /* @__PURE__ */ jsxRuntime.jsx(
24525
- "rect",
24526
- {
24527
- width: "17",
24528
- height: "3",
24529
- rx: "1.5",
24530
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 226.758 61.0942)",
24531
- fill: "#A1A1AA"
24532
- }
24533
- ),
24534
- /* @__PURE__ */ jsxRuntime.jsx(
24535
- "rect",
24536
- {
24537
- width: "12",
24538
- height: "3",
24539
- rx: "1.5",
24540
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 222.399 63.5454)",
24541
- fill: "#A1A1AA"
24542
- }
24543
- ),
24544
- /* @__PURE__ */ jsxRuntime.jsx(
24545
- "path",
24546
- {
24547
- 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",
24548
- fill: "#52525B"
24549
- }
24550
- ),
24551
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_28788_23850)", children: /* @__PURE__ */ jsxRuntime.jsx(
24552
- "path",
24553
- {
24554
- d: "M250.105 82.8025L257.489 82.845L257.514 78.6353",
24555
- stroke: "#A1A1AA",
24556
- "stroke-width": "1.5",
24557
- "stroke-linecap": "round",
24558
- "stroke-linejoin": "round"
24559
- }
24560
- ) }),
24561
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_28788_23850)", children: /* @__PURE__ */ jsxRuntime.jsx(
24562
- "path",
24563
- {
24564
- d: "M260.496 88.8059L267.88 88.8485L267.904 84.6387",
24565
- stroke: "#A1A1AA",
24566
- "stroke-width": "1.5",
24567
- "stroke-linecap": "round",
24568
- "stroke-linejoin": "round"
24569
- }
24570
- ) }),
24571
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_28788_23850)", children: /* @__PURE__ */ jsxRuntime.jsx(
24572
- "path",
24573
- {
24574
- d: "M270.886 94.8093L278.27 94.8519L278.294 90.6421",
24575
- stroke: "#A1A1AA",
24576
- "stroke-width": "1.5",
24577
- "stroke-linecap": "round",
24578
- "stroke-linejoin": "round"
24579
- }
24580
- ) }),
24581
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_28788_23850)", children: /* @__PURE__ */ jsxRuntime.jsx(
24582
- "path",
24583
- {
24584
- d: "M243.113 90.1911L235.728 90.1486L235.704 94.3583",
24585
- stroke: "#A1A1AA",
24586
- "stroke-width": "1.5",
24587
- "stroke-linecap": "round",
24588
- "stroke-linejoin": "round"
24589
- }
24590
- ) }),
24591
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_28788_23850)", children: /* @__PURE__ */ jsxRuntime.jsx(
24592
- "path",
24593
- {
24594
- d: "M253.503 96.1945L246.119 96.152L246.095 100.362",
24595
- stroke: "#A1A1AA",
24596
- "stroke-width": "1.5",
24597
- "stroke-linecap": "round",
24598
- "stroke-linejoin": "round"
24599
- }
24600
- ) }),
24601
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_28788_23850)", children: /* @__PURE__ */ jsxRuntime.jsx(
24602
- "path",
24603
- {
24604
- d: "M263.893 102.198L256.509 102.155L256.484 106.365",
24605
- stroke: "#A1A1AA",
24606
- "stroke-width": "1.5",
24607
- "stroke-linecap": "round",
24608
- "stroke-linejoin": "round"
24609
- }
24610
- ) }),
24611
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
24612
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_28788_23850", children: /* @__PURE__ */ jsxRuntime.jsx(
24613
- "rect",
24614
- {
24615
- width: "12",
24616
- height: "12",
24617
- fill: "white",
24618
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 255.359 75.6509)"
24619
- }
24620
- ) }),
24621
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_28788_23850", children: /* @__PURE__ */ jsxRuntime.jsx(
24622
- "rect",
24623
- {
24624
- width: "12",
24625
- height: "12",
24626
- fill: "white",
24627
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 265.75 81.6543)"
24628
- }
24629
- ) }),
24630
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_28788_23850", children: /* @__PURE__ */ jsxRuntime.jsx(
24631
- "rect",
24632
- {
24633
- width: "12",
24634
- height: "12",
24635
- fill: "white",
24636
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 276.14 87.6577)"
24637
- }
24638
- ) }),
24639
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_28788_23850", children: /* @__PURE__ */ jsxRuntime.jsx(
24640
- "rect",
24641
- {
24642
- width: "12",
24643
- height: "12",
24644
- fill: "white",
24645
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 237.928 85.4561)"
24646
- }
24647
- ) }),
24648
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_28788_23850", children: /* @__PURE__ */ jsxRuntime.jsx(
24649
- "rect",
24650
- {
24651
- width: "12",
24652
- height: "12",
24653
- fill: "white",
24654
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 248.318 91.4595)"
24655
- }
24656
- ) }),
24657
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_28788_23850", children: /* @__PURE__ */ jsxRuntime.jsx(
24658
- "rect",
24659
- {
24660
- width: "12",
24661
- height: "12",
24662
- fill: "white",
24663
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 258.708 97.4629)"
24664
- }
24665
- ) })
24666
- ] })
24667
- ]
24668
- }
24669
- );
24670
- const Note = () => {
24671
- const { id } = reactRouterDom.useParams();
24672
- const {
24673
- gift_card: giftCard,
24674
- isPending,
24675
- isError,
24676
- error
24677
- } = useGiftCard(id, {});
24678
- if (isError) {
24679
- throw error;
24680
- }
24681
- const isReady = !isPending && !!giftCard;
24682
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
24683
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
24684
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Gift Card" }) }),
24685
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the gift card to a new owner" }) })
24686
- ] }),
24687
- isReady && /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteForm, { giftCard })
24688
- ] });
24689
- };
24690
- const GiftCardNoteForm = ({ giftCard }) => {
24691
- var _a, _b;
24692
- const { customers } = useCustomers();
24693
- const form = useForm({
24694
- defaultValues: {
24695
- customer_id: (_a = giftCard.customer) == null ? void 0 : _a.id
24696
- },
24697
- resolver: t(schema)
24698
- });
24699
- const { mutateAsync, isPending } = useTransferGiftCard(giftCard.id);
24700
- const { handleSuccess } = useRouteModal();
24701
- const onSubmit = form.handleSubmit(async (data) => {
24702
- await mutateAsync(
24703
- { customer_id: data.customer_id },
24704
- {
24705
- onSuccess: () => {
24706
- ui.toast.success("Gift card transferred successfully");
24707
- handleSuccess();
24708
- },
24709
- onError: (error) => ui.toast.error(error.message)
24710
- }
24711
- );
24712
- });
24713
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
24714
- KeyboundForm,
24715
- {
24716
- className: "flex flex-1 flex-col overflow-hidden",
24717
- onSubmit,
24718
- children: [
24719
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
24720
- /* @__PURE__ */ jsxRuntime.jsx(TransferIcon, {}),
24721
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-6", children: /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
24722
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Current Owner" }),
24723
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { value: (_b = giftCard.customer) == null ? void 0 : _b.email, readOnly: true, disabled: true }) }),
24724
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
24725
- ] }) }),
24726
- /* @__PURE__ */ jsxRuntime.jsx(
24727
- Form$2.Field,
24728
- {
24729
- control: form.control,
24730
- name: "customer_id",
24731
- render: ({ field: { onChange, ref, ...field } }) => {
24732
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
24733
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New Owner" }),
24734
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { ...field, onValueChange: onChange, children: [
24735
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { ref, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
24736
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: customers == null ? void 0 : customers.map((customer) => {
24737
- const customerName = [
24738
- customer.first_name,
24739
- customer.last_name
24740
- ];
24741
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Item, { value: customer.id, children: [
24742
- customer.email,
24743
- " ",
24744
- customerName.join("").length ? `(${customerName.join(" ")})` : ""
24745
- ] }, customer.id);
24746
- }) })
24747
- ] }) }),
24748
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
24749
- ] });
24750
- }
24751
- }
24752
- )
24753
- ] }),
24754
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
24755
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
24756
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
24757
- ] }) })
24758
- ]
24759
- }
24760
- ) });
24761
- };
24762
24156
  const schema = z.object({
24763
- customer_id: z.string()
24157
+ expires_at: z.date().nullish()
24764
24158
  });
24765
24159
  const columnHelper$7 = createColumnHelper();
24766
24160
  const useGiftCardProductsTableColumns = () => {
@@ -37897,7 +37291,7 @@ const ProductVariantSection = ({
37897
37291
  },
37898
37292
  actions: [
37899
37293
  {
37900
- label: "Edit denomination",
37294
+ label: "Edit denominations",
37901
37295
  to: `denominations`
37902
37296
  },
37903
37297
  {
@@ -38314,11 +37708,11 @@ const GiftCardProductEditDenominationsForm = ({
38314
37708
  size: "small",
38315
37709
  variant: "secondary",
38316
37710
  type: "button",
38317
- className: "rounded-full bg-red-500 text-white p-0 ml-4 hover:bg-red-600",
37711
+ className: "rounded-full p-0 ml-4",
38318
37712
  onClick: () => {
38319
37713
  removeDenomination(index);
38320
37714
  },
38321
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.MinusMini, { className: "rounded-full" })
37715
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XCircleSolid, { className: "rounded-full" })
38322
37716
  }
38323
37717
  ) })
38324
37718
  ]
@@ -38357,8 +37751,8 @@ const GiftCardProductEdit = () => {
38357
37751
  }
38358
37752
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
38359
37753
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
38360
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit gift card product" }) }),
38361
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card product" })
37754
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit gift cards denominations" }) }),
37755
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card denominations" })
38362
37756
  ] }),
38363
37757
  !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditDenominationsForm, { product })
38364
37758
  ] });
@@ -39241,10 +38635,6 @@ const ProductSalesChannels = () => {
39241
38635
  return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { children: !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(EditSalesChannelsForm, { product }) });
39242
38636
  };
39243
38637
  const widgetModule = { widgets: [
39244
- {
39245
- Component: CustomerStoreCreditWidget$1,
39246
- zone: ["customer.details.side.after"]
39247
- },
39248
38638
  {
39249
38639
  Component: CustomerStoreCreditWidget,
39250
38640
  zone: ["customer.details.side.after"]
@@ -39289,16 +38679,12 @@ const routeModule = {
39289
38679
  path: "/gift-cards/:id",
39290
38680
  children: [
39291
38681
  {
39292
- Component: Note$1,
38682
+ Component: Note,
39293
38683
  path: "/gift-cards/:id/note"
39294
38684
  },
39295
38685
  {
39296
38686
  Component: GiftCardExpiration,
39297
38687
  path: "/gift-cards/:id/expiration"
39298
- },
39299
- {
39300
- Component: Note,
39301
- path: "/gift-cards/:id/owner"
39302
38688
  }
39303
38689
  ]
39304
38690
  },