Skip to content

Commit

Permalink
⚡ (webhook) Enable advanced config for Zapier and Make.com
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 6, 2023
1 parent 5bda556 commit c1a636b
Show file tree
Hide file tree
Showing 9 changed files with 479 additions and 328 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
import { Text } from '@chakra-ui/react'
import { useTypebot } from '@/features/editor'
import { defaultWebhookAttributes, MakeComBlock, Webhook } from 'models'
import { useEffect } from 'react'
import { MakeComBlock } from 'models'
import { byId, isNotDefined } from 'utils'

type Props = {
block: MakeComBlock
}

export const MakeComContent = ({ block }: Props) => {
const { webhooks, typebot, updateWebhook } = useTypebot()
const { webhooks } = useTypebot()
const webhook = webhooks.find(byId(block.webhookId))

useEffect(() => {
if (!typebot) return
if (!webhook) {
const { webhookId } = block
const newWebhook = {
id: webhookId,
...defaultWebhookAttributes,
typebotId: typebot.id,
} as Webhook
updateWebhook(webhookId, newWebhook)
}
}, [block, typebot, updateWebhook, webhook])

if (isNotDefined(webhook?.body))
return <Text color="gray.500">Configure...</Text>
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,68 @@
import {
Alert,
AlertIcon,
Button,
Input,
Link,
Stack,
Text,
} from '@chakra-ui/react'
import { Alert, AlertIcon, Button, Link, Stack, Text } from '@chakra-ui/react'
import { ExternalLinkIcon } from '@/components/icons'
import { useTypebot } from '@/features/editor'
import { MakeComBlock } from 'models'
import React from 'react'
import { byId } from 'utils'
import { MakeComBlock, Webhook, WebhookOptions } from 'models'
import React, { useCallback, useEffect, useState } from 'react'
import { byId, env } from 'utils'
import { WebhookAdvancedConfigForm } from '../../webhook/components/WebhookAdvancedConfigForm'
import { useDebouncedCallback } from 'use-debounce'

const debounceWebhookTimeout = 2000

type Props = {
block: MakeComBlock
onOptionsChange: (options: WebhookOptions) => void
}

export const MakeComSettings = ({ block }: Props) => {
const { webhooks } = useTypebot()
const webhook = webhooks.find(byId(block.webhookId))
export const MakeComSettings = ({
block: { webhookId, id: blockId, options },
onOptionsChange,
}: Props) => {
const { webhooks, updateWebhook } = useTypebot()
const webhook = webhooks.find(byId(webhookId))

const [localWebhook, _setLocalWebhook] = useState(webhook)
const updateWebhookDebounced = useDebouncedCallback(
async (newLocalWebhook) => {
await updateWebhook(newLocalWebhook.id, newLocalWebhook)
},
env('E2E_TEST') === 'true' ? 0 : debounceWebhookTimeout
)

const setLocalWebhook = useCallback(
(newLocalWebhook: Webhook) => {
_setLocalWebhook(newLocalWebhook)
updateWebhookDebounced(newLocalWebhook)
},
[updateWebhookDebounced]
)

useEffect(() => {
if (
!localWebhook ||
localWebhook.url ||
!webhook?.url ||
webhook.url === localWebhook.url
)
return
setLocalWebhook({
...localWebhook,
url: webhook?.url,
})
}, [webhook, localWebhook, setLocalWebhook])

useEffect(
() => () => {
updateWebhookDebounced.flush()
},
[updateWebhookDebounced]
)

return (
<Stack spacing={4}>
<Alert status={webhook?.url ? 'success' : 'info'} rounded="md">
<Alert status={localWebhook?.url ? 'success' : 'info'} rounded="md">
<AlertIcon />
{webhook?.url ? (
{localWebhook?.url ? (
<>Your scenario is correctly configured 🚀</>
) : (
<Stack>
Expand All @@ -41,7 +78,15 @@ export const MakeComSettings = ({ block }: Props) => {
</Stack>
)}
</Alert>
{webhook?.url && <Input value={webhook?.url} isDisabled />}
{localWebhook && (
<WebhookAdvancedConfigForm
blockId={blockId}
webhook={localWebhook}
options={options}
onWebhookChange={setLocalWebhook}
onOptionsChange={onOptionsChange}
/>
)}
</Stack>
)
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
import { Text } from '@chakra-ui/react'
import { useTypebot } from '@/features/editor'
import { defaultWebhookAttributes, PabblyConnectBlock, Webhook } from 'models'
import { useEffect } from 'react'
import { PabblyConnectBlock } from 'models'
import { byId, isNotDefined } from 'utils'

type Props = {
block: PabblyConnectBlock
}

export const PabblyConnectContent = ({ block }: Props) => {
const { webhooks, typebot, updateWebhook } = useTypebot()
const { webhooks } = useTypebot()
const webhook = webhooks.find(byId(block.webhookId))

useEffect(() => {
if (!typebot) return
if (!webhook) {
const { webhookId } = block
const newWebhook = {
id: webhookId,
...defaultWebhookAttributes,
typebotId: typebot.id,
} as Webhook
updateWebhook(webhookId, newWebhook)
}
}, [block, typebot, updateWebhook, webhook])

if (isNotDefined(webhook?.body))
return <Text color="gray.500">Configure...</Text>
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Alert, AlertIcon, Button, Link, Stack, Text } from '@chakra-ui/react'
import { ExternalLinkIcon } from '@/components/icons'
import { useTypebot } from '@/features/editor'
import { PabblyConnectBlock, Webhook, WebhookOptions } from 'models'
import React, { useEffect, useState } from 'react'
import { byId, env } from 'utils'
import { WebhookAdvancedConfigForm } from '../../webhook/components/WebhookAdvancedConfigForm'
import { useDebouncedCallback } from 'use-debounce'
import { TextInput } from '@/components/inputs'

const debounceWebhookTimeout = 2000

type Props = {
block: PabblyConnectBlock
onOptionsChange: (options: WebhookOptions) => void
}

export const PabblyConnectSettings = ({
block: { webhookId, id: blockId, options },
onOptionsChange,
}: Props) => {
const { webhooks, updateWebhook } = useTypebot()

const [localWebhook, _setLocalWebhook] = useState(
webhooks.find(byId(webhookId))
)

const updateWebhookDebounced = useDebouncedCallback(
async (newLocalWebhook) => {
await updateWebhook(newLocalWebhook.id, newLocalWebhook)
},
env('E2E_TEST') === 'true' ? 0 : debounceWebhookTimeout
)

const setLocalWebhook = (newLocalWebhook: Webhook) => {
_setLocalWebhook(newLocalWebhook)
updateWebhookDebounced(newLocalWebhook)
}

useEffect(
() => () => {
updateWebhookDebounced.flush()
},
[updateWebhookDebounced]
)

const handleUrlChange = (url: string) =>
localWebhook &&
setLocalWebhook({
...localWebhook,
url,
})

return (
<Stack spacing={4}>
<Alert status={localWebhook?.url ? 'success' : 'info'} rounded="md">
<AlertIcon />
{localWebhook?.url ? (
<>Your scenario is correctly configured 🚀</>
) : (
<Stack>
<Text>Head up to Pabbly Connect to get the webhook URL:</Text>
<Button
as={Link}
href="https://www.pabbly.com/connect/integrations/typebot/"
isExternal
colorScheme="blue"
>
<Text mr="2">Pabbly.com</Text> <ExternalLinkIcon />
</Button>
</Stack>
)}
</Alert>
<TextInput
placeholder="Paste webhook URL..."
defaultValue={localWebhook?.url ?? ''}
onChange={handleUrlChange}
withVariableButton={false}
debounceTimeout={0}
/>
{localWebhook && (
<WebhookAdvancedConfigForm
blockId={blockId}
webhook={localWebhook}
options={options}
onWebhookChange={setLocalWebhook}
onOptionsChange={onOptionsChange}
/>
)}
</Stack>
)
}
Loading

4 comments on commit c1a636b

@vercel
Copy link

@vercel vercel bot commented on c1a636b Mar 6, 2023

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

ns8.vn
1stop.au
yobot.me
klujo.com
me.cr8.ai
247987.com
8jours.top
aginap.com
ai.mprs.in
bee.cr8.ai
bot.aws.bj
bot.bbc.bj
cat.cr8.ai
finplex.be
nepkit.com
pig.cr8.ai
sat.cr8.ai
bot.aipr.kr
bot.joof.it
bull.cr8.ai
docs.cr8.ai
minipost.uk
mole.cr8.ai
team.cr8.ai
wolf.cr8.ai
cinecorn.com
help.taxt.co
kusamint.com
rhino.cr8.ai
sheep.cr8.ai
snake.cr8.ai
svhm.mprs.in
tiger.cr8.ai
video.cr8.ai
yoda.riku.ai
zebra.cr8.ai
bergamo.store
bot.krdfy.com
bot.tvbeat.it
cgcassets.com
cnvhub.com.br
facelabko.com
filmylogy.com
goldorayo.com
rabbit.cr8.ai
signup.cr8.ai
start.taxt.co
turkey.cr8.ai
vhpage.cr8.ai
bot.winglabs.com.br
chat.marius.digital
chatbot.matthesv.de
chatbot.repplai.com
demo.botscientis.us
newsletter.itshcormeos.com
tarian.theiofoundation.org
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
jcapp.virtuesocialmedia.com
liveconvert2.kandalearn.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
bot.seidibergamoseanchetu.it
desabafe.sergiolimajr.com.br
download.venturemarketing.in
jc-app.virtuesocialmedia.com
piazzatorre.barrettamario.it
type.cookieacademyonline.com
upload.atlasoutfittersk9.com
bot.brigadeirosemdrama.com.br
forms.escoladeautomacao.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
elevateyourmind.groovepages.com
viewer-v2-typebot-io.vercel.app
yourfeedback.comebackreward.com
gerador.verificadordehospedes.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
bot.studiotecnicoimmobiliaremerelli.it
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
chrome-os-inquiry-system.itschromeos.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com

@vercel
Copy link

@vercel vercel bot commented on c1a636b Mar 6, 2023

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:

docs – ./apps/docs

docs-typebot-io.vercel.app
docs.typebot.io
docs-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on c1a636b Mar 6, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on c1a636b Mar 6, 2023

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-git-main-typebot-io.vercel.app
app.typebot.io
builder-v2-typebot-io.vercel.app

Please sign in to comment.