@zuplo/zudoku-plugin-monetization 0.0.43 → 0.0.44

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 +371 -136
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { D as formatDurationAdjective, E as formatDuration, O as formatDurationInterval, T as formatPrice, _ as formatPlanPrice, a as planHasDefaultTaxBehavior, b as sameEntitlementSet, c as getPlanPriceSchedule, d as PlanEntitlements, f as PlanPhaseHeader, l as PlanPriceTag, o as subscriptionTaxLegendSentence, p as EntitlementList, r as isCustomPlan, t as PricingTable, u as PlanPriceSchedule, w as formatMinorCurrencyAmount, x as categorizeRateCards, y as comparePlanEntitlements } from "./PricingTable-WkG2n7V-.mjs";
2
2
  import { cn, createPlugin, joinUrl, throwIfProblemJson } from "zudoku";
3
- import { AlertTriangleIcon, ArrowDownIcon, ArrowLeftRightIcon, ArrowUpIcon, CalendarIcon, CheckCheckIcon, CheckIcon, CircleSlashIcon, ClockIcon, CreditCardIcon, Grid2x2XIcon, InfoIcon, Loader2Icon, LockIcon, MoreVerticalIcon, RefreshCcw, RefreshCwIcon, Settings, ShieldIcon, StarsIcon, Trash2Icon, XIcon } from "zudoku/icons";
3
+ import { AlertTriangleIcon, ArrowDownIcon, ArrowLeftRightIcon, ArrowUpIcon, CalendarIcon, CheckCheckIcon, CheckIcon, ChevronDownIcon, CircleSlashIcon, ClockIcon, CreditCardIcon, Grid2x2XIcon, InfoIcon, Loader2Icon, LockIcon, MoreVerticalIcon, RefreshCcw, RefreshCwIcon, Settings, ShieldIcon, StarsIcon, Trash2Icon, XIcon } from "zudoku/icons";
4
4
  import { Link, Outlet, useLocation, useNavigate, useSearchParams } from "zudoku/router";
5
5
  import { useAuth, useZudoku } from "zudoku/hooks";
6
6
  import { QueryClient, QueryClientProvider, queryOptions, useMutation, useQuery, useQueryClient, useSuspenseQuery } from "zudoku/react-query";
@@ -9,6 +9,7 @@ import { createContext, use, useEffect, useMemo, useState } from "react";
9
9
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
10
10
  import { Alert, AlertAction, AlertDescription, AlertTitle } from "zudoku/ui/Alert";
11
11
  import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "zudoku/ui/Card";
12
+ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "zudoku/ui/Collapsible";
12
13
  import { Separator } from "zudoku/ui/Separator";
13
14
  import { Button as Button$1 } from "zudoku/ui/Button";
14
15
  import { DismissibleAlert, DismissibleAlertAction } from "zudoku/ui/DismissibleAlert";
