import { Stack, Flex, Heading, Progress, Text, Skeleton, HStack, Tooltip, } from '@chakra-ui/react' import { AlertIcon } from 'assets/icons' import { Plan, Workspace } from 'db' import React from 'react' import { getChatsLimit, getStorageLimit, parseNumberWithCommas } from 'utils' import { storageToReadable } from './helpers' import { useUsage } from './useUsage' type Props = { workspace: Workspace } export const UsageContent = ({ workspace }: Props) => { const { data, isLoading } = useUsage(workspace.id) const totalChatsUsed = data?.totalChatsUsed ?? 0 const totalStorageUsed = data?.totalStorageUsed ?? 0 const workspaceChatsLimit = getChatsLimit(workspace) const workspaceStorageLimit = getStorageLimit(workspace) const workspaceStorageLimitGigabites = workspaceStorageLimit * 1024 * 1024 * 1024 const chatsPercentage = Math.round( (totalChatsUsed / workspaceChatsLimit) * 100 ) const storagePercentage = Math.round( (totalStorageUsed / workspaceStorageLimitGigabites) * 100 ) return ( Usage Chats {chatsPercentage >= 80 && ( Your typebots are popular! You will soon reach your plan's chats limit. 🚀

Make sure to update your plan to increase this limit and continue chatting with your users. } >
)} (resets on 1st of every month)
{parseNumberWithCommas(totalChatsUsed)} /{' '} {workspaceChatsLimit === -1 ? 'Unlimited' : parseNumberWithCommas(workspaceChatsLimit)}
= workspaceChatsLimit ? 'red' : 'blue'} />
{workspace.plan !== Plan.FREE && ( Storage {storagePercentage >= 80 && ( Your typebots are popular! You will soon reach your plan's storage limit. 🚀

Make sure to update your plan in order to continue collecting uploaded files. You can also{' '} delete files to free up space. } >
)}
{storageToReadable(totalStorageUsed)} / {workspaceStorageLimit} GB
= workspaceStorageLimitGigabites ? 'red' : 'blue' } rounded="full" hasStripe isIndeterminate={isLoading} />
)}
) }