2
0

chore(editor): 👔 Send email disabled in preview

This commit is contained in:
Baptiste Arnaud
2022-02-13 07:49:56 +01:00
parent f57827c530
commit f8a64151ef
7 changed files with 41 additions and 10 deletions

View File

@ -31,7 +31,8 @@ export const ChatBlock = ({
onScroll,
onBlockEnd,
}: ChatBlockProps) => {
const { typebot, updateVariableValue, createEdge, apiHost } = useTypebot()
const { typebot, updateVariableValue, createEdge, apiHost, isPreview } =
useTypebot()
const [displayedSteps, setDisplayedSteps] = useState<PublicStep[]>([])
const currentStepIndex = displayedSteps.length - 1
@ -67,6 +68,7 @@ export const ChatBlock = ({
typebotId: typebot.id,
indices: { blockIndex, stepIndex: currentStepIndex },
variables: typebot.variables,
isPreview,
updateVariableValue,
},
})

View File

@ -14,6 +14,7 @@ import { Answer, BackgroundType, Edge, PublicTypebot } from 'models'
export type TypebotViewerProps = {
typebot: PublicTypebot
isPreview?: boolean
apiHost?: string
onNewBlockVisible?: (edge: Edge) => void
onNewAnswer?: (answer: Answer) => void
@ -22,6 +23,7 @@ export type TypebotViewerProps = {
export const TypebotViewer = ({
typebot,
apiHost = process.env.NEXT_PUBLIC_VIEWER_HOST,
isPreview = false,
onNewBlockVisible,
onNewAnswer,
onCompleted,
@ -66,7 +68,7 @@ export const TypebotViewer = ({
}:wght@300;400;600&display=swap');`,
}}
/>
<TypebotContext typebot={typebot} apiHost={apiHost}>
<TypebotContext typebot={typebot} apiHost={apiHost} isPreview={isPreview}>
<AnswersContext>
<div
className="flex text-base overflow-hidden bg-cover h-screen w-screen flex-col items-center typebot-container"

View File

@ -4,6 +4,7 @@ import React, { createContext, ReactNode, useContext, useState } from 'react'
const typebotContext = createContext<{
typebot: PublicTypebot
apiHost: string
isPreview: boolean
updateVariableValue: (variableId: string, value: string) => void
createEdge: (edge: Edge) => void
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@ -14,10 +15,12 @@ export const TypebotContext = ({
children,
typebot,
apiHost,
isPreview,
}: {
children: ReactNode
typebot: PublicTypebot
apiHost: string
isPreview: boolean
}) => {
const [localTypebot, setLocalTypebot] = useState<PublicTypebot>(typebot)
@ -42,6 +45,7 @@ export const TypebotContext = ({
value={{
typebot: localTypebot,
apiHost,
isPreview,
updateVariableValue,
createEdge,
}}

View File

@ -15,6 +15,7 @@ import {
import { stringify } from 'qs'
import { sendRequest } from 'utils'
import { sendGaEvent } from '../../lib/gtag'
import { sendInfoMessage } from './postMessage'
import { parseVariables, parseVariablesInObject } from './variable'
const safeEval = eval
@ -24,6 +25,7 @@ type IntegrationContext = {
apiHost: string
typebotId: string
indices: Indices
isPreview: boolean
variables: Variable[]
updateVariableValue: (variableId: string, value: string) => void
}
@ -177,8 +179,10 @@ const executeWebhook = async (
const sendEmail = async (
step: SendEmailStep,
{ variables, apiHost }: IntegrationContext
{ variables, apiHost, isPreview }: IntegrationContext
) => {
if (isPreview) sendInfoMessage('Emails are not sent in preview mode')
if (isPreview) return step.outgoingEdgeId
const { options } = step
const { error } = await sendRequest({
url: `${apiHost}/api/integrations/email`,

View File

@ -0,0 +1,3 @@
export const sendInfoMessage = (typebotInfo: string) => {
parent.postMessage({ typebotInfo })
}