2
0
Files
bot/apps/builder/layouts/results/AnalyticsContent.tsx

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-01-03 17:39:59 +01:00
import { Flex, useToast } from '@chakra-ui/react'
import { StatsCards } from 'components/analytics/StatsCards'
import { Graph } from 'components/shared/Graph'
2022-01-06 09:40:56 +01:00
import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
import { Stats } from 'models'
2021-12-24 10:08:41 +01:00
import React from 'react'
2022-01-03 17:39:59 +01:00
import { useAnswersCount } from 'services/analytics'
2021-12-24 10:08:41 +01:00
2022-01-03 17:39:59 +01:00
export const AnalyticsContent = ({ stats }: { stats?: Stats }) => {
const { typebot, publishedTypebot } = useTypebot()
const toast = useToast({
position: 'top-right',
status: 'error',
})
const { answersCounts } = useAnswersCount({
typebotId: typebot?.id,
onError: (err) => toast({ title: err.name, description: err.message }),
})
return (
<Flex
w="full"
pos="relative"
bgColor="gray.50"
h="full"
justifyContent="center"
>
{publishedTypebot && (
<Graph
flex="1"
answersCounts={[
{ blockId: 'start-block', totalAnswers: stats?.totalViews ?? 0 },
...(answersCounts ?? []),
]}
/>
2022-01-03 17:39:59 +01:00
)}
<StatsCards stats={stats} pos="absolute" top={10} />
</Flex>
)
2021-12-24 10:08:41 +01:00
}