From 4630512b8ba8f4dfed23754d6f17ae398c9d8bdf Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 1 Mar 2022 07:55:20 +0100 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=20=F0=9F=90=9B=20subscribe=20un?= =?UTF-8?q?sub=20zapier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bodies/ZapierSettings.tsx | 1 + .../contents/ZapierContent.tsx | 23 +++++++++++++++---- .../steps/[stepId]/subscribeWebhook.ts | 5 +++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/builder/components/shared/Graph/Nodes/StepNode/SettingsPopoverContent/bodies/ZapierSettings.tsx b/apps/builder/components/shared/Graph/Nodes/StepNode/SettingsPopoverContent/bodies/ZapierSettings.tsx index 72f300f6c..ded9828e0 100644 --- a/apps/builder/components/shared/Graph/Nodes/StepNode/SettingsPopoverContent/bodies/ZapierSettings.tsx +++ b/apps/builder/components/shared/Graph/Nodes/StepNode/SettingsPopoverContent/bodies/ZapierSettings.tsx @@ -20,6 +20,7 @@ type Props = { export const ZapierSettings = ({ step }: Props) => { const { webhooks } = useTypebot() const webhook = webhooks.find(byId(step.webhookId)) + return ( { - const { webhooks } = useTypebot() - const webhook = webhooks.find(byId(webhookId)) +export const ZapierContent = ({ step }: Props) => { + const { webhooks, typebot, updateWebhook } = useTypebot() + 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)) return Configure... diff --git a/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/subscribeWebhook.ts b/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/subscribeWebhook.ts index 6704b829e..5ef4b7640 100644 --- a/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/subscribeWebhook.ts +++ b/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/subscribeWebhook.ts @@ -24,7 +24,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { const { webhookId } = typebot.blocks .find(byId(blockId)) ?.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' }) } catch (err) {