@ -0,0 +1,9 @@
|
||||
import { defaultButtonLabel } from '../constants'
|
||||
import { ChoiceInputBlock } from './schema'
|
||||
|
||||
export const defaultChoiceInputOptions = {
|
||||
buttonLabel: defaultButtonLabel,
|
||||
searchInputPlaceholder: 'Filter the options...',
|
||||
isMultipleChoice: false,
|
||||
isSearchable: false,
|
||||
} as const satisfies ChoiceInputBlock['options']
|
1
packages/schemas/features/blocks/inputs/choice/index.ts
Normal file
1
packages/schemas/features/blocks/inputs/choice/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './schema'
|
64
packages/schemas/features/blocks/inputs/choice/schema.ts
Normal file
64
packages/schemas/features/blocks/inputs/choice/schema.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import { z } from 'zod'
|
||||
import { InputBlockType } from '../constants'
|
||||
import { itemBaseSchemas } from '../../../items/shared'
|
||||
import { optionBaseSchema, blockBaseSchema } from '../../shared'
|
||||
import { conditionSchema } from '../../logic'
|
||||
|
||||
export const choiceInputOptionsSchema = optionBaseSchema.merge(
|
||||
z.object({
|
||||
isMultipleChoice: z.boolean().optional(),
|
||||
buttonLabel: z.string().optional(),
|
||||
dynamicVariableId: z.string().optional(),
|
||||
isSearchable: z.boolean().optional(),
|
||||
searchInputPlaceholder: z.string().optional(),
|
||||
})
|
||||
)
|
||||
|
||||
export const buttonItemSchemas = {
|
||||
v5: itemBaseSchemas.v5.extend({
|
||||
content: z.string().optional(),
|
||||
displayCondition: z
|
||||
.object({
|
||||
isEnabled: z.boolean().optional(),
|
||||
condition: conditionSchema.optional(),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
v6: itemBaseSchemas.v6.extend({
|
||||
content: z.string().optional(),
|
||||
displayCondition: z
|
||||
.object({
|
||||
isEnabled: z.boolean().optional(),
|
||||
condition: conditionSchema.optional(),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
}
|
||||
|
||||
export const buttonItemSchema = z.union([
|
||||
buttonItemSchemas.v5,
|
||||
buttonItemSchemas.v6,
|
||||
])
|
||||
|
||||
export const buttonsInputV5Schema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([InputBlockType.CHOICE]),
|
||||
items: z.array(buttonItemSchemas.v5),
|
||||
options: choiceInputOptionsSchema.optional(),
|
||||
})
|
||||
)
|
||||
|
||||
export const buttonsInputSchemas = {
|
||||
v5: buttonsInputV5Schema,
|
||||
v6: buttonsInputV5Schema.extend({
|
||||
items: z.array(buttonItemSchemas.v6),
|
||||
}),
|
||||
} as const
|
||||
|
||||
export const buttonsInputSchema = z.union([
|
||||
buttonsInputSchemas.v5,
|
||||
buttonsInputSchemas.v6,
|
||||
])
|
||||
|
||||
export type ButtonItem = z.infer<typeof buttonItemSchema>
|
||||
export type ChoiceInputBlock = z.infer<typeof buttonsInputSchema>
|
Reference in New Issue
Block a user