feat(results): ✨ Add logs in results
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
import { TypebotViewer } from 'bot-engine'
|
||||
import { Log } from 'db'
|
||||
import { Answer, PublicTypebot, VariableWithValue } from 'models'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { upsertAnswer } from 'services/answer'
|
||||
import { SEO } from '../components/Seo'
|
||||
import { createResult, updateResult } from '../services/result'
|
||||
import { createLog, createResult, updateResult } from '../services/result'
|
||||
import { ErrorPage } from './ErrorPage'
|
||||
|
||||
export type TypebotPageProps = {
|
||||
@ -58,6 +59,14 @@ export const TypebotPage = ({
|
||||
if (error) setError(error)
|
||||
}
|
||||
|
||||
const handleNewLog = async (
|
||||
log: Omit<Log, 'id' | 'createdAt' | 'resultId'>
|
||||
) => {
|
||||
if (!resultId) return setError(new Error('Result was not created'))
|
||||
const { error } = await createLog(resultId, log)
|
||||
if (error) setError(error)
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <ErrorPage error={error} />
|
||||
}
|
||||
@ -74,6 +83,7 @@ export const TypebotPage = ({
|
||||
onNewAnswer={handleNewAnswer}
|
||||
onCompleted={handleCompleted}
|
||||
onVariablesPrefilled={initializeResult}
|
||||
onNewLog={handleNewLog}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user