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