Skip to content

Commit

Permalink
fix(dashboard): 🐛 Duplicate typebot
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 15, 2022
1 parent 8583e2a commit ea80fd6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
24 changes: 12 additions & 12 deletions apps/builder/services/typebots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
})
}

Expand Down

3 comments on commit ea80fd6

@vercel
Copy link

@vercel vercel bot commented on ea80fd6 Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
next.typebot.io

@vercel
Copy link

@vercel vercel bot commented on ea80fd6 Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

viewer-v2-typebot-io.vercel.app
typebot-viewer.vercel.app
viewer-v2-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on ea80fd6 Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.