@@ -263,8 +264,13 @@ const formatBillingCycle = (duration) => {
263
264
  * The price is derived from the plan's rate cards via {@link formatPlanPrice}
264
265
  * and rendered in the plan's own billing cadence, so it stays correct for any
265
266
  * cadence (e.g. `$2.99/hour`).
267
+ *
268
+ * Pass `collapsibleDetails` to hide the "What's included" section behind a
269
+ * collapsed-by-default toggle — used on the plan-change confirmation page where
270
+ * the current and new plan are stacked and the user opens each to compare. Pass
271
+ * `label` to render a small eyebrow above the name (e.g. "Current plan").
266
272
  */
267
- const PlanSummaryCard = ({ plan, descriptionFallback, taxAmount, taxLabel, taxInclusive, units, entitlementsItemClassName }) => {
273
+ const PlanSummaryCard = ({ plan, label, descriptionFallback, taxAmount, taxLabel, taxInclusive, units, entitlementsItemClassName, collapsibleDetails = false }) => {
268
274
  const priceLabel = formatPlanPrice(plan);
269
275
  const schedule = getPlanPriceSchedule(plan);
270
276
  const billingCycle = plan.billingCadence ? formatDuration(plan.billingCadence) : null;
@@ -287,13 +293,20 @@ const PlanSummaryCard = ({ plan, descriptionFallback, taxAmount, taxLabel, taxIn
287
293
  children: plan.name.at(0)?.toUpperCase()
288
294
  }), /* @__PURE__ */ jsxs("div", {
289
295
  className: "flex flex-col",
290
- children: [/* @__PURE__ */ jsx("span", {
291
- className: "text-lg font-bold",
292
- children: plan.name
293
- }), /* @__PURE__ */ jsx("span", {
294
- className: "text-sm font-normal text-muted-foreground",
295
- children: plan.description || descriptionFallback
296
- })]
296
+ children: [
297
+ label && /* @__PURE__ */ jsx("span", {
298
+ className: "text-xs font-medium text-muted-foreground uppercase tracking-wide",
299
+ children: label
300
+ }),
301
+ /* @__PURE__ */ jsx("span", {
302
+ className: "text-lg font-bold",
303
+ children: plan.name
304
+ }),
305
+ /* @__PURE__ */ jsx("span", {
306
+ className: "text-sm font-normal text-muted-foreground",
307
+ children: plan.description || descriptionFallback
308
+ })
309
+ ]
297
310
  })]
298
311
  }), !schedule && /* @__PURE__ */ jsxs("div", {
299
312
  className: "text-right",
@@ -314,20 +327,28 @@ const PlanSummaryCard = ({ plan, descriptionFallback, taxAmount, taxLabel, taxIn
314
327
  className: "text-right",
315
328
  children: [taxLine, billedLine]
316
329
  })]
317
- })] }), /* @__PURE__ */ jsxs(CardContent, { children: [
318
- /* @__PURE__ */ jsx(Separator, {}),
319
- /* @__PURE__ */ jsx("div", {
320
- className: "text-sm font-medium mb-3 mt-3",
321
- children: "What's included:"
322
- }),
323
- /* @__PURE__ */ jsx(PlanEntitlements, {
330
+ })] }), /* @__PURE__ */ jsxs(CardContent, { children: [/* @__PURE__ */ jsx(Separator, {}), collapsibleDetails ? /* @__PURE__ */ jsxs(Collapsible, { children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
331
+ className: "group flex w-full items-center justify-between text-sm font-medium mt-3",
332
+ children: ["Plan details", /* @__PURE__ */ jsx(ChevronDownIcon, { className: "size-4 text-muted-foreground transition-transform group-data-[state=open]:rotate-180" })]
333
+ }), /* @__PURE__ */ jsx(CollapsibleContent, {
334
+ className: "mt-3",
335
+ children: /* @__PURE__ */ jsx(PlanEntitlements, {
324
336
  phases: plan.phases,
325
337
  currency: plan.currency,
326
338
  billingCadence: plan.billingCadence,
327
339
  units,
328
340
  itemClassName: entitlementsItemClassName
329
341
  })
330
- ] })]
342
+ })] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
343
+ className: "text-sm font-medium mb-3 mt-3",
344
+ children: "What's included:"
345
+ }), /* @__PURE__ */ jsx(PlanEntitlements, {
346
+ phases: plan.phases,
347
+ currency: plan.currency,
348
+ billingCadence: plan.billingCadence,
349
+ units,
350
+ itemClassName: entitlementsItemClassName
351
+ })] })] })]
331
352
  });
332
353
  };
333
354
  //#endregion
@@ -802,76 +823,121 @@ const getSubscriptionPlanView = (subscription, options) => {
802
823
  };
803
824
  /** Whether a resolved view has any entitlements to render. */
804
825
  const hasSubscriptionEntitlements = (view) => view.usingItems ? view.entitlements.quotas.length > 0 || view.entitlements.features.length > 0 : view.fallbackPhases.some((p) => p.rateCards?.some((rc) => rc.entitlementTemplate));
805
- //#endregion
806
- //#region src/pages/components/SubscriptionEntitlements.tsx
826
+ const phaseStatus = (phase, now) => {
827
+ if (phase.activeTo && new Date(phase.activeTo).getTime() < now) return "past";
828
+ if (new Date(phase.activeFrom).getTime() > now) return "future";
829
+ return "current";
830
+ };
807
831
  /**
808
- * Render a subscription's entitlements from a resolved
809
- * {@link SubscriptionPlanView}: the active phase's *provisioned* items when
810
- * present (the real included quotas + per-unit prices), otherwise the catalog
811
- * plan's phases. Centralizes the "items, else fall back to plan phases" branch
812
- * shared by the subscription details page and the Switch Plan baseline.
813
- *
814
- * Renders `null` when there's nothing to show, so callers can wrap it with
815
- * {@link hasSubscriptionEntitlements} (for a section header / border) without
816
- * leaving an empty container behind.
832
+ * Rate cards for one subscription phase: its own provisioned items (the
833
+ * authoritative quotas/fees), falling back to the catalog plan phase with the
834
+ * same `key` when a phase (typically a future one) hasn't been provisioned yet.
817
835
  */
