2
0

feat(results): Add logs in results

This commit is contained in:
Baptiste Arnaud
2022-03-01 11:40:22 +01:00
parent 4630512b8b
commit ebf92b5536
27 changed files with 408 additions and 120 deletions

View File

@ -9,18 +9,26 @@ const answersContext = createContext<{
//@ts-ignore
}>({})
export const AnswersContext = ({ children }: { children: ReactNode }) => {
export const AnswersContext = ({
children,
onNewAnswer,
}: {
onNewAnswer: (answer: Answer) => void
children: ReactNode
}) => {
const [resultValues, setResultValues] = useState<ResultValues>({
answers: [],
prefilledVariables: [],
createdAt: new Date().toISOString(),
})
const addAnswer = (answer: Answer) =>
const addAnswer = (answer: Answer) => {
setResultValues((resultValues) => ({
...resultValues,
answers: [...resultValues.answers, answer],
}))
onNewAnswer(answer)
}
const setPrefilledVariables = (variables: VariableWithValue[]) =>
setResultValues((resultValues) => ({

View File

@ -1,3 +1,4 @@
import { Log } from 'db'
import { Edge, PublicTypebot } from 'models'
import React, {
createContext,
@ -13,6 +14,7 @@ const typebotContext = createContext<{
isPreview: boolean
updateVariableValue: (variableId: string, value: string) => void
createEdge: (edge: Edge) => void
onNewLog: (log: Omit<Log, 'id' | 'createdAt' | 'resultId'>) => void
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
}>({})
@ -22,11 +24,13 @@ export const TypebotContext = ({
typebot,
apiHost,
isPreview,
onNewLog,
}: {
children: ReactNode
typebot: PublicTypebot
apiHost: string
isPreview: boolean
onNewLog: (log: Omit<Log, 'id' | 'createdAt' | 'resultId'>) => void
}) => {
const [localTypebot, setLocalTypebot] = useState<PublicTypebot>(typebot)
@ -63,6 +67,7 @@ export const TypebotContext = ({
isPreview,
updateVariableValue,
createEdge,
onNewLog,
}}
>
{children}