Skip to content

Commit

Permalink
feat(engine): ⚗️ Await for result update
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed May 22, 2022
1 parent 350719c commit 391aead
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apps/builder/components/dashboard/OnboardingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/bot-engine/src/components/TypebotViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>
onNewLog?: (log: Omit<Log, 'id' | 'createdAt' | 'resultId'>) => void
onCompleted?: () => void
onVariablesUpdated?: (variables: VariableWithValue[]) => void
Expand Down
6 changes: 3 additions & 3 deletions packages/bot-engine/src/contexts/AnswersContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> | undefined
updateVariables: (variables: VariableWithValue[]) => void
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
Expand All @@ -17,7 +17,7 @@ export const AnswersContext = ({
onVariablesUpdated,
}: {
resultId?: string
onNewAnswer: (answer: Answer) => void
onNewAnswer: (answer: Answer) => Promise<void> | undefined
onVariablesUpdated?: (variables: VariableWithValue[]) => void
children: ReactNode
}) => {
Expand All @@ -32,7 +32,7 @@ export const AnswersContext = ({
...resultValues,
answers: [...resultValues.answers, answer],
}))
onNewAnswer(answer)
return onNewAnswer && onNewAnswer(answer)
}

const updateVariables = (variables: VariableWithValue[]) =>
Expand Down

0 comments on commit 391aead

Please sign in to comment.