818
- const SubscriptionEntitlements = ({ view, currency, billingCadence, units, itemClassName }) => {
819
- if (view.usingItems) {
820
- const { quotas, features } = view.entitlements;
821
- return /* @__PURE__ */ jsx(EntitlementList, {
822
- quotas,
823
- features,
824
- itemClassName
825
- });
826
- }
827
- if (view.fallbackPhases.length === 0) return null;
828
- return /* @__PURE__ */ jsx(PlanEntitlements, {
829
- phases: view.fallbackPhases,
830
- currency,
831
- billingCadence,
832
- units,
833
- itemClassName
834
- });
836
+ const phaseRateCards = (plan, phase) => phase.items.length > 0 ? subscriptionItemsToRateCards(phase.items) : plan.phases?.find((p) => p.key === phase.key)?.rateCards ?? [];
837
+ const phasesByActiveFrom = (subscription) => [...subscription.phases].sort((a, b) => new Date(a.activeFrom).getTime() - new Date(b.activeFrom).getTime());
838
+ /**
839
+ * A clean ISO-8601 duration between two instants, preferring whole calendar
840
+ * units (years/months/weeks) over raw days so it formats the same way catalog
841
+ * plan durations do (e.g. `P1W` → "week", `P3M` → "3 months") rather than as
842
+ * "7 days" / "90 days". Returns `undefined` for a non-positive span.
843
+ */
844
+ const isoDurationBetween = (from, to) => {
845
+ const a = new Date(from);
846
+ const b = new Date(to);
847
+ const ms = b.getTime() - a.getTime();
848
+ if (!(ms > 0)) return void 0;
849
+ let months = (b.getFullYear() - a.getFullYear()) * 12 + (b.getMonth() - a.getMonth());
850
+ const anchor = new Date(a);
851
+ anchor.setMonth(a.getMonth() + months);
852
+ if (anchor.getTime() > b.getTime()) months -= 1;
853
+ const exact = new Date(a);
854
+ exact.setMonth(a.getMonth() + months);
855
+ if (months >= 1 && exact.getTime() === b.getTime()) return months % 12 === 0 ? `P${months / 12}Y` : `P${months}M`;
856
+ const days = Math.round(ms / 864e5);
857
+ if (days >= 7 && days % 7 === 0) return `P${days / 7}W`;
858
+ return `P${days}D`;
835
859
  };
836
- //#endregion
837
- //#region src/pages/components/CurrentPlanBaseline.tsx
838
860
  /**
839
- * Baseline shown at the top of the Switch Plan modal: the current plan's price
840
- * and what it actually includes, so users have a concrete reference to compare
841
- * targets against. Both the price and the entitlements come from the
842
- * subscription's *provisioned* items (real included quotas + recurring fees),
843
- * falling back to the plan's rate cards only when items aren't present — see
844
- * {@link getSubscriptionPlanView}.
861
+ * The intended length of a subscription phase: the matching catalog plan
862
+ * phase's authored `duration` when available (the cleanest source), otherwise
863
+ * computed from the phase's own `activeFrom`/`activeTo`. `undefined` for an
864
+ * open-ended (final) phase the price schedule labels that one "After that".
845
865
  */
846
- const CurrentPlanBaseline = ({ subscription, units }) => {
866
+ const phaseDuration = (plan, phase) => {
867
+ const catalog = plan.phases?.find((p) => p.key === phase.key)?.duration;
868
+ if (catalog) return catalog;
869
+ if (!phase.activeTo) return void 0;
870
+ return isoDurationBetween(phase.activeFrom, phase.activeTo);
871
+ };
872
+ /**
873
+ * Resolve EVERY phase of a subscription (not just the active one) to a
874
+ * {@link SubscriptionPhaseView}, ordered by `activeFrom` and tagged
875
+ * past/current/future. Generalizes {@link getSubscriptionPlanView}: each phase's
876
+ * price and entitlements come from its own provisioned items (the authoritative
877
+ * source), falling back to the catalog plan phase with the same `key` when a
878
+ * phase (typically a future one) hasn't been provisioned yet. Powers the
879
+ * subscription details page's current + upcoming + previous phase timeline.
880
+ */
881
+ const getSubscriptionPhaseViews = (subscription, options) => {
847
882
  const plan = subscription.plan;
848
- const view = getSubscriptionPlanView(subscription, { units });
849
- return /* @__PURE__ */ jsxs("div", {
850
- className: "border rounded-lg p-4",
851
- children: [/* @__PURE__ */ jsxs("div", {
852
- className: "flex items-start justify-between gap-3 flex-wrap",
853
- children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
854
- className: "text-xs font-medium text-muted-foreground uppercase tracking-wide",
855
- children: "Current Plan"
856
- }), /* @__PURE__ */ jsx("div", {
857
- className: "text-lg font-bold text-foreground",
858
- children: plan.name
859
- })] }), /* @__PURE__ */ jsx(PlanPriceTag, {
860
- label: view.priceLabel,
861
- currency: view.currency,
862
- billingCadence: view.billingCadence
863
- })]
864
- }), hasSubscriptionEntitlements(view) && /* @__PURE__ */ jsx("div", {
865
- className: "mt-3 pt-3 border-t",
866
- children: /* @__PURE__ */ jsx(SubscriptionEntitlements, {
867
- view,
868
- currency: view.currency,
869
- billingCadence: view.billingCadence,
870
- units
871
- })
872
- })]
883
+ const currency = subscription.currency ?? plan.currency;
884
+ const billingCadence = subscription.billingCadence ?? plan.billingCadence;
885
+ const now = Date.now();
886
+ return phasesByActiveFrom(subscription).map((phase) => {
887
+ const rateCards = phaseRateCards(plan, phase);
888
+ return {
889
+ id: phase.id,
890
+ name: phase.name,
891
+ status: phaseStatus(phase, now),
892
+ activeFrom: phase.activeFrom,
893
+ activeTo: phase.activeTo,
894
+ priceLabel: formatPlanPrice({
895
+ ...plan,
896
+ billingCadence,
897
+ phases: [{
898
+ key: phase.key,
899
+ name: phase.name,
900
+ rateCards
901
+ }]
902
+ }),
903
+ entitlements: categorizeRateCards(rateCards, {
904
+ currency,
905
+ units: options?.units,
906
+ planBillingCadence: billingCadence
907
+ }),
908
+ billingCadence,
909
+ currency
910
+ };
873
911
  });
