2
0

feat(api): Add routes for subscribing webhook

This commit is contained in:
Baptiste Arnaud
2022-02-21 11:46:56 +01:00
parent 5a80774ff5
commit 68ae69f366
21 changed files with 470 additions and 175 deletions

View File

@ -51,6 +51,10 @@ import { stringify } from 'qs'
import { isChoiceInput, isConditionStep, sendRequest } from 'utils'
import { parseBlocksToPublicBlocks } from './publicTypebot'
export type TypebotInDashboard = Pick<
Typebot,
'id' | 'name' | 'publishedTypebotId'
>
export const useTypebots = ({
folderId,
onError,
@ -59,11 +63,10 @@ export const useTypebots = ({
onError: (error: Error) => void
}) => {
const params = stringify({ folderId })
const { data, error, mutate } = useSWR<{ typebots: Typebot[] }, Error>(
`/api/typebots?${params}`,
fetcher,
{ dedupingInterval: 0 }
)
const { data, error, mutate } = useSWR<
{ typebots: TypebotInDashboard[] },
Error
>(`/api/typebots?${params}`, fetcher, { dedupingInterval: 0 })
if (error) onError(error)
return {
typebots: data?.typebots,
@ -93,11 +96,13 @@ export const importTypebot = async (typebot: Typebot) =>
body: typebot,
})
export const duplicateTypebot = async (typebot: Typebot) => {
export const duplicateTypebot = async (typebotId: string) => {
const { data: typebotToDuplicate } = await getTypebot(typebotId)
if (!typebotToDuplicate) return { error: new Error('Typebot not found') }
const duplicatedTypebot: Omit<Typebot, 'id'> = omit(
{
...typebot,
name: `${typebot.name} copy`,
...typebotToDuplicate,
name: `${typebotToDuplicate.name} copy`,
publishedTypebotId: null,
publicId: null,
},
@ -110,6 +115,12 @@ export const duplicateTypebot = async (typebot: Typebot) => {
})
}
const getTypebot = (typebotId: string) =>
sendRequest<Typebot>({
url: `/api/typebots/${typebotId}`,
method: 'GET',
})
export const deleteTypebot = async (id: string) =>
sendRequest({
url: `/api/typebots/${id}`,