import { Stack, Heading, chakra, HStack, Menu, MenuButton, Button, MenuList, MenuItem, Text, } 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, computePrice, formatPrice, } from 'utils' import { MoreInfoTooltip } from '../MoreInfoTooltip' import { FeaturesList } from './components/FeaturesList' type StarterPlanContentProps = { initialChatsLimitIndex?: number initialStorageLimitIndex?: number onPayClick: (props: { selectedChatsLimitIndex: number selectedStorageLimitIndex: number }) => Promise } export const StarterPlanContent = ({ initialChatsLimitIndex, initialStorageLimitIndex, onPayClick, }: StarterPlanContentProps) => { 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.STARTER].totalIncluded + chatsLimit[Plan.STARTER].increaseStep.amount * (selectedChatsLimitIndex ?? 0) === workspaceChatsLimit && storageLimit[Plan.STARTER].totalIncluded + storageLimit[Plan.STARTER].increaseStep.amount * (selectedStorageLimitIndex ?? 0) === workspaceStorageLimit const getButtonLabel = () => { if ( selectedChatsLimitIndex === undefined || selectedStorageLimitIndex === undefined ) return '' if (workspace?.plan === Plan.PRO) return 'Downgrade' if (workspace?.plan === Plan.STARTER) { 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 ( Upgrade to Starter For individuals & small businesses. {formatPrice( computePrice( Plan.STARTER, selectedChatsLimitIndex ?? 0, selectedStorageLimitIndex ?? 0 ) ?? NaN )} / month } size="sm" isLoading={selectedChatsLimitIndex === undefined} > {parseNumberWithCommas( chatsLimit.STARTER.totalIncluded + chatsLimit.STARTER.increaseStep.amount * (selectedChatsLimitIndex ?? 0) )} {selectedChatsLimitIndex !== 0 && ( setSelectedChatsLimitIndex(0)}> {parseNumberWithCommas( chatsLimit.STARTER.totalIncluded )} )} {selectedChatsLimitIndex !== 1 && ( setSelectedChatsLimitIndex(1)}> {parseNumberWithCommas( chatsLimit.STARTER.totalIncluded + chatsLimit.STARTER.increaseStep.amount )} )} {selectedChatsLimitIndex !== 2 && ( setSelectedChatsLimitIndex(2)}> {parseNumberWithCommas( chatsLimit.STARTER.totalIncluded + chatsLimit.STARTER.increaseStep.amount * 2 )} )} {selectedChatsLimitIndex !== 3 && ( setSelectedChatsLimitIndex(3)}> {parseNumberWithCommas( chatsLimit.STARTER.totalIncluded + chatsLimit.STARTER.increaseStep.amount * 3 )} )} {selectedChatsLimitIndex !== 4 && ( setSelectedChatsLimitIndex(4)}> {parseNumberWithCommas( chatsLimit.STARTER.totalIncluded + chatsLimit.STARTER.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.STARTER.totalIncluded + storageLimit.STARTER.increaseStep.amount * (selectedStorageLimitIndex ?? 0) )} {selectedStorageLimitIndex !== 0 && ( setSelectedStorageLimitIndex(0)}> {parseNumberWithCommas( storageLimit.STARTER.totalIncluded )} )} {selectedStorageLimitIndex !== 1 && ( setSelectedStorageLimitIndex(1)}> {parseNumberWithCommas( storageLimit.STARTER.totalIncluded + storageLimit.STARTER.increaseStep.amount )} )} {selectedStorageLimitIndex !== 2 && ( setSelectedStorageLimitIndex(2)}> {parseNumberWithCommas( storageLimit.STARTER.totalIncluded + storageLimit.STARTER.increaseStep.amount * 2 )} )} {selectedStorageLimitIndex !== 3 && ( setSelectedStorageLimitIndex(3)}> {parseNumberWithCommas( storageLimit.STARTER.totalIncluded + storageLimit.STARTER.increaseStep.amount * 3 )} )} {selectedStorageLimitIndex !== 4 && ( setSelectedStorageLimitIndex(4)}> {parseNumberWithCommas( storageLimit.STARTER.totalIncluded + storageLimit.STARTER.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. , 'Branding removed', 'File upload input block', 'Create folders', ]} /> ) }