import * as Panelbear from "@panelbear/panelbear-js"; import clsx from "clsx"; import type { Subscription } from "db"; import { SubscriptionStatus } from "db"; import useSubscription from "app/core/hooks/use-subscription"; export default function Plans() { const { hasActiveSubscription, subscription, subscribe, changePlan } = useSubscription(); return (
{pricing.tiers.map((tier) => { const isCurrentTier = subscription?.paddlePlanId === tier.planId; const isActiveTier = hasActiveSubscription && isCurrentTier; const cta = getCTA({ subscription, tier }); return (

{tier.title}

{tier.yearly ? (

Get 2 months free!

) : null}

{tier.price}€ {tier.frequency}

{tier.yearly ? (

Billed yearly ({tier.price * 12}€)

) : null}

{tier.description}

); })}
); } function getCTA({ subscription, tier, }: { subscription?: Subscription; tier: typeof pricing["tiers"][number]; }): string { if (!subscription) { return "Subscribe"; } const isCancelling = subscription.status === SubscriptionStatus.deleted; if (isCancelling) { return "Resubscribe"; } const isCurrentTier = subscription.paddlePlanId === tier.planId; const hasActiveSubscription = subscription.status !== SubscriptionStatus.deleted; const isActiveTier = hasActiveSubscription && isCurrentTier; if (isActiveTier) { return "Current plan"; } return `Switch to ${tier.title}`; } const pricing = { tiers: [ { title: "Yearly", planId: 727544, price: 12.5, frequency: "/month", description: "Text and call anyone, anywhere in the world, all year long.", yearly: true, }, { title: "Monthly", planId: 727540, price: 15, frequency: "/month", description: "Text and call anyone, anywhere in the world.", yearly: false, }, ], };