From 391aeaddf12590db0ce7a40dce5a31d31285b971 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Sun, 22 May 2022 08:33:50 -0700 Subject: [PATCH] =?UTF-8?q?feat(engine):=20=E2=9A=97=EF=B8=8F=20Await=20fo?= =?UTF-8?q?r=20result=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/builder/components/dashboard/OnboardingModal.tsx | 2 +- .../src/components/ChatBlock/ChatStep/InputChatStep.tsx | 6 +++--- packages/bot-engine/src/components/TypebotViewer.tsx | 2 +- packages/bot-engine/src/contexts/AnswersContext.tsx | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/builder/components/dashboard/OnboardingModal.tsx b/apps/builder/components/dashboard/OnboardingModal.tsx index de7003d07..d6ffee948 100644 --- a/apps/builder/components/dashboard/OnboardingModal.tsx +++ b/apps/builder/components/dashboard/OnboardingModal.tsx @@ -81,7 +81,7 @@ export const OnboardingModal = ({ totalTypebots }: Props) => { setTypebot(data as Typebot) } - const handleNewAnswer = (answer: Answer) => { + const handleNewAnswer = async (answer: Answer) => { const isName = answer.variableId === 'cl126f4hf000i2e6d8zvzc3t1' const isCompany = answer.variableId === 'cl126jqww000w2e6dq9yv4ifq' const isCategories = answer.variableId === 'cl126mo3t001b2e6dvyi16bkd' diff --git a/packages/bot-engine/src/components/ChatBlock/ChatStep/InputChatStep.tsx b/packages/bot-engine/src/components/ChatBlock/ChatStep/InputChatStep.tsx index 18b842732..6e02ebd3b 100644 --- a/packages/bot-engine/src/components/ChatBlock/ChatStep/InputChatStep.tsx +++ b/packages/bot-engine/src/components/ChatBlock/ChatStep/InputChatStep.tsx @@ -32,11 +32,11 @@ export const InputChatStep = ({ ? variableId && typebot.variables.find(byId(variableId))?.value : undefined - const handleSubmit = (content: string) => { + const handleSubmit = async (content: string) => { setAnswer(content) const isRetry = !isInputValid(content, step.type) - if (!isRetry) - addAnswer({ + if (!isRetry && addAnswer) + await addAnswer({ stepId: step.id, blockId: step.blockId, content, diff --git a/packages/bot-engine/src/components/TypebotViewer.tsx b/packages/bot-engine/src/components/TypebotViewer.tsx index 6b357e260..8659e1700 100644 --- a/packages/bot-engine/src/components/TypebotViewer.tsx +++ b/packages/bot-engine/src/components/TypebotViewer.tsx @@ -30,7 +30,7 @@ export type TypebotViewerProps = { predefinedVariables?: { [key: string]: string | undefined } resultId?: string onNewBlockVisible?: (edge: Edge) => void - onNewAnswer?: (answer: Answer) => void + onNewAnswer?: (answer: Answer) => Promise onNewLog?: (log: Omit) => void onCompleted?: () => void onVariablesUpdated?: (variables: VariableWithValue[]) => void diff --git a/packages/bot-engine/src/contexts/AnswersContext.tsx b/packages/bot-engine/src/contexts/AnswersContext.tsx index 75d0ee1f7..61af7729d 100644 --- a/packages/bot-engine/src/contexts/AnswersContext.tsx +++ b/packages/bot-engine/src/contexts/AnswersContext.tsx @@ -4,7 +4,7 @@ import React, { createContext, ReactNode, useContext, useState } from 'react' const answersContext = createContext<{ resultId?: string resultValues: ResultValues - addAnswer: (answer: Answer) => void + addAnswer: (answer: Answer) => Promise | undefined updateVariables: (variables: VariableWithValue[]) => void // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore @@ -17,7 +17,7 @@ export const AnswersContext = ({ onVariablesUpdated, }: { resultId?: string - onNewAnswer: (answer: Answer) => void + onNewAnswer: (answer: Answer) => Promise | undefined onVariablesUpdated?: (variables: VariableWithValue[]) => void children: ReactNode }) => { @@ -32,7 +32,7 @@ export const AnswersContext = ({ ...resultValues, answers: [...resultValues.answers, answer], })) - onNewAnswer(answer) + return onNewAnswer && onNewAnswer(answer) } const updateVariables = (variables: VariableWithValue[]) =>