2
0

feat(dashboard): Duplicate webhooks on typebot duplication

This commit is contained in:
Baptiste Arnaud
2022-03-21 19:20:44 +01:00
parent 71816f76ad
commit b2bf6f09f6
2 changed files with 35 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import cuid from 'cuid'
import { Webhook } from 'models'
import { sendRequest } from 'utils'
@ -7,3 +8,15 @@ export const saveWebhook = (webhookId: string, webhook: Partial<Webhook>) =>
url: `/api/webhooks/${webhookId}`,
body: webhook,
})
export const duplicateWebhook = async (
webhookId: string
): Promise<Webhook | undefined> => {
const { data } = await sendRequest<{ webhook: Webhook }>(
`/api/webhooks/${webhookId}`
)
if (!data) return
const newWebhook = { ...data.webhook, id: cuid() }
await saveWebhook(newWebhook.id, newWebhook)
return newWebhook
}