diff --git a/app/package.json b/app/package.json index 8efb6c9..352ad90 100644 --- a/app/package.json +++ b/app/package.json @@ -34,7 +34,8 @@ "liquidjs": "^10.15.0", "lodash-es": "^4.17.21", "oauth4webapi": "^2.11.1", - "swr": "^2.2.5" + "swr": "^2.2.5", + "json-schema-form-react": "link:json-schema-form-react" }, "devDependencies": { "@aws-sdk/client-s3": "^3.613.0", diff --git a/app/src/ui/modules/auth/LoginForm.tsx b/app/src/ui/modules/auth/LoginForm.tsx index 4f1887d..c20206b 100644 --- a/app/src/ui/modules/auth/LoginForm.tsx +++ b/app/src/ui/modules/auth/LoginForm.tsx @@ -1,7 +1,7 @@ -import { typeboxResolver } from "@hookform/resolvers/typebox"; -import { Type } from "core/utils"; +import type { ValueError } from "@sinclair/typebox/value"; +import { type TSchema, Type, Value } from "core/utils"; +import { Form, type Validator } from "json-schema-form-react"; import type { ComponentPropsWithoutRef } from "react"; -import { useForm } from "react-hook-form"; import { twMerge } from "tailwind-merge"; import { Button } from "ui/components/buttons/Button"; import * as Formy from "ui/components/form/Formy"; @@ -11,6 +11,13 @@ export type LoginFormProps = Omit, "onSubmit"> formData?: any; }; +class TypeboxValidator implements Validator { + async validate(schema: TSchema, data: any) { + return Value.Check(schema, data) ? [] : [...Value.Errors(schema, data)]; + } +} +const validator = new TypeboxValidator(); + const schema = Type.Object({ email: Type.String({ pattern: "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$" @@ -20,36 +27,39 @@ const schema = Type.Object({ }) }); -export function LoginForm({ formData, className, method = "POST", ...props }: LoginFormProps) { - const { - register, - formState: { isValid, errors } - } = useForm({ - mode: "onChange", - defaultValues: formData, - resolver: typeboxResolver(schema) - }); - +export function LoginForm({ formData, className, ...props }: LoginFormProps) { return ( -
- - Email address - - - - Password - - + + {({ errors, submitting }) => ( + <> +
{JSON.stringify(errors, null, 2)}
+ + Email address + + + + Password + + - -
+ + + )} + ); } diff --git a/app/src/ui/routes/auth/auth.login.tsx b/app/src/ui/routes/auth/auth.login.tsx index a9cebdc..9a05b76 100644 --- a/app/src/ui/routes/auth/auth.login.tsx +++ b/app/src/ui/routes/auth/auth.login.tsx @@ -22,7 +22,6 @@ export function AuthLogin() { }, {} ) as Record; - //console.log("oauth", oauth, strategies); return ( diff --git a/bun.lockb b/bun.lockb index 6aed431..62f83ac 100755 Binary files a/bun.lockb and b/bun.lockb differ