@lodashventure/medusa-membership 0.4.1 → 0.4.3

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.
@@ -3,27 +3,46 @@ const jsxRuntime = require("react/jsx-runtime");
3
3
  const adminSdk = require("@medusajs/admin-sdk");
4
4
  const ui = require("@medusajs/ui");
5
5
  const axios = require("axios");
6
- const reactQuery = require("@tanstack/react-query");
6
+ const react = require("react");
7
7
  const Medusa = require("@medusajs/js-sdk");
8
8
  const icons = require("@medusajs/icons");
9
- const react = require("react");
10
9
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
11
10
  const axios__default = /* @__PURE__ */ _interopDefault(axios);
12
11
  const Medusa__default = /* @__PURE__ */ _interopDefault(Medusa);
13
12
  const useMembershipConfig = (storeId, options) => {
14
- return reactQuery.useQuery({
15
- ...options,
16
- queryKey: ["membership-config", storeId],
17
- queryFn: async () => {
18
- if (!storeId) {
19
- throw new Error("No store id found");
20
- }
13
+ const [data, setData] = react.useState(void 0);
14
+ const [isLoading, setIsLoading] = react.useState(true);
15
+ const [error, setError] = react.useState(null);
16
+ const fetchConfig = async () => {
17
+ if (!storeId) {
18
+ setError(new Error("No store id found"));
19
+ setIsLoading(false);
20
+ return;
21
+ }
22
+ try {
23
+ setIsLoading(true);
24
+ setError(null);
21
25
  const { data: config2 } = await axios__default.default.get(
22
26
  `/admin/membership/config/${storeId}`
23
27
  );
24
- return config2;
28
+ setData(config2);
29
+ } catch (err) {
30
+ setError(
31
+ err instanceof Error ? err : new Error("Failed to fetch config")
32
+ );
33
+ } finally {
34
+ setIsLoading(false);
25
35
  }
26
- });
36
+ };
37
+ react.useEffect(() => {
38
+ fetchConfig();
39
+ }, [storeId, options == null ? void 0 : options.enabled]);
40
+ return {
41
+ data,
42
+ isLoading,
43
+ error,
44
+ refetch: fetchConfig
45
+ };
27
46
  };
28
47
  const sdk = new Medusa__default.default({
29
48
  baseUrl: "/",
@@ -33,45 +52,102 @@ const sdk = new Medusa__default.default({
33
52
  }
34
53
  });
35
54
  const useStore = () => {
36
- return reactQuery.useQuery({
37
- queryFn: async () => {
38
- var _a;
55
+ const [data, setData] = react.useState(void 0);
56
+ const [isLoading, setIsLoading] = react.useState(true);
57
+ const [error, setError] = react.useState(null);
58
+ const fetchStore = async () => {
59
+ var _a;
60
+ try {
61
+ setIsLoading(true);
62
+ setError(null);
39
63
  const response = await sdk.admin.store.list();
40
64
  const activeStore = (_a = response.stores) == null ? void 0 : _a[0];
41
65
  if (!activeStore) {
42
66
  throw new Error("No active store found");
43
67
  }
44
- return activeStore;
45
- },
46
- queryKey: ["store"]
47
- });
68
+ setData(activeStore);
69
+ } catch (err) {
70
+ setError(err instanceof Error ? err : new Error("Failed to fetch store"));
71
+ } finally {
72
+ setIsLoading(false);
73
+ }
74
+ };
75
+ react.useEffect(() => {
76
+ fetchStore();
77
+ }, []);
78
+ return {
79
+ data,
80
+ isLoading,
81
+ error,
82
+ refetch: fetchStore
83
+ };
48
84
  };
49
85
  const usePromotionCollectable = (id) => {
50
- return reactQuery.useQuery({
51
- queryKey: ["promotion-collectable", id],
52
- queryFn: () => axios__default.default.get(`/admin/promotions/${id}/update-collectable`)
53
- });
86
+ const [data, setData] = react.useState(void 0);
87
+ const [isLoading, setIsLoading] = react.useState(true);
88
+ const [error, setError] = react.useState(null);
89
+ const fetchCollectable = async () => {
90
+ try {
91
+ setIsLoading(true);
92
+ setError(null);
93
+ const response = await axios__default.default.get(
94
+ `/admin/promotions/${id}/update-collectable`
95
+ );
96
+ setData(response);
97
+ } catch (err) {
98
+ setError(
99
+ err instanceof Error ? err : new Error("Failed to fetch collectable")
100
+ );
101
+ } finally {
102
+ setIsLoading(false);
103
+ }
104
+ };
105
+ react.useEffect(() => {
106
+ fetchCollectable();
107
+ }, [id]);
108
+ return {
109
+ data,
110
+ isLoading,
111
+ error,
112
+ refetch: fetchCollectable
113
+ };
54
114
  };
55
115
  const useUpdatePromotionCollectable = (id) => {
56
- const queryClient = reactQuery.useQueryClient();
57
- return reactQuery.useMutation({
58
- mutationFn: (data) => axios__default.default.patch(`/admin/promotions/${id}/update-collectable`, data),
59
- onSuccess: () => {
60
- queryClient.invalidateQueries({
61
- queryKey: ["promotion-collectable", id]
62
- });
116
+ const [isPending, setIsPending] = react.useState(false);
117
+ const [error, setError] = react.useState(null);
118
+ const mutate = async (data, { onSuccess } = {}) => {
119
+ try {
120
+ setIsPending(true);
121
+ setError(null);
122
+ const response = await axios__default.default.patch(
123
+ `/admin/promotions/${id}/update-collectable`,
124
+ data
125
+ );
63
126
  ui.toast.success("Coupon collection updated successfully", {
64
127
  dismissable: true,
65
128
  duration: 2500
66
129
  });
67
- },
68
- onError: () => {
130
+ if (onSuccess) {
131
+ onSuccess();
132
+ }
133
+ return response.data;
134
+ } catch (err) {
135
+ const error2 = err instanceof Error ? err : new Error("Failed to update coupon collection");
136
+ setError(error2);
69
137
  ui.toast.error("Failed to update coupon collection", {
70
138
  dismissable: true,
71
139
  duration: 2500
72
140
  });
141
+ throw error2;
142
+ } finally {
143
+ setIsPending(false);
73
144
  }
74
- });
145
+ };
146
+ return {
147
+ mutate,
148
+ isPending,
149
+ error
150
+ };
75
151
  };
76
152
  const PromotionWidget = ({ data }) => {
77
153
  const { id } = data;
@@ -119,24 +195,38 @@ adminSdk.defineWidgetConfig({
119
195
  zone: "promotion.details.side.after"
120
196
  });
121
197
  const useUpdateMembershipConfig = () => {
122
- const queryClient = reactQuery.useQueryClient();
123
- return reactQuery.useMutation({
124
- mutationFn: async ({ storeId, config: config2 }) => {
125
- if (!storeId) {
126
- throw new Error("No store id found");
127
- }
198
+ const [isPending, setIsPending] = react.useState(false);
199
+ const [error, setError] = react.useState(null);
200
+ const mutate = async ({ storeId, config: config2 }, {
201
+ onSuccess
202
+ } = {}) => {
203
+ if (!storeId) {
204
+ throw new Error("No store id found");
205
+ }
206
+ try {
207
+ setIsPending(true);
208
+ setError(null);
128
209
  const response = await axios__default.default.patch(
129
210
  `/admin/membership/config/${storeId}`,
130
211
  config2
131
212
  );
213
+ if (onSuccess) {
214
+ onSuccess(response.data);
215
+ }
132
216
  return response.data;
133
- },
134
- onSuccess: (data) => {
135
- queryClient.invalidateQueries({
136
- queryKey: ["membership-config", data.membershipConfig.store_id]
137
- });
217
+ } catch (err) {
218
+ const error2 = err instanceof Error ? err : new Error("Failed to update config");
219
+ setError(error2);
220
+ throw error2;
221
+ } finally {
222
+ setIsPending(false);
138
223
  }
139
- });
224
+ };
225
+ return {
226
+ mutate,
227
+ isPending,
228
+ error
229
+ };
140
230
  };
141
231
  const MembershipPage = () => {
142
232
  const { data: store } = useStore();
@@ -275,42 +365,93 @@ const config$2 = adminSdk.defineRouteConfig({
275
365
  icon: icons.Users
276
366
  });
277
367
  const useCreateMembershipConsent = () => {
278
- const queryClient = reactQuery.useQueryClient();
279
- return reactQuery.useMutation({
280
- mutationFn: async (data) => {
368
+ const [isPending, setIsPending] = react.useState(false);
369
+ const [error, setError] = react.useState(null);
370
+ const mutate = async (data, { onSuccess } = {}) => {
371
+ try {
372
+ setIsPending(true);
373
+ setError(null);
281
374
  const response = await axios__default.default.post("/admin/membership-consents", data);
375
+ if (onSuccess) {
376
+ onSuccess();
377
+ }
282
378
  return response.data;
283
- },
284
- onSuccess: () => {
285
- queryClient.invalidateQueries({ queryKey: ["membership-consents"] });
379
+ } catch (err) {
380
+ const error2 = err instanceof Error ? err : new Error("Failed to create consent");
381
+ setError(error2);
382
+ throw error2;
383
+ } finally {
384
+ setIsPending(false);
286
385
  }
287
- });
386
+ };
387
+ return {
388
+ mutate,
389
+ isPending,
390
+ error
391
+ };
288
392
  };
289
393
  const useDeleteMembershipConsent = () => {
290
- const queryClient = reactQuery.useQueryClient();
291
- return reactQuery.useMutation({
292
- mutationFn: async (id) => {
394
+ const [isPending, setIsPending] = react.useState(false);
395
+ const [error, setError] = react.useState(null);
396
+ const mutate = async (id, { onSuccess } = {}) => {
397
+ try {
398
+ setIsPending(true);
399
+ setError(null);
293
400
  await axios__default.default.delete(`/admin/membership-consents/${id}`);
294
- },
295
- onSuccess: () => {
296
- queryClient.invalidateQueries({ queryKey: ["membership-consents"] });
401
+ if (onSuccess) {
402
+ onSuccess();
403
+ }
404
+ } catch (err) {
405
+ const error2 = err instanceof Error ? err : new Error("Failed to delete consent");
406
+ setError(error2);
407
+ throw error2;
408
+ } finally {
409
+ setIsPending(false);
297
410
  }
298
- });
411
+ };
412
+ return {
413
+ mutate,
414
+ isPending,
415
+ error
416
+ };
299
417
  };
300
- const MEMBERSHIP_TIERS_QUERY_KEY$1 = ["membership-consents"];
301
418
  const useMembershipConsents = () => {
302
- return reactQuery.useQuery({
303
- queryKey: [...MEMBERSHIP_TIERS_QUERY_KEY$1],
304
- queryFn: async () => {
419
+ const [data, setData] = react.useState(void 0);
420
+ const [isLoading, setIsLoading] = react.useState(true);
421
+ const [error, setError] = react.useState(null);
422
+ const fetchConsents = async () => {
423
+ try {
424
+ setIsLoading(true);
425
+ setError(null);
305
426
  const response = await axios__default.default.get("/admin/membership-consents");
306
- return response.data;
427
+ setData(
428
+ response.data
429
+ );
430
+ } catch (err) {
431
+ setError(
432
+ err instanceof Error ? err : new Error("Failed to fetch consents")
433
+ );
434
+ } finally {
435
+ setIsLoading(false);
307
436
  }
308
- });
437
+ };
438
+ react.useEffect(() => {
439
+ fetchConsents();
440
+ }, []);
441
+ return {
442
+ data,
443
+ isLoading,
444
+ error,
445
+ refetch: fetchConsents
446
+ };
309
447
  };
310
448
  const useUpdateMembershipConsent = () => {
311
- const queryClient = reactQuery.useQueryClient();
312
- return reactQuery.useMutation({
313
- mutationFn: async (consentKey) => {
449
+ const [isPending, setIsPending] = react.useState(false);
450
+ const [error, setError] = react.useState(null);
451
+ const mutate = async (consentKey, { onSuccess } = {}) => {
452
+ try {
453
+ setIsPending(true);
454
+ setError(null);
314
455
  const response = await axios__default.default.patch(
315
456
  `/admin/membership-consents/${consentKey.id}`,
316
457
  {
@@ -318,12 +459,23 @@ const useUpdateMembershipConsent = () => {
318
459
  description: consentKey.description
319
460
  }
320
461
  );
462
+ if (onSuccess) {
463
+ onSuccess();
464
+ }
321
465
  return response.data;
322
- },
323
- onSuccess: () => {
324
- queryClient.invalidateQueries({ queryKey: ["membership-consents"] });
466
+ } catch (err) {
467
+ const error2 = err instanceof Error ? err : new Error("Failed to update consent");
468
+ setError(error2);
469
+ throw error2;
470
+ } finally {
471
+ setIsPending(false);
325
472
  }
326
- });
473
+ };
474
+ return {
475
+ mutate,
476
+ isPending,
477
+ error
478
+ };
327
479
  };
328
480
  const columnHelper$1 = ui.createDataTableColumnHelper();
329
481
  const columns$1 = [
@@ -535,29 +687,56 @@ const config$1 = adminSdk.defineRouteConfig({
535
687
  label: "Membership Consents"
536
688
  });
537
689
  const useCreateMembershipTier = () => {
538
- const queryClient = reactQuery.useQueryClient();
539
- return reactQuery.useMutation({
540
- mutationFn: async (data) => {
690
+ const [isPending, setIsPending] = react.useState(false);
691
+ const [error, setError] = react.useState(null);
692
+ const mutate = async (data, { onSuccess } = {}) => {
693
+ try {
694
+ setIsPending(true);
695
+ setError(null);
541
696
  const response = await axios__default.default.post("/admin/member-tiers", data);
697
+ if (onSuccess) {
698
+ onSuccess();
699
+ }
542
700
  return response.data;
543
- },
544
- onSuccess: () => {
545
- queryClient.invalidateQueries({ queryKey: ["membership-tiers"] });
701
+ } catch (err) {
702
+ const error2 = err instanceof Error ? err : new Error("Failed to create tier");
703
+ setError(error2);
704
+ throw error2;
705
+ } finally {
706
+ setIsPending(false);
546
707
  }
547
- });
708
+ };
709
+ return {
710
+ mutate,
711
+ isPending,
712
+ error
713
+ };
548
714
  };
549
715
  const useDeleteMembershipTier = () => {
550
- const queryClient = reactQuery.useQueryClient();
551
- return reactQuery.useMutation({
552
- mutationFn: async (id) => {
716
+ const [isPending, setIsPending] = react.useState(false);
717
+ const [error, setError] = react.useState(null);
718
+ const mutate = async (id, { onSuccess } = {}) => {
719
+ try {
720
+ setIsPending(true);
721
+ setError(null);
553
722
  await axios__default.default.delete(`/admin/member-tiers/${id}`);
554
- },
555
- onSuccess: () => {
556
- queryClient.invalidateQueries({ queryKey: ["member-tiers"] });
723
+ if (onSuccess) {
724
+ onSuccess();
725
+ }
726
+ } catch (err) {
727
+ const error2 = err instanceof Error ? err : new Error("Failed to delete tier");
728
+ setError(error2);
729
+ throw error2;
730
+ } finally {
731
+ setIsPending(false);
557
732
  }
558
- });
733
+ };
734
+ return {
735
+ mutate,
736
+ isPending,
737
+ error
738
+ };
559
739
  };
560
- const MEMBERSHIP_TIERS_QUERY_KEY = ["membership-tiers"];
561
740
  const useMembershipTiers = (params = {
562
741
  limit: 15,
563
742
  offset: 0,
@@ -565,32 +744,66 @@ const useMembershipTiers = (params = {
565
744
  min_points: "ASC"
566
745
  }
567
746
  }) => {
568
- return reactQuery.useQuery({
569
- queryKey: [...MEMBERSHIP_TIERS_QUERY_KEY, params],
570
- queryFn: async () => {
747
+ var _a;
748
+ const [data, setData] = react.useState(void 0);
749
+ const [isLoading, setIsLoading] = react.useState(true);
750
+ const [error, setError] = react.useState(null);
751
+ const fetchTiers = async () => {
752
+ try {
753
+ setIsLoading(true);
754
+ setError(null);
571
755
  const response = await axios__default.default.get("/admin/member-tiers", {
572
756
  params
573
757
  });
574
- return response.data;
758
+ setData(
759
+ response.data
760
+ );
761
+ } catch (err) {
762
+ setError(err instanceof Error ? err : new Error("Failed to fetch tiers"));
763
+ } finally {
764
+ setIsLoading(false);
575
765
  }
576
- });
766
+ };
767
+ react.useEffect(() => {
768
+ fetchTiers();
769
+ }, [params.limit, params.offset, (_a = params.order) == null ? void 0 : _a.min_points]);
770
+ return {
771
+ data,
772
+ isLoading,
773
+ error,
774
+ refetch: fetchTiers
775
+ };
577
776
  };
578
777
  const useUpdateMembershipTier = () => {
579
- const queryClient = reactQuery.useQueryClient();
580
- return reactQuery.useMutation({
581
- mutationFn: async (tier) => {
778
+ const [isPending, setIsPending] = react.useState(false);
779
+ const [error, setError] = react.useState(null);
780
+ const mutate = async (tier, { onSuccess } = {}) => {
781
+ try {
782
+ setIsPending(true);
783
+ setError(null);
582
784
  const response = await axios__default.default.patch(`/admin/member-tiers/${tier.id}`, {
583
785
  name: tier.name,
584
786
  description: tier.description,
585
787
  privilege_description: tier.privilege_description,
586
788
  min_points: tier.min_points
587
789
  });
790
+ if (onSuccess) {
791
+ onSuccess();
792
+ }
588
793
  return response.data;
589
- },
590
- onSuccess: () => {
591
- queryClient.invalidateQueries({ queryKey: ["member-tiers"] });
794
+ } catch (err) {
795
+ const error2 = err instanceof Error ? err : new Error("Failed to update tier");
796
+ setError(error2);
797
+ throw error2;
798
+ } finally {
799
+ setIsPending(false);
592
800
  }
593
- });
801
+ };
802
+ return {
803
+ mutate,
804
+ isPending,
805
+ error
806
+ };
594
807
  };
595
808
  const columnHelper = ui.createDataTableColumnHelper();
596
809
  const columns = [
@@ -878,11 +1091,13 @@ const formModule = { customFields: {} };
878
1091
  const displayModule = {
879
1092
  displays: {}
880
1093
  };
1094
+ const i18nModule = { resources: {} };
881
1095
  const plugin = {
882
1096
  widgetModule,
883
1097
  routeModule,
884
1098
  menuItemModule,
885
1099
  formModule,
886
- displayModule
1100
+ displayModule,
1101
+ i18nModule
887
1102
  };
888
1103
  module.exports = plugin;
@@ -2,24 +2,43 @@ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
3
3
  import { toast, Container, Heading, Switch, Label, Text, Input, Button, createDataTableColumnHelper, usePrompt, useDataTable, DataTable, Drawer, Textarea } from "@medusajs/ui";
4
4
  import axios from "axios";
5
- import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
5
+ import { useState, useEffect } from "react";
6
6
  import Medusa from "@medusajs/js-sdk";
7
7
  import { Users } from "@medusajs/icons";
8
- import { useState, useEffect } from "react";
9
8
  const useMembershipConfig = (storeId, options) => {
10
- return useQuery({
11
- ...options,
12
- queryKey: ["membership-config", storeId],
13
- queryFn: async () => {
14
- if (!storeId) {
15
- throw new Error("No store id found");
16
- }
9
+ const [data, setData] = useState(void 0);
10
+ const [isLoading, setIsLoading] = useState(true);
11
+ const [error, setError] = useState(null);
12
+ const fetchConfig = async () => {
13
+ if (!storeId) {
14
+ setError(new Error("No store id found"));
15
+ setIsLoading(false);
16
+ return;
17
+ }
18
+ try {
19
+ setIsLoading(true);
20
+ setError(null);
17
21
  const { data: config2 } = await axios.get(
18
22
  `/admin/membership/config/${storeId}`
19
23
  );
20
- return config2;
24
+ setData(config2);
25
+ } catch (err) {
26
+ setError(
27
+ err instanceof Error ? err : new Error("Failed to fetch config")
28
+ );
29
+ } finally {
30
+ setIsLoading(false);
21
31
  }
22
- });
32
+ };
33
+ useEffect(() => {
34
+ fetchConfig();
35
+ }, [storeId, options == null ? void 0 : options.enabled]);
36
+ return {
37
+ data,
38
+ isLoading,
39
+ error,
40
+ refetch: fetchConfig
41
+ };
23
42
  };
24
43
  const sdk = new Medusa({
25
44
  baseUrl: "/",
@@ -29,45 +48,102 @@ const sdk = new Medusa({
29
48
  }
30
49
  });
31
50
  const useStore = () => {
32
- return useQuery({
33
- queryFn: async () => {
34
- var _a;
51
+ const [data, setData] = useState(void 0);
52
+ const [isLoading, setIsLoading] = useState(true);
53
+ const [error, setError] = useState(null);
54
+ const fetchStore = async () => {
55
+ var _a;
56
+ try {
57
+ setIsLoading(true);
58
+ setError(null);
35
59
  const response = await sdk.admin.store.list();
36
60
  const activeStore = (_a = response.stores) == null ? void 0 : _a[0];
37
61
  if (!activeStore) {
38
62
  throw new Error("No active store found");
39
63
  }
40
- return activeStore;
41
- },
42
- queryKey: ["store"]
43
- });
64
+ setData(activeStore);
65
+ } catch (err) {
66
+ setError(err instanceof Error ? err : new Error("Failed to fetch store"));
67
+ } finally {
68
+ setIsLoading(false);
69
+ }
70
+ };
71
+ useEffect(() => {
72
+ fetchStore();
73
+ }, []);
74
+ return {
75
+ data,
76
+ isLoading,
77
+ error,
78
+ refetch: fetchStore
79
+ };
44
80
  };
45
81
  const usePromotionCollectable = (id) => {
46
- return useQuery({
47
- queryKey: ["promotion-collectable", id],
48
- queryFn: () => axios.get(`/admin/promotions/${id}/update-collectable`)
49
- });
82
+ const [data, setData] = useState(void 0);
83
+ const [isLoading, setIsLoading] = useState(true);
84
+ const [error, setError] = useState(null);
85
+ const fetchCollectable = async () => {
86
+ try {
87
+ setIsLoading(true);
88
+ setError(null);
89
+ const response = await axios.get(
90
+ `/admin/promotions/${id}/update-collectable`
91
+ );
92
+ setData(response);
93
+ } catch (err) {
94
+ setError(
95
+ err instanceof Error ? err : new Error("Failed to fetch collectable")
96
+ );
97
+ } finally {
98
+ setIsLoading(false);
99
+ }
100
+ };
101
+ useEffect(() => {
102
+ fetchCollectable();
103
+ }, [id]);
104
+ return {
105
+ data,
106
+ isLoading,
107
+ error,
108
+ refetch: fetchCollectable
109
+ };
50
110
  };
51
111
  const useUpdatePromotionCollectable = (id) => {
52
- const queryClient = useQueryClient();
53
- return useMutation({
54
- mutationFn: (data) => axios.patch(`/admin/promotions/${id}/update-collectable`, data),
55
- onSuccess: () => {
56
- queryClient.invalidateQueries({
57
- queryKey: ["promotion-collectable", id]
58
- });
112
+ const [isPending, setIsPending] = useState(false);
113
+ const [error, setError] = useState(null);
114
+ const mutate = async (data, { onSuccess } = {}) => {
115
+ try {
116
+ setIsPending(true);
117
+ setError(null);
118
+ const response = await axios.patch(
119
+ `/admin/promotions/${id}/update-collectable`,
120
+ data
121
+ );
59
122
  toast.success("Coupon collection updated successfully", {
60
123
  dismissable: true,
61
124
  duration: 2500
62
125
  });
63
- },
64
- onError: () => {
126
+ if (onSuccess) {
127
+ onSuccess();
128
+ }
129
+ return response.data;
130
+ } catch (err) {
131
+ const error2 = err instanceof Error ? err : new Error("Failed to update coupon collection");
132
+ setError(error2);
65
133
  toast.error("Failed to update coupon collection", {
66
134
  dismissable: true,
67
135
  duration: 2500
68
136
  });
137
+ throw error2;
138
+ } finally {
139
+ setIsPending(false);
69
140
  }
70
- });
141
+ };
142
+ return {
143
+ mutate,
144
+ isPending,
145
+ error
146
+ };
71
147
  };
72
148
  const PromotionWidget = ({ data }) => {
73
149
  const { id } = data;
@@ -115,24 +191,38 @@ defineWidgetConfig({
115
191
  zone: "promotion.details.side.after"
116
192
  });
117
193
  const useUpdateMembershipConfig = () => {
118
- const queryClient = useQueryClient();
119
- return useMutation({
120
- mutationFn: async ({ storeId, config: config2 }) => {
121
- if (!storeId) {
122
- throw new Error("No store id found");
123
- }
194
+ const [isPending, setIsPending] = useState(false);
195
+ const [error, setError] = useState(null);
196
+ const mutate = async ({ storeId, config: config2 }, {
197
+ onSuccess
198
+ } = {}) => {
199
+ if (!storeId) {
200
+ throw new Error("No store id found");
201
+ }
202
+ try {
203
+ setIsPending(true);
204
+ setError(null);
124
205
  const response = await axios.patch(
125
206
  `/admin/membership/config/${storeId}`,
126
207
  config2
127
208
  );
209
+ if (onSuccess) {
210
+ onSuccess(response.data);
211
+ }
128
212
  return response.data;
129
- },
130
- onSuccess: (data) => {
131
- queryClient.invalidateQueries({
132
- queryKey: ["membership-config", data.membershipConfig.store_id]
133
- });
213
+ } catch (err) {
214
+ const error2 = err instanceof Error ? err : new Error("Failed to update config");
215
+ setError(error2);
216
+ throw error2;
217
+ } finally {
218
+ setIsPending(false);
134
219
  }
135
- });
220
+ };
221
+ return {
222
+ mutate,
223
+ isPending,
224
+ error
225
+ };
136
226
  };
137
227
  const MembershipPage = () => {
138
228
  const { data: store } = useStore();
@@ -271,42 +361,93 @@ const config$2 = defineRouteConfig({
271
361
  icon: Users
272
362
  });
273
363
  const useCreateMembershipConsent = () => {
274
- const queryClient = useQueryClient();
275
- return useMutation({
276
- mutationFn: async (data) => {
364
+ const [isPending, setIsPending] = useState(false);
365
+ const [error, setError] = useState(null);
366
+ const mutate = async (data, { onSuccess } = {}) => {
367
+ try {
368
+ setIsPending(true);
369
+ setError(null);
277
370
  const response = await axios.post("/admin/membership-consents", data);
371
+ if (onSuccess) {
372
+ onSuccess();
373
+ }
278
374
  return response.data;
279
- },
280
- onSuccess: () => {
281
- queryClient.invalidateQueries({ queryKey: ["membership-consents"] });
375
+ } catch (err) {
376
+ const error2 = err instanceof Error ? err : new Error("Failed to create consent");
377
+ setError(error2);
378
+ throw error2;
379
+ } finally {
380
+ setIsPending(false);
282
381
  }
283
- });
382
+ };
383
+ return {
384
+ mutate,
385
+ isPending,
386
+ error
387
+ };
284
388
  };
285
389
  const useDeleteMembershipConsent = () => {
286
- const queryClient = useQueryClient();
287
- return useMutation({
288
- mutationFn: async (id) => {
390
+ const [isPending, setIsPending] = useState(false);
391
+ const [error, setError] = useState(null);
392
+ const mutate = async (id, { onSuccess } = {}) => {
393
+ try {
394
+ setIsPending(true);
395
+ setError(null);
289
396
  await axios.delete(`/admin/membership-consents/${id}`);
290
- },
291
- onSuccess: () => {
292
- queryClient.invalidateQueries({ queryKey: ["membership-consents"] });
397
+ if (onSuccess) {
398
+ onSuccess();
399
+ }
400
+ } catch (err) {
401
+ const error2 = err instanceof Error ? err : new Error("Failed to delete consent");
402
+ setError(error2);
403
+ throw error2;
404
+ } finally {
405
+ setIsPending(false);
293
406
  }
294
- });
407
+ };
408
+ return {
409
+ mutate,
410
+ isPending,
411
+ error
412
+ };
295
413
  };
296
- const MEMBERSHIP_TIERS_QUERY_KEY$1 = ["membership-consents"];
297
414
  const useMembershipConsents = () => {
298
- return useQuery({
299
- queryKey: [...MEMBERSHIP_TIERS_QUERY_KEY$1],
300
- queryFn: async () => {
415
+ const [data, setData] = useState(void 0);
416
+ const [isLoading, setIsLoading] = useState(true);
417
+ const [error, setError] = useState(null);
418
+ const fetchConsents = async () => {
419
+ try {
420
+ setIsLoading(true);
421
+ setError(null);
301
422
  const response = await axios.get("/admin/membership-consents");
302
- return response.data;
423
+ setData(
424
+ response.data
425
+ );
426
+ } catch (err) {
427
+ setError(
428
+ err instanceof Error ? err : new Error("Failed to fetch consents")
429
+ );
430
+ } finally {
431
+ setIsLoading(false);
303
432
  }
304
- });
433
+ };
434
+ useEffect(() => {
435
+ fetchConsents();
436
+ }, []);
437
+ return {
438
+ data,
439
+ isLoading,
440
+ error,
441
+ refetch: fetchConsents
442
+ };
305
443
  };
306
444
  const useUpdateMembershipConsent = () => {
307
- const queryClient = useQueryClient();
308
- return useMutation({
309
- mutationFn: async (consentKey) => {
445
+ const [isPending, setIsPending] = useState(false);
446
+ const [error, setError] = useState(null);
447
+ const mutate = async (consentKey, { onSuccess } = {}) => {
448
+ try {
449
+ setIsPending(true);
450
+ setError(null);
310
451
  const response = await axios.patch(
311
452
  `/admin/membership-consents/${consentKey.id}`,
312
453
  {
@@ -314,12 +455,23 @@ const useUpdateMembershipConsent = () => {
314
455
  description: consentKey.description
315
456
  }
316
457
  );
458
+ if (onSuccess) {
459
+ onSuccess();
460
+ }
317
461
  return response.data;
318
- },
319
- onSuccess: () => {
320
- queryClient.invalidateQueries({ queryKey: ["membership-consents"] });
462
+ } catch (err) {
463
+ const error2 = err instanceof Error ? err : new Error("Failed to update consent");
464
+ setError(error2);
465
+ throw error2;
466
+ } finally {
467
+ setIsPending(false);
321
468
  }
322
- });
469
+ };
470
+ return {
471
+ mutate,
472
+ isPending,
473
+ error
474
+ };
323
475
  };
324
476
  const columnHelper$1 = createDataTableColumnHelper();
325
477
  const columns$1 = [
@@ -531,29 +683,56 @@ const config$1 = defineRouteConfig({
531
683
  label: "Membership Consents"
532
684
  });
533
685
  const useCreateMembershipTier = () => {
534
- const queryClient = useQueryClient();
535
- return useMutation({
536
- mutationFn: async (data) => {
686
+ const [isPending, setIsPending] = useState(false);
687
+ const [error, setError] = useState(null);
688
+ const mutate = async (data, { onSuccess } = {}) => {
689
+ try {
690
+ setIsPending(true);
691
+ setError(null);
537
692
  const response = await axios.post("/admin/member-tiers", data);
693
+ if (onSuccess) {
694
+ onSuccess();
695
+ }
538
696
  return response.data;
539
- },
540
- onSuccess: () => {
541
- queryClient.invalidateQueries({ queryKey: ["membership-tiers"] });
697
+ } catch (err) {
698
+ const error2 = err instanceof Error ? err : new Error("Failed to create tier");
699
+ setError(error2);
700
+ throw error2;
701
+ } finally {
702
+ setIsPending(false);
542
703
  }
543
- });
704
+ };
705
+ return {
706
+ mutate,
707
+ isPending,
708
+ error
709
+ };
544
710
  };
545
711
  const useDeleteMembershipTier = () => {
546
- const queryClient = useQueryClient();
547
- return useMutation({
548
- mutationFn: async (id) => {
712
+ const [isPending, setIsPending] = useState(false);
713
+ const [error, setError] = useState(null);
714
+ const mutate = async (id, { onSuccess } = {}) => {
715
+ try {
716
+ setIsPending(true);
717
+ setError(null);
549
718
  await axios.delete(`/admin/member-tiers/${id}`);
550
- },
551
- onSuccess: () => {
552
- queryClient.invalidateQueries({ queryKey: ["member-tiers"] });
719
+ if (onSuccess) {
720
+ onSuccess();
721
+ }
722
+ } catch (err) {
723
+ const error2 = err instanceof Error ? err : new Error("Failed to delete tier");
724
+ setError(error2);
725
+ throw error2;
726
+ } finally {
727
+ setIsPending(false);
553
728
  }
554
- });
729
+ };
730
+ return {
731
+ mutate,
732
+ isPending,
733
+ error
734
+ };
555
735
  };
556
- const MEMBERSHIP_TIERS_QUERY_KEY = ["membership-tiers"];
557
736
  const useMembershipTiers = (params = {
558
737
  limit: 15,
559
738
  offset: 0,
@@ -561,32 +740,66 @@ const useMembershipTiers = (params = {
561
740
  min_points: "ASC"
562
741
  }
563
742
  }) => {
564
- return useQuery({
565
- queryKey: [...MEMBERSHIP_TIERS_QUERY_KEY, params],
566
- queryFn: async () => {
743
+ var _a;
744
+ const [data, setData] = useState(void 0);
745
+ const [isLoading, setIsLoading] = useState(true);
746
+ const [error, setError] = useState(null);
747
+ const fetchTiers = async () => {
748
+ try {
749
+ setIsLoading(true);
750
+ setError(null);
567
751
  const response = await axios.get("/admin/member-tiers", {
568
752
  params
569
753
  });
570
- return response.data;
754
+ setData(
755
+ response.data
756
+ );
757
+ } catch (err) {
758
+ setError(err instanceof Error ? err : new Error("Failed to fetch tiers"));
759
+ } finally {
760
+ setIsLoading(false);
571
761
  }
572
- });
762
+ };
763
+ useEffect(() => {
764
+ fetchTiers();
765
+ }, [params.limit, params.offset, (_a = params.order) == null ? void 0 : _a.min_points]);
766
+ return {
767
+ data,
768
+ isLoading,
769
+ error,
770
+ refetch: fetchTiers
771
+ };
573
772
  };
574
773
  const useUpdateMembershipTier = () => {
575
- const queryClient = useQueryClient();
576
- return useMutation({
577
- mutationFn: async (tier) => {
774
+ const [isPending, setIsPending] = useState(false);
775
+ const [error, setError] = useState(null);
776
+ const mutate = async (tier, { onSuccess } = {}) => {
777
+ try {
778
+ setIsPending(true);
779
+ setError(null);
578
780
  const response = await axios.patch(`/admin/member-tiers/${tier.id}`, {
579
781
  name: tier.name,
580
782
  description: tier.description,
581
783
  privilege_description: tier.privilege_description,
582
784
  min_points: tier.min_points
583
785
  });
786
+ if (onSuccess) {
787
+ onSuccess();
788
+ }
584
789
  return response.data;
585
- },
586
- onSuccess: () => {
587
- queryClient.invalidateQueries({ queryKey: ["member-tiers"] });
790
+ } catch (err) {
791
+ const error2 = err instanceof Error ? err : new Error("Failed to update tier");
792
+ setError(error2);
793
+ throw error2;
794
+ } finally {
795
+ setIsPending(false);
588
796
  }
589
- });
797
+ };
798
+ return {
799
+ mutate,
800
+ isPending,
801
+ error
802
+ };
590
803
  };
591
804
  const columnHelper = createDataTableColumnHelper();
592
805
  const columns = [
@@ -874,12 +1087,14 @@ const formModule = { customFields: {} };
874
1087
  const displayModule = {
875
1088
  displays: {}
876
1089
  };
1090
+ const i18nModule = { resources: {} };
877
1091
  const plugin = {
878
1092
  widgetModule,
879
1093
  routeModule,
880
1094
  menuItemModule,
881
1095
  formModule,
882
- displayModule
1096
+ displayModule,
1097
+ i18nModule
883
1098
  };
884
1099
  export {
885
1100
  plugin as default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lodashventure/medusa-membership",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "A starter for Medusa plugins.",
5
5
  "author": "Medusa (https://medusajs.com)",
6
6
  "license": "MIT",
@@ -29,12 +29,12 @@
29
29
  "prepublishOnly": "medusa plugin:build"
30
30
  },
31
31
  "devDependencies": {
32
- "@medusajs/admin-sdk": "2.11.0",
33
- "@medusajs/cli": "2.11.0",
34
- "@medusajs/framework": "2.11.0",
35
- "@medusajs/icons": "^2.11.0",
36
- "@medusajs/medusa": "2.11.0",
37
- "@medusajs/test-utils": "2.11.0",
32
+ "@medusajs/admin-sdk": "2.11.1",
33
+ "@medusajs/cli": "2.11.1",
34
+ "@medusajs/framework": "2.11.1",
35
+ "@medusajs/icons": "^2.11.1",
36
+ "@medusajs/medusa": "2.11.1",
37
+ "@medusajs/test-utils": "2.11.1",
38
38
  "@medusajs/ui": "4.0.4",
39
39
  "@swc/core": "1.5.7",
40
40
  "@types/node": "^20.0.0",
@@ -49,15 +49,14 @@
49
49
  "yalc": "^1.0.0-pre.53"
50
50
  },
51
51
  "peerDependencies": {
52
- "@medusajs/admin-sdk": "2.11.0",
53
- "@medusajs/cli": "2.11.0",
54
- "@medusajs/framework": "2.11.0",
55
- "@medusajs/icons": "^2.11.0",
56
- "@medusajs/js-sdk": "*",
57
- "@medusajs/medusa": "2.11.0",
58
- "@medusajs/test-utils": "2.11.0",
59
- "@medusajs/ui": "4.0.3",
60
- "@tanstack/react-query": "*"
52
+ "@medusajs/admin-sdk": "2.11.1",
53
+ "@medusajs/cli": "2.11.1",
54
+ "@medusajs/framework": "2.11.1",
55
+ "@medusajs/icons": "^2.11.1",
56
+ "@medusajs/js-sdk": "2.11.1",
57
+ "@medusajs/medusa": "2.11.1",
58
+ "@medusajs/test-utils": "2.11.1",
59
+ "@medusajs/ui": "4.0.3"
61
60
  },
62
61
  "engines": {
63
62
  "node": ">=20"