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