2023-12-22 09:13:53 +01:00
|
|
|
import { z } from '../zod'
|
2022-11-21 11:12:43 +01:00
|
|
|
import { answerInputSchema, answerSchema } from './answer'
|
2022-11-18 18:21:40 +01:00
|
|
|
import { variableWithValueSchema } from './typebot/variable'
|
2023-11-08 15:34:16 +01:00
|
|
|
import {
|
|
|
|
Result as ResultPrisma,
|
|
|
|
Log as LogPrisma,
|
|
|
|
VisitedEdge,
|
|
|
|
} from '@typebot.io/prisma'
|
|
|
|
import { InputBlockType } from './blocks/inputs/constants'
|
2021-12-22 14:59:07 +01:00
|
|
|
|
2023-03-09 08:46:36 +01:00
|
|
|
export const resultSchema = z.object({
|
|
|
|
id: z.string(),
|
|
|
|
createdAt: z.date(),
|
|
|
|
typebotId: z.string(),
|
|
|
|
variables: z.array(variableWithValueSchema),
|
|
|
|
isCompleted: z.boolean(),
|
|
|
|
hasStarted: z.boolean().nullable(),
|
|
|
|
isArchived: z.boolean().nullable(),
|
|
|
|
}) satisfies z.ZodType<ResultPrisma>
|
2022-11-18 18:21:40 +01:00
|
|
|
|
2023-03-14 16:42:12 +01:00
|
|
|
export const resultWithAnswersSchema = resultSchema.merge(
|
2022-11-18 18:21:40 +01:00
|
|
|
z.object({
|
|
|
|
answers: z.array(answerSchema),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-11-08 15:34:16 +01:00
|
|
|
export const visitedEdgeSchema = z.object({
|
|
|
|
edgeId: z.string(),
|
|
|
|
resultId: z.string(),
|
|
|
|
index: z.number(),
|
|
|
|
}) satisfies z.ZodType<VisitedEdge>
|
|
|
|
|
2023-03-14 16:42:12 +01:00
|
|
|
export const resultWithAnswersInputSchema = resultSchema.merge(
|
2022-11-21 11:12:43 +01:00
|
|
|
z.object({
|
|
|
|
answers: z.array(answerInputSchema),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-03-09 08:46:36 +01:00
|
|
|
export const logSchema = z.object({
|
|
|
|
id: z.string(),
|
|
|
|
createdAt: z.date(),
|
|
|
|
resultId: z.string(),
|
|
|
|
status: z.string(),
|
|
|
|
description: z.string(),
|
|
|
|
details: z.string().nullable(),
|
|
|
|
}) satisfies z.ZodType<LogPrisma>
|
2022-11-18 18:21:40 +01:00
|
|
|
|
|
|
|
export type Result = z.infer<typeof resultSchema>
|
|
|
|
export type ResultWithAnswers = z.infer<typeof resultWithAnswersSchema>
|
2022-11-21 11:12:43 +01:00
|
|
|
export type ResultWithAnswersInput = z.infer<
|
|
|
|
typeof resultWithAnswersInputSchema
|
|
|
|
>
|
2022-11-18 18:21:40 +01:00
|
|
|
export type Log = z.infer<typeof logSchema>
|
2022-02-22 10:16:35 +01:00
|
|
|
|
2023-03-07 14:41:57 +01:00
|
|
|
export type ResultValuesInput = Pick<
|
2022-11-21 11:12:43 +01:00
|
|
|
ResultWithAnswersInput,
|
2022-03-28 17:07:47 +02:00
|
|
|
'answers' | 'createdAt' | 'variables'
|
2022-02-22 10:16:35 +01:00
|
|
|
>
|
2022-03-21 17:05:51 +01:00
|
|
|
|
2023-03-07 14:41:57 +01:00
|
|
|
export type ResultValues = Pick<
|
|
|
|
ResultWithAnswers,
|
|
|
|
'answers' | 'createdAt' | 'variables'
|
|
|
|
>
|
|
|
|
|
2022-03-21 17:05:51 +01:00
|
|
|
export type ResultHeaderCell = {
|
2022-07-01 17:08:35 +02:00
|
|
|
id: string
|
2022-03-21 17:05:51 +01:00
|
|
|
label: string
|
2022-11-06 09:57:08 +01:00
|
|
|
blocks?: {
|
|
|
|
id: string
|
|
|
|
groupId: string
|
|
|
|
}[]
|
2022-06-11 07:27:38 +02:00
|
|
|
blockType?: InputBlockType
|
2022-11-06 09:57:08 +01:00
|
|
|
variableIds?: string[]
|
2022-03-21 17:05:51 +01:00
|
|
|
}
|
2024-01-12 10:16:01 +01:00
|
|
|
|
|
|
|
export type CellValueType = { element?: JSX.Element; plainText: string }
|
|
|
|
|
|
|
|
export type TableData = {
|
|
|
|
id: Pick<CellValueType, 'plainText'>
|
|
|
|
} & Record<string, CellValueType>
|