import { Button, Card, List, ThemeIcon, Title, Text, Group, Select, Container, Stack, Badge, Flex, Switch, Alert, } from "@mantine/core"; import { useState } from "react"; import { IconCheck, IconInfoCircle } from "@tabler/icons-react"; import { getCheckoutLink } from "@/ee/billing/services/billing-service.ts"; import { useBillingPlans } from "@/ee/billing/queries/billing-query.ts"; import { useAtomValue } from "jotai"; import { workspaceAtom } from "@/features/user/atoms/current-user-atom"; export default function BillingPlans() { const { data: plans } = useBillingPlans(); const workspace = useAtomValue(workspaceAtom); const [isAnnual, setIsAnnual] = useState(true); const [selectedTierValue, setSelectedTierValue] = useState( null, ); const handleCheckout = async (priceId: string) => { try { const checkoutLink = await getCheckoutLink({ priceId: priceId, }); window.location.href = checkoutLink.url; } catch (err) { console.error("Failed to get checkout link", err); } }; // TODO: remove by July 30. // Check if workspace was created between June 28 and July 14, 2025 const showTieredPricingNotice = (() => { if (!workspace?.createdAt) return false; const createdDate = new Date(workspace.createdAt); const startDate = new Date('2025-06-20'); const endDate = new Date('2025-07-14'); return createdDate >= startDate && createdDate <= endDate; })(); if (!plans || plans.length === 0) { return null; } // Check if any plan is tiered const hasTieredPlans = plans.some(plan => plan.billingScheme === 'tiered' && plan.pricingTiers?.length > 0); const firstTieredPlan = plans.find(plan => plan.billingScheme === 'tiered' && plan.pricingTiers?.length > 0); // Set initial tier value if not set and we have tiered plans if (hasTieredPlans && !selectedTierValue && firstTieredPlan) { setSelectedTierValue(firstTieredPlan.pricingTiers[0].upTo.toString()); return null; } // For tiered plans, ensure we have a selected tier if (hasTieredPlans && !selectedTierValue) { return null; } const selectData = firstTieredPlan?.pricingTiers ?.filter((tier) => !tier.custom) .map((tier, index) => { const prevMaxUsers = index > 0 ? firstTieredPlan.pricingTiers[index - 1].upTo : 0; return { value: tier.upTo.toString(), label: `${prevMaxUsers + 1}-${tier.upTo} users`, }; }) || []; return ( {/* Tiered pricing notice for eligible workspaces */} {showTieredPricingNotice && !hasTieredPlans && ( } title="Want the old tiered pricing?" color="blue" mb="lg" > Contact support to switch back to our tiered pricing model. )} {/* Controls Section */} {/* Team Size and Billing Controls */} {hasTieredPlans && (