@growth-operations/ui-shared 1.5.5 → 1.5.6
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/package.json +1 -1
- package/src/billing/BillingTab.jsx +45 -23
package/package.json
CHANGED
|
@@ -286,34 +286,64 @@ function TrialSubscriptionBilling({ context, state, appKey }) {
|
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
function CreditsBilling({ context, state, appKey }) {
|
|
289
|
-
// The Stripe portal session lets an EXISTING paid customer manage
|
|
290
|
-
//
|
|
291
|
-
// selection is the <PlanGrid> below, which pre-creates a per-tier checkout.
|
|
289
|
+
// The Stripe portal session lets an EXISTING paid customer manage/switch/cancel
|
|
290
|
+
// their plan, with proration handled by Stripe.
|
|
292
291
|
const { portalUrl, loading, error, notReady } = usePortalSession({
|
|
293
292
|
context,
|
|
294
293
|
state,
|
|
295
294
|
appKey,
|
|
296
295
|
});
|
|
297
296
|
|
|
298
|
-
const hasPlans = (state?.plans?.length ?? 0) > 0;
|
|
299
297
|
const onPaidPlan = !!state?.entitlement?.plan;
|
|
300
298
|
|
|
299
|
+
// PAID: do NOT show the plan picker. The picker's "Choose" starts a NEW Stripe
|
|
300
|
+
// Checkout subscription — clicking another tier would create a SECOND
|
|
301
|
+
// subscription (double-bill), not switch in place. Plan changes (upgrade/
|
|
302
|
+
// downgrade/cancel) go through the Stripe Customer Portal, which swaps the
|
|
303
|
+
// subscription item with proration. So on a paid plan we show the meter + a
|
|
304
|
+
// "Manage subscription" portal link only. (Matches toast/sparkfly.)
|
|
305
|
+
if (onPaidPlan) {
|
|
306
|
+
return (
|
|
307
|
+
<Flex direction="column" gap="medium">
|
|
308
|
+
<CreditMeter
|
|
309
|
+
entitlement={state?.entitlement}
|
|
310
|
+
creditMeter={state?.credit_meter}
|
|
311
|
+
/>
|
|
312
|
+
{!notReady &&
|
|
313
|
+
(error ? (
|
|
314
|
+
<Alert title="Couldn't open billing" variant="danger">
|
|
315
|
+
<Text>{error}</Text>
|
|
316
|
+
</Alert>
|
|
317
|
+
) : (
|
|
318
|
+
<LoadingButton
|
|
319
|
+
href={portalUrl ? { url: portalUrl, external: true } : undefined}
|
|
320
|
+
loading={loading}
|
|
321
|
+
disabled={!portalUrl}
|
|
322
|
+
variant="primary"
|
|
323
|
+
>
|
|
324
|
+
{portalUrl ? "Manage subscription" : "Preparing billing…"}
|
|
325
|
+
</LoadingButton>
|
|
326
|
+
))}
|
|
327
|
+
<Text format={{ fontStyle: "italic" }}>
|
|
328
|
+
Change or cancel your plan in Stripe — billing is managed across all
|
|
329
|
+
Growth Operations apps.
|
|
330
|
+
</Text>
|
|
331
|
+
</Flex>
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// FREE tier: show the upgrade path (PlanGrid → first-paid Checkout). PlanGrid
|
|
336
|
+
// renders nothing if no plans are mirrored yet, so fall back to a portal CTA
|
|
337
|
+
// then so the tab isn't empty.
|
|
338
|
+
const hasPlans = (state?.plans?.length ?? 0) > 0;
|
|
301
339
|
return (
|
|
302
340
|
<Flex direction="column" gap="medium">
|
|
303
341
|
<CreditMeter
|
|
304
342
|
entitlement={state?.entitlement}
|
|
305
343
|
creditMeter={state?.credit_meter}
|
|
306
344
|
/>
|
|
307
|
-
|
|
308
|
-
{/* The dynamically-rendered upgrade path (tiers from the Stripe catalog).
|
|
309
|
-
Renders nothing if no plans are mirrored yet. */}
|
|
310
345
|
<PlanGrid context={context} state={state} appKey={appKey} />
|
|
311
|
-
|
|
312
|
-
{/* Manage-billing link: relevant once the customer is on a paid plan
|
|
313
|
-
(change/cancel/invoices in Stripe). Hidden in the not-ready
|
|
314
|
-
(un-provisioned) state. When no plans are mirrored AND not on a paid
|
|
315
|
-
plan, fall back to the portal as the only CTA so the tab isn't empty. */}
|
|
316
|
-
{!notReady && (onPaidPlan || !hasPlans) &&
|
|
346
|
+
{!notReady && !hasPlans &&
|
|
317
347
|
(error ? (
|
|
318
348
|
<Alert title="Couldn't open billing" variant="danger">
|
|
319
349
|
<Text>{error}</Text>
|
|
@@ -323,19 +353,11 @@ function CreditsBilling({ context, state, appKey }) {
|
|
|
323
353
|
href={portalUrl ? { url: portalUrl, external: true } : undefined}
|
|
324
354
|
loading={loading}
|
|
325
355
|
disabled={!portalUrl}
|
|
326
|
-
variant=
|
|
356
|
+
variant="primary"
|
|
327
357
|
>
|
|
328
|
-
{portalUrl
|
|
329
|
-
? onPaidPlan
|
|
330
|
-
? "Manage billing in Stripe"
|
|
331
|
-
: "Buy credits in Stripe"
|
|
332
|
-
: "Preparing billing…"}
|
|
358
|
+
{portalUrl ? "Buy credits in Stripe" : "Preparing billing…"}
|
|
333
359
|
</LoadingButton>
|
|
334
360
|
))}
|
|
335
|
-
|
|
336
|
-
{/* Footer note only when PlanGrid isn't rendering one (PlanGrid owns the
|
|
337
|
-
canonical "managed in Stripe" line when plans are present — avoid
|
|
338
|
-
showing it twice). */}
|
|
339
361
|
{!hasPlans && (
|
|
340
362
|
<Text format={{ fontStyle: "italic" }}>
|
|
341
363
|
Billing is managed in Stripe across all Growth Operations apps.
|