@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,32 @@
|
|
|
1
|
+
import type { BillingSnapshot } from "../../core/types.js";
|
|
2
|
+
|
|
3
|
+
export const TrialLimitBanner = ({
|
|
4
|
+
snapshot,
|
|
5
|
+
trialEndsAt,
|
|
6
|
+
className = "",
|
|
7
|
+
}: {
|
|
8
|
+
snapshot?: BillingSnapshot | null;
|
|
9
|
+
trialEndsAt?: string | null;
|
|
10
|
+
className?: string;
|
|
11
|
+
}) => {
|
|
12
|
+
if (snapshot?.activeCategory !== "trial") {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const resolvedTrialEnd =
|
|
17
|
+
trialEndsAt ??
|
|
18
|
+
(typeof snapshot.metadata?.trialEnd === "string"
|
|
19
|
+
? snapshot.metadata.trialEnd
|
|
20
|
+
: null);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<div
|
|
24
|
+
className={`rounded-lg border border-sky-300 bg-sky-50 px-4 py-3 text-sm text-sky-900 dark:border-sky-800 dark:bg-sky-950/40 dark:text-sky-200 ${className}`}
|
|
25
|
+
>
|
|
26
|
+
Trial plan active
|
|
27
|
+
{resolvedTrialEnd
|
|
28
|
+
? ` until ${new Date(resolvedTrialEnd).toLocaleDateString()}.`
|
|
29
|
+
: ". Upgrade before your trial ends to avoid interruptions."}
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AvailableAction,
|
|
3
|
+
BillingSnapshot,
|
|
4
|
+
UIPlanEntry,
|
|
5
|
+
RecurringCycle,
|
|
6
|
+
} from "../core/types.js";
|
|
7
|
+
import type { ConnectedProduct } from "./widgets/types.js";
|
|
8
|
+
|
|
9
|
+
const CYCLE_KEY_ALIASES: Record<RecurringCycle, string[]> = {
|
|
10
|
+
"every-month": ["every-month", "monthly", "month"],
|
|
11
|
+
"every-three-months": ["every-three-months", "quarterly", "every-quarter"],
|
|
12
|
+
"every-six-months": ["every-six-months", "semiannual", "semi-annually"],
|
|
13
|
+
"every-year": ["every-year", "yearly", "annual"],
|
|
14
|
+
custom: ["custom"],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** Format a billing cycle enum value to a human-readable label (e.g. `"every-month"` → `"Monthly"`). */
|
|
18
|
+
export const formatRecurringCycle = (cycle: RecurringCycle) => {
|
|
19
|
+
if (cycle === "every-month") return "Monthly";
|
|
20
|
+
if (cycle === "every-three-months") return "Quarterly";
|
|
21
|
+
if (cycle === "every-six-months") return "Semi-annual";
|
|
22
|
+
if (cycle === "every-year") return "Yearly";
|
|
23
|
+
return "Custom";
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Resolve the Creem product ID for a plan given the selected billing cycle. Handles cycle aliases and partial matches. */
|
|
27
|
+
export const resolveProductIdForPlan = (
|
|
28
|
+
plan: UIPlanEntry,
|
|
29
|
+
selectedCycle: RecurringCycle | undefined,
|
|
30
|
+
) => {
|
|
31
|
+
const productIds = plan.creemProductIds;
|
|
32
|
+
if (!productIds) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const aliases = selectedCycle
|
|
37
|
+
? CYCLE_KEY_ALIASES[selectedCycle]
|
|
38
|
+
: CYCLE_KEY_ALIASES.custom;
|
|
39
|
+
for (const alias of aliases) {
|
|
40
|
+
if (productIds[alias]) {
|
|
41
|
+
return productIds[alias];
|
|
42
|
+
}
|
|
43
|
+
const partial = Object.entries(productIds).find(([key]) =>
|
|
44
|
+
key.toLowerCase().includes(alias),
|
|
45
|
+
);
|
|
46
|
+
if (partial) {
|
|
47
|
+
return partial[1];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return Object.values(productIds)[0];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** Local variant of `hasBillingAction` for use in shared UI code. */
|
|
55
|
+
export const hasBillingActionLocal = (
|
|
56
|
+
snapshot: BillingSnapshot,
|
|
57
|
+
action: AvailableAction,
|
|
58
|
+
) => snapshot.availableActions.includes(action);
|
|
59
|
+
|
|
60
|
+
/** Format a price amount (in cents) to a localized currency string (e.g. `999` + `"USD"` → `"$9.99"`). */
|
|
61
|
+
export const formatPrice = (amount: number, currency: string): string => {
|
|
62
|
+
return new Intl.NumberFormat(undefined, {
|
|
63
|
+
style: "currency",
|
|
64
|
+
currency,
|
|
65
|
+
minimumFractionDigits: 0,
|
|
66
|
+
maximumFractionDigits: 2,
|
|
67
|
+
}).format(amount / 100);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** Resolve the formatted price and billing interval for a product by its ID. Returns `null` if not found. */
|
|
71
|
+
export const resolveProductPrice = (
|
|
72
|
+
productId: string | undefined,
|
|
73
|
+
products: ConnectedProduct[],
|
|
74
|
+
): { formatted: string; interval?: string } | null => {
|
|
75
|
+
if (!productId || !products.length) return null;
|
|
76
|
+
const product = products.find((p) => p.id === productId);
|
|
77
|
+
if (!product) return null;
|
|
78
|
+
if (product.price == null || !product.currency) return null;
|
|
79
|
+
const formatted = formatPrice(product.price, product.currency);
|
|
80
|
+
return { formatted, interval: product.billingPeriod ?? undefined };
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const INTERVAL_LABELS: Record<string, string> = {
|
|
84
|
+
month: "/mo",
|
|
85
|
+
"every-month": "/mo",
|
|
86
|
+
"every-three-months": "/3mo",
|
|
87
|
+
"every-six-months": "/6mo",
|
|
88
|
+
year: "/yr",
|
|
89
|
+
"every-year": "/yr",
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/** Format the total price for a seat-based plan (e.g. `"$10/mo × 5 seats"`). Returns `null` if product not found. */
|
|
93
|
+
export const formatSeatPrice = (
|
|
94
|
+
productId: string | undefined,
|
|
95
|
+
products: ConnectedProduct[],
|
|
96
|
+
seats: number,
|
|
97
|
+
): string | null => {
|
|
98
|
+
const resolved = resolveProductPrice(productId, products);
|
|
99
|
+
if (!resolved) return null;
|
|
100
|
+
const suffix = resolved.interval
|
|
101
|
+
? (INTERVAL_LABELS[resolved.interval] ?? "")
|
|
102
|
+
: "";
|
|
103
|
+
if (seats <= 1) {
|
|
104
|
+
return `${resolved.formatted}${suffix}`;
|
|
105
|
+
}
|
|
106
|
+
return `${resolved.formatted}${suffix} × ${seats} seats`;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/** Format a product's price with its billing interval suffix (e.g. `"$10/mo"`). Returns `null` if product not found. */
|
|
110
|
+
export const formatPriceWithInterval = (
|
|
111
|
+
productId: string | undefined,
|
|
112
|
+
products: ConnectedProduct[],
|
|
113
|
+
): string | null => {
|
|
114
|
+
const resolved = resolveProductPrice(productId, products);
|
|
115
|
+
if (!resolved) return null;
|
|
116
|
+
const suffix = resolved.interval
|
|
117
|
+
? (INTERVAL_LABELS[resolved.interval] ?? "")
|
|
118
|
+
: "";
|
|
119
|
+
return `${resolved.formatted}${suffix}`;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/** Split a price label into main amount, interval suffix, and trailing text (e.g. `"$10/mo × 5 seats"` → `{ main: "$10", suffix: "/mo", tail: "× 5 seats" }`). */
|
|
123
|
+
export const splitPriceLabel = (
|
|
124
|
+
value: string | null,
|
|
125
|
+
): { main: string; suffix: string | null; tail: string } | null => {
|
|
126
|
+
if (!value) return null;
|
|
127
|
+
const match = value.match(/^(.*?)(\/[a-z0-9]+)(.*)$/i);
|
|
128
|
+
if (!match) return { main: value, suffix: null, tail: "" };
|
|
129
|
+
return {
|
|
130
|
+
main: match[1]?.trim() ?? value,
|
|
131
|
+
suffix: match[2] ?? null,
|
|
132
|
+
tail: match[3]?.trim() ?? "",
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/** Join CSS class tokens, filtering out falsy values. Lightweight alternative to `clsx`. */
|
|
137
|
+
export const cx = (...tokens: Array<string | undefined | false>) =>
|
|
138
|
+
tokens.filter(Boolean).join(" ");
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useState, type PropsWithChildren } from "react";
|
|
2
|
+
import { useQuery, useConvex } from "convex/react";
|
|
3
|
+
import { CustomerPortalButton } from "../primitives/CustomerPortalButton.js";
|
|
4
|
+
import type {
|
|
5
|
+
BillingPermissions,
|
|
6
|
+
ConnectedBillingApi,
|
|
7
|
+
ConnectedBillingModel,
|
|
8
|
+
} from "./types.js";
|
|
9
|
+
|
|
10
|
+
export const BillingPortal = ({
|
|
11
|
+
api,
|
|
12
|
+
permissions,
|
|
13
|
+
className = "",
|
|
14
|
+
children,
|
|
15
|
+
}: PropsWithChildren<{
|
|
16
|
+
api: ConnectedBillingApi;
|
|
17
|
+
permissions?: BillingPermissions;
|
|
18
|
+
class?: string;
|
|
19
|
+
className?: string;
|
|
20
|
+
}>) => {
|
|
21
|
+
const canAccess = permissions?.canAccessPortal !== false;
|
|
22
|
+
|
|
23
|
+
const client = useConvex();
|
|
24
|
+
|
|
25
|
+
const billingUiModelRef = api.uiModel;
|
|
26
|
+
const portalUrlRef = api.customers?.portalUrl;
|
|
27
|
+
|
|
28
|
+
const modelRaw = useQuery(billingUiModelRef, {});
|
|
29
|
+
const model = modelRaw as ConnectedBillingModel | undefined;
|
|
30
|
+
const hasCreemCustomer = model?.hasCreemCustomer ?? false;
|
|
31
|
+
|
|
32
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
33
|
+
|
|
34
|
+
const openPortal = async () => {
|
|
35
|
+
if (!portalUrlRef) return;
|
|
36
|
+
setIsLoading(true);
|
|
37
|
+
try {
|
|
38
|
+
const { url } = await client.action(portalUrlRef, {});
|
|
39
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
40
|
+
} finally {
|
|
41
|
+
setIsLoading(false);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
if (!portalUrlRef || !hasCreemCustomer || !canAccess) return null;
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<CustomerPortalButton
|
|
49
|
+
disabled={isLoading}
|
|
50
|
+
onOpenPortal={openPortal}
|
|
51
|
+
className={className}
|
|
52
|
+
>
|
|
53
|
+
{children ?? "Manage billing"}
|
|
54
|
+
</CustomerPortalButton>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useContext, useEffect } from "react";
|
|
2
|
+
import { ProductGroupContext } from "./productGroupContext.js";
|
|
3
|
+
import type { ProductType } from "./types.js";
|
|
4
|
+
|
|
5
|
+
export const ProductItem = ({
|
|
6
|
+
productId,
|
|
7
|
+
type,
|
|
8
|
+
title,
|
|
9
|
+
description,
|
|
10
|
+
}: {
|
|
11
|
+
productId: string;
|
|
12
|
+
type: ProductType;
|
|
13
|
+
title?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
}) => {
|
|
16
|
+
const rootContext = useContext(ProductGroupContext);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!rootContext) return;
|
|
20
|
+
const registration = { productId, type, title, description };
|
|
21
|
+
const unregister = rootContext.registerItem(registration);
|
|
22
|
+
return unregister;
|
|
23
|
+
}, [rootContext, productId, type, title, description]);
|
|
24
|
+
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useState,
|
|
3
|
+
useCallback,
|
|
4
|
+
useMemo,
|
|
5
|
+
useEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
type PropsWithChildren,
|
|
8
|
+
} from "react";
|
|
9
|
+
import { useQuery, useConvex } from "convex/react";
|
|
10
|
+
|
|
11
|
+
import { CheckoutButton } from "../primitives/CheckoutButton.js";
|
|
12
|
+
import { formatPriceWithInterval, splitPriceLabel } from "../shared.js";
|
|
13
|
+
import { ProductGroupContext } from "./productGroupContext.js";
|
|
14
|
+
import { renderMarkdown } from "../../core/markdown.js";
|
|
15
|
+
import { pendingCheckout } from "../../core/pendingCheckout.js";
|
|
16
|
+
|
|
17
|
+
import type {
|
|
18
|
+
BillingPermissions,
|
|
19
|
+
CheckoutIntent,
|
|
20
|
+
ConnectedBillingApi,
|
|
21
|
+
ConnectedBillingModel,
|
|
22
|
+
ProductItemRegistration,
|
|
23
|
+
Transition,
|
|
24
|
+
} from "./types.js";
|
|
25
|
+
|
|
26
|
+
export const ProductRoot = ({
|
|
27
|
+
api,
|
|
28
|
+
permissions,
|
|
29
|
+
transition = [],
|
|
30
|
+
className = "",
|
|
31
|
+
layout = "default",
|
|
32
|
+
styleVariant = "legacy",
|
|
33
|
+
showImages = false,
|
|
34
|
+
pricingCtaVariant = "faded",
|
|
35
|
+
successUrl,
|
|
36
|
+
onBeforeCheckout,
|
|
37
|
+
children,
|
|
38
|
+
}: PropsWithChildren<{
|
|
39
|
+
api: ConnectedBillingApi;
|
|
40
|
+
permissions?: BillingPermissions;
|
|
41
|
+
transition?: Transition[];
|
|
42
|
+
class?: string;
|
|
43
|
+
className?: string;
|
|
44
|
+
layout?: "default" | "single";
|
|
45
|
+
styleVariant?: "legacy" | "pricing";
|
|
46
|
+
showImages?: boolean;
|
|
47
|
+
pricingCtaVariant?: "filled" | "faded";
|
|
48
|
+
successUrl?: string;
|
|
49
|
+
onBeforeCheckout?: (intent: CheckoutIntent) => Promise<boolean> | boolean;
|
|
50
|
+
}>) => {
|
|
51
|
+
const client = useConvex();
|
|
52
|
+
|
|
53
|
+
const billingUiModelRef = api.uiModel;
|
|
54
|
+
const checkoutLinkRef = api.checkouts.create;
|
|
55
|
+
|
|
56
|
+
const modelRaw = useQuery(billingUiModelRef, {});
|
|
57
|
+
const model = (modelRaw ?? null) as ConnectedBillingModel | null;
|
|
58
|
+
|
|
59
|
+
const [registeredItems, setRegisteredItems] = useState<
|
|
60
|
+
ProductItemRegistration[]
|
|
61
|
+
>([]);
|
|
62
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
63
|
+
const [error, setError] = useState<string | null>(null);
|
|
64
|
+
|
|
65
|
+
const contextValue = useMemo(
|
|
66
|
+
() => ({
|
|
67
|
+
registerItem: (item: ProductItemRegistration) => {
|
|
68
|
+
setRegisteredItems((prev) => [
|
|
69
|
+
...prev.filter((c) => c.productId !== item.productId),
|
|
70
|
+
item,
|
|
71
|
+
]);
|
|
72
|
+
return () => {
|
|
73
|
+
setRegisteredItems((prev) =>
|
|
74
|
+
prev.filter((c) => c.productId !== item.productId),
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
[],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const canCheckout =
|
|
83
|
+
!model?.user && onBeforeCheckout != null
|
|
84
|
+
? true
|
|
85
|
+
: permissions?.canCheckout !== false;
|
|
86
|
+
const allProducts = useMemo(
|
|
87
|
+
() => model?.allProducts ?? [],
|
|
88
|
+
[model?.allProducts],
|
|
89
|
+
);
|
|
90
|
+
const rawOwnedProductIds = useMemo(
|
|
91
|
+
() => model?.ownedProductIds ?? [],
|
|
92
|
+
[model?.ownedProductIds],
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// Pending checkout resume after auth
|
|
96
|
+
const pendingCheckoutHandled = useRef(false);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (!model?.user || pendingCheckoutHandled.current) return;
|
|
99
|
+
pendingCheckoutHandled.current = true;
|
|
100
|
+
const pending = pendingCheckout.load();
|
|
101
|
+
if (!pending) return;
|
|
102
|
+
if ((model.ownedProductIds ?? []).includes(pending.productId)) {
|
|
103
|
+
pendingCheckout.clear();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
startCheckout(pending.productId);
|
|
107
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
108
|
+
}, [model?.user]);
|
|
109
|
+
|
|
110
|
+
// Resolve effective ownership by applying transition rules
|
|
111
|
+
const effectiveOwnedProductIds = useMemo(() => {
|
|
112
|
+
const effective = new Set(rawOwnedProductIds);
|
|
113
|
+
for (const rule of transition) {
|
|
114
|
+
if (rule.kind === "via_product" && effective.has(rule.viaProductId)) {
|
|
115
|
+
effective.add(rule.to);
|
|
116
|
+
effective.delete(rule.from);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return [...effective];
|
|
120
|
+
}, [rawOwnedProductIds, transition]);
|
|
121
|
+
|
|
122
|
+
const activeOwnedProductId =
|
|
123
|
+
registeredItems.find((item) =>
|
|
124
|
+
effectiveOwnedProductIds.includes(item.productId),
|
|
125
|
+
)?.productId ?? null;
|
|
126
|
+
|
|
127
|
+
const isLowerTierThan = useCallback(
|
|
128
|
+
(productId: string, targetId: string): boolean => {
|
|
129
|
+
const visited = new Set<string>();
|
|
130
|
+
const queue = [productId];
|
|
131
|
+
while (queue.length > 0) {
|
|
132
|
+
const current = queue.shift()!;
|
|
133
|
+
if (visited.has(current)) continue;
|
|
134
|
+
visited.add(current);
|
|
135
|
+
for (const rule of transition) {
|
|
136
|
+
if (rule.from === current) {
|
|
137
|
+
if (rule.to === targetId) return true;
|
|
138
|
+
queue.push(rule.to);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
},
|
|
144
|
+
[transition],
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const resolveCheckoutProductId = useCallback(
|
|
148
|
+
(toProductId: string) => {
|
|
149
|
+
if (!activeOwnedProductId) {
|
|
150
|
+
return toProductId;
|
|
151
|
+
}
|
|
152
|
+
const rule = transition.find(
|
|
153
|
+
(r) => r.from === activeOwnedProductId && r.to === toProductId,
|
|
154
|
+
);
|
|
155
|
+
if (!rule) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
if (rule.kind === "via_product") {
|
|
159
|
+
return rule.viaProductId;
|
|
160
|
+
}
|
|
161
|
+
return toProductId;
|
|
162
|
+
},
|
|
163
|
+
[activeOwnedProductId, transition],
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
const getFallbackSuccessUrl = (): string | undefined => {
|
|
167
|
+
if (typeof window === "undefined") return undefined;
|
|
168
|
+
return `${window.location.origin}${window.location.pathname}`;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const getPreferredTheme = (): "light" | "dark" => {
|
|
172
|
+
if (typeof window === "undefined") return "light";
|
|
173
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
174
|
+
? "dark"
|
|
175
|
+
: "light";
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const startCheckout = useCallback(
|
|
179
|
+
async (checkoutProductId: string) => {
|
|
180
|
+
if (onBeforeCheckout) {
|
|
181
|
+
const proceed = await onBeforeCheckout({
|
|
182
|
+
productId: checkoutProductId,
|
|
183
|
+
});
|
|
184
|
+
if (!proceed) return;
|
|
185
|
+
}
|
|
186
|
+
setIsLoading(true);
|
|
187
|
+
setError(null);
|
|
188
|
+
try {
|
|
189
|
+
const { url } = await client.action(checkoutLinkRef, {
|
|
190
|
+
productId: checkoutProductId,
|
|
191
|
+
...(successUrl ? { successUrl } : {}),
|
|
192
|
+
fallbackSuccessUrl: getFallbackSuccessUrl(),
|
|
193
|
+
theme: getPreferredTheme(),
|
|
194
|
+
});
|
|
195
|
+
window.addEventListener(
|
|
196
|
+
"beforeunload",
|
|
197
|
+
(e) => {
|
|
198
|
+
e.stopImmediatePropagation();
|
|
199
|
+
},
|
|
200
|
+
{ capture: true, once: true },
|
|
201
|
+
);
|
|
202
|
+
window.location.href = url;
|
|
203
|
+
} catch (checkoutError) {
|
|
204
|
+
setError(
|
|
205
|
+
checkoutError instanceof Error
|
|
206
|
+
? checkoutError.message
|
|
207
|
+
: "Checkout failed",
|
|
208
|
+
);
|
|
209
|
+
} finally {
|
|
210
|
+
setIsLoading(false);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
[client, checkoutLinkRef, successUrl, onBeforeCheckout],
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<ProductGroupContext.Provider value={contextValue}>
|
|
218
|
+
<div className="hidden" aria-hidden="true">
|
|
219
|
+
{children}
|
|
220
|
+
</div>
|
|
221
|
+
|
|
222
|
+
<section
|
|
223
|
+
className={`${styleVariant === "pricing" ? "space-y-0" : "space-y-3"} ${className}`}
|
|
224
|
+
>
|
|
225
|
+
{error && <p className="text-sm text-red-600">{error}</p>}
|
|
226
|
+
|
|
227
|
+
<div
|
|
228
|
+
className={
|
|
229
|
+
styleVariant === "pricing"
|
|
230
|
+
? layout === "single"
|
|
231
|
+
? "flex justify-center"
|
|
232
|
+
: "grid grid-cols-1 gap-1 lg:grid-cols-2"
|
|
233
|
+
: `flex gap-3 ${layout === "single" ? "justify-center" : "flex-wrap items-center"}`
|
|
234
|
+
}
|
|
235
|
+
>
|
|
236
|
+
{registeredItems.map((item) => {
|
|
237
|
+
const isOwned = effectiveOwnedProductIds.includes(item.productId);
|
|
238
|
+
const isIncluded =
|
|
239
|
+
!isOwned &&
|
|
240
|
+
activeOwnedProductId != null &&
|
|
241
|
+
isLowerTierThan(item.productId, activeOwnedProductId);
|
|
242
|
+
const checkoutProductId = resolveCheckoutProductId(item.productId);
|
|
243
|
+
const matchedProduct = allProducts.find(
|
|
244
|
+
(p) => p.id === item.productId,
|
|
245
|
+
);
|
|
246
|
+
const resolvedTitle =
|
|
247
|
+
item.title ?? matchedProduct?.name ?? item.productId;
|
|
248
|
+
const resolvedDescription =
|
|
249
|
+
item.description ?? matchedProduct?.description;
|
|
250
|
+
const resolvedImageUrl = matchedProduct?.imageUrl;
|
|
251
|
+
const resolvedPrice = formatPriceWithInterval(
|
|
252
|
+
item.productId,
|
|
253
|
+
allProducts,
|
|
254
|
+
);
|
|
255
|
+
const splitPrice = splitPriceLabel(resolvedPrice);
|
|
256
|
+
const descriptionLines = (resolvedDescription ?? "")
|
|
257
|
+
.split(/\r?\n/)
|
|
258
|
+
.map((line) => line.trim())
|
|
259
|
+
.filter(Boolean)
|
|
260
|
+
.map((line) => line.replace(/^(?:[-*]\s+|[✔✓]\s*)/, "").trim())
|
|
261
|
+
.filter(Boolean);
|
|
262
|
+
|
|
263
|
+
if (styleVariant === "pricing") {
|
|
264
|
+
return (
|
|
265
|
+
<article
|
|
266
|
+
key={item.productId}
|
|
267
|
+
className={`w-full ${layout === "single" ? "max-w-[680px]" : "max-w-none"} rounded-2xl bg-surface-base ${isIncluded ? "opacity-60" : ""}`}
|
|
268
|
+
>
|
|
269
|
+
{showImages && resolvedImageUrl && (
|
|
270
|
+
<div className="p-1">
|
|
271
|
+
<img
|
|
272
|
+
src={resolvedImageUrl}
|
|
273
|
+
alt={resolvedTitle}
|
|
274
|
+
className="aspect-[16/9] w-full rounded-xl object-cover"
|
|
275
|
+
loading="lazy"
|
|
276
|
+
/>
|
|
277
|
+
</div>
|
|
278
|
+
)}
|
|
279
|
+
|
|
280
|
+
<div className="px-6 pb-6 pt-6">
|
|
281
|
+
<div className="mb-3 flex min-h-6 items-center justify-between gap-2">
|
|
282
|
+
<h3 className="title-s text-foreground-default">
|
|
283
|
+
{resolvedTitle}
|
|
284
|
+
</h3>
|
|
285
|
+
{isOwned ? (
|
|
286
|
+
<span className="badge-faded-sm">Owned</span>
|
|
287
|
+
) : isIncluded ? (
|
|
288
|
+
<span className="badge-faded-sm">Included</span>
|
|
289
|
+
) : null}
|
|
290
|
+
</div>
|
|
291
|
+
|
|
292
|
+
{splitPrice && (
|
|
293
|
+
<div className="flex items-baseline gap-1">
|
|
294
|
+
<span className="heading-s text-foreground-default">
|
|
295
|
+
{splitPrice.main}
|
|
296
|
+
</span>
|
|
297
|
+
{splitPrice.suffix && (
|
|
298
|
+
<span className="title-s text-foreground-placeholder">
|
|
299
|
+
{splitPrice.suffix}
|
|
300
|
+
</span>
|
|
301
|
+
)}
|
|
302
|
+
{splitPrice.tail && (
|
|
303
|
+
<span className="title-s text-foreground-placeholder">
|
|
304
|
+
{splitPrice.tail}
|
|
305
|
+
</span>
|
|
306
|
+
)}
|
|
307
|
+
</div>
|
|
308
|
+
)}
|
|
309
|
+
|
|
310
|
+
<div className="mb-4 mt-6 flex min-h-8 items-start">
|
|
311
|
+
{checkoutProductId && !isOwned && !isIncluded ? (
|
|
312
|
+
<CheckoutButton
|
|
313
|
+
productId={checkoutProductId}
|
|
314
|
+
disabled={isLoading || !canCheckout}
|
|
315
|
+
onCheckout={() => startCheckout(checkoutProductId)}
|
|
316
|
+
className={`${pricingCtaVariant === "filled" ? "button-filled" : "button-faded"} w-full`}
|
|
317
|
+
>
|
|
318
|
+
{activeOwnedProductId ? "Upgrade" : "Buy now"}
|
|
319
|
+
</CheckoutButton>
|
|
320
|
+
) : !isOwned && !isIncluded ? (
|
|
321
|
+
<CheckoutButton
|
|
322
|
+
productId={item.productId}
|
|
323
|
+
disabled={isLoading || !canCheckout}
|
|
324
|
+
onCheckout={() => startCheckout(item.productId)}
|
|
325
|
+
className={`${pricingCtaVariant === "filled" ? "button-filled" : "button-faded"} w-full`}
|
|
326
|
+
>
|
|
327
|
+
Buy now
|
|
328
|
+
</CheckoutButton>
|
|
329
|
+
) : null}
|
|
330
|
+
</div>
|
|
331
|
+
|
|
332
|
+
{descriptionLines.length > 0 && (
|
|
333
|
+
<div className="w-full pt-4">
|
|
334
|
+
<p className="label-m mb-4 font-semibold text-foreground-default">
|
|
335
|
+
What's included:
|
|
336
|
+
</p>
|
|
337
|
+
<ul className="space-y-2">
|
|
338
|
+
{descriptionLines.map((feature) => (
|
|
339
|
+
<li
|
|
340
|
+
key={feature}
|
|
341
|
+
className="flex items-center gap-2"
|
|
342
|
+
>
|
|
343
|
+
<span className="inline-flex h-5 w-5 shrink-0 items-center justify-center text-foreground-muted">
|
|
344
|
+
<svg
|
|
345
|
+
aria-hidden="true"
|
|
346
|
+
viewBox="0 0 24 24"
|
|
347
|
+
fill="none"
|
|
348
|
+
className="h-4 w-4"
|
|
349
|
+
>
|
|
350
|
+
<path
|
|
351
|
+
d="M20 6L9 17L4 12"
|
|
352
|
+
stroke="currentColor"
|
|
353
|
+
strokeWidth="2.5"
|
|
354
|
+
strokeLinecap="round"
|
|
355
|
+
strokeLinejoin="round"
|
|
356
|
+
/>
|
|
357
|
+
</svg>
|
|
358
|
+
</span>
|
|
359
|
+
<span className="body-m text-foreground-default">
|
|
360
|
+
{feature}
|
|
361
|
+
</span>
|
|
362
|
+
</li>
|
|
363
|
+
))}
|
|
364
|
+
</ul>
|
|
365
|
+
</div>
|
|
366
|
+
)}
|
|
367
|
+
</div>
|
|
368
|
+
</article>
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Legacy style variant
|
|
373
|
+
return (
|
|
374
|
+
<article
|
|
375
|
+
key={item.productId}
|
|
376
|
+
className={`max-w-sm rounded-xl border p-4 shadow-sm ${
|
|
377
|
+
isIncluded
|
|
378
|
+
? "border-zinc-100 bg-zinc-50 opacity-60 dark:border-zinc-800 dark:bg-zinc-900"
|
|
379
|
+
: "border-zinc-200 bg-zinc-50 dark:border-zinc-800 dark:bg-zinc-950"
|
|
380
|
+
}`}
|
|
381
|
+
>
|
|
382
|
+
<h3 className="text-base font-semibold text-zinc-900 dark:text-zinc-100">
|
|
383
|
+
{resolvedTitle}
|
|
384
|
+
</h3>
|
|
385
|
+
|
|
386
|
+
{resolvedPrice && (
|
|
387
|
+
<p
|
|
388
|
+
className={`mt-2 text-2xl font-bold ${
|
|
389
|
+
isIncluded
|
|
390
|
+
? "text-zinc-400 dark:text-zinc-500"
|
|
391
|
+
: "text-zinc-900 dark:text-zinc-100"
|
|
392
|
+
}`}
|
|
393
|
+
>
|
|
394
|
+
{resolvedPrice}
|
|
395
|
+
</p>
|
|
396
|
+
)}
|
|
397
|
+
|
|
398
|
+
<div className="mt-4">
|
|
399
|
+
{isOwned ? (
|
|
400
|
+
<span className="inline-flex rounded-md bg-emerald-100 px-3 py-2 text-sm font-medium text-emerald-700">
|
|
401
|
+
Owned
|
|
402
|
+
</span>
|
|
403
|
+
) : isIncluded ? (
|
|
404
|
+
<span className="inline-flex rounded-md bg-zinc-100 px-3 py-2 text-sm font-medium text-zinc-500 dark:bg-zinc-800 dark:text-zinc-400">
|
|
405
|
+
Included
|
|
406
|
+
</span>
|
|
407
|
+
) : checkoutProductId ? (
|
|
408
|
+
<CheckoutButton
|
|
409
|
+
productId={checkoutProductId}
|
|
410
|
+
disabled={isLoading || !canCheckout}
|
|
411
|
+
onCheckout={() => startCheckout(checkoutProductId)}
|
|
412
|
+
>
|
|
413
|
+
{activeOwnedProductId ? "Upgrade" : "Buy now"}
|
|
414
|
+
</CheckoutButton>
|
|
415
|
+
) : (
|
|
416
|
+
<CheckoutButton
|
|
417
|
+
productId={item.productId}
|
|
418
|
+
disabled={isLoading || !canCheckout}
|
|
419
|
+
onCheckout={() => startCheckout(item.productId)}
|
|
420
|
+
>
|
|
421
|
+
Buy now
|
|
422
|
+
</CheckoutButton>
|
|
423
|
+
)}
|
|
424
|
+
</div>
|
|
425
|
+
|
|
426
|
+
{resolvedDescription && (
|
|
427
|
+
<div
|
|
428
|
+
className="creem-prose mt-4 text-sm text-zinc-600 dark:text-zinc-300"
|
|
429
|
+
dangerouslySetInnerHTML={{
|
|
430
|
+
__html: renderMarkdown(resolvedDescription),
|
|
431
|
+
}}
|
|
432
|
+
/>
|
|
433
|
+
)}
|
|
434
|
+
</article>
|
|
435
|
+
);
|
|
436
|
+
})}
|
|
437
|
+
</div>
|
|
438
|
+
</section>
|
|
439
|
+
</ProductGroupContext.Provider>
|
|
440
|
+
);
|
|
441
|
+
};
|