874
912
  };
913
+ /**
914
+ * Build a catalog-shaped {@link Plan} from a subscription's *own* current and
915
+ * future phases (past phases dropped), so the plan-change confirmation page can
916
+ * render the current subscription with the exact same pricing-table card
917
+ * ({@link formatPlanPrice} / `getPlanPriceSchedule` / `PlanEntitlements`) used
918
+ * for the new plan. Each phase's rate cards come from its provisioned items
919
+ * (the authoritative source) — the embedded `subscription.plan` snapshot is
920
+ * unreliable here (it can arrive with `phases: []`), so we never read its
921
+ * phases for pricing. Each phase's `duration` is carried so the price schedule
922
+ * labels read "First 3 months" / "After that" exactly like the new plan, rather
923
+ * than falling back to the phase name (see {@link phaseDuration}).
924
+ */
925
+ const subscriptionToCurrentPlan = (subscription) => {
926
+ const plan = subscription.plan;
927
+ const now = Date.now();
928
+ const phases = phasesByActiveFrom(subscription).filter((p) => !(p.activeTo && new Date(p.activeTo).getTime() < now)).map((phase) => ({
929
+ key: phase.key,
930
+ name: phase.name,
931
+ duration: phaseDuration(plan, phase),
932
+ rateCards: phaseRateCards(plan, phase)
933
+ }));
934
+ return {
935
+ ...plan,
936
+ currency: subscription.currency ?? plan.currency,
937
+ billingCadence: subscription.billingCadence ?? plan.billingCadence,
938
+ phases
939
+ };
940
+ };
875
941
  //#endregion
876
942
  //#region src/pages/SubscriptionChangeConfirmPage.tsx
