import { Stack, Heading, chakra, HStack, Menu, MenuButton, Button, MenuList, MenuItem, Text, } from '@chakra-ui/react' import { ChevronLeftIcon } from '@/components/icons' import { useWorkspace } from '@/features/workspace' import { Plan } from 'db' import { useEffect, useState } from 'react' import { parseNumberWithCommas } from 'utils' import { chatsLimit, computePrice, formatPrice, getChatsLimit, getStorageLimit, storageLimit, } from 'utils/pricing' import { FeaturesList } from './components/FeaturesList' import { MoreInfoTooltip } from '@/components/MoreInfoTooltip' type StarterPlanContentProps = { initialChatsLimitIndex?: number initialStorageLimitIndex?: number currency?: 'eur' | 'usd' isLoading?: boolean onPayClick: (props: { selectedChatsLimitIndex: number selectedStorageLimitIndex: number }) => void } export const StarterPlanContent = ({ initialChatsLimitIndex, initialStorageLimitIndex, isLoading, currency, onPayClick, }: StarterPlanContentProps) => { const { workspace } = useWorkspace() const [selectedChatsLimitIndex, setSelectedChatsLimitIndex] = useState() const [selectedStorageLimitIndex, setSelectedStorageLimitIndex] = useState() 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 onPayClick({ selectedChatsLimitIndex, selectedStorageLimitIndex, }) } return ( Upgrade to Starter For individuals & small businesses. {formatPrice( computePrice( Plan.STARTER, selectedChatsLimitIndex ?? 0, selectedStorageLimitIndex ?? 0 ) ?? NaN, currency )} / month } size="sm" isLoading={selectedChatsLimitIndex === undefined} > {selectedChatsLimitIndex !== undefined ? parseNumberWithCommas( chatsLimit.STARTER.totalIncluded + chatsLimit.STARTER.increaseStep.amount * selectedChatsLimitIndex ) : undefined} {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} > {selectedStorageLimitIndex !== undefined ? parseNumberWithCommas( storageLimit.STARTER.totalIncluded + storageLimit.STARTER.increaseStep.amount * selectedStorageLimitIndex ) : undefined} {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', ]} /> ) }