2
0

feat(engine): Add Rating input

This commit is contained in:
Baptiste Arnaud
2022-06-07 19:09:08 +02:00
parent 301097623b
commit b1aecf843b
19 changed files with 455 additions and 28 deletions

View File

@ -7,3 +7,4 @@ export * from './date'
export * from './choice'
export * from './payment'
export * from './phone'
export * from './rating'

View File

@ -9,6 +9,7 @@ import {
phoneNumberInputOptionsSchema,
phoneNumberInputStepSchema,
} from './phone'
import { ratingInputOptionsSchema, ratingInputStepSchema } from './rating'
import { textInputOptionsSchema, textInputSchema } from './text'
import { urlInputOptionsSchema, urlInputSchema } from './url'
@ -22,6 +23,7 @@ export const inputStepOptionsSchema = textInputOptionsSchema
.or(phoneNumberInputOptionsSchema)
.or(dateInputOptionsSchema)
.or(paymentInputOptionsSchema)
.or(ratingInputOptionsSchema)
export const inputStepSchema = textInputSchema
.or(numberInputSchema)
@ -31,6 +33,7 @@ export const inputStepSchema = textInputSchema
.or(phoneNumberInputStepSchema)
.or(choiceInputSchema)
.or(paymentInputSchema)
.or(ratingInputStepSchema)
export type InputStep = z.infer<typeof inputStepSchema>
export type InputStepOptions = z.infer<typeof inputStepOptionsSchema>

View File

@ -0,0 +1,41 @@
import { z } from 'zod'
import {
defaultButtonLabel,
InputStepType,
optionBaseSchema,
stepBaseSchema,
} from '../shared'
export const defaultRatingInputOptions: RatingInputOptions = {
buttonType: 'Numbers',
length: 10,
labels: { button: defaultButtonLabel },
customIcon: { isEnabled: false },
}
export const ratingInputOptionsSchema = optionBaseSchema.and(
z.object({
buttonType: z.literal('Icons').or(z.literal('Numbers')),
length: z.number(),
labels: z.object({
left: z.string().optional(),
right: z.string().optional(),
middle: z.string().optional(),
button: z.string(),
}),
customIcon: z.object({
isEnabled: z.boolean(),
svg: z.string().optional(),
}),
})
)
export const ratingInputStepSchema = stepBaseSchema.and(
z.object({
type: z.literal(InputStepType.RATING),
options: ratingInputOptionsSchema,
})
)
export type RatingInputStep = z.infer<typeof ratingInputStepSchema>
export type RatingInputOptions = z.infer<typeof ratingInputOptionsSchema>

View File

@ -39,6 +39,7 @@ export enum InputStepType {
PHONE = 'phone number input',
CHOICE = 'choice input',
PAYMENT = 'payment input',
RATING = 'rating input',
}
export enum LogicStepType {