@zuplo/zudoku-plugin-monetization 0.0.18 → 0.0.20
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/dist/index.mjs +64 -31
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -81,8 +81,13 @@ const useDeploymentName = () => {
|
|
|
81
81
|
|
|
82
82
|
//#endregion
|
|
83
83
|
//#region src/hooks/usePlans.ts
|
|
84
|
-
const usePlans = (
|
|
85
|
-
|
|
84
|
+
const usePlans = () => {
|
|
85
|
+
const zudoku = useZudoku();
|
|
86
|
+
const auth = useAuth();
|
|
87
|
+
return useSuspenseQuery({
|
|
88
|
+
queryKey: [`/v3/zudoku-metering/${useDeploymentName()}/pricing-page`],
|
|
89
|
+
meta: { context: auth.isAuthenticated ? zudoku : void 0 }
|
|
90
|
+
});
|
|
86
91
|
};
|
|
87
92
|
|
|
88
93
|
//#endregion
|
|
@@ -271,7 +276,7 @@ const CheckoutConfirmPage = () => {
|
|
|
271
276
|
const zudoku = useZudoku();
|
|
272
277
|
const deploymentName = useDeploymentName();
|
|
273
278
|
const navigate = useNavigate();
|
|
274
|
-
const { data: plans } = usePlans(
|
|
279
|
+
const { data: plans } = usePlans();
|
|
275
280
|
const selectedPlan = plans?.items?.find((plan) => plan.id === planId);
|
|
276
281
|
if (!planId) throw new Error("Parameter `planId` missing");
|
|
277
282
|
const rateCards = selectedPlan?.phases.at(-1)?.rateCards;
|
|
@@ -651,10 +656,7 @@ const PricingPage = ({ subtitle = "See our pricing options and choose the one th
|
|
|
651
656
|
const zudoku = useZudoku();
|
|
652
657
|
const deploymentName = useDeploymentName();
|
|
653
658
|
const auth = useAuth();
|
|
654
|
-
const { data: pricingTable } =
|
|
655
|
-
queryKey: [`/v3/zudoku-metering/${deploymentName}/pricing-page`],
|
|
656
|
-
meta: { context: auth.isAuthenticated ? zudoku : void 0 }
|
|
657
|
-
});
|
|
659
|
+
const { data: pricingTable } = usePlans();
|
|
658
660
|
const { data: subscriptions = { items: [] } } = useQuery({
|
|
659
661
|
meta: { context: zudoku },
|
|
660
662
|
queryKey: [`/v3/zudoku-metering/${deploymentName}/subscriptions`],
|
|
@@ -1187,7 +1189,12 @@ const ChangeIndicator = ({ change }) => {
|
|
|
1187
1189
|
if (change === "decrease" || change === "removed" || change === "downgraded") return /* @__PURE__ */ jsx(ArrowDownIcon, { className: "w-4 h-4 text-amber-600 shrink-0" });
|
|
1188
1190
|
return /* @__PURE__ */ jsx(CheckIcon, { className: "w-4 h-4 text-green-600 shrink-0" });
|
|
1189
1191
|
};
|
|
1190
|
-
const
|
|
1192
|
+
const modeLabelMap = {
|
|
1193
|
+
upgrade: "Upgrade",
|
|
1194
|
+
downgrade: "Downgrade",
|
|
1195
|
+
private: "Switch"
|
|
1196
|
+
};
|
|
1197
|
+
const PlanComparisonItem = ({ comparison, subscriptionId, mode, onRequestChange }) => {
|
|
1191
1198
|
const price = getPriceFromPlan(comparison.plan);
|
|
1192
1199
|
const isCustom = comparison.plan.key === "enterprise";
|
|
1193
1200
|
const displayPrice = price.monthly;
|
|
@@ -1216,14 +1223,14 @@ const PlanComparisonItem = ({ comparison, subscriptionId, onRequestChange }) =>
|
|
|
1216
1223
|
size: "sm",
|
|
1217
1224
|
children: "Contact Sales"
|
|
1218
1225
|
}) : /* @__PURE__ */ jsx(Button$1, {
|
|
1219
|
-
variant:
|
|
1226
|
+
variant: mode === "upgrade" ? "default" : "outline",
|
|
1220
1227
|
onClick: () => onRequestChange({
|
|
1221
1228
|
subscriptionId,
|
|
1222
1229
|
plan: comparison.plan,
|
|
1223
|
-
mode
|
|
1230
|
+
mode
|
|
1224
1231
|
}),
|
|
1225
1232
|
size: "sm",
|
|
1226
|
-
children:
|
|
1233
|
+
children: modeLabelMap[mode]
|
|
1227
1234
|
})]
|
|
1228
1235
|
}), hasChanges && /* @__PURE__ */ jsxs("div", {
|
|
1229
1236
|
className: "space-y-1.5",
|
|
@@ -1335,7 +1342,7 @@ const ConfirmSwitchAlert = ({ switchTo, onRequestClose }) => {
|
|
|
1335
1342
|
onSuccess: async (subscription) => {
|
|
1336
1343
|
await queryClient.invalidateQueries();
|
|
1337
1344
|
navigate(`/subscriptions/${subscription.id}`, { state: { planSwitched: {
|
|
1338
|
-
|
|
1345
|
+
mode: switchTo.mode,
|
|
1339
1346
|
newPlanName: switchTo.plan.name
|
|
1340
1347
|
} } });
|
|
1341
1348
|
onRequestClose();
|
|
@@ -1349,7 +1356,11 @@ const ConfirmSwitchAlert = ({ switchTo, onRequestClose }) => {
|
|
|
1349
1356
|
open: true,
|
|
1350
1357
|
onOpenChange: onRequestClose,
|
|
1351
1358
|
children: /* @__PURE__ */ jsxs(AlertDialogContent, { children: [/* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
|
|
1352
|
-
/* @__PURE__ */ jsxs(AlertDialogTitle, { children: [
|
|
1359
|
+
/* @__PURE__ */ jsxs(AlertDialogTitle, { children: [
|
|
1360
|
+
"Confirm",
|
|
1361
|
+
" ",
|
|
1362
|
+
switchTo.mode === "private" ? "plan change" : switchTo.mode === "upgrade" ? "upgrade" : "downgrade"
|
|
1363
|
+
] }),
|
|
1353
1364
|
mutation.isError && /* @__PURE__ */ jsx(Alert, {
|
|
1354
1365
|
variant: "destructive",
|
|
1355
1366
|
children: /* @__PURE__ */ jsx(AlertDescription, {
|
|
@@ -1357,31 +1368,34 @@ const ConfirmSwitchAlert = ({ switchTo, onRequestClose }) => {
|
|
|
1357
1368
|
children: mutation.error.message
|
|
1358
1369
|
})
|
|
1359
1370
|
}),
|
|
1360
|
-
/* @__PURE__ */ jsx(AlertDialogDescription, { children: switchTo.mode === "upgrade" ? `Are you sure you want to upgrade to ${switchTo.plan.name}? This will take effect immediately.` : `Are you sure you want to downgrade to ${switchTo.plan.name}? This will take effect at the start of your next billing cycle.` })
|
|
1371
|
+
/* @__PURE__ */ jsx(AlertDialogDescription, { children: switchTo.mode === "private" ? `Are you sure you want to switch to ${switchTo.plan.name}? This will take effect immediately.` : switchTo.mode === "upgrade" ? `Are you sure you want to upgrade to ${switchTo.plan.name}? This will take effect immediately.` : `Are you sure you want to downgrade to ${switchTo.plan.name}? This will take effect at the start of your next billing cycle.` })
|
|
1361
1372
|
] }), /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [/* @__PURE__ */ jsx(AlertDialogCancel, {
|
|
1362
1373
|
disabled: mutation.isPending,
|
|
1363
1374
|
children: "Cancel"
|
|
1364
1375
|
}), /* @__PURE__ */ jsx(ActionButton, {
|
|
1365
1376
|
isPending: mutation.isPending,
|
|
1366
1377
|
onClick: () => mutation.mutate(),
|
|
1367
|
-
children: switchTo.mode
|
|
1378
|
+
children: modeLabelMap[switchTo.mode]
|
|
1368
1379
|
})] })] })
|
|
1369
1380
|
});
|
|
1370
1381
|
};
|
|
1371
1382
|
const SwitchPlanModal = ({ subscription, children }) => {
|
|
1372
1383
|
const [open, setOpen] = useState(false);
|
|
1373
|
-
const { data: plansData } = usePlans(
|
|
1384
|
+
const { data: plansData } = usePlans();
|
|
1374
1385
|
const [switchTo, setSwitchTo] = useState(null);
|
|
1375
1386
|
const currentPlan = plansData?.items.find((p) => p.id === subscription.plan.id);
|
|
1376
|
-
const { upgrades, downgrades } = useMemo(() => {
|
|
1387
|
+
const { upgrades, downgrades, privatePlans } = useMemo(() => {
|
|
1377
1388
|
if (!plansData?.items || !currentPlan) return {
|
|
1378
1389
|
upgrades: [],
|
|
1379
|
-
downgrades: []
|
|
1390
|
+
downgrades: [],
|
|
1391
|
+
privatePlans: []
|
|
1380
1392
|
};
|
|
1393
|
+
const isPrivatePlan = (plan) => plan.metadata?.zuplo_is_private === "true";
|
|
1381
1394
|
const allComparisons = plansData.items.filter((p) => p.id !== currentPlan.id).map((plan) => comparePlans(currentPlan, plan));
|
|
1382
1395
|
return {
|
|
1383
|
-
upgrades: allComparisons.filter((c) => c.isUpgrade),
|
|
1384
|
-
downgrades: allComparisons.filter((c) => !c.isUpgrade)
|
|
1396
|
+
upgrades: allComparisons.filter((c) => c.isUpgrade && !isPrivatePlan(c.plan)),
|
|
1397
|
+
downgrades: allComparisons.filter((c) => !c.isUpgrade && !isPrivatePlan(c.plan)),
|
|
1398
|
+
privatePlans: allComparisons.filter((c) => isPrivatePlan(c.plan))
|
|
1385
1399
|
};
|
|
1386
1400
|
}, [plansData?.items, currentPlan]);
|
|
1387
1401
|
return /* @__PURE__ */ jsxs(Fragment, { children: [switchTo !== null && /* @__PURE__ */ jsx(ConfirmSwitchAlert, {
|
|
@@ -1432,11 +1446,8 @@ const SwitchPlanModal = ({ subscription, children }) => {
|
|
|
1432
1446
|
children: upgrades.map((comparison) => /* @__PURE__ */ jsx(PlanComparisonItem, {
|
|
1433
1447
|
comparison,
|
|
1434
1448
|
subscriptionId: subscription.id,
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
plan,
|
|
1438
|
-
mode: "upgrade"
|
|
1439
|
-
})
|
|
1449
|
+
mode: "upgrade",
|
|
1450
|
+
onRequestChange: setSwitchTo
|
|
1440
1451
|
}, comparison.plan.id))
|
|
1441
1452
|
})] }),
|
|
1442
1453
|
downgrades.length > 0 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
|
|
@@ -1456,11 +1467,29 @@ const SwitchPlanModal = ({ subscription, children }) => {
|
|
|
1456
1467
|
children: downgrades.map((comparison) => /* @__PURE__ */ jsx(PlanComparisonItem, {
|
|
1457
1468
|
comparison,
|
|
1458
1469
|
subscriptionId: subscription.id,
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1470
|
+
mode: "downgrade",
|
|
1471
|
+
onRequestChange: setSwitchTo
|
|
1472
|
+
}, comparison.plan.id))
|
|
1473
|
+
})] }),
|
|
1474
|
+
privatePlans.length > 0 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
|
|
1475
|
+
className: "flex items-center justify-between mb-3",
|
|
1476
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1477
|
+
className: "flex items-center gap-2",
|
|
1478
|
+
children: [/* @__PURE__ */ jsx(ArrowLeftRightIcon, { className: "size-5 text-muted-foreground" }), /* @__PURE__ */ jsx("span", {
|
|
1479
|
+
className: "font-medium text-foreground",
|
|
1480
|
+
children: "Private Plan Option"
|
|
1481
|
+
})]
|
|
1482
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1483
|
+
className: "text-sm text-muted-foreground",
|
|
1484
|
+
children: "Takes effect immediately"
|
|
1485
|
+
})]
|
|
1486
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1487
|
+
className: "space-y-3",
|
|
1488
|
+
children: privatePlans.map((comparison) => /* @__PURE__ */ jsx(PlanComparisonItem, {
|
|
1489
|
+
comparison,
|
|
1490
|
+
subscriptionId: subscription.id,
|
|
1491
|
+
mode: "private",
|
|
1492
|
+
onRequestChange: setSwitchTo
|
|
1464
1493
|
}, comparison.plan.id))
|
|
1465
1494
|
})] })
|
|
1466
1495
|
]
|
|
@@ -1717,7 +1746,11 @@ const ActiveSubscription = ({ subscription, deploymentName }) => {
|
|
|
1717
1746
|
variant: "info",
|
|
1718
1747
|
children: [
|
|
1719
1748
|
/* @__PURE__ */ jsx(CheckCheckIcon, { className: "size-4" }),
|
|
1720
|
-
/* @__PURE__ */ jsxs(AlertTitle, { children: [
|
|
1749
|
+
/* @__PURE__ */ jsxs(AlertTitle, { children: [
|
|
1750
|
+
"Plan",
|
|
1751
|
+
" ",
|
|
1752
|
+
planSwitched.mode === "upgrade" ? "upgraded" : planSwitched.mode === "downgrade" ? "downgraded" : "changed"
|
|
1753
|
+
] }),
|
|
1721
1754
|
/* @__PURE__ */ jsxs(AlertDescription, { children: [
|
|
1722
1755
|
"You have successfully switched to ",
|
|
1723
1756
|
planSwitched.newPlanName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/zudoku-plugin-monetization",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/zuplo/zudoku",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"react": "19.2.4",
|
|
32
32
|
"react-dom": "19.2.4",
|
|
33
33
|
"tsdown": "0.20.3",
|
|
34
|
-
"zudoku": "0.
|
|
34
|
+
"zudoku": "0.70.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": ">=19.2.0",
|