@zuplo/zudoku-plugin-monetization 0.0.19 → 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.
Files changed (2) hide show
  1. package/dist/index.mjs +54 -23
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1189,7 +1189,12 @@ const ChangeIndicator = ({ change }) => {
1189
1189
  if (change === "decrease" || change === "removed" || change === "downgraded") return /* @__PURE__ */ jsx(ArrowDownIcon, { className: "w-4 h-4 text-amber-600 shrink-0" });
1190
1190
  return /* @__PURE__ */ jsx(CheckIcon, { className: "w-4 h-4 text-green-600 shrink-0" });
1191
1191
  };
1192
- const PlanComparisonItem = ({ comparison, subscriptionId, onRequestChange }) => {
1192
+ const modeLabelMap = {
1193
+ upgrade: "Upgrade",
1194
+ downgrade: "Downgrade",
1195
+ private: "Switch"
1196
+ };
1197
+ const PlanComparisonItem = ({ comparison, subscriptionId, mode, onRequestChange }) => {
1193
1198
  const price = getPriceFromPlan(comparison.plan);
1194
1199
  const isCustom = comparison.plan.key === "enterprise";
1195
1200
  const displayPrice = price.monthly;
@@ -1218,14 +1223,14 @@ const PlanComparisonItem = ({ comparison, subscriptionId, onRequestChange }) =>
1218
1223
  size: "sm",
1219
1224
  children: "Contact Sales"
1220
1225
  }) : /* @__PURE__ */ jsx(Button$1, {
1221
- variant: comparison.isUpgrade ? "default" : "outline",
1226
+ variant: mode === "upgrade" ? "default" : "outline",
1222
1227
  onClick: () => onRequestChange({
1223
1228
  subscriptionId,
1224
1229
  plan: comparison.plan,
1225
- mode: comparison.isUpgrade ? "upgrade" : "downgrade"
1230
+ mode
1226
1231
  }),
1227
1232
  size: "sm",
1228
- children: comparison.isUpgrade ? "Upgrade" : "Downgrade"
1233
+ children: modeLabelMap[mode]
1229
1234
  })]
1230
1235
  }), hasChanges && /* @__PURE__ */ jsxs("div", {
1231
1236
  className: "space-y-1.5",
@@ -1337,7 +1342,7 @@ const ConfirmSwitchAlert = ({ switchTo, onRequestClose }) => {
1337
1342
  onSuccess: async (subscription) => {
1338
1343
  await queryClient.invalidateQueries();
1339
1344
  navigate(`/subscriptions/${subscription.id}`, { state: { planSwitched: {
1340
- isUpgrade: switchTo.mode === "upgrade",
1345
+ mode: switchTo.mode,
1341
1346
  newPlanName: switchTo.plan.name
1342
1347
  } } });
1343
1348
  onRequestClose();
@@ -1351,7 +1356,11 @@ const ConfirmSwitchAlert = ({ switchTo, onRequestClose }) => {
1351
1356
  open: true,
1352
1357
  onOpenChange: onRequestClose,
1353
1358
  children: /* @__PURE__ */ jsxs(AlertDialogContent, { children: [/* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
1354
- /* @__PURE__ */ jsxs(AlertDialogTitle, { children: ["Confirm ", switchTo.mode === "upgrade" ? "upgrade" : "downgrade"] }),
1359
+ /* @__PURE__ */ jsxs(AlertDialogTitle, { children: [
1360
+ "Confirm",
1361
+ " ",
1362
+ switchTo.mode === "private" ? "plan change" : switchTo.mode === "upgrade" ? "upgrade" : "downgrade"
1363
+ ] }),
1355
1364
  mutation.isError && /* @__PURE__ */ jsx(Alert, {
1356
1365
  variant: "destructive",
1357
1366
  children: /* @__PURE__ */ jsx(AlertDescription, {
@@ -1359,14 +1368,14 @@ const ConfirmSwitchAlert = ({ switchTo, onRequestClose }) => {
1359
1368
  children: mutation.error.message
1360
1369
  })
1361
1370
  }),
1362
- /* @__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.` })
1363
1372
  ] }), /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [/* @__PURE__ */ jsx(AlertDialogCancel, {
1364
1373
  disabled: mutation.isPending,
1365
1374
  children: "Cancel"
1366
1375
  }), /* @__PURE__ */ jsx(ActionButton, {
1367
1376
  isPending: mutation.isPending,
1368
1377
  onClick: () => mutation.mutate(),
1369
- children: switchTo.mode === "upgrade" ? "Upgrade" : "Downgrade"
1378
+ children: modeLabelMap[switchTo.mode]
1370
1379
  })] })] })
1371
1380
  });
1372
1381
  };
