From b17e135cf67fda980e1793a1162018812502d888 Mon Sep 17 00:00:00 2001 From: m5r Date: Tue, 19 Oct 2021 19:59:20 +0200 Subject: [PATCH] reflect when user has cancelled his sub --- app/settings/components/billing/plans.tsx | 18 ++++++++---------- app/settings/hooks/use-subscription.ts | 6 +++++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/settings/components/billing/plans.tsx b/app/settings/components/billing/plans.tsx index aa3ed15..a576fb3 100644 --- a/app/settings/components/billing/plans.tsx +++ b/app/settings/components/billing/plans.tsx @@ -5,17 +5,15 @@ import clsx from "clsx"; import useSubscription from "../../hooks/use-subscription"; export default function Plans() { - const { subscription, subscribe, changePlan } = useSubscription(); - const hasSubscription = Boolean(subscription); + const { hasActiveSubscription, subscription, subscribe, changePlan } = useSubscription(); return (
{pricing.tiers.map((tier) => { - const isCurrentTier = - !subscription?.paddlePlanId && tier.planId === -1 - ? true - : subscription?.paddlePlanId === tier.planId; - const cta = isCurrentTier ? "Current plan" : !!subscription ? `Switch to ${tier.title}` : "Subscribe"; + const isFreeTier = tier.planId === -1; + const isCurrentTier = subscription?.paddlePlanId === tier.planId; + const isActiveTier = (!hasActiveSubscription && isFreeTier) || (hasActiveSubscription && isCurrentTier); + const cta = isActiveTier ? "Current plan" : !!subscription ? `Switch to ${tier.title}` : "Subscribe"; return (