🪥 Consult submissions
This commit is contained in:
@@ -11,18 +11,18 @@ import { deepEqual } from 'fast-equals'
|
||||
type Props = {
|
||||
typebot: PublicTypebot
|
||||
onNewBlockVisible: (blockId: string) => void
|
||||
onAnswersUpdate: (answers: Answer[]) => void
|
||||
onNewAnswer: (answer: Answer) => void
|
||||
onCompleted: () => void
|
||||
}
|
||||
export const ConversationContainer = ({
|
||||
typebot,
|
||||
onNewBlockVisible,
|
||||
onAnswersUpdate,
|
||||
onNewAnswer,
|
||||
onCompleted,
|
||||
}: Props) => {
|
||||
const { document: frameDocument } = useFrame()
|
||||
const [displayedBlocks, setDisplayedBlocks] = useState<Block[]>([])
|
||||
const [localAnswers, setLocalAnswers] = useState<Answer[]>([])
|
||||
const [localAnswer, setLocalAnswer] = useState<Answer | undefined>()
|
||||
const { answers } = useAnswers()
|
||||
const bottomAnchor = useRef<HTMLDivElement | null>(null)
|
||||
|
||||
@@ -44,9 +44,10 @@ export const ConversationContainer = ({
|
||||
}, [typebot.theme, frameDocument])
|
||||
|
||||
useEffect(() => {
|
||||
if (deepEqual(localAnswers, answers)) return
|
||||
setLocalAnswers(answers)
|
||||
onAnswersUpdate(answers)
|
||||
const answer = [...answers].pop()
|
||||
if (!answer || deepEqual(localAnswer, answer)) return
|
||||
setLocalAnswer(answer)
|
||||
onNewAnswer(answer)
|
||||
}, [answers])
|
||||
|
||||
return (
|
||||
|
||||
@@ -10,13 +10,13 @@ import { AnswersContext } from '../contexts/AnswersContext'
|
||||
export type TypebotViewerProps = {
|
||||
typebot: PublicTypebot
|
||||
onNewBlockVisible?: (blockId: string) => void
|
||||
onAnswersUpdate?: (answers: Answer[]) => void
|
||||
onNewAnswer?: (answer: Answer) => void
|
||||
onCompleted?: () => void
|
||||
}
|
||||
export const TypebotViewer = ({
|
||||
typebot,
|
||||
onNewBlockVisible,
|
||||
onAnswersUpdate,
|
||||
onNewAnswer,
|
||||
onCompleted,
|
||||
}: TypebotViewerProps) => {
|
||||
const containerBgColor = useMemo(
|
||||
@@ -29,8 +29,8 @@ export const TypebotViewer = ({
|
||||
const handleNewBlockVisible = (blockId: string) => {
|
||||
if (onNewBlockVisible) onNewBlockVisible(blockId)
|
||||
}
|
||||
const handleAnswersUpdate = (answers: Answer[]) => {
|
||||
if (onAnswersUpdate) onAnswersUpdate(answers)
|
||||
const handleNewAnswer = (answer: Answer) => {
|
||||
if (onNewAnswer) onNewAnswer(answer)
|
||||
}
|
||||
const handleCompleted = () => {
|
||||
if (onCompleted) onCompleted()
|
||||
@@ -60,7 +60,7 @@ export const TypebotViewer = ({
|
||||
<ConversationContainer
|
||||
typebot={typebot}
|
||||
onNewBlockVisible={handleNewBlockVisible}
|
||||
onAnswersUpdate={handleAnswersUpdate}
|
||||
onNewAnswer={handleNewAnswer}
|
||||
onCompleted={handleCompleted}
|
||||
/>
|
||||
</div>
|
||||
|
||||
3
packages/bot-engine/src/models/answer.ts
Normal file
3
packages/bot-engine/src/models/answer.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Answer as AnswerFromPrisma } from 'db'
|
||||
|
||||
export type Answer = Omit<AnswerFromPrisma, 'resultId'>
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './typebot'
|
||||
export * from './publicTypebot'
|
||||
export * from './result'
|
||||
export * from './answer'
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
import { Result as ResultFromPrisma } from 'db'
|
||||
|
||||
export type Result = Omit<ResultFromPrisma, 'answers'> & {
|
||||
answers: Answer[]
|
||||
}
|
||||
|
||||
export type Answer = {
|
||||
blockId: string
|
||||
stepId: string
|
||||
content: string
|
||||
}
|
||||
export type Result = Omit<ResultFromPrisma, 'createdAt'> & { createdAt: string }
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `answers` on the `Result` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "Result" DROP COLUMN "answers";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Answer" (
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"resultId" TEXT NOT NULL,
|
||||
"stepId" TEXT NOT NULL,
|
||||
"blockId" TEXT NOT NULL,
|
||||
"content" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Answer_resultId_blockId_stepId_key" ON "Answer"("resultId", "blockId", "stepId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Answer" ADD CONSTRAINT "Answer_resultId_fkey" FOREIGN KEY ("resultId") REFERENCES "Result"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -115,6 +115,17 @@ model Result {
|
||||
updatedAt DateTime @default(now())
|
||||
typebotId String
|
||||
typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
|
||||
answers Json[]
|
||||
answers Answer[]
|
||||
isCompleted Boolean?
|
||||
}
|
||||
|
||||
model Answer {
|
||||
createdAt DateTime @default(now())
|
||||
resultId String
|
||||
result Result @relation(fields: [resultId], references: [id], onDelete: Cascade)
|
||||
stepId String
|
||||
blockId String
|
||||
content String
|
||||
|
||||
@@unique([resultId, blockId, stepId])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user