fix(editor): 🐛 subscribe unsub zapier
This commit is contained in:
@ -20,6 +20,7 @@ type Props = {
|
|||||||
export const ZapierSettings = ({ step }: Props) => {
|
export const ZapierSettings = ({ step }: Props) => {
|
||||||
const { webhooks } = useTypebot()
|
const { webhooks } = useTypebot()
|
||||||
const webhook = webhooks.find(byId(step.webhookId))
|
const webhook = webhooks.find(byId(step.webhookId))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing={4}>
|
<Stack spacing={4}>
|
||||||
<Alert
|
<Alert
|
||||||
|
@ -1,15 +1,30 @@
|
|||||||
import { Text } from '@chakra-ui/react'
|
import { Text } from '@chakra-ui/react'
|
||||||
import { useTypebot } from 'contexts/TypebotContext'
|
import { useTypebot } from 'contexts/TypebotContext'
|
||||||
import { ZapierStep } from 'models'
|
import { defaultWebhookAttributes, Webhook, ZapierStep } from 'models'
|
||||||
|
import { useEffect } from 'react'
|
||||||
import { byId, isNotDefined } from 'utils'
|
import { byId, isNotDefined } from 'utils'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
step: ZapierStep
|
step: ZapierStep
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ZapierContent = ({ step: { webhookId } }: Props) => {
|
export const ZapierContent = ({ step }: Props) => {
|
||||||
const { webhooks } = useTypebot()
|
const { webhooks, typebot, updateWebhook } = useTypebot()
|
||||||
const webhook = webhooks.find(byId(webhookId))
|
const webhook = webhooks.find(byId(step.webhookId))
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!typebot) return
|
||||||
|
if (!webhook) {
|
||||||
|
const { webhookId } = step
|
||||||
|
const newWebhook = {
|
||||||
|
id: webhookId,
|
||||||
|
...defaultWebhookAttributes,
|
||||||
|
typebotId: typebot.id,
|
||||||
|
} as Webhook
|
||||||
|
updateWebhook(webhookId, newWebhook)
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [])
|
||||||
|
|
||||||
if (isNotDefined(webhook?.body))
|
if (isNotDefined(webhook?.body))
|
||||||
return <Text color="gray.500">Configure...</Text>
|
return <Text color="gray.500">Configure...</Text>
|
||||||
|
@ -24,7 +24,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
const { webhookId } = typebot.blocks
|
const { webhookId } = typebot.blocks
|
||||||
.find(byId(blockId))
|
.find(byId(blockId))
|
||||||
?.steps.find(byId(stepId)) as WebhookStep
|
?.steps.find(byId(stepId)) as WebhookStep
|
||||||
await prisma.webhook.update({ where: { id: webhookId }, data: { url } })
|
await prisma.webhook.update({
|
||||||
|
where: { id: webhookId },
|
||||||
|
data: { url, body: '{{state}}' },
|
||||||
|
})
|
||||||
|
|
||||||
return res.send({ message: 'success' })
|
return res.send({ message: 'success' })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
Reference in New Issue
Block a user