@fantastic.dev/better-stripe 0.7.0 → 0.8.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/CHANGELOG.md +23 -18
- package/README.md +122 -90
- package/dist/client/billing/checkout.d.ts +1 -1
- package/dist/client/billing/checkout.d.ts.map +1 -1
- package/dist/client/billing/checkout.js +7 -2
- package/dist/client/billing/checkout.js.map +1 -1
- package/dist/client/connect/paymentMethods.d.ts.map +1 -1
- package/dist/client/connect/paymentMethods.js.map +1 -1
- package/dist/client/connect/refundActor.d.ts.map +1 -1
- package/dist/client/connect/refundActor.js.map +1 -1
- package/dist/client/connect/refunds.d.ts.map +1 -1
- package/dist/client/connect/refunds.js.map +1 -1
- package/dist/client/connect/transfers.d.ts.map +1 -1
- package/dist/client/connect/transfers.js +15 -4
- package/dist/client/connect/transfers.js.map +1 -1
- package/dist/client/core/accountDefaults.d.ts +6 -0
- package/dist/client/core/accountDefaults.d.ts.map +1 -0
- package/dist/client/core/accountDefaults.js +15 -0
- package/dist/client/core/accountDefaults.js.map +1 -0
- package/dist/client/core/accounts.d.ts +1 -5
- package/dist/client/core/accounts.d.ts.map +1 -1
- package/dist/client/core/accounts.js +2 -14
- package/dist/client/core/accounts.js.map +1 -1
- package/dist/client/core/fees.d.ts.map +1 -1
- package/dist/client/core/fees.js +7 -2
- package/dist/client/core/fees.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/products/prices.d.ts.map +1 -1
- package/dist/client/products/prices.js.map +1 -1
- package/dist/client/products/products.d.ts.map +1 -1
- package/dist/client/products/products.js +3 -1
- package/dist/client/products/products.js.map +1 -1
- package/dist/client/utils/owner.d.ts.map +1 -1
- package/dist/client/utils/owner.js +3 -1
- package/dist/client/utils/owner.js.map +1 -1
- package/dist/client/utils/stripeDashboardUrl.d.ts.map +1 -1
- package/dist/client/utils/stripeDashboardUrl.js.map +1 -1
- package/dist/client/webhooks/helpers.d.ts +10 -0
- package/dist/client/webhooks/helpers.d.ts.map +1 -1
- package/dist/client/webhooks/helpers.js +18 -0
- package/dist/client/webhooks/helpers.js.map +1 -1
- package/dist/client/webhooks/processors.d.ts.map +1 -1
- package/dist/client/webhooks/processors.js +1 -19
- package/dist/client/webhooks/processors.js.map +1 -1
- package/dist/component/connect/mutations.d.ts.map +1 -1
- package/dist/component/connect/mutations.js +4 -33
- package/dist/component/connect/mutations.js.map +1 -1
- package/dist/component/connect/schema.d.ts.map +1 -1
- package/dist/component/connect/schema.js.map +1 -1
- package/dist/component/lib/paymentSeller.d.ts +3 -0
- package/dist/component/lib/paymentSeller.d.ts.map +1 -0
- package/dist/component/lib/paymentSeller.js +10 -0
- package/dist/component/lib/paymentSeller.js.map +1 -0
- package/dist/component/lib/reversals.d.ts +10 -0
- package/dist/component/lib/reversals.d.ts.map +1 -1
- package/dist/component/lib/reversals.js +17 -0
- package/dist/component/lib/reversals.js.map +1 -1
- package/dist/react/components/ConnectProvider.d.ts +1 -1
- package/dist/react/components/ConnectProvider.d.ts.map +1 -1
- package/dist/react/components/ConnectProvider.js +18 -4
- package/dist/react/components/ConnectProvider.js.map +1 -1
- package/dist/react/components/ConnectStatusBadge.d.ts.map +1 -1
- package/dist/react/components/ConnectStatusBadge.js.map +1 -1
- package/dist/react/components/EmbeddedDisputes.d.ts +1 -1
- package/dist/react/components/EmbeddedDisputes.d.ts.map +1 -1
- package/dist/react/components/EmbeddedDisputes.js +1 -1
- package/dist/react/components/EmbeddedDisputes.js.map +1 -1
- package/dist/react/components/SplitBreakdown.d.ts.map +1 -1
- package/dist/react/components/SplitBreakdown.js +12 -2
- package/dist/react/components/SplitBreakdown.js.map +1 -1
- package/dist/react/hooks/useCheckoutSession.d.ts.map +1 -1
- package/dist/react/hooks/useCheckoutSession.js.map +1 -1
- package/dist/react/hooks/useConfirmPayment.d.ts.map +1 -1
- package/dist/react/hooks/useConfirmPayment.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/workflows/Account.d.ts +67 -0
- package/dist/react/workflows/Account.d.ts.map +1 -0
- package/dist/react/workflows/Account.js +74 -0
- package/dist/react/workflows/Account.js.map +1 -0
- package/dist/react/workflows/Billing.d.ts +60 -0
- package/dist/react/workflows/Billing.d.ts.map +1 -0
- package/dist/react/workflows/Billing.js +84 -0
- package/dist/react/workflows/Billing.js.map +1 -0
- package/dist/react/workflows/BillingPlans.d.ts +45 -0
- package/dist/react/workflows/BillingPlans.d.ts.map +1 -0
- package/dist/react/workflows/BillingPlans.js +51 -0
- package/dist/react/workflows/BillingPlans.js.map +1 -0
- package/dist/react/workflows/Checkout.d.ts +46 -0
- package/dist/react/workflows/Checkout.d.ts.map +1 -0
- package/dist/react/workflows/Checkout.js +61 -0
- package/dist/react/workflows/Checkout.js.map +1 -0
- package/dist/react/workflows/CheckoutChooser.d.ts +20 -0
- package/dist/react/workflows/CheckoutChooser.d.ts.map +1 -0
- package/dist/react/workflows/CheckoutChooser.js +24 -0
- package/dist/react/workflows/CheckoutChooser.js.map +1 -0
- package/dist/react/workflows/CheckoutForms.d.ts +26 -0
- package/dist/react/workflows/CheckoutForms.d.ts.map +1 -0
- package/dist/react/workflows/CheckoutForms.js +126 -0
- package/dist/react/workflows/CheckoutForms.js.map +1 -0
- package/dist/react/workflows/ClipboardButton.d.ts +17 -0
- package/dist/react/workflows/ClipboardButton.d.ts.map +1 -0
- package/dist/react/workflows/ClipboardButton.js +35 -0
- package/dist/react/workflows/ClipboardButton.js.map +1 -0
- package/dist/react/workflows/Collection.d.ts +30 -0
- package/dist/react/workflows/Collection.d.ts.map +1 -0
- package/dist/react/workflows/Collection.js +25 -0
- package/dist/react/workflows/Collection.js.map +1 -0
- package/dist/react/workflows/Collections.d.ts +56 -0
- package/dist/react/workflows/Collections.d.ts.map +1 -0
- package/dist/react/workflows/Collections.js +111 -0
- package/dist/react/workflows/Collections.js.map +1 -0
- package/dist/react/workflows/Connect.d.ts +19 -0
- package/dist/react/workflows/Connect.d.ts.map +1 -0
- package/dist/react/workflows/Connect.js +43 -0
- package/dist/react/workflows/Connect.js.map +1 -0
- package/dist/react/workflows/Costs.d.ts +48 -0
- package/dist/react/workflows/Costs.d.ts.map +1 -0
- package/dist/react/workflows/Costs.js +66 -0
- package/dist/react/workflows/Costs.js.map +1 -0
- package/dist/react/workflows/Disputes.d.ts +36 -0
- package/dist/react/workflows/Disputes.d.ts.map +1 -0
- package/dist/react/workflows/Disputes.js +74 -0
- package/dist/react/workflows/Disputes.js.map +1 -0
- package/dist/react/workflows/Earnings.d.ts +42 -0
- package/dist/react/workflows/Earnings.d.ts.map +1 -0
- package/dist/react/workflows/Earnings.js +38 -0
- package/dist/react/workflows/Earnings.js.map +1 -0
- package/dist/react/workflows/Financials.d.ts +43 -0
- package/dist/react/workflows/Financials.d.ts.map +1 -0
- package/dist/react/workflows/Financials.js +57 -0
- package/dist/react/workflows/Financials.js.map +1 -0
- package/dist/react/workflows/IntegrationSwitch.d.ts +23 -0
- package/dist/react/workflows/IntegrationSwitch.d.ts.map +1 -0
- package/dist/react/workflows/IntegrationSwitch.js +31 -0
- package/dist/react/workflows/IntegrationSwitch.js.map +1 -0
- package/dist/react/workflows/Onboarding.d.ts +56 -0
- package/dist/react/workflows/Onboarding.d.ts.map +1 -0
- package/dist/react/workflows/Onboarding.js +86 -0
- package/dist/react/workflows/Onboarding.js.map +1 -0
- package/dist/react/workflows/Overview.d.ts +51 -0
- package/dist/react/workflows/Overview.d.ts.map +1 -0
- package/dist/react/workflows/Overview.js +63 -0
- package/dist/react/workflows/Overview.js.map +1 -0
- package/dist/react/workflows/PaymentMethods.d.ts +35 -0
- package/dist/react/workflows/PaymentMethods.d.ts.map +1 -0
- package/dist/react/workflows/PaymentMethods.js +63 -0
- package/dist/react/workflows/PaymentMethods.js.map +1 -0
- package/dist/react/workflows/PaymentReceipt.d.ts +20 -0
- package/dist/react/workflows/PaymentReceipt.d.ts.map +1 -0
- package/dist/react/workflows/PaymentReceipt.js +24 -0
- package/dist/react/workflows/PaymentReceipt.js.map +1 -0
- package/dist/react/workflows/Payouts.d.ts +47 -0
- package/dist/react/workflows/Payouts.d.ts.map +1 -0
- package/dist/react/workflows/Payouts.js +87 -0
- package/dist/react/workflows/Payouts.js.map +1 -0
- package/dist/react/workflows/Products.d.ts +92 -0
- package/dist/react/workflows/Products.d.ts.map +1 -0
- package/dist/react/workflows/Products.js +179 -0
- package/dist/react/workflows/Products.js.map +1 -0
- package/dist/react/workflows/ReferralLinks.d.ts +26 -0
- package/dist/react/workflows/ReferralLinks.d.ts.map +1 -0
- package/dist/react/workflows/ReferralLinks.js +30 -0
- package/dist/react/workflows/ReferralLinks.js.map +1 -0
- package/dist/react/workflows/Refunds.d.ts +72 -0
- package/dist/react/workflows/Refunds.d.ts.map +1 -0
- package/dist/react/workflows/Refunds.js +95 -0
- package/dist/react/workflows/Refunds.js.map +1 -0
- package/dist/react/workflows/Setup.d.ts +50 -0
- package/dist/react/workflows/Setup.d.ts.map +1 -0
- package/dist/react/workflows/Setup.js +59 -0
- package/dist/react/workflows/Setup.js.map +1 -0
- package/dist/react/workflows/Storefront.d.ts +53 -0
- package/dist/react/workflows/Storefront.d.ts.map +1 -0
- package/dist/react/workflows/Storefront.js +44 -0
- package/dist/react/workflows/Storefront.js.map +1 -0
- package/dist/react/workflows/SubscriptionOverview.d.ts +13 -0
- package/dist/react/workflows/SubscriptionOverview.d.ts.map +1 -0
- package/dist/react/workflows/SubscriptionOverview.js +26 -0
- package/dist/react/workflows/SubscriptionOverview.js.map +1 -0
- package/dist/react/workflows/Subscriptions.d.ts +92 -0
- package/dist/react/workflows/Subscriptions.d.ts.map +1 -0
- package/dist/react/workflows/Subscriptions.js +149 -0
- package/dist/react/workflows/Subscriptions.js.map +1 -0
- package/dist/react/workflows/Tasks.d.ts +40 -0
- package/dist/react/workflows/Tasks.d.ts.map +1 -0
- package/dist/react/workflows/Tasks.js +113 -0
- package/dist/react/workflows/Tasks.js.map +1 -0
- package/dist/react/workflows/checkout-options.d.ts +37 -0
- package/dist/react/workflows/checkout-options.d.ts.map +1 -0
- package/dist/react/workflows/checkout-options.js +43 -0
- package/dist/react/workflows/checkout-options.js.map +1 -0
- package/dist/react/workflows/current-subscription.d.ts +11 -0
- package/dist/react/workflows/current-subscription.d.ts.map +1 -0
- package/dist/react/workflows/current-subscription.js +14 -0
- package/dist/react/workflows/current-subscription.js.map +1 -0
- package/dist/react/workflows/filters.d.ts +17 -0
- package/dist/react/workflows/filters.d.ts.map +1 -0
- package/dist/react/workflows/filters.js +23 -0
- package/dist/react/workflows/filters.js.map +1 -0
- package/dist/react/workflows/index.d.ts +70 -0
- package/dist/react/workflows/index.d.ts.map +1 -0
- package/dist/react/workflows/index.js +38 -0
- package/dist/react/workflows/index.js.map +1 -0
- package/dist/react/workflows/useWorkflowAction.d.ts +11 -0
- package/dist/react/workflows/useWorkflowAction.d.ts.map +1 -0
- package/dist/react/workflows/useWorkflowAction.js +68 -0
- package/dist/react/workflows/useWorkflowAction.js.map +1 -0
- package/dist/react/workflows/useWorkflowResource.d.ts +9 -0
- package/dist/react/workflows/useWorkflowResource.d.ts.map +1 -0
- package/dist/react/workflows/useWorkflowResource.js +67 -0
- package/dist/react/workflows/useWorkflowResource.js.map +1 -0
- package/docs/react-workflows-audit.md +66 -0
- package/docs/react-workflows.md +231 -0
- package/package.json +19 -3
- package/src/client/billing/checkout-ui-modes.test.ts +49 -0
- package/src/client/billing/checkout.ts +8 -3
- package/src/client/billing/invoices.test.ts +12 -6
- package/src/client/connect/paymentMethods.test.ts +3 -1
- package/src/client/connect/paymentMethods.ts +4 -1
- package/src/client/connect/refundActor.ts +1 -2
- package/src/client/connect/refunds.test.ts +35 -10
- package/src/client/connect/refunds.ts +4 -1
- package/src/client/connect/transfers.test.ts +66 -12
- package/src/client/connect/transfers.ts +32 -8
- package/src/client/core/accountDefaults.ts +15 -0
- package/src/client/core/accounts.ts +14 -17
- package/src/client/core/config.test.ts +2 -1
- package/src/client/core/descriptors.test.ts +6 -4
- package/src/client/core/fees.test.ts +20 -28
- package/src/client/core/fees.ts +9 -2
- package/src/client/index.test.ts +22 -22
- package/src/client/index.ts +1 -1
- package/src/client/products/prices.test.ts +8 -2
- package/src/client/products/prices.ts +4 -1
- package/src/client/products/products.test.ts +61 -20
- package/src/client/products/products.ts +3 -1
- package/src/client/utils/data.test.ts +3 -1
- package/src/client/utils/owner.test.ts +4 -1
- package/src/client/utils/owner.ts +5 -1
- package/src/client/utils/stripeDashboardUrl.ts +1 -4
- package/src/client/webhooks/handler.test.ts +16 -19
- package/src/client/webhooks/helpers.test.ts +26 -13
- package/src/client/webhooks/helpers.ts +23 -0
- package/src/client/webhooks/hooks.test.ts +1 -2
- package/src/client/webhooks/processors.test.ts +18 -34
- package/src/client/webhooks/processors.ts +1 -23
- package/src/client/webhooks.test.ts +1 -2
- package/src/component/_generated/api.ts +2 -0
- package/src/component/connect/mutations.ts +5 -46
- package/src/component/connect/schema.ts +4 -3
- package/src/component/connect.test.ts +1 -5
- package/src/component/lib/paymentSeller.ts +15 -0
- package/src/component/lib/reversals.ts +30 -2
- package/src/component/subscription-scoping.test.ts +5 -1
- package/src/component/triggers.test.ts +7 -4
- package/src/react/components/BuyerBillingView.render.test.tsx +7 -2
- package/src/react/components/ConnectProvider.live.test.tsx +61 -0
- package/src/react/components/ConnectProvider.tsx +18 -4
- package/src/react/components/ConnectStatusBadge.tsx +1 -4
- package/src/react/components/DisputeDetail.render.test.tsx +5 -1
- package/src/react/components/EarningsSummary.render.test.tsx +2 -6
- package/src/react/components/EmbeddedDisputes.render.test.tsx +7 -5
- package/src/react/components/EmbeddedDisputes.tsx +4 -1
- package/src/react/components/EvidenceForm.render.test.tsx +2 -8
- package/src/react/components/SplitBreakdown.render.test.tsx +28 -5
- package/src/react/components/SplitBreakdown.tsx +12 -2
- package/src/react/hooks/useCheckoutSession.ts +1 -2
- package/src/react/hooks/useConfirmPayment.ts +1 -2
- package/src/react/hooks/useEarnings.test.ts +43 -8
- package/src/react/hooks/useStripeMode.test.ts +5 -8
- package/src/react/index.ts +3 -0
- package/src/react/workflows/Account.test.tsx +31 -0
- package/src/react/workflows/Account.tsx +183 -0
- package/src/react/workflows/Billing.test.tsx +45 -0
- package/src/react/workflows/Billing.tsx +213 -0
- package/src/react/workflows/BillingPlans.test.tsx +31 -0
- package/src/react/workflows/BillingPlans.tsx +130 -0
- package/src/react/workflows/Checkout.test.tsx +118 -0
- package/src/react/workflows/Checkout.tsx +135 -0
- package/src/react/workflows/CheckoutChooser.test.tsx +44 -0
- package/src/react/workflows/CheckoutChooser.tsx +77 -0
- package/src/react/workflows/CheckoutForm.test.tsx +66 -0
- package/src/react/workflows/CheckoutForms.test.tsx +123 -0
- package/src/react/workflows/CheckoutForms.tsx +247 -0
- package/src/react/workflows/ClipboardButton.test.tsx +34 -0
- package/src/react/workflows/ClipboardButton.tsx +67 -0
- package/src/react/workflows/Collection.tsx +76 -0
- package/src/react/workflows/Collections.test.tsx +86 -0
- package/src/react/workflows/Collections.tsx +213 -0
- package/src/react/workflows/Connect.test.tsx +50 -0
- package/src/react/workflows/Connect.tsx +107 -0
- package/src/react/workflows/Costs.test.tsx +41 -0
- package/src/react/workflows/Costs.tsx +133 -0
- package/src/react/workflows/Disputes.test.tsx +25 -0
- package/src/react/workflows/Disputes.tsx +164 -0
- package/src/react/workflows/Earnings.test.ts +19 -0
- package/src/react/workflows/Earnings.tsx +84 -0
- package/src/react/workflows/Financials.test.tsx +35 -0
- package/src/react/workflows/Financials.tsx +117 -0
- package/src/react/workflows/IntegrationSwitch.test.tsx +36 -0
- package/src/react/workflows/IntegrationSwitch.tsx +63 -0
- package/src/react/workflows/Onboarding.test.tsx +75 -0
- package/src/react/workflows/Onboarding.tsx +171 -0
- package/src/react/workflows/Overview.test.tsx +57 -0
- package/src/react/workflows/Overview.tsx +123 -0
- package/src/react/workflows/PaymentMethods.test.tsx +60 -0
- package/src/react/workflows/PaymentMethods.tsx +117 -0
- package/src/react/workflows/PaymentReceipt.test.tsx +24 -0
- package/src/react/workflows/PaymentReceipt.tsx +46 -0
- package/src/react/workflows/Payouts.test.tsx +82 -0
- package/src/react/workflows/Payouts.tsx +212 -0
- package/src/react/workflows/Products.test.tsx +90 -0
- package/src/react/workflows/Products.tsx +377 -0
- package/src/react/workflows/ReferralLinks.test.tsx +39 -0
- package/src/react/workflows/ReferralLinks.tsx +75 -0
- package/src/react/workflows/Refunds.test.tsx +75 -0
- package/src/react/workflows/Refunds.tsx +223 -0
- package/src/react/workflows/Setup.test.tsx +25 -0
- package/src/react/workflows/Setup.tsx +166 -0
- package/src/react/workflows/Storefront.test.tsx +82 -0
- package/src/react/workflows/Storefront.tsx +138 -0
- package/src/react/workflows/SubscriptionOverview.test.tsx +27 -0
- package/src/react/workflows/SubscriptionOverview.tsx +48 -0
- package/src/react/workflows/Subscriptions.test.tsx +61 -0
- package/src/react/workflows/Subscriptions.tsx +282 -0
- package/src/react/workflows/Tasks.test.tsx +23 -0
- package/src/react/workflows/Tasks.tsx +199 -0
- package/src/react/workflows/checkout-options.ts +42 -0
- package/src/react/workflows/current-subscription.test.ts +29 -0
- package/src/react/workflows/current-subscription.ts +25 -0
- package/src/react/workflows/filters.test.ts +12 -0
- package/src/react/workflows/filters.ts +22 -0
- package/src/react/workflows/index.ts +238 -0
- package/src/react/workflows/native-interactions.test.tsx +73 -0
- package/src/react/workflows/public-workflows.test.tsx +216 -0
- package/src/react/workflows/useWorkflowAction.test.tsx +54 -0
- package/src/react/workflows/useWorkflowAction.ts +75 -0
- package/src/react/workflows/useWorkflowResource.test.tsx +41 -0
- package/src/react/workflows/useWorkflowResource.ts +78 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { formatPriceWithInterval } from "../lib/price-helpers.js";
|
|
4
|
+
export type StorefrontPrice = {
|
|
5
|
+
stripePriceId: string;
|
|
6
|
+
unitAmount: number;
|
|
7
|
+
currency: string;
|
|
8
|
+
type: string;
|
|
9
|
+
interval?: string | null;
|
|
10
|
+
intervalCount?: number | null;
|
|
11
|
+
active?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type StorefrontProduct = {
|
|
14
|
+
stripeProductId: string;
|
|
15
|
+
name: string;
|
|
16
|
+
description?: string | null;
|
|
17
|
+
active?: boolean;
|
|
18
|
+
prices: StorefrontPrice[];
|
|
19
|
+
};
|
|
20
|
+
export type StorefrontStore = {
|
|
21
|
+
accountId: string;
|
|
22
|
+
name: string;
|
|
23
|
+
products: StorefrontProduct[];
|
|
24
|
+
};
|
|
25
|
+
export type StorefrontSelection = {
|
|
26
|
+
store: StorefrontStore;
|
|
27
|
+
product: StorefrontProduct;
|
|
28
|
+
price: StorefrontPrice;
|
|
29
|
+
referralCode?: string;
|
|
30
|
+
};
|
|
31
|
+
export type StorefrontCard = StorefrontSelection & {
|
|
32
|
+
formattedPrice: string;
|
|
33
|
+
purchaseLabel: string;
|
|
34
|
+
accessibilityLabel: string;
|
|
35
|
+
checkoutUrl?: string;
|
|
36
|
+
purchase: () => void;
|
|
37
|
+
};
|
|
38
|
+
export type StorefrontRenderProps = {
|
|
39
|
+
stores: StorefrontStore[];
|
|
40
|
+
cards: StorefrontCard[];
|
|
41
|
+
isLoading: boolean;
|
|
42
|
+
isEmpty: boolean;
|
|
43
|
+
canPurchase: boolean;
|
|
44
|
+
};
|
|
45
|
+
export type StorefrontProps = {
|
|
46
|
+
stores: StorefrontStore[] | undefined;
|
|
47
|
+
storeId?: string;
|
|
48
|
+
referralCode?: string;
|
|
49
|
+
canPurchase?: boolean;
|
|
50
|
+
getCheckoutUrl?: (selection: StorefrontSelection) => string;
|
|
51
|
+
onSelectPrice?: (selection: StorefrontSelection) => void;
|
|
52
|
+
children?: (state: StorefrontRenderProps) => ReactNode;
|
|
53
|
+
};
|
|
54
|
+
export function Storefront({
|
|
55
|
+
stores,
|
|
56
|
+
storeId,
|
|
57
|
+
referralCode,
|
|
58
|
+
canPurchase = true,
|
|
59
|
+
getCheckoutUrl,
|
|
60
|
+
onSelectPrice,
|
|
61
|
+
children,
|
|
62
|
+
}: StorefrontProps) {
|
|
63
|
+
const visible =
|
|
64
|
+
stores?.filter((store) => !storeId || store.accountId === storeId) ?? [];
|
|
65
|
+
const cards: StorefrontCard[] = visible.flatMap((store) =>
|
|
66
|
+
store.products
|
|
67
|
+
.filter((product) => product.active !== false)
|
|
68
|
+
.flatMap((product) =>
|
|
69
|
+
product.prices
|
|
70
|
+
.filter((price) => price.active !== false)
|
|
71
|
+
.map((price) => {
|
|
72
|
+
const selection = { store, product, price, referralCode };
|
|
73
|
+
return {
|
|
74
|
+
...selection,
|
|
75
|
+
formattedPrice: formatPriceWithInterval({
|
|
76
|
+
...price,
|
|
77
|
+
active: true,
|
|
78
|
+
}),
|
|
79
|
+
purchaseLabel:
|
|
80
|
+
price.type === "recurring" ? "Subscribe" : "Buy now",
|
|
81
|
+
accessibilityLabel: `${price.type === "recurring" ? "Subscribe to" : "Buy"} ${product.name}`,
|
|
82
|
+
checkoutUrl: getCheckoutUrl?.(selection),
|
|
83
|
+
purchase: () => {
|
|
84
|
+
if (canPurchase) onSelectPrice?.(selection);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}),
|
|
88
|
+
),
|
|
89
|
+
);
|
|
90
|
+
const state = {
|
|
91
|
+
stores: visible,
|
|
92
|
+
cards,
|
|
93
|
+
isLoading: stores === undefined,
|
|
94
|
+
isEmpty: stores !== undefined && !visible.length,
|
|
95
|
+
canPurchase,
|
|
96
|
+
};
|
|
97
|
+
if (children) return <>{children(state)}</>;
|
|
98
|
+
if (state.isLoading) return <p role="status">Loading stores…</p>;
|
|
99
|
+
if (state.isEmpty) return <p>No stores available yet.</p>;
|
|
100
|
+
return (
|
|
101
|
+
<div data-better-stripe="storefront">
|
|
102
|
+
{visible.map((store) => (
|
|
103
|
+
<section key={store.accountId}>
|
|
104
|
+
<h2>{store.name}</h2>
|
|
105
|
+
{!cards.some((card) => card.store.accountId === store.accountId) && (
|
|
106
|
+
<p>No products available yet.</p>
|
|
107
|
+
)}
|
|
108
|
+
{cards
|
|
109
|
+
.filter((card) => card.store.accountId === store.accountId)
|
|
110
|
+
.map((card) => (
|
|
111
|
+
<article key={card.price.stripePriceId}>
|
|
112
|
+
<h3>{card.product.name}</h3>
|
|
113
|
+
<p>{card.product.description}</p>
|
|
114
|
+
<p>{card.formattedPrice}</p>
|
|
115
|
+
{card.checkoutUrl && canPurchase ? (
|
|
116
|
+
<a
|
|
117
|
+
href={card.checkoutUrl}
|
|
118
|
+
aria-label={card.accessibilityLabel}
|
|
119
|
+
>
|
|
120
|
+
{card.purchaseLabel}
|
|
121
|
+
</a>
|
|
122
|
+
) : (
|
|
123
|
+
<button
|
|
124
|
+
type="button"
|
|
125
|
+
disabled={!canPurchase || !onSelectPrice}
|
|
126
|
+
aria-label={card.accessibilityLabel}
|
|
127
|
+
onClick={card.purchase}
|
|
128
|
+
>
|
|
129
|
+
{card.purchaseLabel}
|
|
130
|
+
</button>
|
|
131
|
+
)}
|
|
132
|
+
</article>
|
|
133
|
+
))}
|
|
134
|
+
</section>
|
|
135
|
+
))}
|
|
136
|
+
</div>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
3
|
+
import { afterEach, expect, it } from "vitest";
|
|
4
|
+
import { SubscriptionOverview } from "./SubscriptionOverview.js";
|
|
5
|
+
afterEach(cleanup);
|
|
6
|
+
it("renders loading, empty, and current subscription states without app providers", () => {
|
|
7
|
+
const { rerender } = render(
|
|
8
|
+
<SubscriptionOverview subscriptions={undefined} />,
|
|
9
|
+
);
|
|
10
|
+
expect(screen.getByRole("status").textContent).toContain("Loading");
|
|
11
|
+
rerender(<SubscriptionOverview subscriptions={[]} />);
|
|
12
|
+
expect(screen.getByText("No subscription yet.")).toBeTruthy();
|
|
13
|
+
rerender(
|
|
14
|
+
<SubscriptionOverview
|
|
15
|
+
subscriptions={[
|
|
16
|
+
{
|
|
17
|
+
stripeSubscriptionId: "sub_old",
|
|
18
|
+
status: "canceled",
|
|
19
|
+
cancelAtPeriodEnd: true,
|
|
20
|
+
},
|
|
21
|
+
{ stripeSubscriptionId: "sub_new", status: "active" },
|
|
22
|
+
]}
|
|
23
|
+
/>,
|
|
24
|
+
);
|
|
25
|
+
expect(screen.getByText("sub_new")).toBeTruthy();
|
|
26
|
+
expect(screen.queryByText("sub_old")).toBeNull();
|
|
27
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { SubscriptionRow } from "./Subscriptions.js";
|
|
4
|
+
import { currentSubscriptionFrom } from "./current-subscription.js";
|
|
5
|
+
import { SubscriptionCard } from "../components/SubscriptionCard.js";
|
|
6
|
+
export type SubscriptionOverviewState<Row> = {
|
|
7
|
+
subscription: Row | null;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
isEmpty: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type SubscriptionOverviewProps<
|
|
12
|
+
Row extends SubscriptionRow = SubscriptionRow,
|
|
13
|
+
> = {
|
|
14
|
+
subscriptions: Row[] | undefined;
|
|
15
|
+
children?: (state: SubscriptionOverviewState<Row>) => ReactNode;
|
|
16
|
+
};
|
|
17
|
+
export function SubscriptionOverview<Row extends SubscriptionRow>({
|
|
18
|
+
subscriptions,
|
|
19
|
+
children,
|
|
20
|
+
}: SubscriptionOverviewProps<Row>) {
|
|
21
|
+
const subscription = currentSubscriptionFrom(
|
|
22
|
+
(subscriptions ?? []).map((row) => ({
|
|
23
|
+
...row,
|
|
24
|
+
cancelAtPeriodEnd: row.cancelAtPeriodEnd ?? false,
|
|
25
|
+
})),
|
|
26
|
+
);
|
|
27
|
+
const state = {
|
|
28
|
+
subscription,
|
|
29
|
+
isLoading: subscriptions === undefined,
|
|
30
|
+
isEmpty: subscriptions !== undefined && !subscription,
|
|
31
|
+
};
|
|
32
|
+
if (children) return <>{children(state)}</>;
|
|
33
|
+
if (state.isLoading) return <p role="status">Loading subscription…</p>;
|
|
34
|
+
if (!subscription) return <p>No subscription yet.</p>;
|
|
35
|
+
return (
|
|
36
|
+
<section data-better-stripe="subscription-overview">
|
|
37
|
+
<h2>Your subscription</h2>
|
|
38
|
+
<p>{subscription.stripeSubscriptionId}</p>
|
|
39
|
+
<SubscriptionCard
|
|
40
|
+
subscription={{
|
|
41
|
+
...subscription,
|
|
42
|
+
isTrialing:
|
|
43
|
+
subscription.isTrialing ?? subscription.status === "trialing",
|
|
44
|
+
}}
|
|
45
|
+
/>
|
|
46
|
+
</section>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, cleanup, renderHook } from "@testing-library/react";
|
|
3
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
4
|
+
import { useSubscriptionManager } from "./Subscriptions.js";
|
|
5
|
+
afterEach(cleanup);
|
|
6
|
+
it("validates quantity changes and exposes server confirmation as pending webhook synchronization", async () => {
|
|
7
|
+
const onAction = vi.fn().mockResolvedValue(null);
|
|
8
|
+
const { result } = renderHook(() =>
|
|
9
|
+
useSubscriptionManager({
|
|
10
|
+
scopeKey: "buyer",
|
|
11
|
+
subscription: { stripeSubscriptionId: "sub_one", status: "active" },
|
|
12
|
+
onAction,
|
|
13
|
+
}),
|
|
14
|
+
);
|
|
15
|
+
act(() => result.current.setQuantity("1.5"));
|
|
16
|
+
await act(async () => {
|
|
17
|
+
await result.current.run("quantity");
|
|
18
|
+
});
|
|
19
|
+
expect(onAction).not.toHaveBeenCalled();
|
|
20
|
+
expect(result.current.message).toContain("integer");
|
|
21
|
+
act(() => result.current.setQuantity("3"));
|
|
22
|
+
await act(async () => {
|
|
23
|
+
await result.current.run("quantity");
|
|
24
|
+
});
|
|
25
|
+
expect(onAction).toHaveBeenCalledWith({
|
|
26
|
+
type: "quantity",
|
|
27
|
+
stripeSubscriptionId: "sub_one",
|
|
28
|
+
quantity: 3,
|
|
29
|
+
});
|
|
30
|
+
expect(result.current.message).toContain("Waiting for Stripe webhook sync");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("retains the pending subscription action when a second action is attempted", async () => {
|
|
34
|
+
let finish!: () => void;
|
|
35
|
+
const onAction = vi.fn(
|
|
36
|
+
() =>
|
|
37
|
+
new Promise<void>((resolve) => {
|
|
38
|
+
finish = resolve;
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
const { result } = renderHook(() =>
|
|
42
|
+
useSubscriptionManager({
|
|
43
|
+
scopeKey: "buyer",
|
|
44
|
+
subscription: { stripeSubscriptionId: "sub_one", status: "active" },
|
|
45
|
+
onAction,
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
let pending!: Promise<unknown>;
|
|
49
|
+
act(() => {
|
|
50
|
+
pending = result.current.run("pause");
|
|
51
|
+
});
|
|
52
|
+
await act(async () => {
|
|
53
|
+
await result.current.run("cancel");
|
|
54
|
+
});
|
|
55
|
+
expect(result.current.pendingAction).toBe("pause subscription");
|
|
56
|
+
expect(onAction).toHaveBeenCalledTimes(1);
|
|
57
|
+
await act(async () => {
|
|
58
|
+
finish();
|
|
59
|
+
await pending;
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useId, useState, type ReactNode } from "react";
|
|
3
|
+
import { useWorkflowAction } from "./useWorkflowAction.js";
|
|
4
|
+
import {
|
|
5
|
+
Collection,
|
|
6
|
+
type CollectionProps,
|
|
7
|
+
type WorkflowColumn,
|
|
8
|
+
} from "./Collection.js";
|
|
9
|
+
import { SubscriptionCard } from "../components/SubscriptionCard.js";
|
|
10
|
+
export type SubscriptionRow = {
|
|
11
|
+
stripeSubscriptionId: string;
|
|
12
|
+
status: string;
|
|
13
|
+
isTrialing?: boolean;
|
|
14
|
+
cancelAtPeriodEnd?: boolean;
|
|
15
|
+
isCollectionPaused?: boolean;
|
|
16
|
+
currentPeriodEnd?: string | null;
|
|
17
|
+
trialEnd?: string | null;
|
|
18
|
+
quantity?: number;
|
|
19
|
+
userId?: string;
|
|
20
|
+
};
|
|
21
|
+
export type SubscriptionActionType =
|
|
22
|
+
| "pause"
|
|
23
|
+
| "resume"
|
|
24
|
+
| "reactivate"
|
|
25
|
+
| "cancel"
|
|
26
|
+
| "price"
|
|
27
|
+
| "quantity"
|
|
28
|
+
| "trial"
|
|
29
|
+
| "endTrial";
|
|
30
|
+
export type SubscriptionCommand = {
|
|
31
|
+
type: SubscriptionActionType;
|
|
32
|
+
stripeSubscriptionId: string;
|
|
33
|
+
stripePriceId?: string;
|
|
34
|
+
quantity?: number;
|
|
35
|
+
trialEnd?: string;
|
|
36
|
+
};
|
|
37
|
+
export type SubscriptionManagerOptions = {
|
|
38
|
+
scopeKey: string;
|
|
39
|
+
subscription: SubscriptionRow | null | undefined;
|
|
40
|
+
onAction: (command: SubscriptionCommand) => Promise<unknown>;
|
|
41
|
+
};
|
|
42
|
+
const labels: Record<SubscriptionActionType, string> = {
|
|
43
|
+
pause: "pause subscription",
|
|
44
|
+
resume: "resume subscription",
|
|
45
|
+
reactivate: "reactivate subscription",
|
|
46
|
+
cancel: "cancel subscription",
|
|
47
|
+
price: "change plan",
|
|
48
|
+
quantity: "update quantity",
|
|
49
|
+
trial: "update trial end",
|
|
50
|
+
endTrial: "end trial now",
|
|
51
|
+
};
|
|
52
|
+
export function useSubscriptionManager(props: SubscriptionManagerOptions) {
|
|
53
|
+
const scope = `${props.scopeKey}:${props.subscription?.stripeSubscriptionId ?? ""}`;
|
|
54
|
+
const initial = { scope, quantity: "1", selectedPriceId: "", trialEnd: "" };
|
|
55
|
+
const [fields, setFields] = useState(initial);
|
|
56
|
+
if (fields.scope !== scope) setFields(initial);
|
|
57
|
+
const [operation, setOperation] = useState<SubscriptionActionType>("pause");
|
|
58
|
+
const action = useWorkflowAction(async (type: SubscriptionActionType) => {
|
|
59
|
+
setOperation(type);
|
|
60
|
+
if (!props.subscription) throw new Error("Select a subscription first.");
|
|
61
|
+
const request: SubscriptionCommand = {
|
|
62
|
+
type,
|
|
63
|
+
stripeSubscriptionId: props.subscription.stripeSubscriptionId,
|
|
64
|
+
};
|
|
65
|
+
if (type === "quantity") {
|
|
66
|
+
const quantity = Number(fields.quantity);
|
|
67
|
+
if (
|
|
68
|
+
!/^\d+$/.test(fields.quantity) ||
|
|
69
|
+
!Number.isSafeInteger(quantity) ||
|
|
70
|
+
quantity < 1
|
|
71
|
+
)
|
|
72
|
+
throw new Error("Enter a positive integer quantity.");
|
|
73
|
+
request.quantity = quantity;
|
|
74
|
+
}
|
|
75
|
+
if (type === "price") {
|
|
76
|
+
if (!fields.selectedPriceId) throw new Error("Choose a price first.");
|
|
77
|
+
request.stripePriceId = fields.selectedPriceId;
|
|
78
|
+
}
|
|
79
|
+
if (type === "trial") {
|
|
80
|
+
if (!fields.trialEnd || Number.isNaN(new Date(fields.trialEnd).getTime()))
|
|
81
|
+
throw new Error("Enter a valid trial end date.");
|
|
82
|
+
request.trialEnd = fields.trialEnd;
|
|
83
|
+
}
|
|
84
|
+
if (type === "endTrial") request.trialEnd = "now";
|
|
85
|
+
await props.onAction(request);
|
|
86
|
+
return `${labels[type]} requested. Waiting for Stripe webhook sync.`;
|
|
87
|
+
}, scope);
|
|
88
|
+
const active =
|
|
89
|
+
props.subscription?.status === "active" ||
|
|
90
|
+
props.subscription?.status === "trialing";
|
|
91
|
+
return {
|
|
92
|
+
...fields,
|
|
93
|
+
setQuantity: (quantity: string) =>
|
|
94
|
+
setFields((previous) => ({ ...previous, quantity })),
|
|
95
|
+
setSelectedPriceId: (selectedPriceId: string) =>
|
|
96
|
+
setFields((previous) => ({ ...previous, selectedPriceId })),
|
|
97
|
+
setTrialEnd: (trialEnd: string) =>
|
|
98
|
+
setFields((previous) => ({ ...previous, trialEnd })),
|
|
99
|
+
pendingAction: action.isPending ? labels[operation] : null,
|
|
100
|
+
isPending: action.isPending,
|
|
101
|
+
message: action.error ?? action.result ?? null,
|
|
102
|
+
error: action.error,
|
|
103
|
+
canPause: active && !props.subscription?.isCollectionPaused,
|
|
104
|
+
canResume: !!props.subscription?.isCollectionPaused,
|
|
105
|
+
canReactivate: active && !!props.subscription?.cancelAtPeriodEnd,
|
|
106
|
+
run: action.run,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export type SubscriptionManagerProps = SubscriptionManagerOptions & {
|
|
110
|
+
children?: (state: ReturnType<typeof useSubscriptionManager>) => ReactNode;
|
|
111
|
+
};
|
|
112
|
+
export function SubscriptionManager(props: SubscriptionManagerProps) {
|
|
113
|
+
const state = useSubscriptionManager(props);
|
|
114
|
+
const id = useId();
|
|
115
|
+
if (props.children) return <>{props.children(state)}</>;
|
|
116
|
+
if (!props.subscription) return <p>No subscription selected.</p>;
|
|
117
|
+
return (
|
|
118
|
+
<section
|
|
119
|
+
data-better-stripe="subscription-manager"
|
|
120
|
+
aria-busy={state.isPending}
|
|
121
|
+
>
|
|
122
|
+
<SubscriptionCard
|
|
123
|
+
subscription={{
|
|
124
|
+
...props.subscription,
|
|
125
|
+
isTrialing: props.subscription.isTrialing ?? false,
|
|
126
|
+
cancelAtPeriodEnd: props.subscription.cancelAtPeriodEnd ?? false,
|
|
127
|
+
}}
|
|
128
|
+
/>
|
|
129
|
+
{state.message && (
|
|
130
|
+
<p role={state.error ? "alert" : "status"}>{state.message}</p>
|
|
131
|
+
)}
|
|
132
|
+
{(
|
|
133
|
+
[
|
|
134
|
+
["pause", state.canPause],
|
|
135
|
+
["resume", state.canResume],
|
|
136
|
+
["reactivate", state.canReactivate],
|
|
137
|
+
[
|
|
138
|
+
"cancel",
|
|
139
|
+
!props.subscription.cancelAtPeriodEnd &&
|
|
140
|
+
props.subscription.status !== "canceled",
|
|
141
|
+
],
|
|
142
|
+
] as const
|
|
143
|
+
).map(([type, enabled]) => (
|
|
144
|
+
<button
|
|
145
|
+
type="button"
|
|
146
|
+
key={type}
|
|
147
|
+
disabled={!enabled || state.isPending}
|
|
148
|
+
onClick={() => {
|
|
149
|
+
void state.run(type);
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
152
|
+
{state.pendingAction === labels[type] ? "Processing…" : labels[type]}
|
|
153
|
+
</button>
|
|
154
|
+
))}
|
|
155
|
+
<form
|
|
156
|
+
onSubmit={(event) => {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
void state.run("price");
|
|
159
|
+
}}
|
|
160
|
+
>
|
|
161
|
+
<label htmlFor={`${id}-price`}>Price ID</label>
|
|
162
|
+
<input
|
|
163
|
+
id={`${id}-price`}
|
|
164
|
+
required
|
|
165
|
+
value={state.selectedPriceId}
|
|
166
|
+
onChange={(event) => state.setSelectedPriceId(event.target.value)}
|
|
167
|
+
/>
|
|
168
|
+
<button type="submit" disabled={state.isPending}>
|
|
169
|
+
Change plan
|
|
170
|
+
</button>
|
|
171
|
+
</form>
|
|
172
|
+
<form
|
|
173
|
+
onSubmit={(event) => {
|
|
174
|
+
event.preventDefault();
|
|
175
|
+
void state.run("quantity");
|
|
176
|
+
}}
|
|
177
|
+
>
|
|
178
|
+
<label htmlFor={`${id}-quantity`}>Quantity</label>
|
|
179
|
+
<input
|
|
180
|
+
id={`${id}-quantity`}
|
|
181
|
+
type="number"
|
|
182
|
+
min="1"
|
|
183
|
+
step="1"
|
|
184
|
+
required
|
|
185
|
+
value={state.quantity}
|
|
186
|
+
onChange={(event) => state.setQuantity(event.target.value)}
|
|
187
|
+
/>
|
|
188
|
+
<button type="submit" disabled={state.isPending}>
|
|
189
|
+
Update quantity
|
|
190
|
+
</button>
|
|
191
|
+
</form>
|
|
192
|
+
<form
|
|
193
|
+
onSubmit={(event) => {
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
void state.run("trial");
|
|
196
|
+
}}
|
|
197
|
+
>
|
|
198
|
+
<label htmlFor={`${id}-trial`}>Trial end</label>
|
|
199
|
+
<input
|
|
200
|
+
id={`${id}-trial`}
|
|
201
|
+
type="datetime-local"
|
|
202
|
+
required
|
|
203
|
+
value={state.trialEnd}
|
|
204
|
+
onChange={(event) => state.setTrialEnd(event.target.value)}
|
|
205
|
+
/>
|
|
206
|
+
<button type="submit" disabled={state.isPending}>
|
|
207
|
+
Set trial end
|
|
208
|
+
</button>
|
|
209
|
+
</form>
|
|
210
|
+
<button
|
|
211
|
+
type="button"
|
|
212
|
+
disabled={state.isPending}
|
|
213
|
+
onClick={() => {
|
|
214
|
+
void state.run("endTrial");
|
|
215
|
+
}}
|
|
216
|
+
>
|
|
217
|
+
End trial now
|
|
218
|
+
</button>
|
|
219
|
+
</section>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
export const SUBSCRIPTION_FILTERS = [
|
|
223
|
+
{ label: "All", value: "all" },
|
|
224
|
+
{ label: "Active", value: "active" },
|
|
225
|
+
{ label: "Trialing", value: "trialing" },
|
|
226
|
+
{ label: "Past Due", value: "past_due" },
|
|
227
|
+
{ label: "Canceled", value: "canceled" },
|
|
228
|
+
] as const;
|
|
229
|
+
export function useSubscriptionFilter<T extends { status: string }>(
|
|
230
|
+
subscriptions: T[] | undefined,
|
|
231
|
+
) {
|
|
232
|
+
const [filter, setFilter] = useState("all");
|
|
233
|
+
return {
|
|
234
|
+
filter,
|
|
235
|
+
setFilter,
|
|
236
|
+
filtered:
|
|
237
|
+
filter === "all"
|
|
238
|
+
? (subscriptions ?? [])
|
|
239
|
+
: (subscriptions?.filter((row) => row.status === filter) ?? []),
|
|
240
|
+
countByStatus: (status: string) =>
|
|
241
|
+
subscriptions?.filter((row) => row.status === status).length ?? 0,
|
|
242
|
+
tabs: SUBSCRIPTION_FILTERS,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
export type SubscriptionsProps<Row extends SubscriptionRow = SubscriptionRow> =
|
|
246
|
+
Omit<CollectionProps<Row>, "getKey" | "columns"> & {
|
|
247
|
+
columns?: WorkflowColumn<Row>[];
|
|
248
|
+
};
|
|
249
|
+
export function Subscriptions<Row extends SubscriptionRow>(
|
|
250
|
+
props: SubscriptionsProps<Row>,
|
|
251
|
+
) {
|
|
252
|
+
const columns: WorkflowColumn<Row>[] = [
|
|
253
|
+
{
|
|
254
|
+
id: "id",
|
|
255
|
+
label: "Subscription",
|
|
256
|
+
cell: (row) => row.stripeSubscriptionId,
|
|
257
|
+
},
|
|
258
|
+
{ id: "status", label: "Status", cell: (row) => row.status },
|
|
259
|
+
{
|
|
260
|
+
id: "period",
|
|
261
|
+
label: "Current period end",
|
|
262
|
+
cell: (row) =>
|
|
263
|
+
row.currentPeriodEnd
|
|
264
|
+
? new Date(row.currentPeriodEnd).toLocaleDateString()
|
|
265
|
+
: "Not supplied",
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
id: "trial",
|
|
269
|
+
label: "Trial end",
|
|
270
|
+
cell: (row) =>
|
|
271
|
+
row.trialEnd ? new Date(row.trialEnd).toLocaleDateString() : "None",
|
|
272
|
+
},
|
|
273
|
+
];
|
|
274
|
+
return (
|
|
275
|
+
<Collection
|
|
276
|
+
emptyLabel="No subscriptions yet."
|
|
277
|
+
{...props}
|
|
278
|
+
columns={props.columns ?? columns}
|
|
279
|
+
getKey={(row) => row.stripeSubscriptionId}
|
|
280
|
+
/>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, cleanup, renderHook } from "@testing-library/react";
|
|
3
|
+
import { afterEach, expect, it } from "vitest";
|
|
4
|
+
import { useTaskRunner } from "./Tasks.js";
|
|
5
|
+
afterEach(cleanup);
|
|
6
|
+
it("retains per-operation results and errors and keeps only a bounded activity log", async () => {
|
|
7
|
+
const { result } = renderHook(() => useTaskRunner({ maxEntries: 2 }));
|
|
8
|
+
await act(async () => {
|
|
9
|
+
await result.current.run("Products", async () => ({ count: 3 }));
|
|
10
|
+
});
|
|
11
|
+
expect(result.current.results.Products).toBe("Completed");
|
|
12
|
+
await act(async () => {
|
|
13
|
+
await result.current.run("Accounts", async () => {
|
|
14
|
+
throw new Error("Restricted");
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
expect(result.current.errors.Accounts).toBe("Restricted");
|
|
18
|
+
await act(async () => {
|
|
19
|
+
await result.current.run("Subscriptions", async () => null);
|
|
20
|
+
});
|
|
21
|
+
expect(result.current.log).toHaveLength(2);
|
|
22
|
+
expect(result.current.results.Products).toBe("Completed");
|
|
23
|
+
});
|