import { useEffect, useState } from 'react' import { Heading, Modal, ModalBody, Text, ModalContent, ModalFooter, ModalOverlay, Stack, ListItem, UnorderedList, ListIcon, chakra, Tooltip, ListProps, Button, HStack, } from '@chakra-ui/react' import { pay } from 'services/stripe' import { useUser } from 'contexts/UserContext' import { Plan } from 'db' import { useWorkspace } from 'contexts/WorkspaceContext' import { TypebotLogo } from 'assets/logos' import { CheckIcon } from 'assets/icons' import { toTitleCase } from 'utils' import { useToast } from 'components/shared/hooks/useToast' export enum LimitReached { BRAND = 'Remove branding', CUSTOM_DOMAIN = 'Custom domain', FOLDER = 'Create folders', } type UpgradeModalProps = { type?: LimitReached isOpen: boolean onClose: () => void plan?: Plan } export const UpgradeModal = ({ onClose, isOpen, plan = Plan.PRO, }: UpgradeModalProps) => { const { user } = useUser() const { workspace, refreshWorkspace } = useWorkspace() const [payLoading, setPayLoading] = useState(false) const [currency, setCurrency] = useState<'usd' | 'eur'>('usd') const { showToast } = useToast() useEffect(() => { setCurrency( navigator.languages.find((l) => l.includes('fr')) ? 'eur' : 'usd' ) }, []) const handlePayClick = async () => { if (!user || !workspace) return setPayLoading(true) const response = await pay({ customerId: workspace.stripeId ?? undefined, user, currency, plan: plan === Plan.TEAM ? 'team' : 'pro', workspaceId: workspace.id, }) setPayLoading(false) if (response?.newPlan) { refreshWorkspace({ plan: response.newPlan }) showToast({ status: 'success', title: 'Upgrade success!', description: `Workspace successfully upgraded to ${toTitleCase( response.newPlan )} plan 🎉`, }) } } return ( {plan === Plan.PRO ? ( ) : ( )} ) } const PersonalProPlanContent = ({ currency }: { currency: 'eur' | 'usd' }) => { return ( Upgrade to Personal Pro{' '} plan For solo creators who want to do even more. {currency === 'eur' ? '39€' : '$39'} / month Everything in Personal, plus: ) } const TeamPlanContent = ({ currency }: { currency: 'eur' | 'usd' }) => { return ( Upgrade to Team plan For teams to build typebots together in one spot. {currency === 'eur' ? '99€' : '$99'} / month } hasArrow placement="top" > Everything in Pro , plus: ) } const FeatureList = ({ features, ...props }: { features: string[] } & ListProps) => ( {features.map((feat) => ( {feat} ))} )