2
0
Files
bot/apps/builder/layouts/results/AnalyticsContent.tsx
Baptiste Arnaud 6322402c96 🖐️ Analytics drop off rates
2022-01-03 17:39:59 +01:00

44 lines
1.3 KiB
TypeScript

import { Flex, useToast } from '@chakra-ui/react'
import { Stats } from 'bot-engine'
import AnalyticsGraph from 'components/analytics/graph/AnalyticsGraph'
import { StatsCards } from 'components/analytics/StatsCards'
import { AnalyticsGraphProvider } from 'contexts/AnalyticsGraphProvider'
import { useTypebot } from 'contexts/TypebotContext'
import React from 'react'
import { useAnswersCount } from 'services/analytics'
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 && (
<AnalyticsGraphProvider initialTypebot={publishedTypebot}>
<AnalyticsGraph
flex="1"
answersCounts={[
{ blockId: 'start-block', totalAnswers: stats?.totalViews ?? 0 },
...(answersCounts ?? []),
]}
/>
</AnalyticsGraphProvider>
)}
<StatsCards stats={stats} pos="absolute" top={10} />
</Flex>
)
}