@@ -1375,15 +1384,18 @@ const SwitchPlanModal = ({ subscription, children }) => {
1375
1384
  const { data: plansData } = usePlans();
1376
1385
  const [switchTo, setSwitchTo] = useState(null);
1377
1386
  const currentPlan = plansData?.items.find((p) => p.id === subscription.plan.id);
1378
- const { upgrades, downgrades } = useMemo(() => {
1387
+ const { upgrades, downgrades, privatePlans } = useMemo(() => {
1379
1388
  if (!plansData?.items || !currentPlan) return {
1380
1389
  upgrades: [],
1381
- downgrades: []
1390
+ downgrades: [],
1391
+ privatePlans: []
1382
1392
  };
1393
+ const isPrivatePlan = (plan) => plan.metadata?.zuplo_is_private === "true";
1383
1394
  const allComparisons = plansData.items.filter((p) => p.id !== currentPlan.id).map((plan) => comparePlans(currentPlan, plan));
1384
1395
  return {
1385
- upgrades: allComparisons.filter((c) => c.isUpgrade),
1386
- 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))
1387
1399
  };
1388
1400
  }, [plansData?.items, currentPlan]);
1389
1401
  return /* @__PURE__ */ jsxs(Fragment, { children: [switchTo !== null && /* @__PURE__ */ jsx(ConfirmSwitchAlert, {
@@ -1434,11 +1446,8 @@ const SwitchPlanModal = ({ subscription, children }) => {
1434
1446
  children: upgrades.map((comparison) => /* @__PURE__ */ jsx(PlanComparisonItem, {
1435
1447
  comparison,
1436
1448
  subscriptionId: subscription.id,
1437
- onRequestChange: ({ subscriptionId, plan }) => setSwitchTo({
1438
- subscriptionId,
1439
- plan,
1440
- mode: "upgrade"
1441
- })
1449
+ mode: "upgrade",
1450
+ onRequestChange: setSwitchTo
1442
1451
  }, comparison.plan.id))
1443
1452
  })] }),
1444
1453
  downgrades.length > 0 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
@@ -1458,11 +1467,29 @@ const SwitchPlanModal = ({ subscription, children }) => {
1458
1467
  children: downgrades.map((comparison) => /* @__PURE__ */ jsx(PlanComparisonItem, {
1459
1468
  comparison,
1460
1469
  subscriptionId: subscription.id,
1461
- onRequestChange: ({ subscriptionId, plan }) => setSwitchTo({
1462
- subscriptionId,
1463
- plan,
1464
- mode: "downgrade"
1465
- })
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
1466
1493
  }, comparison.plan.id))
1467
1494
  })] })
1468
1495
  ]
@@ -1719,7 +1746,11 @@ const ActiveSubscription = ({ subscription, deploymentName }) => {
1719
1746
  variant: "info",
1720
1747
  children: [
1721
1748
  /* @__PURE__ */ jsx(CheckCheckIcon, { className: "size-4" }),
1722
- /* @__PURE__ */ jsxs(AlertTitle, { children: ["Plan ", planSwitched.isUpgrade ? "upgraded" : "downgraded"] }),
1749
+ /* @__PURE__ */ jsxs(AlertTitle, { children: [
1750
+ "Plan",
1751
+ " ",
1752
+ planSwitched.mode === "upgrade" ? "upgraded" : planSwitched.mode === "downgrade" ? "downgraded" : "changed"
1753
+ ] }),
1723
1754
  /* @__PURE__ */ jsxs(AlertDescription, { children: [
1724
1755
  "You have successfully switched to ",
1725
1756
  planSwitched.newPlanName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/zudoku-plugin-monetization",
3
- "version": "0.0.19",
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.69.3"
34
+ "zudoku": "0.70.2"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "react": ">=19.2.0",