From 2ca1f64ae6f9e77c23bae10674278b4f9c715193 Mon Sep 17 00:00:00 2001 From: dswbx Date: Wed, 9 Jul 2025 08:13:32 +0200 Subject: [PATCH] fix json field form, replaced auth form --- app/package.json | 5 +- app/src/modules/ModuleApi.ts | 8 ++- .../ui/components/display/ErrorBoundary.tsx | 10 +-- .../form/native-form/NativeForm.tsx | 1 - app/src/ui/elements/auth/AuthForm.tsx | 66 ++++++------------- .../routes/data/forms/entity.fields.form.tsx | 47 +++++++++---- 6 files changed, 68 insertions(+), 69 deletions(-) diff --git a/app/package.json b/app/package.json index 95d2a495..746e016b 100644 --- a/app/package.json +++ b/app/package.json @@ -60,8 +60,7 @@ "bcryptjs": "^3.0.2", "dayjs": "^1.11.13", "fast-xml-parser": "^5.0.8", - "hono": "^4.7.11", - "json-schema-form-react": "^0.0.2", + "hono": "4.8.3", "json-schema-library": "10.0.0-rc7", "json-schema-to-ts": "^3.1.1", "kysely": "^0.27.6", @@ -100,7 +99,7 @@ "dotenv": "^16.4.7", "jotai": "^2.12.2", "jsdom": "^26.0.0", - "jsonv-ts": "^0.2.2", + "jsonv-ts": "link:jsonv-ts", "kysely-d1": "^0.3.0", "kysely-generic-sqlite": "^1.2.1", "libsql-stateless-easy": "^1.8.0", diff --git a/app/src/modules/ModuleApi.ts b/app/src/modules/ModuleApi.ts index f8a295c4..d8955b8c 100644 --- a/app/src/modules/ModuleApi.ts +++ b/app/src/modules/ModuleApi.ts @@ -1,5 +1,5 @@ import type { PrimaryFieldType } from "core"; -import { $console } from "core/utils"; +import { $console, isPlainObject } from "core/utils"; import { isDebug } from "core/env"; import { encodeSearch } from "core/utils/reqres"; import type { ApiFetcher } from "Api"; @@ -95,7 +95,11 @@ export abstract class ModuleApi { private renderFallback() { if (this.props.fallback) { - return typeof this.props.fallback === "function" - ? this.props.fallback({ error: this.state.error!, resetError: this.resetError }) - : this.props.fallback; + return typeof this.props.fallback === "function" ? ( + this.props.fallback({ error: this.state.error!, resetError: this.resetError }) + ) : ( + {this.props.fallback} + ); } - return Error; + return Error1; } override render() { diff --git a/app/src/ui/components/form/native-form/NativeForm.tsx b/app/src/ui/components/form/native-form/NativeForm.tsx index 15b6d5cd..17cc6497 100644 --- a/app/src/ui/components/form/native-form/NativeForm.tsx +++ b/app/src/ui/components/form/native-form/NativeForm.tsx @@ -6,7 +6,6 @@ import { useRef, useState, } from "react"; -import { useEvent } from "ui/hooks/use-event"; import { type CleanOptions, type InputElement, diff --git a/app/src/ui/elements/auth/AuthForm.tsx b/app/src/ui/elements/auth/AuthForm.tsx index 4f22b170..0865317f 100644 --- a/app/src/ui/elements/auth/AuthForm.tsx +++ b/app/src/ui/elements/auth/AuthForm.tsx @@ -1,20 +1,11 @@ import type { AppAuthOAuthStrategy, AppAuthSchema } from "auth/auth-schema"; import clsx from "clsx"; -import { Form } from "json-schema-form-react"; +import { NativeForm } from "ui/components/form/native-form/NativeForm"; import { transform } from "lodash-es"; import type { ComponentPropsWithoutRef } from "react"; import { Button } from "ui/components/buttons/Button"; import { Group, Input, Password, Label } from "ui/components/form/Formy/components"; import { SocialLink } from "./SocialLink"; -import type { Validator } from "json-schema-form-react"; -import { s } from "bknd/core"; -import type { ErrorDetail } from "jsonv-ts"; - -class JsonvTsValidator implements Validator { - async validate(schema: s.Schema, data: any) { - return schema.validate(data).errors; - } -} export type LoginFormProps = Omit, "onSubmit" | "action"> & { className?: string; @@ -25,16 +16,6 @@ export type LoginFormProps = Omit, "onSubmit" | buttonLabel?: string; }; -const validator = new JsonvTsValidator(); -const schema = s.strictObject({ - email: s.string({ - pattern: "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$", - }), - password: s.string({ - minLength: 8, // @todo: this should be configurable - }), -}); - export function AuthForm({ formData, className, @@ -79,38 +60,31 @@ export function AuthForm({ )} -
- {({ errors, submitting }) => ( - <> - - - - - - - - + + + + + + + + - - - )} -
+ + ); } diff --git a/app/src/ui/routes/data/forms/entity.fields.form.tsx b/app/src/ui/routes/data/forms/entity.fields.form.tsx index 60be4c8e..ee8bf76e 100644 --- a/app/src/ui/routes/data/forms/entity.fields.form.tsx +++ b/app/src/ui/routes/data/forms/entity.fields.form.tsx @@ -23,6 +23,7 @@ import { MantineSelect } from "ui/components/form/hook-form-mantine/MantineSelec import type { TPrimaryFieldFormat } from "data/fields/PrimaryField"; import { s, stringIdentifier } from "bknd/core"; import { standardSchemaResolver } from "@hookform/resolvers/standard-schema"; +import ErrorBoundary from "ui/components/display/ErrorBoundary"; const fieldsSchemaObject = originalFieldsSchemaObject; const fieldsSchema = s.anyOf(Object.values(fieldsSchemaObject)); @@ -453,19 +454,17 @@ function EntityField({
- { - setValue(`${prefix}.config`, { - ...getValues([`fields.${index}.config`])[0], - ...value, - }); - }} - /> + + { + setValue(`${prefix}.config`, { + ...getValues([`fields.${index}.config`])[0], + ...value, + }); + }} + /> +
@@ -490,3 +489,25 @@ function EntityField({ ); } + +const SpecificForm = ({ + field, + onChange, +}: { + field: FieldArrayWithId; + onChange: (value: any) => void; +}) => { + const type = field.field.type; + const specificData = omit(field.field.config, commonProps); + + return ( + + ); +};