feat(dashboard): ✨ Duplicate webhooks on typebot duplication
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user