From f7b608e539c57f6e1f0b33b9df4f5907a2c026d7 Mon Sep 17 00:00:00 2001 From: Bruno Tot Date: Thu, 7 Sep 2023 14:44:09 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20[chore]:=20Automated=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/types/Payload.type.ts | 7 +++---- .../src/components/controls/UserFormControls.tsx | 2 +- packages/react/examples/playground/src/main.tsx | 2 +- packages/react/src/hooks/useForm/index.tsx | 7 ++----- packages/react/src/hooks/useValidation/index.ts | 11 +++++------ 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/packages/core/src/types/Payload.type.ts b/packages/core/src/types/Payload.type.ts index 79e942547..656ae1d12 100644 --- a/packages/core/src/types/Payload.type.ts +++ b/packages/core/src/types/Payload.type.ts @@ -1,8 +1,7 @@ import { EvaluatedStrategy } from "./EvaluatedStrategy"; import { $ } from "./namespace/Utility.ns"; -export type Payload = EvaluatedStrategy< +export type Payload< T, - undefined, - $.TArgGet<"partial">["enabled"] ->; + TPartial extends $.TArg<"partial"> = $.TArgGet<"partial">["enabled"] +> = EvaluatedStrategy; diff --git a/packages/react/examples/playground/src/components/controls/UserFormControls.tsx b/packages/react/examples/playground/src/components/controls/UserFormControls.tsx index 586bda23f..bacd20f54 100644 --- a/packages/react/examples/playground/src/components/controls/UserFormControls.tsx +++ b/packages/react/examples/playground/src/components/controls/UserFormControls.tsx @@ -27,7 +27,7 @@ export default function UserFormInput() { ] = useForm(UserForm, { validationGroups: GROUPS, onSubmit: () => alert("Congrats, you don't have any validation errors!"), - whenChanged: () => setNumberOfStateChanges((p) => ++p), + onChange: () => setNumberOfStateChanges((p) => ++p), defaultValue: undefined, standalone: true, validateImmediately: !SUBMIT_BUTTON_TRIGGERS_VALIDATION, diff --git a/packages/react/examples/playground/src/main.tsx b/packages/react/examples/playground/src/main.tsx index 64e4ae30f..dfee7471b 100644 --- a/packages/react/examples/playground/src/main.tsx +++ b/packages/react/examples/playground/src/main.tsx @@ -1,5 +1,5 @@ import ReactDOM from "react-dom/client"; -import "tdv-core/dist/polyfill.d.ts"; +import "tdv-core/dist/polyfill.d"; import App from "./App.tsx"; ReactDOM.createRoot(document.getElementById("root")!).render(); diff --git a/packages/react/src/hooks/useForm/index.tsx b/packages/react/src/hooks/useForm/index.tsx index abe3b0930..40330dc00 100644 --- a/packages/react/src/hooks/useForm/index.tsx +++ b/packages/react/src/hooks/useForm/index.tsx @@ -1,5 +1,5 @@ import { useContext, useEffect, useState } from "react"; -import { Class, Payload } from "tdv-core"; +import { Class } from "tdv-core"; import { FormContext } from "../../contexts/FormContext"; import useEffectWhenMounted from "../useAfterMount"; import useMutations from "../useMutations"; @@ -35,10 +35,7 @@ import ns from "./types"; * @typeParam TClass - represents parent form class model holding context of current compontent * @typeParam TBody - represents writable scope of `TClass` (it can be TClass itself or a chunk of its fields) */ -export default function useForm< - TClass, - TBody extends Payload = Payload ->( +export default function useForm( model: Class, { defaultValue, diff --git a/packages/react/src/hooks/useValidation/index.ts b/packages/react/src/hooks/useValidation/index.ts index ed15ce366..f9a3f5314 100644 --- a/packages/react/src/hooks/useValidation/index.ts +++ b/packages/react/src/hooks/useValidation/index.ts @@ -27,10 +27,7 @@ import ns from "./types"; * @typeParam TClass - represents parent form class model holding context of current compontent * @typeParam TBody - represents writable scope of `TClass` (it can be TClass itself or a chunk of its fields) */ -export default function useValidation< - TClass, - TBody extends Payload = Payload ->( +export default function useValidation( model: Class, { defaultValue, groups }: ns.UseValidationConfig = {} ): ns.UseValidationReturn { @@ -40,7 +37,9 @@ export default function useValidation< const [simpleErrors, setSimpleErrors] = useState({} as Errors); useEffect(() => { - const { errors, detailedErrors } = processor.validate(form); + const { errors, detailedErrors } = processor.validate( + form as Payload + ); setDetails(detailedErrors); setSimpleErrors(errors); }, [form]); @@ -49,7 +48,7 @@ export default function useValidation< form, setForm, { - isValid: processor.isValid(form), + isValid: processor.isValid(form as Payload), processor, errors: simpleErrors, detailedErrors: details,