2
0

feat(dashboard): New create typebot menu

This commit is contained in:
Baptiste Arnaud
2022-04-05 10:49:32 +02:00
parent eb5a5d9a15
commit 660b220f8d
7 changed files with 143 additions and 25 deletions

View File

@@ -113,7 +113,11 @@ export const CreateNewTypebotButtons = () => {
Import a file Import a file
</ImportTypebotFromFileButton> </ImportTypebotFromFileButton>
</Stack> </Stack>
<TemplatesModal isOpen={isOpen} onClose={onClose} /> <TemplatesModal
isOpen={isOpen}
onClose={onClose}
onTypebotChoose={handleCreateSubmit}
/>
</VStack> </VStack>
) )
} }

View File

@@ -1,16 +1,18 @@
import { import {
Button, Button,
chakra,
Divider,
Heading, Heading,
HStack, HStack,
Modal, Modal,
ModalBody, ModalBody,
ModalContent, ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay, ModalOverlay,
Stack, Stack,
Tooltip,
useToast, useToast,
} from '@chakra-ui/react' } from '@chakra-ui/react'
import { ExternalLinkIcon } from 'assets/icons'
import { TypebotViewer } from 'bot-engine' import { TypebotViewer } from 'bot-engine'
import { Typebot } from 'models' import { Typebot } from 'models'
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
@@ -18,10 +20,17 @@ import { parseTypebotToPublicTypebot } from 'services/publicTypebot'
import { sendRequest } from 'utils' import { sendRequest } from 'utils'
import { TemplateProps, templates } from './data' import { TemplateProps, templates } from './data'
type Props = { isOpen: boolean; onClose: () => void } type Props = {
isOpen: boolean
onClose: () => void
onTypebotChoose: (typebot: Typebot) => void
}
export const TemplatesModal = ({ isOpen, onClose }: Props) => { export const TemplatesModal = ({ isOpen, onClose, onTypebotChoose }: Props) => {
const [typebot, setTypebot] = useState<Typebot>() const [typebot, setTypebot] = useState<Typebot>()
const [selectedTemplate, setSelectedTemplate] = useState<TemplateProps>(
templates[0]
)
const toast = useToast({ const toast = useToast({
position: 'top-right', position: 'top-right',
@@ -34,6 +43,7 @@ export const TemplatesModal = ({ isOpen, onClose }: Props) => {
}, []) }, [])
const fetchTemplate = async (template: TemplateProps) => { const fetchTemplate = async (template: TemplateProps) => {
setSelectedTemplate(template)
const { data, error } = await sendRequest(`/templates/${template.fileName}`) const { data, error } = await sendRequest(`/templates/${template.fileName}`)
if (error) return toast({ title: error.name, description: error.message }) if (error) return toast({ title: error.name, description: error.message })
setTypebot(data as Typebot) setTypebot(data as Typebot)
@@ -42,20 +52,83 @@ export const TemplatesModal = ({ isOpen, onClose }: Props) => {
return ( return (
<Modal isOpen={isOpen} onClose={onClose} size="6xl"> <Modal isOpen={isOpen} onClose={onClose} size="6xl">
<ModalOverlay /> <ModalOverlay />
<ModalContent> <ModalContent h="85vh">
<ModalHeader as={HStack} justifyContent="space-between" w="full"> <ModalBody as={HStack} p="0">
<Heading fontSize="xl">Lead generation</Heading> <Stack w="full" h="full">
</ModalHeader> <Heading pl="10" pt="4" fontSize="2xl">
<ModalBody as={HStack}> {selectedTemplate.emoji}{' '}
{typebot && ( <chakra.span ml="2">{selectedTemplate.name}</chakra.span>
<TypebotViewer typebot={parseTypebotToPublicTypebot(typebot)} /> </Heading>
)} {typebot && (
<Stack> <TypebotViewer
<Button colorScheme="blue">Use this template</Button> typebot={parseTypebotToPublicTypebot(typebot)}
key={typebot.id}
/>
)}
</Stack>
<Stack
h="full"
py="6"
w="300px"
px="4"
borderLeftWidth={1}
justify="space-between"
>
<Stack spacing={4}>
<Button
colorScheme="blue"
onClick={() => typebot && onTypebotChoose(typebot)}
>
Use this template
</Button>
<Divider />
<Stack>
{templates.map((template) => (
<Tooltip
key={template.name}
isDisabled={!template.isComingSoon}
label="Coming soon!"
>
<span>
<Button
onClick={() => fetchTemplate(template)}
w="full"
variant={
selectedTemplate.name === template.name
? 'solid'
: 'ghost'
}
isDisabled={template.isComingSoon}
>
{template.emoji}{' '}
<chakra.span minW="200px" textAlign="left" ml="3">
{template.name}
</chakra.span>
</Button>
</span>
</Tooltip>
))}
</Stack>
</Stack>
<Stack>
<Divider />
<Tooltip label="Coming soon!" placement="top">
<span>
<Button
w="full"
variant="ghost"
isDisabled
leftIcon={<ExternalLinkIcon />}
>
Community templates
</Button>
</span>
</Tooltip>
</Stack>
</Stack> </Stack>
</ModalBody> </ModalBody>
<ModalFooter />
</ModalContent> </ModalContent>
</Modal> </Modal>
) )

View File

@@ -1,6 +1,41 @@
export type TemplateProps = { name: string; emoji: string; fileName: string } export type TemplateProps = {
name: string
emoji: string
fileName: string
isComingSoon?: boolean
}
export const templates: TemplateProps[] = [ export const templates: TemplateProps[] = [
{ name: 'Lead Generation', emoji: '🤝', fileName: 'lead-gen.json' }, { name: 'Lead Generation', emoji: '🤝', fileName: 'lead-gen.json' },
{ name: 'Customer Support', emoji: '😍', fileName: 'customer-support.json' }, { name: 'Customer Support', emoji: '😍', fileName: 'customer-support.json' },
{
name: 'Quiz',
emoji: '🕹️',
fileName: 'customer-support.json',
isComingSoon: true,
},
{
name: 'Lead Scoring',
emoji: '🏆',
fileName: 'customer-support.json',
isComingSoon: true,
},
{
name: 'FAQ',
emoji: '💬',
fileName: 'customer-support.json',
isComingSoon: true,
},
{
name: 'Conversational Resume',
emoji: '👨‍💼',
fileName: 'customer-support.json',
isComingSoon: true,
},
{
name: 'User Onboarding',
emoji: '🧑‍🚀',
fileName: 'customer-support.json',
isComingSoon: true,
},
] ]

View File

@@ -140,11 +140,13 @@ test.describe.parallel('Editor', () => {
]) ])
await page.goto(`/typebots/${typebotId}/edit`) await page.goto(`/typebots/${typebotId}/edit`)
await page.click('text="My awesome typebot"')
await page.fill('input[value="My awesome typebot"]', 'My superb typebot')
await page.click('[data-testid="editable-icon"]') await page.click('[data-testid="editable-icon"]')
await page.fill('input[placeholder="Search..."]', 'love') await page.fill('input[placeholder="Search..."]', 'love')
await page.click('text="😍"') await page.click('text="😍"')
await page.click('text="My awesome typebot"')
await page.fill('input[value="My awesome typebot"]', 'My superb typebot')
await page.press('input[value="My superb typebot"]', 'Enter')
await page.goto(`/typebots`) await page.goto(`/typebots`)
await expect(page.locator('text="😍"')).toBeVisible() await expect(page.locator('text="😍"')).toBeVisible()
await expect(page.locator('text="My superb typebot"')).toBeVisible() await expect(page.locator('text="My superb typebot"')).toBeVisible()

View File

@@ -11,7 +11,6 @@ test.describe.parallel('Templates page', () => {
test('From file should import correctly', async ({ page }) => { test('From file should import correctly', async ({ page }) => {
await page.goto('/typebots/create') await page.goto('/typebots/create')
await page.click('[data-testid="more-button"]')
await page.setInputFiles( await page.setInputFiles(
'input[type="file"]', 'input[type="file"]',
path.join(__dirname, '../fixtures/typebots/singleChoiceTarget.json') path.join(__dirname, '../fixtures/typebots/singleChoiceTarget.json')
@@ -21,8 +20,11 @@ test.describe.parallel('Templates page', () => {
test('Templates should be previewable and usable', async ({ page }) => { test('Templates should be previewable and usable', async ({ page }) => {
await page.goto('/typebots/create') await page.goto('/typebots/create')
await page.click('[aria-label="Preview"] >> nth=0') await page.click('text=Start from a template')
await expect(typebotViewer(page).locator('text=Hi!')).toBeVisible() await page.click('text=Customer Support')
await expect(
typebotViewer(page).locator('text=How can I help you?')
).toBeVisible()
await page.click('text=Use this template') await page.click('text=Use this template')
await expect(page).toHaveURL(new RegExp(`/edit`)) await expect(page).toHaveURL(new RegExp(`/edit`))
}) })

View File

@@ -2,7 +2,8 @@
"id": "cl16la7p900990b1a72qjqbb3", "id": "cl16la7p900990b1a72qjqbb3",
"createdAt": "2022-03-25T15:39:33.885Z", "createdAt": "2022-03-25T15:39:33.885Z",
"updatedAt": "2022-03-25T15:42:12.544Z", "updatedAt": "2022-03-25T15:42:12.544Z",
"name": "My typebot", "name": "Customer Support",
"icon": "😍",
"ownerId": "cl13od3wt0000pl1aat7bdrxf", "ownerId": "cl13od3wt0000pl1aat7bdrxf",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,

View File

@@ -2,7 +2,8 @@
"id": "qgMiLSr4W1ftXocFncin1G", "id": "qgMiLSr4W1ftXocFncin1G",
"createdAt": "2022-02-05T06:21:16.522Z", "createdAt": "2022-02-05T06:21:16.522Z",
"updatedAt": "2022-02-05T06:21:16.522Z", "updatedAt": "2022-02-05T06:21:16.522Z",
"name": "My typebot", "name": "Lead Generation",
"icon": "🤝",
"ownerId": "ckz6t9iep0006k31a22j05fwq", "ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,