Skip to content

Commit

Permalink
feat(dashboard): ✨ New create typebot menu
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 5, 2022
1 parent eb5a5d9 commit 660b220
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ export const CreateNewTypebotButtons = () => {
Import a file
</ImportTypebotFromFileButton>
</Stack>
<TemplatesModal isOpen={isOpen} onClose={onClose} />
<TemplatesModal
isOpen={isOpen}
onClose={onClose}
onTypebotChoose={handleCreateSubmit}
/>
</VStack>
)
}
105 changes: 89 additions & 16 deletions apps/builder/components/templates/TemplatesModal.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
import {
Button,
chakra,
Divider,
Heading,
HStack,
Modal,
ModalBody,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Stack,
Tooltip,
useToast,
} from '@chakra-ui/react'
import { ExternalLinkIcon } from 'assets/icons'
import { TypebotViewer } from 'bot-engine'
import { Typebot } from 'models'
import React, { useEffect, useState } from 'react'
import { parseTypebotToPublicTypebot } from 'services/publicTypebot'
import { sendRequest } from 'utils'
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 [selectedTemplate, setSelectedTemplate] = useState<TemplateProps>(
templates[0]
)

const toast = useToast({
position: 'top-right',
Expand All @@ -34,6 +43,7 @@ export const TemplatesModal = ({ isOpen, onClose }: Props) => {
}, [])

const fetchTemplate = async (template: TemplateProps) => {
setSelectedTemplate(template)
const { data, error } = await sendRequest(`/templates/${template.fileName}`)
if (error) return toast({ title: error.name, description: error.message })
setTypebot(data as Typebot)
Expand All @@ -42,20 +52,83 @@ export const TemplatesModal = ({ isOpen, onClose }: Props) => {
return (
<Modal isOpen={isOpen} onClose={onClose} size="6xl">
<ModalOverlay />
<ModalContent>
<ModalHeader as={HStack} justifyContent="space-between" w="full">
<Heading fontSize="xl">Lead generation</Heading>
</ModalHeader>
<ModalBody as={HStack}>
{typebot && (
<TypebotViewer typebot={parseTypebotToPublicTypebot(typebot)} />
)}
<Stack>
<Button colorScheme="blue">Use this template</Button>
<ModalContent h="85vh">
<ModalBody as={HStack} p="0">
<Stack w="full" h="full">
<Heading pl="10" pt="4" fontSize="2xl">
{selectedTemplate.emoji}{' '}
<chakra.span ml="2">{selectedTemplate.name}</chakra.span>
</Heading>
{typebot && (
<TypebotViewer
typebot={parseTypebotToPublicTypebot(typebot)}
key={typebot.id}
/>
)}
</Stack>
</ModalBody>

<ModalFooter />
<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>
</ModalBody>
</ModalContent>
</Modal>
)
Expand Down
37 changes: 36 additions & 1 deletion apps/builder/components/templates/data.ts
Original file line number Diff line number Diff line change
@@ -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[] = [
{ name: 'Lead Generation', emoji: '🤝', fileName: 'lead-gen.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,
},
]
6 changes: 4 additions & 2 deletions apps/builder/playwright/tests/editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ test.describe.parallel('Editor', () => {
])

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.fill('input[placeholder="Search..."]', 'love')
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 expect(page.locator('text="😍"')).toBeVisible()
await expect(page.locator('text="My superb typebot"')).toBeVisible()
Expand Down
8 changes: 5 additions & 3 deletions apps/builder/playwright/tests/templates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ test.describe.parallel('Templates page', () => {

test('From file should import correctly', async ({ page }) => {
await page.goto('/typebots/create')
await page.click('[data-testid="more-button"]')
await page.setInputFiles(
'input[type="file"]',
path.join(__dirname, '../fixtures/typebots/singleChoiceTarget.json')
Expand All @@ -21,8 +20,11 @@ test.describe.parallel('Templates page', () => {

test('Templates should be previewable and usable', async ({ page }) => {
await page.goto('/typebots/create')
await page.click('[aria-label="Preview"] >> nth=0')
await expect(typebotViewer(page).locator('text=Hi!')).toBeVisible()
await page.click('text=Start from a template')
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 expect(page).toHaveURL(new RegExp(`/edit`))
})
Expand Down
3 changes: 2 additions & 1 deletion apps/builder/public/templates/customer-support.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"id": "cl16la7p900990b1a72qjqbb3",
"createdAt": "2022-03-25T15:39:33.885Z",
"updatedAt": "2022-03-25T15:42:12.544Z",
"name": "My typebot",
"name": "Customer Support",
"icon": "😍",
"ownerId": "cl13od3wt0000pl1aat7bdrxf",
"publishedTypebotId": null,
"folderId": null,
Expand Down
3 changes: 2 additions & 1 deletion apps/builder/public/templates/lead-gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"id": "qgMiLSr4W1ftXocFncin1G",
"createdAt": "2022-02-05T06:21:16.522Z",
"updatedAt": "2022-02-05T06:21:16.522Z",
"name": "My typebot",
"name": "Lead Generation",
"icon": "🤝",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null,
"folderId": null,
Expand Down

4 comments on commit 660b220

@vercel
Copy link

@vercel vercel bot commented on 660b220 Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 660b220 Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 660b220 Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 660b220 Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.