2022-06-02 07:54:48 +02:00
|
|
|
import { Flex, useDisclosure } from '@chakra-ui/react'
|
2022-01-03 17:39:59 +01:00
|
|
|
import { StatsCards } from 'components/analytics/StatsCards'
|
2022-02-02 08:05:02 +01:00
|
|
|
import { Graph } from 'components/shared/Graph'
|
2022-06-02 07:54:48 +02:00
|
|
|
import { useToast } from 'components/shared/hooks/useToast'
|
2022-04-05 14:55:19 +02:00
|
|
|
import { UpgradeModal } from 'components/shared/modals/UpgradeModal'
|
2022-02-11 18:06:59 +01:00
|
|
|
import { GraphProvider } from 'contexts/GraphContext'
|
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 }) => {
|
2022-02-13 06:53:48 +01:00
|
|
|
const { isOpen, onOpen, onClose } = useDisclosure()
|
2022-01-03 17:39:59 +01:00
|
|
|
const { typebot, publishedTypebot } = useTypebot()
|
2022-06-02 07:54:48 +02:00
|
|
|
const { showToast } = useToast()
|
2022-01-03 17:39:59 +01:00
|
|
|
const { answersCounts } = useAnswersCount({
|
2022-02-16 07:37:05 +01:00
|
|
|
typebotId: publishedTypebot && typebot?.id,
|
2022-06-02 07:54:48 +02:00
|
|
|
onError: (err) => showToast({ title: err.name, description: err.message }),
|
2022-01-03 17:39:59 +01:00
|
|
|
})
|
|
|
|
return (
|
|
|
|
<Flex
|
|
|
|
w="full"
|
|
|
|
pos="relative"
|
|
|
|
bgColor="gray.50"
|
|
|
|
h="full"
|
|
|
|
justifyContent="center"
|
|
|
|
>
|
2022-02-11 18:06:59 +01:00
|
|
|
{publishedTypebot && answersCounts && stats && (
|
|
|
|
<GraphProvider blocks={publishedTypebot?.blocks ?? []} isReadOnly>
|
|
|
|
<Graph
|
|
|
|
flex="1"
|
|
|
|
typebot={publishedTypebot}
|
2022-02-13 06:53:48 +01:00
|
|
|
onUnlockProPlanClick={onOpen}
|
2022-02-11 18:06:59 +01:00
|
|
|
answersCounts={[
|
|
|
|
{ ...answersCounts[0], totalAnswers: stats?.totalStarts },
|
|
|
|
...answersCounts?.slice(1),
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</GraphProvider>
|
2022-01-03 17:39:59 +01:00
|
|
|
)}
|
2022-02-13 06:53:48 +01:00
|
|
|
<UpgradeModal onClose={onClose} isOpen={isOpen} />
|
2022-01-03 17:39:59 +01:00
|
|
|
<StatsCards stats={stats} pos="absolute" top={10} />
|
|
|
|
</Flex>
|
|
|
|
)
|
2021-12-24 10:08:41 +01:00
|
|
|
}
|