Skip to content

Commit

Permalink
✨ (template) Add FAQ bot template
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Oct 13, 2022
1 parent 40d2db5 commit b87ba40
Show file tree
Hide file tree
Showing 4 changed files with 603 additions and 27 deletions.
27 changes: 13 additions & 14 deletions apps/builder/components/shared/hooks/useToast.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { useToast as useChakraToast, UseToastOptions } from '@chakra-ui/react'
import { useCallback } from 'react'

export const useToast = () => {
const toast = useChakraToast()

const showToast = ({
title,
description,
status = 'error',
...props
}: UseToastOptions) => {
toast({
position: 'bottom-right',
description,
title,
status,
...props,
})
}
const showToast = useCallback(
({ title, description, status = 'error', ...props }: UseToastOptions) => {
toast({
position: 'bottom-right',
description,
title,
status,
...props,
})
},
[toast]
)

return { showToast }
}
26 changes: 15 additions & 11 deletions apps/builder/components/templates/TemplatesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ExternalLinkIcon } from 'assets/icons'
import { TypebotViewer } from 'bot-engine'
import { useToast } from 'components/shared/hooks/useToast'
import { Typebot } from 'models'
import React, { useEffect, useState } from 'react'
import React, { useCallback, useEffect, useState } from 'react'
import { parseTypebotToPublicTypebot } from 'services/publicTypebot'
import { getViewerUrl, sendRequest } from 'utils'
import { TemplateProps, templates } from './data'
Expand All @@ -35,18 +35,22 @@ export const TemplatesModal = ({ isOpen, onClose, onTypebotChoose }: Props) => {

const { showToast } = useToast()

const fetchTemplate = useCallback(
async (template: TemplateProps) => {
setSelectedTemplate(template)
const { data, error } = await sendRequest(
`/templates/${template.fileName}`
)
if (error)
return showToast({ title: error.name, description: error.message })
setTypebot(data as Typebot)
},
[showToast]
)

useEffect(() => {
fetchTemplate(templates[0])
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

const fetchTemplate = async (template: TemplateProps) => {
setSelectedTemplate(template)
const { data, error } = await sendRequest(`/templates/${template.fileName}`)
if (error)
return showToast({ title: error.name, description: error.message })
setTypebot(data as Typebot)
}
}, [fetchTemplate])

const onUseThisTemplateClick = () => {
if (!typebot) return
Expand Down
3 changes: 1 addition & 2 deletions apps/builder/components/templates/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export const templates: TemplateProps[] = [
{
name: 'FAQ',
emoji: '💬',
fileName: 'customer-support.json',
isComingSoon: true,
fileName: 'faq.json',
},
{
name: 'Conversational Resume',
Expand Down
Loading

0 comments on commit b87ba40

Please sign in to comment.