877
943
  const SubscriptionChangeConfirmPage = () => {
@@ -911,20 +977,27 @@ const SubscriptionChangeConfirmPage = () => {
911
977
  children: /* @__PURE__ */ jsxs("div", {
912
978
  className: "space-y-3",
913
979
  children: [
914
- currentSubscription && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(CurrentPlanBaseline, {
915
- subscription: currentSubscription,
916
- units: pricing?.units
980
+ currentSubscription && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(PlanSummaryCard, {
981
+ plan: subscriptionToCurrentPlan(currentSubscription),
982
+ label: "Current plan",
983
+ descriptionFallback: "",
984
+ taxLabel: "",
985
+ taxInclusive: false,
986
+ units: pricing?.units,
987
+ collapsibleDetails: true
917
988
  }), /* @__PURE__ */ jsxs("div", {
918
989
  className: "flex items-center justify-center gap-1.5 text-sm text-muted-foreground",
919
990
  children: [/* @__PURE__ */ jsx(ArrowDownIcon, { className: "size-4" }), " Changing to"]
920
991
  })] }),
921
992
  selectedPlan && /* @__PURE__ */ jsx(PlanSummaryCard, {
922
993
  plan: selectedPlan,
923
- descriptionFallback: "New plan",
994
+ label: "New plan",
995
+ descriptionFallback: "",
924
996
  taxAmount,
925
997
  taxLabel,
926
998
  taxInclusive,
927
- units: pricing?.units
999
+ units: pricing?.units,
1000
+ collapsibleDetails: true
928
1001
  }),
929
1002
  /* @__PURE__ */ jsxs("div", {
930
1003
  className: "rounded-lg bg-muted/50 p-3 text-sm space-y-1",
@@ -1446,6 +1519,76 @@ const RestoreSubscriptionDialog = ({ open, onOpenChange, planName, subscriptionI
1446
1519
  });
1447
1520
  };
1448
1521
  //#endregion
1522
+ //#region src/pages/components/SubscriptionEntitlements.tsx
1523
+ /**
1524
+ * Render a subscription's entitlements from a resolved
1525
+ * {@link SubscriptionPlanView}: the active phase's *provisioned* items when
1526
+ * present (the real included quotas + per-unit prices), otherwise the catalog
1527
+ * plan's phases. Centralizes the "items, else fall back to plan phases" branch
1528
+ * shared by the subscription details page and the Switch Plan baseline.
1529
+ *
1530
+ * Renders `null` when there's nothing to show, so callers can wrap it with
1531
+ * {@link hasSubscriptionEntitlements} (for a section header / border) without
1532
+ * leaving an empty container behind.
1533
+ */
1534
+ const SubscriptionEntitlements = ({ view, currency, billingCadence, units, itemClassName }) => {
1535
+ if (view.usingItems) {
1536
+ const { quotas, features } = view.entitlements;
1537
+ return /* @__PURE__ */ jsx(EntitlementList, {
1538
+ quotas,
1539
+ features,
1540
+ itemClassName
1541
+ });
1542
+ }
1543
+ if (view.fallbackPhases.length === 0) return null;
1544
+ return /* @__PURE__ */ jsx(PlanEntitlements, {
1545
+ phases: view.fallbackPhases,
1546
+ currency,
1547
+ billingCadence,
1548
+ units,
1549
+ itemClassName
1550
+ });
1551
+ };
1552
+ //#endregion
1553
+ //#region src/pages/components/CurrentPlanBaseline.tsx
1554
+ /**
1555
+ * Baseline shown at the top of the Switch Plan modal: the current plan's price
1556
+ * and what it actually includes, so users have a concrete reference to compare
1557
+ * targets against. Both the price and the entitlements come from the
1558
+ * subscription's *provisioned* items (real included quotas + recurring fees),
1559
+ * falling back to the plan's rate cards only when items aren't present — see
1560
+ * {@link getSubscriptionPlanView}.
1561
+ */
1562
+ const CurrentPlanBaseline = ({ subscription, units }) => {
1563
+ const plan = subscription.plan;
1564
+ const view = getSubscriptionPlanView(subscription, { units });
1565
+ return /* @__PURE__ */ jsxs("div", {
1566
+ className: "border rounded-lg p-4",
1567
+ children: [/* @__PURE__ */ jsxs("div", {
1568
+ className: "flex items-start justify-between gap-3 flex-wrap",
1569
+ children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
1570
+ className: "text-xs font-medium text-muted-foreground uppercase tracking-wide",
1571
+ children: "Current Plan"
1572
+ }), /* @__PURE__ */ jsx("div", {
1573
+ className: "text-lg font-bold text-foreground",
1574
+ children: plan.name
1575
+ })] }), /* @__PURE__ */ jsx(PlanPriceTag, {
1576
+ label: view.priceLabel,
1577
+ currency: view.currency,
1578
+ billingCadence: view.billingCadence
1579
+ })]
1580
+ }), hasSubscriptionEntitlements(view) && /* @__PURE__ */ jsx("div", {
1581
+ className: "mt-3 pt-3 border-t",
1582
+ children: /* @__PURE__ */ jsx(SubscriptionEntitlements, {
1583
+ view,
1584
+ currency: view.currency,
1585
+ billingCadence: view.billingCadence,
1586
+ units
1587
+ })
1588
+ })]
1589
+ });
1590
+ };
1591
+ //#endregion
1449
1592
  //#region src/pages/components/PlanChangeCard.tsx
