fix(dashboard): 🐛 Duplicate typebot
This commit is contained in:
@ -64,14 +64,15 @@ export const TypebotButton = ({
|
||||
onTypebotDeleted()
|
||||
}
|
||||
|
||||
const handleDuplicateClick = async () => {
|
||||
const handleDuplicateClick = async (e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
const { data: createdTypebot, error } = await duplicateTypebot(typebot)
|
||||
if (error)
|
||||
return toast({
|
||||
title: "Couldn't duplicate typebot",
|
||||
description: error.message,
|
||||
})
|
||||
if (createdTypebot) router.push(`/typebots/${createdTypebot?.id}`)
|
||||
if (createdTypebot) router.push(`/typebots/${createdTypebot?.id}/edit`)
|
||||
}
|
||||
|
||||
const handleDeleteClick = (e: React.MouseEvent) => {
|
||||
|
@ -39,7 +39,7 @@ import {
|
||||
import shortId, { generate } from 'short-uuid'
|
||||
import { Typebot } from 'models'
|
||||
import useSWR from 'swr'
|
||||
import { fetcher, toKebabCase } from './utils'
|
||||
import { fetcher, omit, toKebabCase } from './utils'
|
||||
import {
|
||||
isBubbleStepType,
|
||||
stepTypeHasItems,
|
||||
@ -92,20 +92,20 @@ export const importTypebot = async (typebot: Typebot) =>
|
||||
body: typebot,
|
||||
})
|
||||
|
||||
export const duplicateTypebot = async ({
|
||||
folderId,
|
||||
ownerId,
|
||||
name,
|
||||
}: Typebot) => {
|
||||
const typebot = {
|
||||
folderId,
|
||||
ownerId,
|
||||
name: `${name} copy`,
|
||||
}
|
||||
export const duplicateTypebot = async (typebot: Typebot) => {
|
||||
const duplicatedTypebot: Omit<Typebot, 'id'> = omit(
|
||||
{
|
||||
...typebot,
|
||||
name: `${typebot.name} copy`,
|
||||
publishedTypebotId: null,
|
||||
publicId: null,
|
||||
},
|
||||
'id'
|
||||
)
|
||||
return sendRequest<Typebot>({
|
||||
url: `/api/typebots`,
|
||||
method: 'POST',
|
||||
body: typebot,
|
||||
body: duplicatedTypebot,
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user