From ea80fd6d3ec3e31c99b3cfb2f1d94f45c1c4b749 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 15 Feb 2022 07:38:41 +0100 Subject: [PATCH] =?UTF-8?q?fix(dashboard):=20=F0=9F=90=9B=20Duplicate=20ty?= =?UTF-8?q?pebot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/FolderContent/TypebotButton.tsx | 5 ++-- apps/builder/services/typebots.ts | 24 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/builder/components/dashboard/FolderContent/TypebotButton.tsx b/apps/builder/components/dashboard/FolderContent/TypebotButton.tsx index fa30fbf84..e5ef4c02d 100644 --- a/apps/builder/components/dashboard/FolderContent/TypebotButton.tsx +++ b/apps/builder/components/dashboard/FolderContent/TypebotButton.tsx @@ -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) => { diff --git a/apps/builder/services/typebots.ts b/apps/builder/services/typebots.ts index 8bad52f8d..98569605d 100644 --- a/apps/builder/services/typebots.ts +++ b/apps/builder/services/typebots.ts @@ -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 = omit( + { + ...typebot, + name: `${typebot.name} copy`, + publishedTypebotId: null, + publicId: null, + }, + 'id' + ) return sendRequest({ url: `/api/typebots`, method: 'POST', - body: typebot, + body: duplicatedTypebot, }) }