1450
1593
  const MODE_LABEL = {
1451
1594
  upgrade: "Upgrade",
@@ -1924,6 +2067,75 @@ const ManageSubscription = ({ subscription, planName }) => {
1924
2067
  ] });
1925
2068
  };
1926
2069
  //#endregion
2070
+ //#region src/pages/components/SubscriptionPhases.tsx
2071
+ const phaseDateLabel = (view) => {
2072
+ if (view.status === "current") return "Current phase";
2073
+ if (view.status === "future") return `Starts ${formatDateTime(view.activeFrom)}`;
2074
+ return view.activeTo ? `${formatDateTime(view.activeFrom)} – ${formatDateTime(view.activeTo)}` : formatDateTime(view.activeFrom);
2075
+ };
2076
+ /**
2077
+ * One phase of a subscription: a header with the phase name, its timing
2078
+ * sub-label, and the phase's own price, followed by that phase's included
2079
+ * quotas/features. The header always renders (even when the phase has no
2080
+ * entitlements) so the price/timing is never hidden.
2081
+ */
2082
+ const SubscriptionPhaseSection = ({ view }) => {
2083
+ const dateLabel = phaseDateLabel(view);
2084
+ return /* @__PURE__ */ jsxs("div", {
2085
+ className: "space-y-2",
2086
+ children: [/* @__PURE__ */ jsxs("div", {
2087
+ className: "flex items-baseline justify-between gap-3",
2088
+ children: [/* @__PURE__ */ jsxs("div", {
2089
+ className: "text-sm font-medium text-card-foreground",
2090
+ children: [view.name, dateLabel && /* @__PURE__ */ jsxs("span", {
2091
+ className: "text-muted-foreground font-normal",
2092
+ children: [
2093
+ " ",
2094
+ "· ",
2095
+ dateLabel
2096
+ ]
2097
+ })]
2098
+ }), /* @__PURE__ */ jsx(PlanPriceTag, {
2099
+ label: view.priceLabel,
2100
+ currency: view.currency,
2101
+ billingCadence: view.billingCadence
2102
+ })]
2103
+ }), /* @__PURE__ */ jsx(EntitlementList, {
2104
+ quotas: view.entitlements.quotas,
2105
+ features: view.entitlements.features
2106
+ })]
2107
+ });
2108
+ };
2109
+ /**
2110
+ * The subscription's future phases (each with its start date, price, and
2111
+ * entitlements), shown after the current phase on the details page and on the
2112
+ * Switch Plan baseline. Renders nothing when there are no upcoming phases.
2113
+ */
2114
+ const UpcomingPhases = ({ subscription, units }) => {
2115
+ const future = getSubscriptionPhaseViews(subscription, { units }).filter((v) => v.status === "future");
2116
+ if (future.length === 0) return null;
2117
+ return /* @__PURE__ */ jsx("div", {
2118
+ className: "space-y-4",
2119
+ children: future.map((view) => /* @__PURE__ */ jsx(SubscriptionPhaseSection, { view }, view.id))
2120
+ });
2121
+ };
2122
+ /**
2123
+ * The subscription's already-ended phases, collapsed by default, each labelled
2124
+ * with the exact dates it ran. Lets users review what they previously paid for
2125
+ * without cluttering the page. Renders nothing when there are no past phases.
2126
+ */
2127
+ const PreviousPhases = ({ subscription, units }) => {
2128
+ const past = getSubscriptionPhaseViews(subscription, { units }).filter((v) => v.status === "past");
2129
+ if (past.length === 0) return null;
2130
+ return /* @__PURE__ */ jsxs(Collapsible, { children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
2131
+ className: "group flex w-full items-center justify-between text-sm font-medium",
2132
+ children: ["Previous phases", /* @__PURE__ */ jsx(ChevronDownIcon, { className: "size-4 text-muted-foreground transition-transform group-data-[state=open]:rotate-180" })]
2133
+ }), /* @__PURE__ */ jsx(CollapsibleContent, {
2134
+ className: "mt-3 space-y-4",
2135
+ children: past.map((view) => /* @__PURE__ */ jsx(SubscriptionPhaseSection, { view }, view.id))
2136
+ })] });
2137
+ };
2138
+ //#endregion
1927
2139
  //#region src/pages/subscriptions/SubscriptionPlanDetails.tsx
