2
0

feat(editor): Add Zapier step

This commit is contained in:
Baptiste Arnaud
2022-02-22 08:03:38 +01:00
parent d0994e6577
commit 642a42779b
15 changed files with 117 additions and 13 deletions

View File

@ -1,10 +1,10 @@
import { withSentry } from '@sentry/nextjs'
import { Prisma } from 'db'
import prisma from 'libs/prisma'
import { HttpMethod, IntegrationStepType, Typebot } from 'models'
import { HttpMethod, Typebot } from 'models'
import { NextApiRequest, NextApiResponse } from 'next'
import { authenticateUser } from 'services/api/utils'
import { methodNotAllowed } from 'utils'
import { isWebhookStep, methodNotAllowed } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'PATCH') {
@ -46,7 +46,7 @@ const addUrlToWebhookStep = (
...b,
steps: b.steps.map((s) => {
if (s.id === stepId) {
if (s.type !== IntegrationStepType.WEBHOOK) throw new Error()
if (!isWebhookStep(s)) throw new Error()
return {
...s,
webhook: {

View File

@ -1,11 +1,11 @@
import { withSentry } from '@sentry/nextjs'
import { Prisma } from 'db'
import prisma from 'libs/prisma'
import { IntegrationStepType, Typebot } from 'models'
import { Typebot } from 'models'
import { NextApiRequest, NextApiResponse } from 'next'
import { authenticateUser } from 'services/api/utils'
import { omit } from 'services/utils'
import { methodNotAllowed } from 'utils'
import { isWebhookStep, methodNotAllowed } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'DELETE') {
@ -44,7 +44,7 @@ const removeUrlFromWebhookStep = (
...b,
steps: b.steps.map((s) => {
if (s.id === stepId) {
if (s.type !== IntegrationStepType.WEBHOOK) throw new Error()
if (!isWebhookStep(s)) throw new Error()
return { ...s, webhook: omit(s.webhook, 'url') }
}
return s

View File

@ -1,9 +1,9 @@
import { withSentry } from '@sentry/nextjs'
import prisma from 'libs/prisma'
import { Block, IntegrationStepType } from 'models'
import { Block } from 'models'
import { NextApiRequest, NextApiResponse } from 'next'
import { authenticateUser } from 'services/api/utils'
import { methodNotAllowed } from 'utils'
import { isWebhookStep, methodNotAllowed } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'GET') {
@ -18,7 +18,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
{ blockId: string; id: string; name: string }[]
>((emptyWebhookSteps, block) => {
const steps = block.steps.filter(
(step) => step.type === IntegrationStepType.WEBHOOK && !step.webhook.url
(step) => isWebhookStep(step) && !step.webhook.url
)
return [
...emptyWebhookSteps,