import { FC, useState } from "react"; import { CheckCircle } from "lucide-react"; import { Tab } from "@headlessui/react"; // helpers import { cn } from "@/helpers/common.helper"; export type ProPlanUpgradeProps = { basePlan: "Free" | "One"; features: string[]; verticalFeatureList?: boolean; extraFeatures?: string | React.ReactNode; }; type TProPiceFrequency = "month" | "year"; type TProPlanPrice = { key: string; currency: string; price: number; recurring: TProPiceFrequency; }; // constants export const calculateYearlyDiscount = (monthlyPrice: number, yearlyPricePerMonth: number): number => { const monthlyCost = monthlyPrice * 12; const yearlyCost = yearlyPricePerMonth * 12; const amountSaved = monthlyCost - yearlyCost; const discountPercentage = (amountSaved / monthlyCost) * 100; return Math.floor(discountPercentage); }; const PRO_PLAN_PRICES: TProPlanPrice[] = [ { key: "monthly", currency: "$", price: 8, recurring: "month" }, { key: "yearly", currency: "$", price: 6, recurring: "year" }, ]; export const ProPlanUpgrade: FC = (props) => { const { basePlan, features, verticalFeatureList = false, extraFeatures } = props; // states const [selectedPlan, setSelectedPlan] = useState("month"); // derived const monthlyPrice = PRO_PLAN_PRICES.find((price) => price.recurring === "month")?.price ?? 0; const yearlyPrice = PRO_PLAN_PRICES.find((price) => price.recurring === "year")?.price ?? 0; const yearlyDiscount = calculateYearlyDiscount(monthlyPrice, yearlyPrice); // env const PRO_PLAN_MONTHLY_PAYMENT_URL = process.env.NEXT_PUBLIC_PRO_PLAN_MONTHLY_PAYMENT_URL ?? "https://plane.so/pro"; const PRO_PLAN_YEARLY_PAYMENT_URL = process.env.NEXT_PUBLIC_PRO_PLAN_YEARLY_PAYMENT_URL ?? "https://plane.so/pro"; return (
{PRO_PLAN_PRICES.map((price: TProPlanPrice) => ( cn( "w-full rounded-lg py-1.5 text-sm font-medium leading-5", selected ? "bg-custom-background-100 text-custom-primary-300 shadow" : "hover:bg-custom-primary-100/5 text-custom-text-300 hover:text-custom-text-200" ) } onClick={() => setSelectedPlan(price.recurring)} > <> {price.recurring === "month" && ("Monthly" as string)} {price.recurring === "year" && ("Yearly" as string)} {price.recurring === "year" && ( -{yearlyDiscount}% )} ))}
{PRO_PLAN_PRICES.map((price: TProPlanPrice) => (
Plane Pro
{price.currency} {price.price}
a user per month
{`Everything in ${basePlan} +`}
    {features.map((feature) => (
  • {feature}

  • ))}
{extraFeatures &&
{extraFeatures}
}
))}
); };