import { Stack, Heading, chakra, HStack, Menu, MenuButton, Button, MenuList, MenuItem, Text, Tooltip, Flex, Tag, } from '@chakra-ui/react' import { ChevronLeftIcon } from 'assets/icons' import { useWorkspace } from 'contexts/WorkspaceContext' import { Plan } from 'db' import { useEffect, useState } from 'react' import { chatsLimit, getChatsLimit, getStorageLimit, storageLimit, parseNumberWithCommas, formatPrice, computePrice, } from 'utils' import { MoreInfoTooltip } from '../MoreInfoTooltip' import { FeaturesList } from './components/FeaturesList' type ProPlanContentProps = { initialChatsLimitIndex?: number initialStorageLimitIndex?: number onPayClick: (props: { selectedChatsLimitIndex: number selectedStorageLimitIndex: number }) => Promise } export const ProPlanContent = ({ initialChatsLimitIndex, initialStorageLimitIndex, onPayClick, }: ProPlanContentProps) => { const { workspace } = useWorkspace() const [selectedChatsLimitIndex, setSelectedChatsLimitIndex] = useState() const [selectedStorageLimitIndex, setSelectedStorageLimitIndex] = useState() const [isPaying, setIsPaying] = useState(false) useEffect(() => { if ( selectedChatsLimitIndex === undefined && initialChatsLimitIndex !== undefined ) setSelectedChatsLimitIndex(initialChatsLimitIndex) if ( selectedStorageLimitIndex === undefined && initialStorageLimitIndex !== undefined ) setSelectedStorageLimitIndex(initialStorageLimitIndex) }, [ initialChatsLimitIndex, initialStorageLimitIndex, selectedChatsLimitIndex, selectedStorageLimitIndex, ]) const workspaceChatsLimit = workspace ? getChatsLimit(workspace) : undefined const workspaceStorageLimit = workspace ? getStorageLimit(workspace) : undefined const isCurrentPlan = chatsLimit[Plan.PRO].totalIncluded + chatsLimit[Plan.PRO].increaseStep.amount * (selectedChatsLimitIndex ?? 0) === workspaceChatsLimit && storageLimit[Plan.PRO].totalIncluded + storageLimit[Plan.PRO].increaseStep.amount * (selectedStorageLimitIndex ?? 0) === workspaceStorageLimit const getButtonLabel = () => { if ( selectedChatsLimitIndex === undefined || selectedStorageLimitIndex === undefined ) return '' if (workspace?.plan === Plan.PRO) { if (isCurrentPlan) return 'Your current plan' if ( selectedChatsLimitIndex !== initialChatsLimitIndex || selectedStorageLimitIndex !== initialStorageLimitIndex ) return 'Update' } return 'Upgrade' } const handlePayClick = async () => { if ( selectedChatsLimitIndex === undefined || selectedStorageLimitIndex === undefined ) return setIsPaying(true) await onPayClick({ selectedChatsLimitIndex, selectedStorageLimitIndex, }) setIsPaying(false) } return ( Most popular Upgrade to Pro For agencies & growing startups. {formatPrice( computePrice( Plan.PRO, selectedChatsLimitIndex ?? 0, selectedStorageLimitIndex ?? 0 ) ?? NaN )} / month } hasArrow placement="top" > Everything in Starter , plus: } size="sm" isLoading={selectedChatsLimitIndex === undefined} > {parseNumberWithCommas( chatsLimit.PRO.totalIncluded + chatsLimit.PRO.increaseStep.amount * (selectedChatsLimitIndex ?? 0) )} {selectedChatsLimitIndex !== 0 && ( setSelectedChatsLimitIndex(0)}> {parseNumberWithCommas(chatsLimit.PRO.totalIncluded)} )} {selectedChatsLimitIndex !== 1 && ( setSelectedChatsLimitIndex(1)}> {parseNumberWithCommas( chatsLimit.PRO.totalIncluded + chatsLimit.PRO.increaseStep.amount )} )} {selectedChatsLimitIndex !== 2 && ( setSelectedChatsLimitIndex(2)}> {parseNumberWithCommas( chatsLimit.PRO.totalIncluded + chatsLimit.PRO.increaseStep.amount * 2 )} )} {selectedChatsLimitIndex !== 3 && ( setSelectedChatsLimitIndex(3)}> {parseNumberWithCommas( chatsLimit.PRO.totalIncluded + chatsLimit.PRO.increaseStep.amount * 3 )} )} {selectedChatsLimitIndex !== 4 && ( setSelectedChatsLimitIndex(4)}> {parseNumberWithCommas( chatsLimit.PRO.totalIncluded + chatsLimit.PRO.increaseStep.amount * 4 )} )} {' '} chats/mo A chat is counted whenever a user starts a discussion. It is independant of the number of messages he sends and receives. , } size="sm" isLoading={selectedStorageLimitIndex === undefined} > {parseNumberWithCommas( storageLimit.PRO.totalIncluded + storageLimit.PRO.increaseStep.amount * (selectedStorageLimitIndex ?? 0) )} {selectedStorageLimitIndex !== 0 && ( setSelectedStorageLimitIndex(0)} > {parseNumberWithCommas( storageLimit.PRO.totalIncluded )} )} {selectedStorageLimitIndex !== 1 && ( setSelectedStorageLimitIndex(1)} > {parseNumberWithCommas( storageLimit.PRO.totalIncluded + storageLimit.PRO.increaseStep.amount )} )} {selectedStorageLimitIndex !== 2 && ( setSelectedStorageLimitIndex(2)} > {parseNumberWithCommas( storageLimit.PRO.totalIncluded + storageLimit.PRO.increaseStep.amount * 2 )} )} {selectedStorageLimitIndex !== 3 && ( setSelectedStorageLimitIndex(3)} > {parseNumberWithCommas( storageLimit.PRO.totalIncluded + storageLimit.PRO.increaseStep.amount * 3 )} )} {selectedStorageLimitIndex !== 4 && ( setSelectedStorageLimitIndex(4)} > {parseNumberWithCommas( storageLimit.PRO.totalIncluded + storageLimit.PRO.increaseStep.amount * 4 )} )} {' '} GB of storage You accumulate storage for every file that your user upload into your bot. If you delete the result, it will free up the space. , 'Custom domains', 'In-depth analytics', ]} /> ) }