2022-06-07 08:49:12 +02:00
|
|
|
import { z } from 'zod'
|
2023-01-25 11:27:47 +01:00
|
|
|
import { ItemType } from '../../items/enums'
|
|
|
|
import { itemBaseSchema } from '../../items/baseSchemas'
|
|
|
|
import { optionBaseSchema, blockBaseSchema } from '../baseSchemas'
|
|
|
|
import { defaultButtonLabel } from './constants'
|
|
|
|
import { InputBlockType } from './enums'
|
2022-06-07 08:49:12 +02:00
|
|
|
|
2023-03-14 16:42:12 +01:00
|
|
|
export const choiceInputOptionsSchema = optionBaseSchema.merge(
|
2022-06-07 08:49:12 +02:00
|
|
|
z.object({
|
|
|
|
isMultipleChoice: z.boolean(),
|
|
|
|
buttonLabel: z.string(),
|
2023-02-23 14:44:37 +01:00
|
|
|
dynamicVariableId: z.string().optional(),
|
2023-04-26 17:54:00 +02:00
|
|
|
isSearchable: z.boolean().optional(),
|
2023-05-04 09:20:30 -04:00
|
|
|
searchInputPlaceholder: z.string().optional(),
|
2022-06-07 08:49:12 +02:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-05-04 09:20:30 -04:00
|
|
|
export const defaultChoiceInputOptions = {
|
2022-06-07 08:49:12 +02:00
|
|
|
buttonLabel: defaultButtonLabel,
|
2023-05-04 09:20:30 -04:00
|
|
|
searchInputPlaceholder: 'Filter the options...',
|
2022-06-07 08:49:12 +02:00
|
|
|
isMultipleChoice: false,
|
2023-04-26 17:54:00 +02:00
|
|
|
isSearchable: false,
|
2023-05-04 09:20:30 -04:00
|
|
|
} as const
|
2022-06-07 08:49:12 +02:00
|
|
|
|
2023-03-14 16:42:12 +01:00
|
|
|
export const buttonItemSchema = itemBaseSchema.merge(
|
2022-06-07 08:49:12 +02:00
|
|
|
z.object({
|
2022-06-12 17:34:33 +02:00
|
|
|
type: z.literal(ItemType.BUTTON),
|
|
|
|
content: z.string().optional(),
|
2022-06-07 08:49:12 +02:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-03-14 16:42:12 +01:00
|
|
|
export const choiceInputSchema = blockBaseSchema.merge(
|
2022-06-07 08:49:12 +02:00
|
|
|
z.object({
|
2022-06-12 17:34:33 +02:00
|
|
|
type: z.enum([InputBlockType.CHOICE]),
|
|
|
|
items: z.array(buttonItemSchema),
|
|
|
|
options: choiceInputOptionsSchema,
|
2022-06-07 08:49:12 +02:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
export type ButtonItem = z.infer<typeof buttonItemSchema>
|
2022-06-11 07:27:38 +02:00
|
|
|
export type ChoiceInputBlock = z.infer<typeof choiceInputSchema>
|
2022-06-07 08:49:12 +02:00
|
|
|
export type ChoiceInputOptions = z.infer<typeof choiceInputOptionsSchema>
|