@lodashventure/medusa-membership 0.5.14 → 0.5.15
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.
- package/.medusa/server/src/admin/index.js +227 -227
- package/.medusa/server/src/admin/index.mjs +227 -227
- package/package.json +1 -1
|
@@ -361,20 +361,20 @@ const config$2 = defineRouteConfig({
|
|
|
361
361
|
label: "Membership",
|
|
362
362
|
icon: Users
|
|
363
363
|
});
|
|
364
|
-
const
|
|
364
|
+
const useCreateMembershipConsent = () => {
|
|
365
365
|
const [isPending, setIsPending] = useState(false);
|
|
366
366
|
const [error, setError] = useState(null);
|
|
367
367
|
const mutate = async (data, { onSuccess } = {}) => {
|
|
368
368
|
try {
|
|
369
369
|
setIsPending(true);
|
|
370
370
|
setError(null);
|
|
371
|
-
const response = await axios.post("/admin/
|
|
371
|
+
const response = await axios.post("/admin/membership-consents", data);
|
|
372
372
|
if (onSuccess) {
|
|
373
373
|
onSuccess();
|
|
374
374
|
}
|
|
375
375
|
return response.data;
|
|
376
376
|
} catch (err) {
|
|
377
|
-
const error2 = err instanceof Error ? err : new Error("Failed to create
|
|
377
|
+
const error2 = err instanceof Error ? err : new Error("Failed to create consent");
|
|
378
378
|
setError(error2);
|
|
379
379
|
throw error2;
|
|
380
380
|
} finally {
|
|
@@ -387,19 +387,19 @@ const useCreateMembershipTier = () => {
|
|
|
387
387
|
error
|
|
388
388
|
};
|
|
389
389
|
};
|
|
390
|
-
const
|
|
390
|
+
const useDeleteMembershipConsent = () => {
|
|
391
391
|
const [isPending, setIsPending] = useState(false);
|
|
392
392
|
const [error, setError] = useState(null);
|
|
393
393
|
const mutate = async (id, { onSuccess } = {}) => {
|
|
394
394
|
try {
|
|
395
395
|
setIsPending(true);
|
|
396
396
|
setError(null);
|
|
397
|
-
await axios.delete(`/admin/
|
|
397
|
+
await axios.delete(`/admin/membership-consents/${id}`);
|
|
398
398
|
if (onSuccess) {
|
|
399
399
|
onSuccess();
|
|
400
400
|
}
|
|
401
401
|
} catch (err) {
|
|
402
|
-
const error2 = err instanceof Error ? err : new Error("Failed to delete
|
|
402
|
+
const error2 = err instanceof Error ? err : new Error("Failed to delete consent");
|
|
403
403
|
setError(error2);
|
|
404
404
|
throw error2;
|
|
405
405
|
} finally {
|
|
@@ -412,62 +412,56 @@ const useDeleteMembershipTier = () => {
|
|
|
412
412
|
error
|
|
413
413
|
};
|
|
414
414
|
};
|
|
415
|
-
const
|
|
416
|
-
limit: 15,
|
|
417
|
-
offset: 0,
|
|
418
|
-
order: {
|
|
419
|
-
min_points: "ASC"
|
|
420
|
-
}
|
|
421
|
-
}) => {
|
|
422
|
-
var _a;
|
|
415
|
+
const useMembershipConsents = () => {
|
|
423
416
|
const [data, setData] = useState(void 0);
|
|
424
417
|
const [isLoading, setIsLoading] = useState(true);
|
|
425
418
|
const [error, setError] = useState(null);
|
|
426
|
-
const
|
|
419
|
+
const fetchConsents = async () => {
|
|
427
420
|
try {
|
|
428
421
|
setIsLoading(true);
|
|
429
422
|
setError(null);
|
|
430
|
-
const response = await axios.get("/admin/
|
|
431
|
-
params
|
|
432
|
-
});
|
|
423
|
+
const response = await axios.get("/admin/membership-consents");
|
|
433
424
|
setData(
|
|
434
425
|
response.data
|
|
435
426
|
);
|
|
436
427
|
} catch (err) {
|
|
437
|
-
setError(
|
|
428
|
+
setError(
|
|
429
|
+
err instanceof Error ? err : new Error("Failed to fetch consents")
|
|
430
|
+
);
|
|
438
431
|
} finally {
|
|
439
432
|
setIsLoading(false);
|
|
440
433
|
}
|
|
441
434
|
};
|
|
442
435
|
useEffect(() => {
|
|
443
|
-
|
|
444
|
-
}, [
|
|
436
|
+
fetchConsents();
|
|
437
|
+
}, []);
|
|
445
438
|
return {
|
|
446
439
|
data,
|
|
447
440
|
isLoading,
|
|
448
441
|
error,
|
|
449
|
-
refetch:
|
|
442
|
+
refetch: fetchConsents
|
|
450
443
|
};
|
|
451
444
|
};
|
|
452
|
-
const
|
|
445
|
+
const useUpdateMembershipConsent = () => {
|
|
453
446
|
const [isPending, setIsPending] = useState(false);
|
|
454
447
|
const [error, setError] = useState(null);
|
|
455
|
-
const mutate = async (
|
|
448
|
+
const mutate = async (consentKey, { onSuccess } = {}) => {
|
|
456
449
|
try {
|
|
457
450
|
setIsPending(true);
|
|
458
451
|
setError(null);
|
|
459
|
-
const response = await axios.patch(
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
452
|
+
const response = await axios.patch(
|
|
453
|
+
`/admin/membership-consents/${consentKey.id}`,
|
|
454
|
+
{
|
|
455
|
+
name: consentKey.name,
|
|
456
|
+
description: consentKey.description
|
|
457
|
+
}
|
|
458
|
+
);
|
|
465
459
|
if (onSuccess) {
|
|
466
460
|
onSuccess();
|
|
467
461
|
}
|
|
468
462
|
return response.data;
|
|
469
463
|
} catch (err) {
|
|
470
|
-
const error2 = err instanceof Error ? err : new Error("Failed to update
|
|
464
|
+
const error2 = err instanceof Error ? err : new Error("Failed to update consent");
|
|
471
465
|
setError(error2);
|
|
472
466
|
throw error2;
|
|
473
467
|
} finally {
|
|
@@ -482,46 +476,34 @@ const useUpdateMembershipTier = () => {
|
|
|
482
476
|
};
|
|
483
477
|
const columnHelper$1 = createDataTableColumnHelper();
|
|
484
478
|
const columns$1 = [
|
|
485
|
-
columnHelper$1.accessor("min_points", {
|
|
486
|
-
header: "Min Points"
|
|
487
|
-
}),
|
|
488
479
|
columnHelper$1.accessor("name", {
|
|
489
480
|
header: "Name"
|
|
490
481
|
}),
|
|
491
482
|
columnHelper$1.accessor("description", {
|
|
492
483
|
header: "Description",
|
|
493
484
|
maxSize: 250
|
|
494
|
-
}),
|
|
495
|
-
columnHelper$1.accessor("privilege_description", {
|
|
496
|
-
header: "Privilege Description",
|
|
497
|
-
maxSize: 250
|
|
498
485
|
})
|
|
499
486
|
];
|
|
500
|
-
const
|
|
487
|
+
const MembershipConsentsRenderer = () => {
|
|
501
488
|
const dialog = usePrompt();
|
|
502
489
|
const [pagination, setPagination] = useState({
|
|
503
490
|
pageSize: 1e3,
|
|
504
491
|
pageIndex: 0
|
|
505
492
|
});
|
|
506
493
|
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
|
507
|
-
const [
|
|
494
|
+
const [editingConsent, setEditingConsent] = useState(null);
|
|
508
495
|
const [formData, setFormData] = useState({
|
|
509
496
|
name: "",
|
|
510
|
-
description: ""
|
|
511
|
-
privilege_description: "",
|
|
512
|
-
min_points: 0
|
|
513
|
-
});
|
|
514
|
-
const { data, isLoading, refetch } = useMembershipTiers({
|
|
515
|
-
limit: pagination.pageSize,
|
|
516
|
-
offset: pagination.pageIndex * pagination.pageSize
|
|
497
|
+
description: ""
|
|
517
498
|
});
|
|
518
|
-
const
|
|
519
|
-
const
|
|
520
|
-
const
|
|
499
|
+
const { data, isLoading, refetch } = useMembershipConsents();
|
|
500
|
+
const createConsent = useCreateMembershipConsent();
|
|
501
|
+
const updateConsent = useUpdateMembershipConsent();
|
|
502
|
+
const deleteConsent = useDeleteMembershipConsent();
|
|
521
503
|
const table = useDataTable({
|
|
522
504
|
columns: columns$1,
|
|
523
|
-
data: (data == null ? void 0 : data.
|
|
524
|
-
getRowId: (
|
|
505
|
+
data: (data == null ? void 0 : data.consent_keys) || [],
|
|
506
|
+
getRowId: (consent) => consent.id,
|
|
525
507
|
rowCount: (data == null ? void 0 : data.count) || 0,
|
|
526
508
|
isLoading,
|
|
527
509
|
pagination: {
|
|
@@ -549,29 +531,25 @@ const MembershipTierRenderer = () => {
|
|
|
549
531
|
const handleReset = () => {
|
|
550
532
|
setFormData({
|
|
551
533
|
name: "",
|
|
552
|
-
description: ""
|
|
553
|
-
privilege_description: "",
|
|
554
|
-
min_points: 0
|
|
534
|
+
description: ""
|
|
555
535
|
});
|
|
556
536
|
};
|
|
557
|
-
const openDrawer = (
|
|
558
|
-
if (
|
|
559
|
-
|
|
537
|
+
const openDrawer = (consentKey) => {
|
|
538
|
+
if (consentKey) {
|
|
539
|
+
setEditingConsent(consentKey);
|
|
560
540
|
setFormData({
|
|
561
|
-
name:
|
|
562
|
-
description:
|
|
563
|
-
privilege_description: tier.privilege_description,
|
|
564
|
-
min_points: tier.min_points
|
|
541
|
+
name: consentKey.name,
|
|
542
|
+
description: consentKey.description
|
|
565
543
|
});
|
|
566
544
|
} else {
|
|
567
|
-
|
|
545
|
+
setEditingConsent(null);
|
|
568
546
|
handleReset();
|
|
569
547
|
}
|
|
570
548
|
setIsDrawerOpen(true);
|
|
571
549
|
};
|
|
572
550
|
const closeDrawer = () => {
|
|
573
551
|
setIsDrawerOpen(false);
|
|
574
|
-
|
|
552
|
+
setEditingConsent(null);
|
|
575
553
|
handleReset();
|
|
576
554
|
refetch();
|
|
577
555
|
};
|
|
@@ -582,15 +560,15 @@ const MembershipTierRenderer = () => {
|
|
|
582
560
|
toast.error("Name is required", { dismissable: true, duration: 2500 });
|
|
583
561
|
return;
|
|
584
562
|
}
|
|
585
|
-
if (
|
|
586
|
-
await
|
|
587
|
-
toast.success("
|
|
563
|
+
if (editingConsent) {
|
|
564
|
+
await updateConsent.mutateAsync({ id: editingConsent.id, ...formData });
|
|
565
|
+
toast.success("Consent updated successfully", {
|
|
588
566
|
dismissable: true,
|
|
589
567
|
duration: 2500
|
|
590
568
|
});
|
|
591
569
|
} else {
|
|
592
|
-
await
|
|
593
|
-
toast.success("
|
|
570
|
+
await createConsent.mutateAsync(formData);
|
|
571
|
+
toast.success("Consent created successfully", {
|
|
594
572
|
dismissable: true,
|
|
595
573
|
duration: 2500
|
|
596
574
|
});
|
|
@@ -598,13 +576,13 @@ const MembershipTierRenderer = () => {
|
|
|
598
576
|
closeDrawer();
|
|
599
577
|
} catch (error) {
|
|
600
578
|
if (axios.isAxiosError(error)) {
|
|
601
|
-
toast.error("Error saving
|
|
579
|
+
toast.error("Error saving consent", {
|
|
602
580
|
description: (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message,
|
|
603
581
|
dismissable: true,
|
|
604
582
|
duration: 2500
|
|
605
583
|
});
|
|
606
584
|
} else {
|
|
607
|
-
toast.error("Error saving
|
|
585
|
+
toast.error("Error saving consent", {
|
|
608
586
|
dismissable: true,
|
|
609
587
|
duration: 2500
|
|
610
588
|
});
|
|
@@ -615,27 +593,27 @@ const MembershipTierRenderer = () => {
|
|
|
615
593
|
var _a, _b;
|
|
616
594
|
try {
|
|
617
595
|
const confirmed = await dialog({
|
|
618
|
-
title: "Delete Membership
|
|
619
|
-
description: `Are you sure you want to delete the \`${
|
|
596
|
+
title: "Delete Membership Consent",
|
|
597
|
+
description: `Are you sure you want to delete the \`${editingConsent == null ? void 0 : editingConsent.name}\` consent?`
|
|
620
598
|
});
|
|
621
599
|
if (!confirmed) {
|
|
622
600
|
return;
|
|
623
601
|
}
|
|
624
|
-
await
|
|
625
|
-
toast.success("
|
|
602
|
+
await deleteConsent.mutateAsync(id);
|
|
603
|
+
toast.success("Consent deleted successfully", {
|
|
626
604
|
dismissable: true,
|
|
627
605
|
duration: 2500
|
|
628
606
|
});
|
|
629
607
|
closeDrawer();
|
|
630
608
|
} catch (error) {
|
|
631
609
|
if (axios.isAxiosError(error)) {
|
|
632
|
-
toast.error("Error deleting
|
|
610
|
+
toast.error("Error deleting consent", {
|
|
633
611
|
description: (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message,
|
|
634
612
|
dismissable: true,
|
|
635
613
|
duration: 2500
|
|
636
614
|
});
|
|
637
615
|
} else {
|
|
638
|
-
toast.error("Error deleting
|
|
616
|
+
toast.error("Error deleting consent", {
|
|
639
617
|
dismissable: true,
|
|
640
618
|
duration: 2500
|
|
641
619
|
});
|
|
@@ -645,66 +623,53 @@ const MembershipTierRenderer = () => {
|
|
|
645
623
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
646
624
|
/* @__PURE__ */ jsx(Container, { className: "flex flex-col p-0 overflow-hidden", children: /* @__PURE__ */ jsxs(DataTable, { instance: table, children: [
|
|
647
625
|
/* @__PURE__ */ jsxs(DataTable.Toolbar, { className: "flex flex-col items-start justify-between gap-2 md:flex-row md:items-center", children: [
|
|
648
|
-
/* @__PURE__ */ jsx(Heading, { children: "Membership
|
|
649
|
-
/* @__PURE__ */ jsx(Button, { onClick: () => openDrawer(), children: "Add
|
|
626
|
+
/* @__PURE__ */ jsx(Heading, { children: "Membership Consents" }),
|
|
627
|
+
/* @__PURE__ */ jsx(Button, { onClick: () => openDrawer(), children: "Add Consent" })
|
|
650
628
|
] }),
|
|
651
629
|
/* @__PURE__ */ jsx(DataTable.Table, {})
|
|
652
630
|
] }) }),
|
|
653
631
|
/* @__PURE__ */ jsx(Drawer, { open: isDrawerOpen, onOpenChange: setIsDrawerOpen, children: /* @__PURE__ */ jsxs(Drawer.Content, { children: [
|
|
654
|
-
/* @__PURE__ */ jsx(Drawer.Header, { children: /* @__PURE__ */ jsx(Drawer.Title, { children:
|
|
655
|
-
/* @__PURE__ */ jsxs(Drawer.Body, { "aria-description": "Membership
|
|
656
|
-
/* @__PURE__ */ jsxs(
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
}
|
|
685
|
-
),
|
|
686
|
-
/* @__PURE__ */ jsx(Text, { children: "Points" }),
|
|
687
|
-
/* @__PURE__ */ jsx(
|
|
688
|
-
Input,
|
|
689
|
-
{
|
|
690
|
-
name: "min_points",
|
|
691
|
-
type: "number",
|
|
692
|
-
value: formData.min_points,
|
|
693
|
-
onChange: handleInputChange
|
|
694
|
-
}
|
|
695
|
-
)
|
|
696
|
-
] }),
|
|
632
|
+
/* @__PURE__ */ jsx(Drawer.Header, { children: /* @__PURE__ */ jsx(Drawer.Title, { children: editingConsent ? "Edit Consent" : "Add Consent" }) }),
|
|
633
|
+
/* @__PURE__ */ jsxs(Drawer.Body, { "aria-description": "Membership Consent Form", children: [
|
|
634
|
+
/* @__PURE__ */ jsxs(
|
|
635
|
+
"div",
|
|
636
|
+
{
|
|
637
|
+
className: "space-y-4",
|
|
638
|
+
"aria-description": "Membership Consent Form",
|
|
639
|
+
children: [
|
|
640
|
+
/* @__PURE__ */ jsx(Text, { children: "Name" }),
|
|
641
|
+
/* @__PURE__ */ jsx(
|
|
642
|
+
Input,
|
|
643
|
+
{
|
|
644
|
+
name: "name",
|
|
645
|
+
value: formData.name,
|
|
646
|
+
onChange: handleInputChange
|
|
647
|
+
}
|
|
648
|
+
),
|
|
649
|
+
/* @__PURE__ */ jsx(Text, { children: "Description" }),
|
|
650
|
+
/* @__PURE__ */ jsx(
|
|
651
|
+
Textarea,
|
|
652
|
+
{
|
|
653
|
+
className: "truncate",
|
|
654
|
+
name: "description",
|
|
655
|
+
value: formData.description,
|
|
656
|
+
onChange: handleTextAreaChange
|
|
657
|
+
}
|
|
658
|
+
)
|
|
659
|
+
]
|
|
660
|
+
}
|
|
661
|
+
),
|
|
697
662
|
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2 mt-6", children: [
|
|
698
663
|
/* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: closeDrawer, children: "Cancel" }),
|
|
699
|
-
/* @__PURE__ */ jsx(Button, { onClick: handleSubmit, children:
|
|
664
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleSubmit, children: editingConsent ? "Update" : "Create" })
|
|
700
665
|
] })
|
|
701
666
|
] }),
|
|
702
|
-
/* @__PURE__ */ jsx(Drawer.Footer, { className: "flex justify-start", children:
|
|
667
|
+
/* @__PURE__ */ jsx(Drawer.Footer, { className: "flex justify-start", children: editingConsent && /* @__PURE__ */ jsx(
|
|
703
668
|
Button,
|
|
704
669
|
{
|
|
705
670
|
variant: "danger",
|
|
706
671
|
onClick: () => {
|
|
707
|
-
handleDelete(
|
|
672
|
+
handleDelete(editingConsent.id);
|
|
708
673
|
},
|
|
709
674
|
children: "Delete"
|
|
710
675
|
}
|
|
@@ -712,26 +677,26 @@ const MembershipTierRenderer = () => {
|
|
|
712
677
|
] }) })
|
|
713
678
|
] });
|
|
714
679
|
};
|
|
715
|
-
const
|
|
716
|
-
return /* @__PURE__ */ jsx(
|
|
680
|
+
const MembershipConsentPage = () => {
|
|
681
|
+
return /* @__PURE__ */ jsx(MembershipConsentsRenderer, {});
|
|
717
682
|
};
|
|
718
683
|
const config$1 = defineRouteConfig({
|
|
719
|
-
label: "Membership
|
|
684
|
+
label: "Membership Consents"
|
|
720
685
|
});
|
|
721
|
-
const
|
|
686
|
+
const useCreateMembershipTier = () => {
|
|
722
687
|
const [isPending, setIsPending] = useState(false);
|
|
723
688
|
const [error, setError] = useState(null);
|
|
724
689
|
const mutate = async (data, { onSuccess } = {}) => {
|
|
725
690
|
try {
|
|
726
691
|
setIsPending(true);
|
|
727
692
|
setError(null);
|
|
728
|
-
const response = await axios.post("/admin/
|
|
693
|
+
const response = await axios.post("/admin/member-tiers", data);
|
|
729
694
|
if (onSuccess) {
|
|
730
695
|
onSuccess();
|
|
731
696
|
}
|
|
732
697
|
return response.data;
|
|
733
698
|
} catch (err) {
|
|
734
|
-
const error2 = err instanceof Error ? err : new Error("Failed to create
|
|
699
|
+
const error2 = err instanceof Error ? err : new Error("Failed to create tier");
|
|
735
700
|
setError(error2);
|
|
736
701
|
throw error2;
|
|
737
702
|
} finally {
|
|
@@ -744,19 +709,19 @@ const useCreateMembershipConsent = () => {
|
|
|
744
709
|
error
|
|
745
710
|
};
|
|
746
711
|
};
|
|
747
|
-
const
|
|
712
|
+
const useDeleteMembershipTier = () => {
|
|
748
713
|
const [isPending, setIsPending] = useState(false);
|
|
749
714
|
const [error, setError] = useState(null);
|
|
750
715
|
const mutate = async (id, { onSuccess } = {}) => {
|
|
751
716
|
try {
|
|
752
717
|
setIsPending(true);
|
|
753
718
|
setError(null);
|
|
754
|
-
await axios.delete(`/admin/
|
|
719
|
+
await axios.delete(`/admin/member-tiers/${id}`);
|
|
755
720
|
if (onSuccess) {
|
|
756
721
|
onSuccess();
|
|
757
722
|
}
|
|
758
723
|
} catch (err) {
|
|
759
|
-
const error2 = err instanceof Error ? err : new Error("Failed to delete
|
|
724
|
+
const error2 = err instanceof Error ? err : new Error("Failed to delete tier");
|
|
760
725
|
setError(error2);
|
|
761
726
|
throw error2;
|
|
762
727
|
} finally {
|
|
@@ -769,56 +734,62 @@ const useDeleteMembershipConsent = () => {
|
|
|
769
734
|
error
|
|
770
735
|
};
|
|
771
736
|
};
|
|
772
|
-
const
|
|
737
|
+
const useMembershipTiers = (params = {
|
|
738
|
+
limit: 15,
|
|
739
|
+
offset: 0,
|
|
740
|
+
order: {
|
|
741
|
+
min_points: "ASC"
|
|
742
|
+
}
|
|
743
|
+
}) => {
|
|
744
|
+
var _a;
|
|
773
745
|
const [data, setData] = useState(void 0);
|
|
774
746
|
const [isLoading, setIsLoading] = useState(true);
|
|
775
747
|
const [error, setError] = useState(null);
|
|
776
|
-
const
|
|
748
|
+
const fetchTiers = async () => {
|
|
777
749
|
try {
|
|
778
750
|
setIsLoading(true);
|
|
779
751
|
setError(null);
|
|
780
|
-
const response = await axios.get("/admin/
|
|
752
|
+
const response = await axios.get("/admin/member-tiers", {
|
|
753
|
+
params
|
|
754
|
+
});
|
|
781
755
|
setData(
|
|
782
756
|
response.data
|
|
783
757
|
);
|
|
784
758
|
} catch (err) {
|
|
785
|
-
setError(
|
|
786
|
-
err instanceof Error ? err : new Error("Failed to fetch consents")
|
|
787
|
-
);
|
|
759
|
+
setError(err instanceof Error ? err : new Error("Failed to fetch tiers"));
|
|
788
760
|
} finally {
|
|
789
761
|
setIsLoading(false);
|
|
790
762
|
}
|
|
791
763
|
};
|
|
792
764
|
useEffect(() => {
|
|
793
|
-
|
|
794
|
-
}, []);
|
|
765
|
+
fetchTiers();
|
|
766
|
+
}, [params.limit, params.offset, (_a = params.order) == null ? void 0 : _a.min_points]);
|
|
795
767
|
return {
|
|
796
768
|
data,
|
|
797
769
|
isLoading,
|
|
798
770
|
error,
|
|
799
|
-
refetch:
|
|
771
|
+
refetch: fetchTiers
|
|
800
772
|
};
|
|
801
773
|
};
|
|
802
|
-
const
|
|
774
|
+
const useUpdateMembershipTier = () => {
|
|
803
775
|
const [isPending, setIsPending] = useState(false);
|
|
804
776
|
const [error, setError] = useState(null);
|
|
805
|
-
const mutate = async (
|
|
777
|
+
const mutate = async (tier, { onSuccess } = {}) => {
|
|
806
778
|
try {
|
|
807
779
|
setIsPending(true);
|
|
808
780
|
setError(null);
|
|
809
|
-
const response = await axios.patch(
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
);
|
|
781
|
+
const response = await axios.patch(`/admin/member-tiers/${tier.id}`, {
|
|
782
|
+
name: tier.name,
|
|
783
|
+
description: tier.description,
|
|
784
|
+
privilege_description: tier.privilege_description,
|
|
785
|
+
min_points: tier.min_points
|
|
786
|
+
});
|
|
816
787
|
if (onSuccess) {
|
|
817
788
|
onSuccess();
|
|
818
789
|
}
|
|
819
790
|
return response.data;
|
|
820
791
|
} catch (err) {
|
|
821
|
-
const error2 = err instanceof Error ? err : new Error("Failed to update
|
|
792
|
+
const error2 = err instanceof Error ? err : new Error("Failed to update tier");
|
|
822
793
|
setError(error2);
|
|
823
794
|
throw error2;
|
|
824
795
|
} finally {
|
|
@@ -833,34 +804,46 @@ const useUpdateMembershipConsent = () => {
|
|
|
833
804
|
};
|
|
834
805
|
const columnHelper = createDataTableColumnHelper();
|
|
835
806
|
const columns = [
|
|
807
|
+
columnHelper.accessor("min_points", {
|
|
808
|
+
header: "Min Points"
|
|
809
|
+
}),
|
|
836
810
|
columnHelper.accessor("name", {
|
|
837
811
|
header: "Name"
|
|
838
812
|
}),
|
|
839
813
|
columnHelper.accessor("description", {
|
|
840
814
|
header: "Description",
|
|
841
815
|
maxSize: 250
|
|
816
|
+
}),
|
|
817
|
+
columnHelper.accessor("privilege_description", {
|
|
818
|
+
header: "Privilege Description",
|
|
819
|
+
maxSize: 250
|
|
842
820
|
})
|
|
843
821
|
];
|
|
844
|
-
const
|
|
822
|
+
const MembershipTierRenderer = () => {
|
|
845
823
|
const dialog = usePrompt();
|
|
846
824
|
const [pagination, setPagination] = useState({
|
|
847
825
|
pageSize: 1e3,
|
|
848
826
|
pageIndex: 0
|
|
849
827
|
});
|
|
850
828
|
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
|
851
|
-
const [
|
|
829
|
+
const [editingTier, setEditingTier] = useState(null);
|
|
852
830
|
const [formData, setFormData] = useState({
|
|
853
831
|
name: "",
|
|
854
|
-
description: ""
|
|
832
|
+
description: "",
|
|
833
|
+
privilege_description: "",
|
|
834
|
+
min_points: 0
|
|
855
835
|
});
|
|
856
|
-
const { data, isLoading, refetch } =
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
836
|
+
const { data, isLoading, refetch } = useMembershipTiers({
|
|
837
|
+
limit: pagination.pageSize,
|
|
838
|
+
offset: pagination.pageIndex * pagination.pageSize
|
|
839
|
+
});
|
|
840
|
+
const createTier = useCreateMembershipTier();
|
|
841
|
+
const updateTier = useUpdateMembershipTier();
|
|
842
|
+
const deleteTier = useDeleteMembershipTier();
|
|
860
843
|
const table = useDataTable({
|
|
861
844
|
columns,
|
|
862
|
-
data: (data == null ? void 0 : data.
|
|
863
|
-
getRowId: (
|
|
845
|
+
data: (data == null ? void 0 : data.tiers) || [],
|
|
846
|
+
getRowId: (tier) => tier.id,
|
|
864
847
|
rowCount: (data == null ? void 0 : data.count) || 0,
|
|
865
848
|
isLoading,
|
|
866
849
|
pagination: {
|
|
@@ -888,25 +871,29 @@ const MembershipConsentsRenderer = () => {
|
|
|
888
871
|
const handleReset = () => {
|
|
889
872
|
setFormData({
|
|
890
873
|
name: "",
|
|
891
|
-
description: ""
|
|
874
|
+
description: "",
|
|
875
|
+
privilege_description: "",
|
|
876
|
+
min_points: 0
|
|
892
877
|
});
|
|
893
878
|
};
|
|
894
|
-
const openDrawer = (
|
|
895
|
-
if (
|
|
896
|
-
|
|
879
|
+
const openDrawer = (tier) => {
|
|
880
|
+
if (tier) {
|
|
881
|
+
setEditingTier(tier);
|
|
897
882
|
setFormData({
|
|
898
|
-
name:
|
|
899
|
-
description:
|
|
883
|
+
name: tier.name,
|
|
884
|
+
description: tier.description,
|
|
885
|
+
privilege_description: tier.privilege_description,
|
|
886
|
+
min_points: tier.min_points
|
|
900
887
|
});
|
|
901
888
|
} else {
|
|
902
|
-
|
|
889
|
+
setEditingTier(null);
|
|
903
890
|
handleReset();
|
|
904
891
|
}
|
|
905
892
|
setIsDrawerOpen(true);
|
|
906
893
|
};
|
|
907
894
|
const closeDrawer = () => {
|
|
908
895
|
setIsDrawerOpen(false);
|
|
909
|
-
|
|
896
|
+
setEditingTier(null);
|
|
910
897
|
handleReset();
|
|
911
898
|
refetch();
|
|
912
899
|
};
|
|
@@ -917,15 +904,15 @@ const MembershipConsentsRenderer = () => {
|
|
|
917
904
|
toast.error("Name is required", { dismissable: true, duration: 2500 });
|
|
918
905
|
return;
|
|
919
906
|
}
|
|
920
|
-
if (
|
|
921
|
-
await
|
|
922
|
-
toast.success("
|
|
907
|
+
if (editingTier) {
|
|
908
|
+
await updateTier.mutateAsync({ id: editingTier.id, ...formData });
|
|
909
|
+
toast.success("Tier updated successfully", {
|
|
923
910
|
dismissable: true,
|
|
924
911
|
duration: 2500
|
|
925
912
|
});
|
|
926
913
|
} else {
|
|
927
|
-
await
|
|
928
|
-
toast.success("
|
|
914
|
+
await createTier.mutateAsync(formData);
|
|
915
|
+
toast.success("Tier created successfully", {
|
|
929
916
|
dismissable: true,
|
|
930
917
|
duration: 2500
|
|
931
918
|
});
|
|
@@ -933,13 +920,13 @@ const MembershipConsentsRenderer = () => {
|
|
|
933
920
|
closeDrawer();
|
|
934
921
|
} catch (error) {
|
|
935
922
|
if (axios.isAxiosError(error)) {
|
|
936
|
-
toast.error("Error saving
|
|
923
|
+
toast.error("Error saving tier", {
|
|
937
924
|
description: (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message,
|
|
938
925
|
dismissable: true,
|
|
939
926
|
duration: 2500
|
|
940
927
|
});
|
|
941
928
|
} else {
|
|
942
|
-
toast.error("Error saving
|
|
929
|
+
toast.error("Error saving tier", {
|
|
943
930
|
dismissable: true,
|
|
944
931
|
duration: 2500
|
|
945
932
|
});
|
|
@@ -950,27 +937,27 @@ const MembershipConsentsRenderer = () => {
|
|
|
950
937
|
var _a, _b;
|
|
951
938
|
try {
|
|
952
939
|
const confirmed = await dialog({
|
|
953
|
-
title: "Delete Membership
|
|
954
|
-
description: `Are you sure you want to delete the \`${
|
|
940
|
+
title: "Delete Membership Tier",
|
|
941
|
+
description: `Are you sure you want to delete the \`${editingTier == null ? void 0 : editingTier.name}\` tier?`
|
|
955
942
|
});
|
|
956
943
|
if (!confirmed) {
|
|
957
944
|
return;
|
|
958
945
|
}
|
|
959
|
-
await
|
|
960
|
-
toast.success("
|
|
946
|
+
await deleteTier.mutateAsync(id);
|
|
947
|
+
toast.success("Tier deleted successfully", {
|
|
961
948
|
dismissable: true,
|
|
962
949
|
duration: 2500
|
|
963
950
|
});
|
|
964
951
|
closeDrawer();
|
|
965
952
|
} catch (error) {
|
|
966
953
|
if (axios.isAxiosError(error)) {
|
|
967
|
-
toast.error("Error deleting
|
|
954
|
+
toast.error("Error deleting tier", {
|
|
968
955
|
description: (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message,
|
|
969
956
|
dismissable: true,
|
|
970
957
|
duration: 2500
|
|
971
958
|
});
|
|
972
959
|
} else {
|
|
973
|
-
toast.error("Error deleting
|
|
960
|
+
toast.error("Error deleting tier", {
|
|
974
961
|
dismissable: true,
|
|
975
962
|
duration: 2500
|
|
976
963
|
});
|
|
@@ -980,53 +967,66 @@ const MembershipConsentsRenderer = () => {
|
|
|
980
967
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
981
968
|
/* @__PURE__ */ jsx(Container, { className: "flex flex-col p-0 overflow-hidden", children: /* @__PURE__ */ jsxs(DataTable, { instance: table, children: [
|
|
982
969
|
/* @__PURE__ */ jsxs(DataTable.Toolbar, { className: "flex flex-col items-start justify-between gap-2 md:flex-row md:items-center", children: [
|
|
983
|
-
/* @__PURE__ */ jsx(Heading, { children: "Membership
|
|
984
|
-
/* @__PURE__ */ jsx(Button, { onClick: () => openDrawer(), children: "Add
|
|
970
|
+
/* @__PURE__ */ jsx(Heading, { children: "Membership Tiers" }),
|
|
971
|
+
/* @__PURE__ */ jsx(Button, { onClick: () => openDrawer(), children: "Add Tier" })
|
|
985
972
|
] }),
|
|
986
973
|
/* @__PURE__ */ jsx(DataTable.Table, {})
|
|
987
974
|
] }) }),
|
|
988
975
|
/* @__PURE__ */ jsx(Drawer, { open: isDrawerOpen, onOpenChange: setIsDrawerOpen, children: /* @__PURE__ */ jsxs(Drawer.Content, { children: [
|
|
989
|
-
/* @__PURE__ */ jsx(Drawer.Header, { children: /* @__PURE__ */ jsx(Drawer.Title, { children:
|
|
990
|
-
/* @__PURE__ */ jsxs(Drawer.Body, { "aria-description": "Membership
|
|
991
|
-
/* @__PURE__ */ jsxs(
|
|
992
|
-
"
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
976
|
+
/* @__PURE__ */ jsx(Drawer.Header, { children: /* @__PURE__ */ jsx(Drawer.Title, { children: editingTier ? "Edit Tier" : "Add Tier" }) }),
|
|
977
|
+
/* @__PURE__ */ jsxs(Drawer.Body, { "aria-description": "Membership Tier Form", children: [
|
|
978
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-4", "aria-description": "Membership Tier Form", children: [
|
|
979
|
+
/* @__PURE__ */ jsx(Text, { children: "Name" }),
|
|
980
|
+
/* @__PURE__ */ jsx(
|
|
981
|
+
Input,
|
|
982
|
+
{
|
|
983
|
+
name: "name",
|
|
984
|
+
value: formData.name,
|
|
985
|
+
onChange: handleInputChange
|
|
986
|
+
}
|
|
987
|
+
),
|
|
988
|
+
/* @__PURE__ */ jsx(Text, { children: "Description" }),
|
|
989
|
+
/* @__PURE__ */ jsx(
|
|
990
|
+
Textarea,
|
|
991
|
+
{
|
|
992
|
+
className: "truncate",
|
|
993
|
+
name: "description",
|
|
994
|
+
value: formData.description,
|
|
995
|
+
onChange: handleTextAreaChange
|
|
996
|
+
}
|
|
997
|
+
),
|
|
998
|
+
/* @__PURE__ */ jsx(Text, { children: "Privilege Description" }),
|
|
999
|
+
/* @__PURE__ */ jsx(
|
|
1000
|
+
Textarea,
|
|
1001
|
+
{
|
|
1002
|
+
className: "truncate",
|
|
1003
|
+
name: "privilege_description",
|
|
1004
|
+
value: formData.privilege_description,
|
|
1005
|
+
onChange: handleTextAreaChange
|
|
1006
|
+
}
|
|
1007
|
+
),
|
|
1008
|
+
/* @__PURE__ */ jsx(Text, { children: "Points" }),
|
|
1009
|
+
/* @__PURE__ */ jsx(
|
|
1010
|
+
Input,
|
|
1011
|
+
{
|
|
1012
|
+
name: "min_points",
|
|
1013
|
+
type: "number",
|
|
1014
|
+
value: formData.min_points,
|
|
1015
|
+
onChange: handleInputChange
|
|
1016
|
+
}
|
|
1017
|
+
)
|
|
1018
|
+
] }),
|
|
1019
1019
|
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2 mt-6", children: [
|
|
1020
1020
|
/* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: closeDrawer, children: "Cancel" }),
|
|
1021
|
-
/* @__PURE__ */ jsx(Button, { onClick: handleSubmit, children:
|
|
1021
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleSubmit, children: editingTier ? "Update" : "Create" })
|
|
1022
1022
|
] })
|
|
1023
1023
|
] }),
|
|
1024
|
-
/* @__PURE__ */ jsx(Drawer.Footer, { className: "flex justify-start", children:
|
|
1024
|
+
/* @__PURE__ */ jsx(Drawer.Footer, { className: "flex justify-start", children: editingTier && /* @__PURE__ */ jsx(
|
|
1025
1025
|
Button,
|
|
1026
1026
|
{
|
|
1027
1027
|
variant: "danger",
|
|
1028
1028
|
onClick: () => {
|
|
1029
|
-
handleDelete(
|
|
1029
|
+
handleDelete(editingTier.id);
|
|
1030
1030
|
},
|
|
1031
1031
|
children: "Delete"
|
|
1032
1032
|
}
|
|
@@ -1034,11 +1034,11 @@ const MembershipConsentsRenderer = () => {
|
|
|
1034
1034
|
] }) })
|
|
1035
1035
|
] });
|
|
1036
1036
|
};
|
|
1037
|
-
const
|
|
1038
|
-
return /* @__PURE__ */ jsx(
|
|
1037
|
+
const MembershipTierPage = () => {
|
|
1038
|
+
return /* @__PURE__ */ jsx(MembershipTierRenderer, {});
|
|
1039
1039
|
};
|
|
1040
1040
|
const config = defineRouteConfig({
|
|
1041
|
-
label: "Membership
|
|
1041
|
+
label: "Membership Tiers"
|
|
1042
1042
|
});
|
|
1043
1043
|
const widgetModule = { widgets: [
|
|
1044
1044
|
{
|
|
@@ -1052,13 +1052,13 @@ const routeModule = {
|
|
|
1052
1052
|
Component: BannerUpload,
|
|
1053
1053
|
path: "/membership"
|
|
1054
1054
|
},
|
|
1055
|
-
{
|
|
1056
|
-
Component: MembershipTierPage,
|
|
1057
|
-
path: "/membership/membertier"
|
|
1058
|
-
},
|
|
1059
1055
|
{
|
|
1060
1056
|
Component: MembershipConsentPage,
|
|
1061
1057
|
path: "/membership/member-consents"
|
|
1058
|
+
},
|
|
1059
|
+
{
|
|
1060
|
+
Component: MembershipTierPage,
|
|
1061
|
+
path: "/membership/membertier"
|
|
1062
1062
|
}
|
|
1063
1063
|
]
|
|
1064
1064
|
};
|
|
@@ -1071,13 +1071,13 @@ const menuItemModule = {
|
|
|
1071
1071
|
nested: void 0
|
|
1072
1072
|
},
|
|
1073
1073
|
{
|
|
1074
|
-
label: config.label,
|
|
1074
|
+
label: config$1.label,
|
|
1075
1075
|
icon: void 0,
|
|
1076
1076
|
path: "/membership/member-consents",
|
|
1077
1077
|
nested: void 0
|
|
1078
1078
|
},
|
|
1079
1079
|
{
|
|
1080
|
-
label: config
|
|
1080
|
+
label: config.label,
|
|
1081
1081
|
icon: void 0,
|
|
1082
1082
|
path: "/membership/membertier",
|
|
1083
1083
|
nested: void 0
|