@mmailaender/convex-creem 0.1.0
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/LICENSE +201 -0
- package/README.md +1176 -0
- package/dist/client/helpers.d.ts +17 -0
- package/dist/client/helpers.d.ts.map +1 -0
- package/dist/client/helpers.js +43 -0
- package/dist/client/helpers.js.map +1 -0
- package/dist/client/index.d.ts +1041 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +1068 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/parsers.d.ts +45 -0
- package/dist/client/parsers.d.ts.map +1 -0
- package/dist/client/parsers.js +138 -0
- package/dist/client/parsers.js.map +1 -0
- package/dist/client/polyfill.d.ts +2 -0
- package/dist/client/polyfill.d.ts.map +1 -0
- package/dist/client/polyfill.js +3 -0
- package/dist/client/polyfill.js.map +1 -0
- package/dist/component/_generated/api.d.ts +36 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +542 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +3 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/lib.d.ts +1005 -0
- package/dist/component/lib.d.ts.map +1 -0
- package/dist/component/lib.js +647 -0
- package/dist/component/lib.js.map +1 -0
- package/dist/component/schema.d.ts +191 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +104 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/util.d.ts +61 -0
- package/dist/component/util.d.ts.map +1 -0
- package/dist/component/util.js +142 -0
- package/dist/component/util.js.map +1 -0
- package/dist/core/catalog.d.ts +18 -0
- package/dist/core/catalog.d.ts.map +1 -0
- package/dist/core/catalog.js +82 -0
- package/dist/core/catalog.js.map +1 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/markdown.d.ts +12 -0
- package/dist/core/markdown.d.ts.map +1 -0
- package/dist/core/markdown.js +26 -0
- package/dist/core/markdown.js.map +1 -0
- package/dist/core/payments.d.ts +11 -0
- package/dist/core/payments.d.ts.map +1 -0
- package/dist/core/payments.js +27 -0
- package/dist/core/payments.js.map +1 -0
- package/dist/core/pendingCheckout.d.ts +15 -0
- package/dist/core/pendingCheckout.d.ts.map +1 -0
- package/dist/core/pendingCheckout.js +40 -0
- package/dist/core/pendingCheckout.js.map +1 -0
- package/dist/core/resolver.d.ts +11 -0
- package/dist/core/resolver.d.ts.map +1 -0
- package/dist/core/resolver.js +106 -0
- package/dist/core/resolver.js.map +1 -0
- package/dist/core/selectors.d.ts +12 -0
- package/dist/core/selectors.d.ts.map +1 -0
- package/dist/core/selectors.js +18 -0
- package/dist/core/selectors.js.map +1 -0
- package/dist/core/subscriptionUpdate.d.ts +20 -0
- package/dist/core/subscriptionUpdate.d.ts.map +1 -0
- package/dist/core/subscriptionUpdate.js +64 -0
- package/dist/core/subscriptionUpdate.js.map +1 -0
- package/dist/core/types.d.ts +170 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +15 -0
- package/dist/core/types.js.map +1 -0
- package/dist/design-system/colors/color-utils.d.ts +10 -0
- package/dist/design-system/colors/color-utils.d.ts.map +1 -0
- package/dist/design-system/colors/color-utils.js +91 -0
- package/dist/design-system/colors/color-utils.js.map +1 -0
- package/dist/design-system/colors/config.d.ts +33 -0
- package/dist/design-system/colors/config.d.ts.map +1 -0
- package/dist/design-system/colors/config.js +224 -0
- package/dist/design-system/colors/config.js.map +1 -0
- package/dist/design-system/colors/index.d.ts +3 -0
- package/dist/design-system/colors/index.d.ts.map +1 -0
- package/dist/design-system/colors/index.js +3 -0
- package/dist/design-system/colors/index.js.map +1 -0
- package/dist/design-system/rounded/config.d.ts +31 -0
- package/dist/design-system/rounded/config.d.ts.map +1 -0
- package/dist/design-system/rounded/config.js +76 -0
- package/dist/design-system/rounded/config.js.map +1 -0
- package/dist/design-system/rounded/index.d.ts +2 -0
- package/dist/design-system/rounded/index.d.ts.map +1 -0
- package/dist/design-system/rounded/index.js +2 -0
- package/dist/design-system/rounded/index.js.map +1 -0
- package/dist/design-system/typography/config.d.ts +55 -0
- package/dist/design-system/typography/config.d.ts.map +1 -0
- package/dist/design-system/typography/config.js +308 -0
- package/dist/design-system/typography/config.js.map +1 -0
- package/dist/design-system/typography/index.d.ts +3 -0
- package/dist/design-system/typography/index.d.ts.map +1 -0
- package/dist/design-system/typography/index.js +3 -0
- package/dist/design-system/typography/index.js.map +1 -0
- package/dist/design-system/typography/tokens.d.ts +23 -0
- package/dist/design-system/typography/tokens.d.ts.map +1 -0
- package/dist/design-system/typography/tokens.js +99 -0
- package/dist/design-system/typography/tokens.js.map +1 -0
- package/dist/react/hooks/useCheckoutSuccessParams.d.ts +2 -0
- package/dist/react/hooks/useCheckoutSuccessParams.d.ts.map +1 -0
- package/dist/react/hooks/useCheckoutSuccessParams.js +5 -0
- package/dist/react/hooks/useCheckoutSuccessParams.js.map +1 -0
- package/dist/react/index.d.ts +25 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +22 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/primitives/BillingGate.d.ts +8 -0
- package/dist/react/primitives/BillingGate.d.ts.map +1 -0
- package/dist/react/primitives/BillingGate.js +13 -0
- package/dist/react/primitives/BillingGate.js.map +1 -0
- package/dist/react/primitives/BillingToggle.d.ts +8 -0
- package/dist/react/primitives/BillingToggle.d.ts.map +1 -0
- package/dist/react/primitives/BillingToggle.js +12 -0
- package/dist/react/primitives/BillingToggle.js.map +1 -0
- package/dist/react/primitives/CheckoutButton.d.ts +11 -0
- package/dist/react/primitives/CheckoutButton.d.ts.map +1 -0
- package/dist/react/primitives/CheckoutButton.js +21 -0
- package/dist/react/primitives/CheckoutButton.js.map +1 -0
- package/dist/react/primitives/CheckoutSuccessSummary.d.ts +7 -0
- package/dist/react/primitives/CheckoutSuccessSummary.d.ts.map +1 -0
- package/dist/react/primitives/CheckoutSuccessSummary.js +11 -0
- package/dist/react/primitives/CheckoutSuccessSummary.js.map +1 -0
- package/dist/react/primitives/CustomerPortalButton.d.ts +8 -0
- package/dist/react/primitives/CustomerPortalButton.d.ts.map +1 -0
- package/dist/react/primitives/CustomerPortalButton.js +21 -0
- package/dist/react/primitives/CustomerPortalButton.js.map +1 -0
- package/dist/react/primitives/NumberInput.d.ts +11 -0
- package/dist/react/primitives/NumberInput.d.ts.map +1 -0
- package/dist/react/primitives/NumberInput.js +18 -0
- package/dist/react/primitives/NumberInput.js.map +1 -0
- package/dist/react/primitives/OneTimeCheckoutButton.d.ts +11 -0
- package/dist/react/primitives/OneTimeCheckoutButton.d.ts.map +1 -0
- package/dist/react/primitives/OneTimeCheckoutButton.js +4 -0
- package/dist/react/primitives/OneTimeCheckoutButton.js.map +1 -0
- package/dist/react/primitives/OneTimePaymentStatusBadge.d.ts +6 -0
- package/dist/react/primitives/OneTimePaymentStatusBadge.d.ts.map +1 -0
- package/dist/react/primitives/OneTimePaymentStatusBadge.js +11 -0
- package/dist/react/primitives/OneTimePaymentStatusBadge.js.map +1 -0
- package/dist/react/primitives/PaymentWarningBanner.d.ts +7 -0
- package/dist/react/primitives/PaymentWarningBanner.d.ts.map +1 -0
- package/dist/react/primitives/PaymentWarningBanner.js +18 -0
- package/dist/react/primitives/PaymentWarningBanner.js.map +1 -0
- package/dist/react/primitives/PricingCard.d.ts +37 -0
- package/dist/react/primitives/PricingCard.d.ts.map +1 -0
- package/dist/react/primitives/PricingCard.js +125 -0
- package/dist/react/primitives/PricingCard.js.map +1 -0
- package/dist/react/primitives/PricingSection.d.ts +39 -0
- package/dist/react/primitives/PricingSection.d.ts.map +1 -0
- package/dist/react/primitives/PricingSection.js +24 -0
- package/dist/react/primitives/PricingSection.js.map +1 -0
- package/dist/react/primitives/ScheduledChangeBanner.d.ts +8 -0
- package/dist/react/primitives/ScheduledChangeBanner.d.ts.map +1 -0
- package/dist/react/primitives/ScheduledChangeBanner.js +13 -0
- package/dist/react/primitives/ScheduledChangeBanner.js.map +1 -0
- package/dist/react/primitives/SegmentControl.d.ts +11 -0
- package/dist/react/primitives/SegmentControl.d.ts.map +1 -0
- package/dist/react/primitives/SegmentControl.js +8 -0
- package/dist/react/primitives/SegmentControl.js.map +1 -0
- package/dist/react/primitives/SegmentGroup.d.ts +14 -0
- package/dist/react/primitives/SegmentGroup.d.ts.map +1 -0
- package/dist/react/primitives/SegmentGroup.js +11 -0
- package/dist/react/primitives/SegmentGroup.js.map +1 -0
- package/dist/react/primitives/TrialLimitBanner.d.ts +7 -0
- package/dist/react/primitives/TrialLimitBanner.d.ts.map +1 -0
- package/dist/react/primitives/TrialLimitBanner.js +14 -0
- package/dist/react/primitives/TrialLimitBanner.js.map +1 -0
- package/dist/react/shared.d.ts +28 -0
- package/dist/react/shared.d.ts.map +1 -0
- package/dist/react/shared.js +109 -0
- package/dist/react/shared.js.map +1 -0
- package/dist/react/widgets/BillingPortal.d.ts +9 -0
- package/dist/react/widgets/BillingPortal.d.ts.map +1 -0
- package/dist/react/widgets/BillingPortal.js +30 -0
- package/dist/react/widgets/BillingPortal.js.map +1 -0
- package/dist/react/widgets/ProductItem.d.ts +8 -0
- package/dist/react/widgets/ProductItem.d.ts.map +1 -0
- package/dist/react/widgets/ProductItem.js +14 -0
- package/dist/react/widgets/ProductItem.js.map +1 -0
- package/dist/react/widgets/ProductRoot.d.ts +16 -0
- package/dist/react/widgets/ProductRoot.d.ts.map +1 -0
- package/dist/react/widgets/ProductRoot.js +171 -0
- package/dist/react/widgets/ProductRoot.js.map +1 -0
- package/dist/react/widgets/SubscriptionItem.d.ts +27 -0
- package/dist/react/widgets/SubscriptionItem.d.ts.map +1 -0
- package/dist/react/widgets/SubscriptionItem.js +32 -0
- package/dist/react/widgets/SubscriptionItem.js.map +1 -0
- package/dist/react/widgets/SubscriptionRoot.d.ts +16 -0
- package/dist/react/widgets/SubscriptionRoot.d.ts.map +1 -0
- package/dist/react/widgets/SubscriptionRoot.js +405 -0
- package/dist/react/widgets/SubscriptionRoot.js.map +1 -0
- package/dist/react/widgets/index.d.ts +19 -0
- package/dist/react/widgets/index.d.ts.map +1 -0
- package/dist/react/widgets/index.js +16 -0
- package/dist/react/widgets/index.js.map +1 -0
- package/dist/react/widgets/productGroupContext.d.ts +6 -0
- package/dist/react/widgets/productGroupContext.d.ts.map +1 -0
- package/dist/react/widgets/productGroupContext.js +3 -0
- package/dist/react/widgets/productGroupContext.js.map +1 -0
- package/dist/react/widgets/subscriptionContext.d.ts +6 -0
- package/dist/react/widgets/subscriptionContext.d.ts.map +1 -0
- package/dist/react/widgets/subscriptionContext.js +3 -0
- package/dist/react/widgets/subscriptionContext.js.map +1 -0
- package/dist/react/widgets/types.d.ts +171 -0
- package/dist/react/widgets/types.d.ts.map +1 -0
- package/dist/react/widgets/types.js +2 -0
- package/dist/react/widgets/types.js.map +1 -0
- package/dist/svelte/index.d.ts +22 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +20 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/svelte/primitives/BillingGate.svelte +28 -0
- package/dist/svelte/primitives/BillingToggle.svelte +27 -0
- package/dist/svelte/primitives/CheckoutButton.svelte +60 -0
- package/dist/svelte/primitives/CheckoutSuccessSummary.svelte +34 -0
- package/dist/svelte/primitives/CustomerPortalButton.svelte +60 -0
- package/dist/svelte/primitives/NumberInput.svelte +71 -0
- package/dist/svelte/primitives/OneTimeCheckoutButton.svelte +37 -0
- package/dist/svelte/primitives/OneTimePaymentStatusBadge.svelte +20 -0
- package/dist/svelte/primitives/PaymentWarningBanner.svelte +30 -0
- package/dist/svelte/primitives/PricingCard.svelte +356 -0
- package/dist/svelte/primitives/PricingSection.svelte +121 -0
- package/dist/svelte/primitives/ScheduledChangeBanner.svelte +46 -0
- package/dist/svelte/primitives/SegmentControl.svelte +38 -0
- package/dist/svelte/primitives/SegmentGroup.svelte +52 -0
- package/dist/svelte/primitives/TrialLimitBanner.svelte +32 -0
- package/dist/svelte/primitives/shared.d.ts +13 -0
- package/dist/svelte/primitives/shared.d.ts.map +1 -0
- package/dist/svelte/primitives/shared.js +87 -0
- package/dist/svelte/primitives/shared.js.map +1 -0
- package/dist/svelte/widgets/BillingPortal.svelte +55 -0
- package/dist/svelte/widgets/Product.svelte +35 -0
- package/dist/svelte/widgets/ProductRoot.svelte +428 -0
- package/dist/svelte/widgets/Subscription.svelte +52 -0
- package/dist/svelte/widgets/SubscriptionRoot.svelte +690 -0
- package/dist/svelte/widgets/index.d.ts +19 -0
- package/dist/svelte/widgets/index.d.ts.map +1 -0
- package/dist/svelte/widgets/index.js +16 -0
- package/dist/svelte/widgets/index.js.map +1 -0
- package/dist/svelte/widgets/productGroupContext.d.ts +6 -0
- package/dist/svelte/widgets/productGroupContext.d.ts.map +1 -0
- package/dist/svelte/widgets/productGroupContext.js +2 -0
- package/dist/svelte/widgets/productGroupContext.js.map +1 -0
- package/dist/svelte/widgets/subscriptionContext.d.ts +6 -0
- package/dist/svelte/widgets/subscriptionContext.d.ts.map +1 -0
- package/dist/svelte/widgets/subscriptionContext.js +2 -0
- package/dist/svelte/widgets/subscriptionContext.js.map +1 -0
- package/dist/svelte/widgets/types.d.ts +171 -0
- package/dist/svelte/widgets/types.d.ts.map +1 -0
- package/dist/svelte/widgets/types.js +2 -0
- package/dist/svelte/widgets/types.js.map +1 -0
- package/package.json +182 -0
- package/src/client/helpers.test.ts +139 -0
- package/src/client/helpers.ts +51 -0
- package/src/client/index.test.ts +1554 -0
- package/src/client/index.ts +1504 -0
- package/src/client/parsers.test.ts +1017 -0
- package/src/client/parsers.ts +182 -0
- package/src/client/polyfill.ts +2 -0
- package/src/component/_generated/api.ts +52 -0
- package/src/component/_generated/component.ts +619 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/convex.config.ts +3 -0
- package/src/component/lib.test.ts +1359 -0
- package/src/component/lib.ts +726 -0
- package/src/component/schema.ts +112 -0
- package/src/component/util.test.ts +281 -0
- package/src/component/util.ts +228 -0
- package/src/core/catalog.test.ts +212 -0
- package/src/core/catalog.ts +119 -0
- package/src/core/index.ts +8 -0
- package/src/core/markdown.test.ts +43 -0
- package/src/core/markdown.ts +26 -0
- package/src/core/payments.test.ts +69 -0
- package/src/core/payments.ts +33 -0
- package/src/core/pendingCheckout.test.ts +44 -0
- package/src/core/pendingCheckout.ts +40 -0
- package/src/core/resolver.test.ts +283 -0
- package/src/core/resolver.ts +160 -0
- package/src/core/selectors.test.ts +119 -0
- package/src/core/selectors.ts +35 -0
- package/src/core/subscriptionUpdate.test.ts +164 -0
- package/src/core/subscriptionUpdate.ts +102 -0
- package/src/core/types.ts +220 -0
- package/src/design-system/README.md +40 -0
- package/src/design-system/base.css +27 -0
- package/src/design-system/colors/color-utils.ts +110 -0
- package/src/design-system/colors/config.ts +282 -0
- package/src/design-system/colors/index.ts +2 -0
- package/src/design-system/colors/utilities.css +2328 -0
- package/src/design-system/components/badges.css +65 -0
- package/src/design-system/components/buttons.css +256 -0
- package/src/design-system/components/dialog.css +218 -0
- package/src/design-system/components/icon-buttons.css +115 -0
- package/src/design-system/components/inputs.css +94 -0
- package/src/design-system/components/links.css +53 -0
- package/src/design-system/components/prose.css +67 -0
- package/src/design-system/components/segment-control.css +303 -0
- package/src/design-system/index.css +21 -0
- package/src/design-system/rounded/config.ts +91 -0
- package/src/design-system/rounded/index.ts +1 -0
- package/src/design-system/rounded/utilities.css +37 -0
- package/src/design-system/typography/config.ts +340 -0
- package/src/design-system/typography/index.ts +2 -0
- package/src/design-system/typography/tokens.ts +148 -0
- package/src/design-system/typography/utilities.css +728 -0
- package/src/library.css +20 -0
- package/src/react/hooks/useCheckoutSuccessParams.ts +7 -0
- package/src/react/index.tsx +47 -0
- package/src/react/primitives/BillingGate.tsx +26 -0
- package/src/react/primitives/BillingToggle.tsx +29 -0
- package/src/react/primitives/CheckoutButton.tsx +47 -0
- package/src/react/primitives/CheckoutSuccessSummary.tsx +36 -0
- package/src/react/primitives/CustomerPortalButton.tsx +50 -0
- package/src/react/primitives/NumberInput.tsx +83 -0
- package/src/react/primitives/OneTimeCheckoutButton.tsx +27 -0
- package/src/react/primitives/OneTimePaymentStatusBadge.tsx +18 -0
- package/src/react/primitives/PaymentWarningBanner.tsx +33 -0
- package/src/react/primitives/PricingCard.tsx +421 -0
- package/src/react/primitives/PricingSection.tsx +129 -0
- package/src/react/primitives/ScheduledChangeBanner.tsx +52 -0
- package/src/react/primitives/SegmentControl.tsx +32 -0
- package/src/react/primitives/SegmentGroup.tsx +53 -0
- package/src/react/primitives/TrialLimitBanner.tsx +32 -0
- package/src/react/shared.ts +138 -0
- package/src/react/widgets/BillingPortal.tsx +56 -0
- package/src/react/widgets/ProductItem.tsx +26 -0
- package/src/react/widgets/ProductRoot.tsx +441 -0
- package/src/react/widgets/SubscriptionItem.tsx +71 -0
- package/src/react/widgets/SubscriptionRoot.tsx +759 -0
- package/src/react/widgets/index.ts +36 -0
- package/src/react/widgets/productGroupContext.ts +10 -0
- package/src/react/widgets/subscriptionContext.ts +10 -0
- package/src/react/widgets/types.ts +179 -0
- package/src/svelte/index.ts +43 -0
- package/src/svelte/primitives/BillingGate.svelte +28 -0
- package/src/svelte/primitives/BillingToggle.svelte +27 -0
- package/src/svelte/primitives/CheckoutButton.svelte +60 -0
- package/src/svelte/primitives/CheckoutSuccessSummary.svelte +34 -0
- package/src/svelte/primitives/CustomerPortalButton.svelte +60 -0
- package/src/svelte/primitives/NumberInput.svelte +71 -0
- package/src/svelte/primitives/OneTimeCheckoutButton.svelte +37 -0
- package/src/svelte/primitives/OneTimePaymentStatusBadge.svelte +20 -0
- package/src/svelte/primitives/PaymentWarningBanner.svelte +30 -0
- package/src/svelte/primitives/PricingCard.svelte +356 -0
- package/src/svelte/primitives/PricingSection.svelte +121 -0
- package/src/svelte/primitives/ScheduledChangeBanner.svelte +46 -0
- package/src/svelte/primitives/SegmentControl.svelte +38 -0
- package/src/svelte/primitives/SegmentGroup.svelte +52 -0
- package/src/svelte/primitives/TrialLimitBanner.svelte +32 -0
- package/src/svelte/primitives/shared.ts +113 -0
- package/src/svelte/svelte.d.ts +6 -0
- package/src/svelte/widgets/BillingPortal.svelte +55 -0
- package/src/svelte/widgets/Product.svelte +35 -0
- package/src/svelte/widgets/ProductRoot.svelte +428 -0
- package/src/svelte/widgets/Subscription.svelte +52 -0
- package/src/svelte/widgets/SubscriptionRoot.svelte +690 -0
- package/src/svelte/widgets/index.ts +36 -0
- package/src/svelte/widgets/productGroupContext.ts +7 -0
- package/src/svelte/widgets/subscriptionContext.ts +7 -0
- package/src/svelte/widgets/types.ts +179 -0
- package/src/tailwind.css +6 -0
- package/src/test.ts +18 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { useMemo, useState } from "react";
|
|
2
|
+
import { CheckoutButton } from "./CheckoutButton.js";
|
|
3
|
+
import { NumberInput } from "./NumberInput.js";
|
|
4
|
+
import type { UIPlanEntry, RecurringCycle } from "../../core/types.js";
|
|
5
|
+
import type { ConnectedProduct } from "../widgets/types.js";
|
|
6
|
+
import {
|
|
7
|
+
resolveProductIdForPlan,
|
|
8
|
+
formatPriceWithInterval,
|
|
9
|
+
formatSeatPrice,
|
|
10
|
+
splitPriceLabel,
|
|
11
|
+
} from "../shared.js";
|
|
12
|
+
|
|
13
|
+
const computeTrialDays = (trialEnd: string): number => {
|
|
14
|
+
const end = new Date(trialEnd).getTime();
|
|
15
|
+
const now = Date.now();
|
|
16
|
+
return Math.max(0, Math.ceil((end - now) / (1000 * 60 * 60 * 24)));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const PricingCard = ({
|
|
20
|
+
plan,
|
|
21
|
+
selectedCycle,
|
|
22
|
+
activePlanId,
|
|
23
|
+
subscriptionProductId,
|
|
24
|
+
subscriptionStatus,
|
|
25
|
+
subscriptionTrialEnd,
|
|
26
|
+
products = [],
|
|
27
|
+
units,
|
|
28
|
+
showSeatPicker = false,
|
|
29
|
+
subscribedSeats,
|
|
30
|
+
isGroupSubscribed = false,
|
|
31
|
+
disableCheckout = false,
|
|
32
|
+
disableSwitch = false,
|
|
33
|
+
disableSeats = false,
|
|
34
|
+
className = "",
|
|
35
|
+
onCheckout,
|
|
36
|
+
onSwitchPlan,
|
|
37
|
+
onUpdateSeats,
|
|
38
|
+
onContactSales,
|
|
39
|
+
onCancelSubscription,
|
|
40
|
+
}: {
|
|
41
|
+
plan: UIPlanEntry;
|
|
42
|
+
selectedCycle?: RecurringCycle;
|
|
43
|
+
activePlanId?: string | null;
|
|
44
|
+
subscriptionProductId?: string | null;
|
|
45
|
+
subscriptionStatus?: string | null;
|
|
46
|
+
subscriptionTrialEnd?: string | null;
|
|
47
|
+
products?: ConnectedProduct[];
|
|
48
|
+
units?: number;
|
|
49
|
+
showSeatPicker?: boolean;
|
|
50
|
+
subscribedSeats?: number | null;
|
|
51
|
+
isGroupSubscribed?: boolean;
|
|
52
|
+
disableCheckout?: boolean;
|
|
53
|
+
disableSwitch?: boolean;
|
|
54
|
+
disableSeats?: boolean;
|
|
55
|
+
className?: string;
|
|
56
|
+
onCheckout?: (payload: {
|
|
57
|
+
plan: UIPlanEntry;
|
|
58
|
+
productId: string;
|
|
59
|
+
units?: number;
|
|
60
|
+
}) => Promise<void> | void;
|
|
61
|
+
onSwitchPlan?: (payload: {
|
|
62
|
+
plan: UIPlanEntry;
|
|
63
|
+
productId: string;
|
|
64
|
+
units?: number;
|
|
65
|
+
}) => Promise<void> | void;
|
|
66
|
+
onUpdateSeats?: (payload: { units: number }) => Promise<void> | void;
|
|
67
|
+
onContactSales?: (payload: { plan: UIPlanEntry }) => Promise<void> | void;
|
|
68
|
+
onCancelSubscription?: () => void;
|
|
69
|
+
}) => {
|
|
70
|
+
const isSeatPlan = plan.pricingModel === "seat";
|
|
71
|
+
const [seatCount, setSeatCount] = useState(units ?? 1);
|
|
72
|
+
const [seatAdjustCount, setSeatAdjustCount] = useState(
|
|
73
|
+
subscribedSeats ?? units ?? 1,
|
|
74
|
+
);
|
|
75
|
+
const [editingSeats, setEditingSeats] = useState(false);
|
|
76
|
+
|
|
77
|
+
const [prevUnits, setPrevUnits] = useState(units);
|
|
78
|
+
const [prevSubscribedSeats, setPrevSubscribedSeats] =
|
|
79
|
+
useState(subscribedSeats);
|
|
80
|
+
|
|
81
|
+
if (units !== prevUnits) {
|
|
82
|
+
setPrevUnits(units);
|
|
83
|
+
setSeatCount(units ?? 1);
|
|
84
|
+
}
|
|
85
|
+
if (subscribedSeats !== prevSubscribedSeats || units !== prevUnits) {
|
|
86
|
+
setPrevSubscribedSeats(subscribedSeats);
|
|
87
|
+
setSeatAdjustCount(subscribedSeats ?? units ?? 1);
|
|
88
|
+
setEditingSeats(false);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const effectiveUnits = isSeatPlan
|
|
92
|
+
? showSeatPicker
|
|
93
|
+
? seatCount
|
|
94
|
+
: units
|
|
95
|
+
: undefined;
|
|
96
|
+
|
|
97
|
+
const productId = resolveProductIdForPlan(plan, selectedCycle);
|
|
98
|
+
const priceLabel = formatPriceWithInterval(productId, products);
|
|
99
|
+
|
|
100
|
+
// Exact match: user is subscribed to THIS specific product (plan + cycle)
|
|
101
|
+
const isActiveProduct =
|
|
102
|
+
subscriptionProductId != null &&
|
|
103
|
+
productId != null &&
|
|
104
|
+
productId === subscriptionProductId;
|
|
105
|
+
const isTrialing = isActiveProduct && subscriptionStatus === "trialing";
|
|
106
|
+
const trialDaysLeft =
|
|
107
|
+
isTrialing && subscriptionTrialEnd
|
|
108
|
+
? computeTrialDays(subscriptionTrialEnd)
|
|
109
|
+
: null;
|
|
110
|
+
|
|
111
|
+
// Same plan but different billing cycle — offer to switch interval
|
|
112
|
+
const isActivePlanOtherCycle =
|
|
113
|
+
!isActiveProduct && activePlanId === plan.planId && productId != null;
|
|
114
|
+
// Free plan is active when activePlanId matches and the plan has no product
|
|
115
|
+
const isActiveFreePlan =
|
|
116
|
+
!isActiveProduct &&
|
|
117
|
+
plan.category === "free" &&
|
|
118
|
+
activePlanId === plan.planId;
|
|
119
|
+
// Sibling plan in the same <Subscription> group that already has a subscription
|
|
120
|
+
const isSiblingPlan =
|
|
121
|
+
!isActiveProduct &&
|
|
122
|
+
!isActivePlanOtherCycle &&
|
|
123
|
+
isGroupSubscribed &&
|
|
124
|
+
productId != null &&
|
|
125
|
+
plan.category !== "free" &&
|
|
126
|
+
plan.category !== "enterprise";
|
|
127
|
+
|
|
128
|
+
const showSeatCheckoutControls =
|
|
129
|
+
isSeatPlan && showSeatPicker && !isActiveProduct && !isSiblingPlan;
|
|
130
|
+
const reserveSeatActionHeight =
|
|
131
|
+
isSeatPlan &&
|
|
132
|
+
showSeatPicker &&
|
|
133
|
+
(isActiveProduct || isSiblingPlan || isActivePlanOtherCycle);
|
|
134
|
+
|
|
135
|
+
const seatPriceLabel =
|
|
136
|
+
isActiveProduct && isSeatPlan && subscribedSeats
|
|
137
|
+
? formatSeatPrice(productId, products, subscribedSeats)
|
|
138
|
+
: null;
|
|
139
|
+
const seatsChanged =
|
|
140
|
+
isActiveProduct &&
|
|
141
|
+
isSeatPlan &&
|
|
142
|
+
subscribedSeats != null &&
|
|
143
|
+
seatAdjustCount !== subscribedSeats;
|
|
144
|
+
|
|
145
|
+
const checkoutLabel = isActivePlanOtherCycle
|
|
146
|
+
? "Switch interval"
|
|
147
|
+
: isSiblingPlan
|
|
148
|
+
? "Switch plan"
|
|
149
|
+
: plan.billingType === "onetime"
|
|
150
|
+
? "Buy now"
|
|
151
|
+
: "Subscribe";
|
|
152
|
+
|
|
153
|
+
const handleCheckout = (payload: { productId: string }) => {
|
|
154
|
+
if ((isSiblingPlan || isActivePlanOtherCycle) && onSwitchPlan) {
|
|
155
|
+
onSwitchPlan({
|
|
156
|
+
plan,
|
|
157
|
+
productId: payload.productId,
|
|
158
|
+
units: isSeatPlan
|
|
159
|
+
? (subscribedSeats ?? effectiveUnits)
|
|
160
|
+
: effectiveUnits,
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
onCheckout?.({
|
|
164
|
+
plan,
|
|
165
|
+
productId: payload.productId,
|
|
166
|
+
units: effectiveUnits,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const splitPrice = splitPriceLabel(seatPriceLabel ?? priceLabel);
|
|
172
|
+
|
|
173
|
+
const descriptionLines = useMemo(() => {
|
|
174
|
+
if (!plan.description) return [];
|
|
175
|
+
return plan.description
|
|
176
|
+
.split(/\r?\n/)
|
|
177
|
+
.map((line) => line.trim())
|
|
178
|
+
.filter(Boolean)
|
|
179
|
+
.map((line) => line.replace(/^(?:[-*]\s+|[✔✓]\s*)/, "").trim())
|
|
180
|
+
.filter(Boolean);
|
|
181
|
+
}, [plan.description]);
|
|
182
|
+
|
|
183
|
+
const featureLines = useMemo(() => {
|
|
184
|
+
if (descriptionLines.length < 3) return [];
|
|
185
|
+
return descriptionLines;
|
|
186
|
+
}, [descriptionLines]);
|
|
187
|
+
|
|
188
|
+
const leadDescription = useMemo(() => {
|
|
189
|
+
if (!descriptionLines.length || featureLines.length > 0) return null;
|
|
190
|
+
return descriptionLines[0] ?? null;
|
|
191
|
+
}, [descriptionLines, featureLines]);
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<section
|
|
195
|
+
className={`relative flex flex-col rounded-2xl bg-surface-base p-6 ${
|
|
196
|
+
plan.recommended ? "border-2 border-primary-border-default" : ""
|
|
197
|
+
} ${className}`}
|
|
198
|
+
>
|
|
199
|
+
<div className="mb-3 flex h-5 items-center justify-between gap-2">
|
|
200
|
+
<h3 className="title-s text-foreground-default">
|
|
201
|
+
{plan.title ?? plan.planId}
|
|
202
|
+
</h3>
|
|
203
|
+
{isActiveProduct || isActiveFreePlan ? (
|
|
204
|
+
<span className="badge-faded-sm">
|
|
205
|
+
{isTrialing ? (
|
|
206
|
+
<>
|
|
207
|
+
Free trial
|
|
208
|
+
{trialDaysLeft != null && (
|
|
209
|
+
<>
|
|
210
|
+
 · {trialDaysLeft} day
|
|
211
|
+
{trialDaysLeft === 1 ? "" : "s"} left
|
|
212
|
+
</>
|
|
213
|
+
)}
|
|
214
|
+
</>
|
|
215
|
+
) : (
|
|
216
|
+
"Current plan"
|
|
217
|
+
)}
|
|
218
|
+
</span>
|
|
219
|
+
) : plan.recommended ? (
|
|
220
|
+
<span className="badge-filled-sm">Recommended</span>
|
|
221
|
+
) : null}
|
|
222
|
+
</div>
|
|
223
|
+
|
|
224
|
+
<div className="flex items-baseline gap-1">
|
|
225
|
+
{plan.category === "free" ? (
|
|
226
|
+
<span className="heading-s text-foreground-default">Free</span>
|
|
227
|
+
) : plan.category === "enterprise" ? (
|
|
228
|
+
<span className="heading-s text-foreground-default">Custom</span>
|
|
229
|
+
) : splitPrice ? (
|
|
230
|
+
<>
|
|
231
|
+
<span className="heading-s text-foreground-default">
|
|
232
|
+
{splitPrice.main}
|
|
233
|
+
</span>
|
|
234
|
+
{splitPrice.suffix && (
|
|
235
|
+
<span className="title-s text-foreground-placeholder">
|
|
236
|
+
{splitPrice.suffix}
|
|
237
|
+
</span>
|
|
238
|
+
)}
|
|
239
|
+
{splitPrice.tail && (
|
|
240
|
+
<span className="title-s text-foreground-placeholder">
|
|
241
|
+
{splitPrice.tail}
|
|
242
|
+
</span>
|
|
243
|
+
)}
|
|
244
|
+
</>
|
|
245
|
+
) : null}
|
|
246
|
+
</div>
|
|
247
|
+
|
|
248
|
+
{leadDescription && (
|
|
249
|
+
<p className="mb-4 body-m text-foreground-muted">{leadDescription}</p>
|
|
250
|
+
)}
|
|
251
|
+
|
|
252
|
+
<div
|
|
253
|
+
className={`mb-4 mt-6 ${showSeatCheckoutControls ? "flex flex-col gap-2" : "flex min-h-8 items-start"}`}
|
|
254
|
+
>
|
|
255
|
+
{showSeatCheckoutControls && (
|
|
256
|
+
<div className="flex w-full items-center justify-between rounded-xl bg-surface-subtle py-2 pl-4 pr-2">
|
|
257
|
+
<span className="label-m text-foreground-default">Seats:</span>
|
|
258
|
+
<NumberInput
|
|
259
|
+
value={seatCount}
|
|
260
|
+
min={1}
|
|
261
|
+
compact
|
|
262
|
+
disabled={disableSeats}
|
|
263
|
+
onValueChange={(next) => {
|
|
264
|
+
if (next > 0) setSeatCount(next);
|
|
265
|
+
}}
|
|
266
|
+
/>
|
|
267
|
+
</div>
|
|
268
|
+
)}
|
|
269
|
+
|
|
270
|
+
<div
|
|
271
|
+
className={`${showSeatCheckoutControls ? "w-full" : "flex min-h-8 items-start w-full"} ${
|
|
272
|
+
reserveSeatActionHeight ? "min-h-[4.5rem]" : ""
|
|
273
|
+
}`}
|
|
274
|
+
>
|
|
275
|
+
{isActiveProduct && isSeatPlan && showSeatPicker && onUpdateSeats ? (
|
|
276
|
+
<div className="flex w-full flex-col gap-2">
|
|
277
|
+
{editingSeats ? (
|
|
278
|
+
<>
|
|
279
|
+
<div className="flex w-full items-center justify-between rounded-xl bg-surface-subtle py-2 pl-4 pr-2">
|
|
280
|
+
<span className="label-m text-foreground-default">
|
|
281
|
+
Seats:
|
|
282
|
+
</span>
|
|
283
|
+
<NumberInput
|
|
284
|
+
value={seatAdjustCount}
|
|
285
|
+
min={1}
|
|
286
|
+
compact
|
|
287
|
+
disabled={disableSeats}
|
|
288
|
+
onValueChange={(next) => {
|
|
289
|
+
if (next > 0) setSeatAdjustCount(next);
|
|
290
|
+
}}
|
|
291
|
+
/>
|
|
292
|
+
</div>
|
|
293
|
+
<div className="flex w-full items-center gap-2">
|
|
294
|
+
<button
|
|
295
|
+
type="button"
|
|
296
|
+
className="button-faded h-8 w-full"
|
|
297
|
+
onClick={() => {
|
|
298
|
+
setSeatAdjustCount(subscribedSeats ?? 1);
|
|
299
|
+
setEditingSeats(false);
|
|
300
|
+
}}
|
|
301
|
+
>
|
|
302
|
+
Cancel
|
|
303
|
+
</button>
|
|
304
|
+
<button
|
|
305
|
+
type="button"
|
|
306
|
+
disabled={disableSeats || !seatsChanged}
|
|
307
|
+
className="button-filled h-8 w-full disabled:cursor-not-allowed disabled:opacity-50"
|
|
308
|
+
onClick={() =>
|
|
309
|
+
onUpdateSeats?.({ units: seatAdjustCount })
|
|
310
|
+
}
|
|
311
|
+
>
|
|
312
|
+
Update
|
|
313
|
+
</button>
|
|
314
|
+
</div>
|
|
315
|
+
</>
|
|
316
|
+
) : (
|
|
317
|
+
<>
|
|
318
|
+
<button
|
|
319
|
+
type="button"
|
|
320
|
+
className="button-faded w-full"
|
|
321
|
+
onClick={() => setEditingSeats(true)}
|
|
322
|
+
>
|
|
323
|
+
Change seats
|
|
324
|
+
</button>
|
|
325
|
+
{onCancelSubscription && (
|
|
326
|
+
<button
|
|
327
|
+
type="button"
|
|
328
|
+
className="button-outline w-full"
|
|
329
|
+
onClick={onCancelSubscription}
|
|
330
|
+
>
|
|
331
|
+
Cancel subscription
|
|
332
|
+
</button>
|
|
333
|
+
)}
|
|
334
|
+
</>
|
|
335
|
+
)}
|
|
336
|
+
</div>
|
|
337
|
+
) : isActiveProduct && onCancelSubscription ? (
|
|
338
|
+
<button
|
|
339
|
+
type="button"
|
|
340
|
+
className="button-outline w-full"
|
|
341
|
+
onClick={onCancelSubscription}
|
|
342
|
+
>
|
|
343
|
+
Cancel subscription
|
|
344
|
+
</button>
|
|
345
|
+
) : isActiveProduct ||
|
|
346
|
+
isActiveFreePlan ? /* Keep CTA row height but intentionally empty when current plan has no action */
|
|
347
|
+
null : (isSiblingPlan || isActivePlanOtherCycle) && productId ? (
|
|
348
|
+
<CheckoutButton
|
|
349
|
+
productId={productId}
|
|
350
|
+
disabled={disableSwitch}
|
|
351
|
+
onCheckout={handleCheckout}
|
|
352
|
+
className={`${plan.recommended ? "button-filled" : "button-faded"} w-full`}
|
|
353
|
+
>
|
|
354
|
+
{checkoutLabel}
|
|
355
|
+
</CheckoutButton>
|
|
356
|
+
) : plan.category === "enterprise" ? (
|
|
357
|
+
plan.contactUrl ? (
|
|
358
|
+
<a href={plan.contactUrl} className="button-outline w-full">
|
|
359
|
+
Contact sales
|
|
360
|
+
</a>
|
|
361
|
+
) : onContactSales ? (
|
|
362
|
+
<button
|
|
363
|
+
type="button"
|
|
364
|
+
className="button-outline w-full"
|
|
365
|
+
onClick={() => onContactSales?.({ plan })}
|
|
366
|
+
>
|
|
367
|
+
Contact sales
|
|
368
|
+
</button>
|
|
369
|
+
) : null
|
|
370
|
+
) : productId ? (
|
|
371
|
+
<CheckoutButton
|
|
372
|
+
productId={productId}
|
|
373
|
+
disabled={disableCheckout}
|
|
374
|
+
onCheckout={handleCheckout}
|
|
375
|
+
className={`${plan.recommended ? "button-filled" : "button-faded"} w-full`}
|
|
376
|
+
>
|
|
377
|
+
{checkoutLabel}
|
|
378
|
+
</CheckoutButton>
|
|
379
|
+
) : plan.category !== "free" ? (
|
|
380
|
+
<span className="body-m text-foreground-muted">
|
|
381
|
+
Configure a checkout handler to activate this plan.
|
|
382
|
+
</span>
|
|
383
|
+
) : null}
|
|
384
|
+
</div>
|
|
385
|
+
</div>
|
|
386
|
+
|
|
387
|
+
{featureLines.length > 0 && (
|
|
388
|
+
<div className="w-full pt-4">
|
|
389
|
+
<p className="label-m mb-4 font-semibold text-foreground-default">
|
|
390
|
+
What's included:
|
|
391
|
+
</p>
|
|
392
|
+
<ul className="space-y-2">
|
|
393
|
+
{featureLines.map((feature) => (
|
|
394
|
+
<li key={feature} className="flex items-center gap-2">
|
|
395
|
+
<span className="inline-flex h-5 w-5 shrink-0 items-center justify-center text-foreground-muted">
|
|
396
|
+
<svg
|
|
397
|
+
aria-hidden="true"
|
|
398
|
+
viewBox="0 0 24 24"
|
|
399
|
+
fill="none"
|
|
400
|
+
className="h-4 w-4"
|
|
401
|
+
>
|
|
402
|
+
<path
|
|
403
|
+
d="M20 6L9 17L4 12"
|
|
404
|
+
stroke="currentColor"
|
|
405
|
+
strokeWidth="2.5"
|
|
406
|
+
strokeLinecap="round"
|
|
407
|
+
strokeLinejoin="round"
|
|
408
|
+
/>
|
|
409
|
+
</svg>
|
|
410
|
+
</span>
|
|
411
|
+
<span className="body-m text-foreground-default">
|
|
412
|
+
{feature}
|
|
413
|
+
</span>
|
|
414
|
+
</li>
|
|
415
|
+
))}
|
|
416
|
+
</ul>
|
|
417
|
+
</div>
|
|
418
|
+
)}
|
|
419
|
+
</section>
|
|
420
|
+
);
|
|
421
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { BillingToggle } from "./BillingToggle.js";
|
|
3
|
+
import { PricingCard } from "./PricingCard.js";
|
|
4
|
+
import type {
|
|
5
|
+
BillingSnapshot,
|
|
6
|
+
UIPlanEntry,
|
|
7
|
+
RecurringCycle,
|
|
8
|
+
} from "../../core/types.js";
|
|
9
|
+
import type { ConnectedProduct } from "../widgets/types.js";
|
|
10
|
+
|
|
11
|
+
export const PricingSection = ({
|
|
12
|
+
plans = [],
|
|
13
|
+
snapshot,
|
|
14
|
+
selectedCycle,
|
|
15
|
+
products = [],
|
|
16
|
+
subscriptionProductId,
|
|
17
|
+
subscriptionStatus,
|
|
18
|
+
subscriptionTrialEnd,
|
|
19
|
+
units,
|
|
20
|
+
showSeatPicker = false,
|
|
21
|
+
twoColumnLayout = false,
|
|
22
|
+
subscribedSeats,
|
|
23
|
+
isGroupSubscribed = false,
|
|
24
|
+
disableCheckout = false,
|
|
25
|
+
disableSwitch = false,
|
|
26
|
+
disableSeats = false,
|
|
27
|
+
className = "",
|
|
28
|
+
onCycleChange,
|
|
29
|
+
onCheckout,
|
|
30
|
+
onSwitchPlan,
|
|
31
|
+
onUpdateSeats,
|
|
32
|
+
onContactSales,
|
|
33
|
+
onCancelSubscription,
|
|
34
|
+
}: {
|
|
35
|
+
plans?: UIPlanEntry[];
|
|
36
|
+
snapshot?: BillingSnapshot | null;
|
|
37
|
+
selectedCycle?: RecurringCycle;
|
|
38
|
+
products?: ConnectedProduct[];
|
|
39
|
+
subscriptionProductId?: string | null;
|
|
40
|
+
subscriptionStatus?: string | null;
|
|
41
|
+
subscriptionTrialEnd?: string | null;
|
|
42
|
+
units?: number;
|
|
43
|
+
showSeatPicker?: boolean;
|
|
44
|
+
twoColumnLayout?: boolean;
|
|
45
|
+
subscribedSeats?: number | null;
|
|
46
|
+
isGroupSubscribed?: boolean;
|
|
47
|
+
disableCheckout?: boolean;
|
|
48
|
+
disableSwitch?: boolean;
|
|
49
|
+
disableSeats?: boolean;
|
|
50
|
+
className?: string;
|
|
51
|
+
onCycleChange?: (cycle: RecurringCycle) => void;
|
|
52
|
+
onCheckout?: (payload: {
|
|
53
|
+
plan: UIPlanEntry;
|
|
54
|
+
productId: string;
|
|
55
|
+
units?: number;
|
|
56
|
+
}) => Promise<void> | void;
|
|
57
|
+
onSwitchPlan?: (payload: {
|
|
58
|
+
plan: UIPlanEntry;
|
|
59
|
+
productId: string;
|
|
60
|
+
units?: number;
|
|
61
|
+
}) => Promise<void> | void;
|
|
62
|
+
onUpdateSeats?: (payload: { units: number }) => Promise<void> | void;
|
|
63
|
+
onContactSales?: (payload: { plan: UIPlanEntry }) => Promise<void> | void;
|
|
64
|
+
onCancelSubscription?: () => void;
|
|
65
|
+
}) => {
|
|
66
|
+
const availableCycles = useMemo(() => {
|
|
67
|
+
const set = new Set<RecurringCycle>();
|
|
68
|
+
for (const plan of plans) {
|
|
69
|
+
for (const cycle of plan.billingCycles ?? []) {
|
|
70
|
+
set.add(cycle);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return Array.from(set);
|
|
74
|
+
}, [plans]);
|
|
75
|
+
|
|
76
|
+
const hasEnterprisePlan = plans.some((p) => p.category === "enterprise");
|
|
77
|
+
const effectiveCycle =
|
|
78
|
+
selectedCycle ?? snapshot?.recurringCycle ?? availableCycles[0];
|
|
79
|
+
const showToggle = availableCycles.length > 1;
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<section className={className}>
|
|
83
|
+
{showToggle && (
|
|
84
|
+
<div className="mb-[6.5rem] flex justify-center">
|
|
85
|
+
<BillingToggle
|
|
86
|
+
cycles={availableCycles}
|
|
87
|
+
value={effectiveCycle}
|
|
88
|
+
onValueChange={onCycleChange}
|
|
89
|
+
/>
|
|
90
|
+
</div>
|
|
91
|
+
)}
|
|
92
|
+
|
|
93
|
+
<div
|
|
94
|
+
className={`grid grid-cols-1 gap-1 ${
|
|
95
|
+
showSeatPicker || twoColumnLayout
|
|
96
|
+
? "md:grid-cols-2"
|
|
97
|
+
: hasEnterprisePlan
|
|
98
|
+
? "sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4"
|
|
99
|
+
: "sm:grid-cols-2 md:grid-cols-3"
|
|
100
|
+
}`}
|
|
101
|
+
>
|
|
102
|
+
{plans.map((plan) => (
|
|
103
|
+
<PricingCard
|
|
104
|
+
key={plan.planId}
|
|
105
|
+
plan={plan}
|
|
106
|
+
selectedCycle={effectiveCycle}
|
|
107
|
+
activePlanId={snapshot?.activePlanId}
|
|
108
|
+
subscriptionProductId={subscriptionProductId}
|
|
109
|
+
subscriptionStatus={subscriptionStatus}
|
|
110
|
+
subscriptionTrialEnd={subscriptionTrialEnd}
|
|
111
|
+
products={products}
|
|
112
|
+
units={units}
|
|
113
|
+
showSeatPicker={showSeatPicker}
|
|
114
|
+
subscribedSeats={subscribedSeats}
|
|
115
|
+
isGroupSubscribed={isGroupSubscribed}
|
|
116
|
+
disableCheckout={disableCheckout}
|
|
117
|
+
disableSwitch={disableSwitch}
|
|
118
|
+
disableSeats={disableSeats}
|
|
119
|
+
onCheckout={onCheckout}
|
|
120
|
+
onSwitchPlan={onSwitchPlan}
|
|
121
|
+
onUpdateSeats={onUpdateSeats}
|
|
122
|
+
onContactSales={onContactSales}
|
|
123
|
+
onCancelSubscription={onCancelSubscription}
|
|
124
|
+
/>
|
|
125
|
+
))}
|
|
126
|
+
</div>
|
|
127
|
+
</section>
|
|
128
|
+
);
|
|
129
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { BillingSnapshot } from "../../core/types.js";
|
|
2
|
+
|
|
3
|
+
export const ScheduledChangeBanner = ({
|
|
4
|
+
snapshot,
|
|
5
|
+
className = "",
|
|
6
|
+
isLoading = false,
|
|
7
|
+
onResume,
|
|
8
|
+
}: {
|
|
9
|
+
snapshot?: BillingSnapshot | null;
|
|
10
|
+
className?: string;
|
|
11
|
+
isLoading?: boolean;
|
|
12
|
+
onResume?: () => void;
|
|
13
|
+
}) => {
|
|
14
|
+
if (!snapshot?.metadata || snapshot.metadata.cancelAtPeriodEnd !== true) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const currentPeriodEnd =
|
|
19
|
+
typeof snapshot.metadata.currentPeriodEnd === "string"
|
|
20
|
+
? snapshot.metadata.currentPeriodEnd
|
|
21
|
+
: undefined;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div className={`rounded-xl bg-surface-base p-6 ${className}`}>
|
|
25
|
+
<div className="flex flex-col gap-6 md:flex-row md:items-start md:justify-between md:gap-4">
|
|
26
|
+
<div className="space-y-2">
|
|
27
|
+
<p className="title-s text-foreground-default">
|
|
28
|
+
Cancellation scheduled
|
|
29
|
+
</p>
|
|
30
|
+
<p className="body-m text-foreground-muted">
|
|
31
|
+
You will continue to have access until the end of your current
|
|
32
|
+
billing period
|
|
33
|
+
{currentPeriodEnd
|
|
34
|
+
? ` (${new Date(currentPeriodEnd).toLocaleDateString()})`
|
|
35
|
+
: ""}
|
|
36
|
+
.
|
|
37
|
+
</p>
|
|
38
|
+
</div>
|
|
39
|
+
{onResume && (
|
|
40
|
+
<button
|
|
41
|
+
type="button"
|
|
42
|
+
className="button-faded h-8 shrink-0 disabled:cursor-not-allowed disabled:opacity-50"
|
|
43
|
+
disabled={isLoading}
|
|
44
|
+
onClick={onResume}
|
|
45
|
+
>
|
|
46
|
+
{isLoading ? "Resuming…" : "Undo cancellation"}
|
|
47
|
+
</button>
|
|
48
|
+
)}
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SegmentGroup, type SegmentGroupItem } from "./SegmentGroup.js";
|
|
2
|
+
|
|
3
|
+
export type SegmentControlItem = SegmentGroupItem;
|
|
4
|
+
|
|
5
|
+
export const SegmentControl = ({
|
|
6
|
+
items = [],
|
|
7
|
+
value,
|
|
8
|
+
defaultValue,
|
|
9
|
+
disabled = false,
|
|
10
|
+
className = "",
|
|
11
|
+
onValueChange,
|
|
12
|
+
}: {
|
|
13
|
+
items?: SegmentControlItem[];
|
|
14
|
+
value?: string | null;
|
|
15
|
+
defaultValue?: string;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
className?: string;
|
|
18
|
+
onValueChange?: (value: string) => void;
|
|
19
|
+
}) => {
|
|
20
|
+
if (items.length <= 1) return null;
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<SegmentGroup
|
|
24
|
+
items={items}
|
|
25
|
+
value={value}
|
|
26
|
+
defaultValue={defaultValue}
|
|
27
|
+
disabled={disabled}
|
|
28
|
+
onValueChange={onValueChange}
|
|
29
|
+
className={className}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SegmentGroup as ArkSegmentGroup } from "@ark-ui/react/segment-group";
|
|
2
|
+
|
|
3
|
+
export type SegmentGroupItem = {
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const SegmentGroup = ({
|
|
10
|
+
items = [],
|
|
11
|
+
value,
|
|
12
|
+
defaultValue,
|
|
13
|
+
disabled = false,
|
|
14
|
+
className = "",
|
|
15
|
+
onValueChange,
|
|
16
|
+
}: {
|
|
17
|
+
items?: SegmentGroupItem[];
|
|
18
|
+
value?: string | null;
|
|
19
|
+
defaultValue?: string;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
className?: string;
|
|
22
|
+
onValueChange?: (value: string) => void;
|
|
23
|
+
}) => {
|
|
24
|
+
if (items.length <= 1) return null;
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<ArkSegmentGroup.Root
|
|
28
|
+
value={value ?? undefined}
|
|
29
|
+
defaultValue={defaultValue}
|
|
30
|
+
disabled={disabled}
|
|
31
|
+
className={`segment-group ${className}`}
|
|
32
|
+
onValueChange={(details: { value: string | null }) => {
|
|
33
|
+
if (details.value != null) onValueChange?.(details.value);
|
|
34
|
+
}}
|
|
35
|
+
>
|
|
36
|
+
<ArkSegmentGroup.Indicator className="segment-group-indicator" />
|
|
37
|
+
{items.map((item) => (
|
|
38
|
+
<ArkSegmentGroup.Item
|
|
39
|
+
key={item.value}
|
|
40
|
+
value={item.value}
|
|
41
|
+
disabled={item.disabled}
|
|
42
|
+
className="segment-group-item"
|
|
43
|
+
>
|
|
44
|
+
<ArkSegmentGroup.ItemText className="segment-group-item-text label-m">
|
|
45
|
+
{item.label}
|
|
46
|
+
</ArkSegmentGroup.ItemText>
|
|
47
|
+
<ArkSegmentGroup.ItemControl className="segment-group-item-control" />
|
|
48
|
+
<ArkSegmentGroup.ItemHiddenInput />
|
|
49
|
+
</ArkSegmentGroup.Item>
|
|
50
|
+
))}
|
|
51
|
+
</ArkSegmentGroup.Root>
|
|
52
|
+
);
|
|
53
|
+
};
|