mirror of
https://github.com/ajnart/homarr.git
synced 2026-03-02 02:10:59 +01:00
* feat: update prettier configuration for print width * chore: apply code formatting to entire repository * fix: remove build files * fix: format issue --------- Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
27 lines
830 B
TypeScript
27 lines
830 B
TypeScript
import { useForm, zodResolver } from "@mantine/form";
|
|
|
|
import { useI18n } from "@homarr/translation/client";
|
|
import { z } from "@homarr/validation";
|
|
import type { AnyZodObject, ZodEffects, ZodIntersection } from "@homarr/validation";
|
|
import { zodErrorMap } from "@homarr/validation/form";
|
|
|
|
export const useZodForm = <
|
|
TSchema extends AnyZodObject | ZodEffects<AnyZodObject> | ZodIntersection<AnyZodObject, AnyZodObject>,
|
|
>(
|
|
schema: TSchema,
|
|
options: Omit<
|
|
Exclude<Parameters<typeof useForm<z.infer<TSchema>>>[0], undefined>,
|
|
"validate" | "validateInputOnBlur" | "validateInputOnChange"
|
|
>,
|
|
) => {
|
|
const t = useI18n();
|
|
|
|
z.setErrorMap(zodErrorMap(t));
|
|
return useForm<z.infer<TSchema>>({
|
|
...options,
|
|
validateInputOnBlur: true,
|
|
validateInputOnChange: true,
|
|
validate: zodResolver(schema),
|
|
});
|
|
};
|