refactor login form

This commit is contained in:
2024-07-13 19:15:21 +02:00
parent 7c562e8057
commit fd076517dc
10 changed files with 241 additions and 185 deletions

View File

@@ -0,0 +1,32 @@
import { Input, type InputProps } from "@/components/ui";
import {
type Control,
type FieldValues,
type UseControllerProps,
useController,
} from "react-hook-form";
type Props<T extends FieldValues> = Omit<
UseControllerProps<T>,
"control" | "defaultValue" | "rules"
> &
Omit<InputProps, "value" | "onChange"> & { control: Control<T> };
export const FormInput = <T extends FieldValues>({
control,
name,
disabled,
shouldUnregister,
...rest
}: Props<T>) => {
const {
field,
fieldState: { error },
} = useController({
control,
name,
disabled,
shouldUnregister,
});
return <Input errorMessage={error?.message} {...field} {...rest} />;
};