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

76 lines
2.2 KiB
TypeScript
Raw Normal View History

2022-01-03 17:39:59 +01:00
import { Button, Flex, HStack, Tag, useToast, Text } from '@chakra-ui/react'
2021-12-24 10:08:41 +01:00
import { NextChakraLink } from 'components/nextChakra/NextChakraLink'
import { useTypebot } from 'contexts/TypebotContext'
import { useRouter } from 'next/router'
import React, { useMemo } from 'react'
2022-01-03 17:39:59 +01:00
import { useStats } from 'services/analytics'
2021-12-24 10:08:41 +01:00
import { AnalyticsContent } from './AnalyticsContent'
import { SubmissionsContent } from './SubmissionContent'
export const ResultsContent = () => {
const router = useRouter()
const { typebot } = useTypebot()
const isAnalytics = useMemo(
() => router.pathname.endsWith('analytics'),
[router.pathname]
)
2021-12-30 10:24:16 +01:00
const toast = useToast({
position: 'top-right',
status: 'error',
})
2022-01-03 17:39:59 +01:00
const { stats } = useStats({
2021-12-30 10:24:16 +01:00
typebotId: typebot?.id,
onError: (err) => toast({ title: err.name, description: err.message }),
})
2021-12-24 10:08:41 +01:00
return (
2022-01-03 17:39:59 +01:00
<Flex h="full" w="full">
<Flex
pos="absolute"
zIndex={2}
bgColor="white"
w="full"
justifyContent="center"
h="60px"
>
<HStack maxW="1200px" w="full">
2021-12-24 10:08:41 +01:00
<Button
as={NextChakraLink}
colorScheme={!isAnalytics ? 'blue' : 'gray'}
variant={!isAnalytics ? 'outline' : 'ghost'}
size="sm"
href={`/typebots/${typebot?.id}/results`}
>
2021-12-30 10:24:16 +01:00
<Text>Submissions</Text>
2022-01-03 17:39:59 +01:00
{(stats?.totalStarts ?? 0) > 0 && (
2021-12-30 10:24:16 +01:00
<Tag size="sm" colorScheme="blue" ml="1">
2022-01-03 17:39:59 +01:00
{stats?.totalStarts}
2021-12-30 10:24:16 +01:00
</Tag>
)}
2021-12-24 10:08:41 +01:00
</Button>
<Button
as={NextChakraLink}
colorScheme={isAnalytics ? 'blue' : 'gray'}
variant={isAnalytics ? 'outline' : 'ghost'}
href={`/typebots/${typebot?.id}/results/analytics`}
size="sm"
>
Analytics
</Button>
</HStack>
2022-01-03 17:39:59 +01:00
</Flex>
<Flex pt="60px" w="full" justify="center">
2021-12-30 10:24:16 +01:00
{typebot &&
(isAnalytics ? (
2022-01-03 17:39:59 +01:00
<AnalyticsContent stats={stats} />
2021-12-30 10:24:16 +01:00
) : (
<SubmissionsContent
typebotId={typebot.id}
2022-01-03 17:39:59 +01:00
totalResults={stats?.totalStarts ?? 0}
2021-12-30 10:24:16 +01:00
/>
))}
2022-01-03 17:39:59 +01:00
</Flex>
2021-12-24 10:08:41 +01:00
</Flex>
)
}