diff --git a/src/App.tsx b/src/App.tsx index 403bf20..d355ff2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,9 +5,6 @@ import { SchemaDef } from "./interfaces/schema"; const schema = SchemaDef.parse(personalInfoSchema); -// type FormValues = { -// [P in keyof T]: T[P]; -// }; const FormValues = schema.fields.reduce((acc, currValue) => { if (currValue.type === "field") { acc[currValue.accessorKey] = ""; @@ -18,7 +15,6 @@ const FormValues = schema.fields.reduce((acc, currValue) => { type TFormValues = typeof FormValues; function App() { - console.log({ schema }); const { register, handleSubmit } = useForm(); const onSubmit = (data: TFormValues) => { diff --git a/src/interfaces/field.ts b/src/interfaces/field.ts index fab6190..ff1c477 100644 --- a/src/interfaces/field.ts +++ b/src/interfaces/field.ts @@ -1,8 +1,38 @@ import { z } from "zod"; +const RequiredDef = z.object({ + value: z.boolean(), + message: z.string(), +}); + +const MaxMinLengthDef = z.object({ + value: z.number(), + message: z.string(), +}); + +const MaxMinDef = z.object({ + value: z.number(), + message: z.string(), +}); + +const PatternDef = z.object({ + value: z.string(), + message: z.string(), +}); + export const FieldTypeDef = z.object({ type: z.literal("field"), dataType: z.enum(["text", "number", "email"]), fieldName: z.string(), accessorKey: z.string(), + validation: z + .object({ + required: RequiredDef.optional(), + maxLength: MaxMinLengthDef.optional(), + minLength: MaxMinLengthDef.optional(), + max: MaxMinDef.optional(), + min: MaxMinDef.optional(), + pattern: PatternDef.optional(), + }) + .optional(), });