1928
2140
  const detailLabelClassName = "text-sm font-semibold tracking-wide mb-1";
1929
2141
  const sectionLabelClassName = "text-base font-semibold tracking-wide mb-3 mt-2";
@@ -1935,6 +2147,9 @@ const SubscriptionPlanDetails = ({ subscription }) => {
1935
2147
  const { priceLabel } = view;
1936
2148
  const taxLegendSentence = planHasDefaultTaxBehavior(plan) ? subscriptionTaxLegendSentence(plan.defaultTaxConfig?.behavior ?? "") : void 0;
1937
2149
  const hasEntitlements = hasSubscriptionEntitlements(view);
2150
+ const phaseViews = getSubscriptionPhaseViews(subscription, { units: pricing?.units });
2151
+ const hasUpcomingPhases = phaseViews.some((p) => p.status === "future");
2152
+ const hasPreviousPhases = phaseViews.some((p) => p.status === "past");
1938
2153
  return /* @__PURE__ */ jsxs("div", {
1939
2154
  className: "space-y-4",
1940
2155
  children: [/* @__PURE__ */ jsx(Heading, {
@@ -1945,58 +2160,78 @@ const SubscriptionPlanDetails = ({ subscription }) => {
1945
2160
  children: plan.name
1946
2161
  }), plan.description ? /* @__PURE__ */ jsx(CardDescription, { children: plan.description }) : null] }), /* @__PURE__ */ jsxs(CardContent, {
1947
2162
  className: "space-y-6",
1948
- children: [/* @__PURE__ */ jsxs("dl", {
1949
- className: "grid gap-4 sm:grid-cols-2 text-sm",
1950
- children: [
1951
- /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1952
- className: detailLabelClassName,
1953
- children: "Subscription ID"
1954
- }), /* @__PURE__ */ jsx("dd", {
1955
- className: "text-foreground font-mono text-xs break-all",
1956
- children: subscription.id
1957
- })] }),
1958
- /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1959
- className: detailLabelClassName,
1960
- children: "Active since"
1961
- }), /* @__PURE__ */ jsx("dd", {
1962
- className: "text-foreground",
1963
- children: formatDateTime(subscription.activeFrom)
1964
- })] }),
1965
- /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1966
- className: detailLabelClassName,
1967
- children: "Price"
1968
- }), /* @__PURE__ */ jsxs("dd", { children: [/* @__PURE__ */ jsx("div", {
1969
- className: "flex flex-wrap items-baseline gap-1",
1970
- children: /* @__PURE__ */ jsx(PlanPriceTag, {
1971
- label: priceLabel,
1972
- currency: view.currency,
1973
- billingCadence: view.billingCadence,
1974
- description: true
1975
- })
1976
- }), taxLegendSentence ? /* @__PURE__ */ jsx("p", {
1977
- className: "text-xs text-muted-foreground mt-1",
1978
- children: taxLegendSentence
1979
- }) : null] })] }),
1980
- /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1981
- className: detailLabelClassName,
1982
- children: "Current period"
1983
- }), /* @__PURE__ */ jsx("dd", {
1984
- className: "text-foreground",
1985
- children: subscription.alignment?.currentAlignedBillingPeriod ? formatDateTimeRange(subscription.alignment.currentAlignedBillingPeriod.from, subscription.alignment.currentAlignedBillingPeriod.to) : ""
1986
- })] })
1987
- ]
1988
- }), hasEntitlements ? /* @__PURE__ */ jsxs("div", {
1989
- className: "space-y-2 pt-2 border-t border-border",
1990
- children: [/* @__PURE__ */ jsx("p", {
1991
- className: sectionLabelClassName,
1992
- children: "What's included"
1993
- }), /* @__PURE__ */ jsx(SubscriptionEntitlements, {
1994
- view,
1995
- currency: view.currency,
1996
- billingCadence: view.billingCadence,
1997
- units: pricing?.units
1998
- })]
1999
- }) : null]
2163
+ children: [
2164
+ /* @__PURE__ */ jsxs("dl", {
2165
+ className: "grid gap-4 sm:grid-cols-2 text-sm",
2166
+ children: [
2167
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
2168
+ className: detailLabelClassName,
2169
+ children: "Subscription ID"
2170
+ }), /* @__PURE__ */ jsx("dd", {
2171
+ className: "text-foreground font-mono text-xs break-all",
2172
+ children: subscription.id
2173
+ })] }),
2174
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
2175
+ className: detailLabelClassName,
2176
+ children: "Active since"
2177
+ }), /* @__PURE__ */ jsx("dd", {
2178
+ className: "text-foreground",
2179
+ children: formatDateTime(subscription.activeFrom)
2180
+ })] }),
2181
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
2182
+ className: detailLabelClassName,
2183
+ children: "Price"
2184
+ }), /* @__PURE__ */ jsxs("dd", { children: [/* @__PURE__ */ jsx("div", {
2185
+ className: "flex flex-wrap items-baseline gap-1",
2186
+ children: /* @__PURE__ */ jsx(PlanPriceTag, {
2187
+ label: priceLabel,
2188
+ currency: view.currency,
2189
+ billingCadence: view.billingCadence,
2190
+ description: true
2191
+ })
2192
+ }), taxLegendSentence ? /* @__PURE__ */ jsx("p", {
2193
+ className: "text-xs text-muted-foreground mt-1",
2194
+ children: taxLegendSentence
2195
+ }) : null] })] }),
2196
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
2197
+ className: detailLabelClassName,
2198
+ children: "Current period"
2199
+ }), /* @__PURE__ */ jsx("dd", {
2200
+ className: "text-foreground",
2201
+ children: subscription.alignment?.currentAlignedBillingPeriod ? formatDateTimeRange(subscription.alignment.currentAlignedBillingPeriod.from, subscription.alignment.currentAlignedBillingPeriod.to) : "—"
2202
+ })] })
2203
+ ]
2204
+ }),
2205
+ hasEntitlements ? /* @__PURE__ */ jsxs("div", {
2206
+ className: "space-y-2 pt-2 border-t border-border",
2207
+ children: [/* @__PURE__ */ jsx("p", {
2208
+ className: sectionLabelClassName,
2209
+ children: "What's included"
2210
+ }), /* @__PURE__ */ jsx(SubscriptionEntitlements, {
2211
+ view,
2212
+ currency: view.currency,
2213
+ billingCadence: view.billingCadence,
2214
+ units: pricing?.units
2215
+ })]
2216
+ }) : null,
2217
+ hasUpcomingPhases ? /* @__PURE__ */ jsxs("div", {
2218
+ className: "space-y-3 pt-2 border-t border-border",
2219
+ children: [/* @__PURE__ */ jsx("p", {
2220
+ className: sectionLabelClassName,
2221
+ children: "Upcoming phases"
2222
+ }), /* @__PURE__ */ jsx(UpcomingPhases, {
2223
+ subscription,
2224
+ units: pricing?.units
2225
+ })]
2226
+ }) : null,
2227
+ hasPreviousPhases ? /* @__PURE__ */ jsx("div", {
2228
+ className: "pt-2 border-t border-border",
2229
+ children: /* @__PURE__ */ jsx(PreviousPhases, {
2230
+ subscription,
2231
+ units: pricing?.units
2232
+ })
2233
+ }) : null
2234
+ ]
2000
2235
  })] })]
2001
2236
  });
2002
2237
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/zudoku-plugin-monetization",
3
- "version": "0.0.43",
3
+ "version": "0.0.44",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/zuplo/zudoku",