feat(results): 🛂 Limit incomplete submissions
This commit is contained in:
@ -34,7 +34,9 @@ export const StatsCards = ({
|
|||||||
<Stat bgColor="white" p="4" rounded="md" boxShadow="md">
|
<Stat bgColor="white" p="4" rounded="md" boxShadow="md">
|
||||||
<StatLabel>Completion rate</StatLabel>
|
<StatLabel>Completion rate</StatLabel>
|
||||||
{stats ? (
|
{stats ? (
|
||||||
<StatNumber>{stats.completionRate}%</StatNumber>
|
<StatNumber>
|
||||||
|
{Math.round((stats.totalCompleted / stats.totalStarts) * 100)}%
|
||||||
|
</StatNumber>
|
||||||
) : (
|
) : (
|
||||||
<Skeleton w="50%" h="10px" mt="2" />
|
<Skeleton w="50%" h="10px" mt="2" />
|
||||||
)}
|
)}
|
||||||
|
@ -26,14 +26,11 @@ export const CreateFolderButton = ({ isLoading, onClick }: Props) => {
|
|||||||
<Text>Create a folder</Text>
|
<Text>Create a folder</Text>
|
||||||
{isFreePlan(user) && <Tag colorScheme="orange">Pro</Tag>}
|
{isFreePlan(user) && <Tag colorScheme="orange">Pro</Tag>}
|
||||||
</HStack>
|
</HStack>
|
||||||
{user && (
|
<UpgradeModal
|
||||||
<UpgradeModal
|
isOpen={isOpen}
|
||||||
isOpen={isOpen}
|
onClose={onClose}
|
||||||
onClose={onClose}
|
type={LimitReached.FOLDER}
|
||||||
user={user}
|
/>
|
||||||
type={LimitReached.FOLDER}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
import { Alert, AlertIcon, AlertProps } from '@chakra-ui/react'
|
import {
|
||||||
|
Alert,
|
||||||
|
AlertIcon,
|
||||||
|
AlertProps,
|
||||||
|
Button,
|
||||||
|
HStack,
|
||||||
|
Text,
|
||||||
|
useDisclosure,
|
||||||
|
} from '@chakra-ui/react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import { UpgradeModal } from './modals/UpgradeModal.'
|
||||||
|
import { LimitReached } from './modals/UpgradeModal./UpgradeModal'
|
||||||
|
|
||||||
export const Info = (props: AlertProps) => (
|
export const Info = (props: AlertProps) => (
|
||||||
<Alert status="info" bgColor={'blue.50'} rounded="md" {...props}>
|
<Alert status="info" bgColor={'blue.50'} rounded="md" {...props}>
|
||||||
@ -11,3 +21,32 @@ export const Info = (props: AlertProps) => (
|
|||||||
export const PublishFirstInfo = (props: AlertProps) => (
|
export const PublishFirstInfo = (props: AlertProps) => (
|
||||||
<Info {...props}>You need to publish your typebot first</Info>
|
<Info {...props}>You need to publish your typebot first</Info>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const UnlockProPlanInfo = ({
|
||||||
|
contentLabel,
|
||||||
|
buttonLabel,
|
||||||
|
type,
|
||||||
|
}: {
|
||||||
|
contentLabel: string
|
||||||
|
buttonLabel: string
|
||||||
|
type?: LimitReached
|
||||||
|
}) => {
|
||||||
|
const { isOpen, onOpen, onClose } = useDisclosure()
|
||||||
|
return (
|
||||||
|
<Alert
|
||||||
|
status="info"
|
||||||
|
bgColor={'blue.50'}
|
||||||
|
rounded="md"
|
||||||
|
justifyContent="space-between"
|
||||||
|
>
|
||||||
|
<HStack>
|
||||||
|
<AlertIcon />
|
||||||
|
<Text>{contentLabel}</Text>
|
||||||
|
</HStack>
|
||||||
|
<Button colorScheme="blue" onClick={onOpen}>
|
||||||
|
{buttonLabel}
|
||||||
|
</Button>
|
||||||
|
<UpgradeModal isOpen={isOpen} onClose={onClose} type={type} />
|
||||||
|
</Alert>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -13,8 +13,8 @@ import {
|
|||||||
} from '@chakra-ui/react'
|
} from '@chakra-ui/react'
|
||||||
import { PricingCard } from './PricingCard'
|
import { PricingCard } from './PricingCard'
|
||||||
import { ActionButton } from './ActionButton'
|
import { ActionButton } from './ActionButton'
|
||||||
import { User } from 'db'
|
|
||||||
import { pay } from 'services/stripe'
|
import { pay } from 'services/stripe'
|
||||||
|
import { useUser } from 'contexts/UserContext'
|
||||||
|
|
||||||
export enum LimitReached {
|
export enum LimitReached {
|
||||||
BRAND = 'Remove branding',
|
BRAND = 'Remove branding',
|
||||||
@ -24,18 +24,13 @@ export enum LimitReached {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UpgradeModalProps = {
|
type UpgradeModalProps = {
|
||||||
user: User
|
type?: LimitReached
|
||||||
type: LimitReached
|
|
||||||
isOpen: boolean
|
isOpen: boolean
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UpgradeModal = ({
|
export const UpgradeModal = ({ type, onClose, isOpen }: UpgradeModalProps) => {
|
||||||
type,
|
const { user } = useUser()
|
||||||
user,
|
|
||||||
onClose,
|
|
||||||
isOpen,
|
|
||||||
}: UpgradeModalProps) => {
|
|
||||||
const [payLoading, setPayLoading] = useState(false)
|
const [payLoading, setPayLoading] = useState(false)
|
||||||
const [userLanguage, setUserLanguage] = useState<string>('en')
|
const [userLanguage, setUserLanguage] = useState<string>('en')
|
||||||
|
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
import { Button, Flex, HStack, Tag, useToast, Text } from '@chakra-ui/react'
|
import { Button, Flex, HStack, Tag, useToast, Text } from '@chakra-ui/react'
|
||||||
import { NextChakraLink } from 'components/nextChakra/NextChakraLink'
|
import { NextChakraLink } from 'components/nextChakra/NextChakraLink'
|
||||||
import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
|
import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
|
||||||
|
import { useUser } from 'contexts/UserContext'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import React, { useMemo } from 'react'
|
import React, { useMemo } from 'react'
|
||||||
import { useStats } from 'services/analytics'
|
import { useStats } from 'services/analytics'
|
||||||
|
import { isFreePlan } from 'services/user'
|
||||||
import { AnalyticsContent } from './AnalyticsContent'
|
import { AnalyticsContent } from './AnalyticsContent'
|
||||||
import { SubmissionsContent } from './SubmissionContent'
|
import { SubmissionsContent } from './SubmissionContent'
|
||||||
|
|
||||||
export const ResultsContent = () => {
|
export const ResultsContent = () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const { user } = useUser()
|
||||||
const { typebot } = useTypebot()
|
const { typebot } = useTypebot()
|
||||||
const isAnalytics = useMemo(
|
const isAnalytics = useMemo(
|
||||||
() => router.pathname.endsWith('analytics'),
|
() => router.pathname.endsWith('analytics'),
|
||||||
@ -76,6 +79,11 @@ export const ResultsContent = () => {
|
|||||||
typebotId={typebot.id}
|
typebotId={typebot.id}
|
||||||
onDeleteResults={handleDeletedResults}
|
onDeleteResults={handleDeletedResults}
|
||||||
totalResults={stats?.totalStarts ?? 0}
|
totalResults={stats?.totalStarts ?? 0}
|
||||||
|
totalHiddenResults={
|
||||||
|
isFreePlan(user)
|
||||||
|
? (stats?.totalStarts ?? 0) - (stats?.totalCompleted ?? 0)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Flex>
|
</Flex>
|
||||||
|
@ -10,15 +10,18 @@ import {
|
|||||||
useResults,
|
useResults,
|
||||||
} from 'services/results'
|
} from 'services/results'
|
||||||
import { unparse } from 'papaparse'
|
import { unparse } from 'papaparse'
|
||||||
|
import { UnlockProPlanInfo } from 'components/shared/Info'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
typebotId: string
|
typebotId: string
|
||||||
totalResults: number
|
totalResults: number
|
||||||
|
totalHiddenResults?: number
|
||||||
onDeleteResults: (total: number) => void
|
onDeleteResults: (total: number) => void
|
||||||
}
|
}
|
||||||
export const SubmissionsContent = ({
|
export const SubmissionsContent = ({
|
||||||
typebotId,
|
typebotId,
|
||||||
totalResults,
|
totalResults,
|
||||||
|
totalHiddenResults,
|
||||||
onDeleteResults,
|
onDeleteResults,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const [selectedIndices, setSelectedIndices] = useState<number[]>([])
|
const [selectedIndices, setSelectedIndices] = useState<number[]>([])
|
||||||
@ -65,13 +68,10 @@ export const SubmissionsContent = ({
|
|||||||
setIsDeleteLoading(false)
|
setIsDeleteLoading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalSelected = useMemo(
|
const totalSelected =
|
||||||
() =>
|
selectedIndices.length > 0 && selectedIndices.length === results?.length
|
||||||
selectedIndices.length === results?.length
|
? totalResults - (totalHiddenResults ?? 0)
|
||||||
? totalResults
|
: selectedIndices.length
|
||||||
: selectedIndices.length,
|
|
||||||
[results?.length, selectedIndices.length, totalResults]
|
|
||||||
)
|
|
||||||
|
|
||||||
const handleScrolledToBottom = useCallback(
|
const handleScrolledToBottom = useCallback(
|
||||||
() => setSize((state) => state + 1),
|
() => setSize((state) => state + 1),
|
||||||
@ -111,6 +111,12 @@ export const SubmissionsContent = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack maxW="1200px" w="full" pb="28">
|
<Stack maxW="1200px" w="full" pb="28">
|
||||||
|
{totalHiddenResults && (
|
||||||
|
<UnlockProPlanInfo
|
||||||
|
buttonLabel={`Unlock ${totalHiddenResults} results`}
|
||||||
|
contentLabel="You are seeing complete submissions only."
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Flex w="full" justifyContent="flex-end">
|
<Flex w="full" justifyContent="flex-end">
|
||||||
<ResultsActionButtons
|
<ResultsActionButtons
|
||||||
isDeleteLoading={isDeleteLoading}
|
isDeleteLoading={isDeleteLoading}
|
||||||
|
@ -2,6 +2,7 @@ import { User } from 'db'
|
|||||||
import prisma from 'libs/prisma'
|
import prisma from 'libs/prisma'
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import { getSession } from 'next-auth/react'
|
import { getSession } from 'next-auth/react'
|
||||||
|
import { isFreePlan } from 'services/user'
|
||||||
import { methodNotAllowed } from 'utils'
|
import { methodNotAllowed } from 'utils'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
@ -27,6 +28,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
typebotId,
|
typebotId,
|
||||||
typebot: { ownerId: user.id },
|
typebot: { ownerId: user.id },
|
||||||
answers: { some: {} },
|
answers: { some: {} },
|
||||||
|
isCompleted: isFreePlan(user),
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
createdAt: 'desc',
|
createdAt: 'desc',
|
||||||
|
@ -38,7 +38,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
const stats: Stats = {
|
const stats: Stats = {
|
||||||
totalViews,
|
totalViews,
|
||||||
totalStarts,
|
totalStarts,
|
||||||
completionRate: Math.round((totalCompleted / totalStarts) * 100),
|
totalCompleted,
|
||||||
}
|
}
|
||||||
return res.status(200).send({ stats })
|
return res.status(200).send({ stats })
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import test, { expect, Page } from '@playwright/test'
|
|||||||
import { readFileSync } from 'fs'
|
import { readFileSync } from 'fs'
|
||||||
import { defaultTextInputOptions, InputStepType } from 'models'
|
import { defaultTextInputOptions, InputStepType } from 'models'
|
||||||
import { parse } from 'papaparse'
|
import { parse } from 'papaparse'
|
||||||
|
import path from 'path'
|
||||||
import { generate } from 'short-uuid'
|
import { generate } from 'short-uuid'
|
||||||
import {
|
import {
|
||||||
createResults,
|
createResults,
|
||||||
@ -86,6 +87,17 @@ test.describe('Results page', () => {
|
|||||||
const { data: dataAll } = parse(fileAll)
|
const { data: dataAll } = parse(fileAll)
|
||||||
validateExportAll(dataAll)
|
validateExportAll(dataAll)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test.describe('Free user', () => {
|
||||||
|
test.use({
|
||||||
|
storageState: path.join(__dirname, '../freeUser.json'),
|
||||||
|
})
|
||||||
|
test("Incomplete results shouldn't be displayed", async ({ page }) => {
|
||||||
|
await page.goto(`/typebots/${typebotId}/results`)
|
||||||
|
await page.click('text=Unlock 200 results')
|
||||||
|
await expect(page.locator('text=Upgrade now')).toBeVisible()
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const validateExportSelection = (data: unknown[]) => {
|
const validateExportSelection = (data: unknown[]) => {
|
||||||
|
@ -92,10 +92,10 @@ export const ChatBlock = ({
|
|||||||
const isSingleChoiceStep =
|
const isSingleChoiceStep =
|
||||||
isChoiceInput(currentStep) && !currentStep.options.isMultipleChoice
|
isChoiceInput(currentStep) && !currentStep.options.isMultipleChoice
|
||||||
if (isSingleChoiceStep) {
|
if (isSingleChoiceStep) {
|
||||||
onBlockEnd(
|
const nextEdgeId = currentStep.items.find(
|
||||||
currentStep.items.find((i) => i.content === answerContent)
|
(i) => i.content === answerContent
|
||||||
?.outgoingEdgeId
|
)?.outgoingEdgeId
|
||||||
)
|
if (nextEdgeId) return onBlockEnd(nextEdgeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentStep?.outgoingEdgeId || displayedSteps.length === steps.length)
|
if (currentStep?.outgoingEdgeId || displayedSteps.length === steps.length)
|
||||||
|
@ -5,5 +5,5 @@ export type Answer = Omit<AnswerFromPrisma, 'resultId' | 'createdAt'>
|
|||||||
export type Stats = {
|
export type Stats = {
|
||||||
totalViews: number
|
totalViews: number
|
||||||
totalStarts: number
|
totalStarts: number
|
||||||
completionRate: number
|
totalCompleted: number
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user