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