2022-12-20 16:55:43 +01:00
|
|
|
import {
|
|
|
|
|
Flex,
|
|
|
|
|
Spinner,
|
|
|
|
|
useColorModeValue,
|
|
|
|
|
useDisclosure,
|
|
|
|
|
} from '@chakra-ui/react'
|
2023-03-15 11:51:30 +01:00
|
|
|
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
|
2023-03-15 08:35:16 +01:00
|
|
|
import { Stats } from '@typebot.io/schemas'
|
2021-12-24 10:08:41 +01:00
|
|
|
import React from 'react'
|
2022-11-15 09:35:48 +01:00
|
|
|
import { StatsCards } from './StatsCards'
|
2023-03-15 11:51:30 +01:00
|
|
|
import { ChangePlanModal } from '@/features/billing/components/ChangePlanModal'
|
|
|
|
|
import { Graph } from '@/features/graph/components/Graph'
|
|
|
|
|
import { GraphProvider } from '@/features/graph/providers/GraphProvider'
|
|
|
|
|
import { GroupsCoordinatesProvider } from '@/features/graph/providers/GroupsCoordinateProvider'
|
2023-10-27 09:23:50 +02:00
|
|
|
import { useTranslate } from '@tolgee/react'
|
2023-06-30 12:13:17 +02:00
|
|
|
import { trpc } from '@/lib/trpc'
|
|
|
|
|
import { isDefined } from '@typebot.io/lib'
|
2021-12-24 10:08:41 +01:00
|
|
|
|
2022-11-15 09:35:48 +01:00
|
|
|
export const AnalyticsGraphContainer = ({ stats }: { stats?: Stats }) => {
|
2023-10-27 09:23:50 +02:00
|
|
|
const { t } = useTranslate()
|
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()
|
2023-06-30 12:13:17 +02:00
|
|
|
const { data } = trpc.analytics.getTotalAnswersInBlocks.useQuery(
|
|
|
|
|
{
|
|
|
|
|
typebotId: typebot?.id as string,
|
|
|
|
|
},
|
|
|
|
|
{ enabled: isDefined(publishedTypebot) }
|
|
|
|
|
)
|
|
|
|
|
const startBlockId = publishedTypebot?.groups
|
|
|
|
|
.find((group) => group.blocks.at(0)?.type === 'start')
|
|
|
|
|
?.blocks.at(0)?.id
|
|
|
|
|
|
2022-01-03 17:39:59 +01:00
|
|
|
return (
|
|
|
|
|
<Flex
|
|
|
|
|
w="full"
|
|
|
|
|
pos="relative"
|
2023-06-30 12:13:17 +02:00
|
|
|
bgColor={useColorModeValue('#f4f5f8', 'gray.850')}
|
2022-12-20 16:55:43 +01:00
|
|
|
backgroundImage={useColorModeValue(
|
|
|
|
|
'radial-gradient(#c6d0e1 1px, transparent 0)',
|
|
|
|
|
'radial-gradient(#2f2f39 1px, transparent 0)'
|
|
|
|
|
)}
|
|
|
|
|
backgroundSize="40px 40px"
|
|
|
|
|
backgroundPosition="-19px -19px"
|
2022-01-03 17:39:59 +01:00
|
|
|
h="full"
|
|
|
|
|
justifyContent="center"
|
|
|
|
|
>
|
2023-06-30 12:13:17 +02:00
|
|
|
{publishedTypebot &&
|
|
|
|
|
data?.totalAnswersInBlocks &&
|
|
|
|
|
stats &&
|
|
|
|
|
startBlockId ? (
|
2022-06-26 16:12:28 +02:00
|
|
|
<GraphProvider isReadOnly>
|
|
|
|
|
<GroupsCoordinatesProvider groups={publishedTypebot?.groups}>
|
|
|
|
|
<Graph
|
|
|
|
|
flex="1"
|
|
|
|
|
typebot={publishedTypebot}
|
|
|
|
|
onUnlockProPlanClick={onOpen}
|
2023-06-30 12:13:17 +02:00
|
|
|
totalAnswersInBlocks={
|
|
|
|
|
startBlockId
|
2022-12-22 17:02:34 +01:00
|
|
|
? [
|
2023-06-30 12:13:17 +02:00
|
|
|
{
|
|
|
|
|
blockId: startBlockId,
|
|
|
|
|
total: stats.totalViews,
|
|
|
|
|
},
|
|
|
|
|
...data.totalAnswersInBlocks,
|
2022-12-22 17:02:34 +01:00
|
|
|
]
|
|
|
|
|
: []
|
|
|
|
|
}
|
2022-06-26 16:12:28 +02:00
|
|
|
/>
|
|
|
|
|
</GroupsCoordinatesProvider>
|
2022-02-11 18:06:59 +01:00
|
|
|
</GraphProvider>
|
2022-06-26 16:12:28 +02:00
|
|
|
) : (
|
|
|
|
|
<Flex
|
|
|
|
|
justify="center"
|
|
|
|
|
align="center"
|
|
|
|
|
boxSize="full"
|
|
|
|
|
bgColor="rgba(255, 255, 255, 0.5)"
|
|
|
|
|
>
|
|
|
|
|
<Spinner color="gray" />
|
|
|
|
|
</Flex>
|
2022-01-03 17:39:59 +01:00
|
|
|
)}
|
2022-09-24 08:58:23 +02:00
|
|
|
<ChangePlanModal
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
isOpen={isOpen}
|
2023-04-06 17:31:23 +02:00
|
|
|
type={t('billing.limitMessage.analytics')}
|
2023-09-25 17:20:42 +02:00
|
|
|
excludedPlans={['STARTER']}
|
2022-09-24 08:58:23 +02:00
|
|
|
/>
|
2023-06-30 12:13:17 +02:00
|
|
|
<StatsCards stats={stats} pos="absolute" />
|
2022-01-03 17:39:59 +01:00
|
|
|
</Flex>
|
|
|
|
|
)
|
2021-12-24 10:08:41 +01:00
|
|
|
}
|