Skip to content

Commit

Permalink
πŸ”„ [chore]: Automated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
brunotot committed Sep 7, 2023
1 parent 7a4326f commit f7b608e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
7 changes: 3 additions & 4 deletions packages/core/src/types/Payload.type.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { EvaluatedStrategy } from "./EvaluatedStrategy";
import { $ } from "./namespace/Utility.ns";

export type Payload<T> = EvaluatedStrategy<
export type Payload<
T,
undefined,
$.TArgGet<"partial">["enabled"]
>;
TPartial extends $.TArg<"partial"> = $.TArgGet<"partial">["enabled"]
> = EvaluatedStrategy<T, undefined, TPartial>;
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function UserFormInput() {
] = useForm<UserForm>(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,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/examples/playground/src/main.tsx
Original file line number Diff line number Diff line change
@@ -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(<App />);
7 changes: 2 additions & 5 deletions packages/react/src/hooks/useForm/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<TClass> = Payload<TClass>
>(
export default function useForm<TClass, TBody = TClass>(
model: Class<TClass>,
{
defaultValue,
Expand Down
11 changes: 5 additions & 6 deletions packages/react/src/hooks/useValidation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TClass> = Payload<TClass>
>(
export default function useValidation<TClass, TBody = TClass>(
model: Class<TClass>,
{ defaultValue, groups }: ns.UseValidationConfig<TBody> = {}
): ns.UseValidationReturn<TClass, TBody> {
Expand All @@ -40,7 +37,9 @@ export default function useValidation<
const [simpleErrors, setSimpleErrors] = useState({} as Errors<TClass>);

useEffect(() => {
const { errors, detailedErrors } = processor.validate(form);
const { errors, detailedErrors } = processor.validate(
form as Payload<TClass>
);
setDetails(detailedErrors);
setSimpleErrors(errors);
}, [form]);
Expand All @@ -49,7 +48,7 @@ export default function useValidation<
form,
setForm,
{
isValid: processor.isValid(form),
isValid: processor.isValid(form as Payload<TClass>),
processor,
errors: simpleErrors,
detailedErrors: details,
Expand Down

0 comments on commit f7b608e

Please sign in to comment.