cal.pub0.org/packages/features/form-builder/FormBuilderFieldsSchema.ts

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-01-24 14:45:22 +00:00
import { z } from "zod";
export const fieldsSchema = z.array(
z.object({
name: z.string(),
label: z.string(),
type: z.enum([
2023-02-01 05:18:42 +00:00
"name",
2023-01-24 14:45:22 +00:00
"text",
"textarea",
"number",
2023-01-24 14:45:22 +00:00
"email",
"phone",
"address",
"multiemail",
"select",
"multiselect",
"checkbox",
"radio",
"radioInput",
"boolean",
2023-01-24 14:45:22 +00:00
]),
options: z.array(z.object({ label: z.string(), value: z.string() })).optional(),
optionsInputs: z
.record(
z.object({
//TODO: Support all as needed
type: z.enum(["address", "phone"]),
required: z.boolean().optional(),
placeholder: z.string().optional(),
})
)
.optional(),
placeholder: z.string().optional(),
required: z.boolean(),
hidden: z.boolean().optional(),
2023-02-07 12:35:36 +00:00
editable: z.enum([
"system", // Can't be deleted, can't be hidden, name can't be edited, can't be marked optional
"system-but-optional", // Can't be deleted. Name can't be edited. But can be hidden or be marked optional
"user", // Fully editable
"user-readonly", // All fields are readOnly.
]),
2023-01-24 14:45:22 +00:00
sources: z
.array(
z.object({
// Unique ID for the `type`. If type is workflow, it's the workflow ID
id: z.string(),
type: z.union([z.literal("user"), z.literal("system"), z.string()]),
label: z.string(),
editUrl: z.string().optional(),
})
)
.optional(),
})
);