feat: add i18n translated form errors (#509)

This commit is contained in:
Meier Lukas
2024-05-18 16:55:08 +02:00
committed by GitHub
parent b312032f02
commit dfed804f65
32 changed files with 501 additions and 156 deletions

View File

@@ -4,7 +4,7 @@ import { useRouter } from "next/navigation";
import { Button, PasswordInput, Stack, TextInput } from "@mantine/core";
import { clientApi } from "@homarr/api/client";
import { useForm, zodResolver } from "@homarr/form";
import { useZodForm } from "@homarr/form";
import {
showErrorNotification,
showSuccessNotification,
@@ -24,18 +24,17 @@ export const RegistrationForm = ({ invite }: RegistrationFormProps) => {
const t = useScopedI18n("user");
const router = useRouter();
const { mutate, isPending } = clientApi.user.register.useMutation();
const form = useForm<FormType>({
validate: zodResolver(validation.user.registration),
const form = useZodForm(validation.user.registration, {
initialValues: {
username: "",
password: "",
confirmPassword: "",
},
validateInputOnBlur: true,
validateInputOnChange: true,
});
const handleSubmit = (values: FormType) => {
const handleSubmit = (
values: z.infer<typeof validation.user.registration>,
) => {
mutate(
{
...values,
@@ -88,5 +87,3 @@ export const RegistrationForm = ({ invite }: RegistrationFormProps) => {
</Stack>
);
};
type FormType = z.infer<typeof validation.user.registration>;

View File

@@ -13,7 +13,7 @@ import {
import { IconAlertTriangle } from "@tabler/icons-react";
import { signIn } from "@homarr/auth/client";
import { useForm, zodResolver } from "@homarr/form";
import { useZodForm } from "@homarr/form";
import {
showErrorNotification,
showSuccessNotification,
@@ -27,15 +27,16 @@ export const LoginForm = () => {
const router = useRouter();
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string>();
const form = useForm<FormType>({
validate: zodResolver(validation.user.signIn),
const form = useZodForm(validation.user.signIn, {
initialValues: {
name: "",
password: "",
},
});
const handleSubmitAsync = async (values: FormType) => {
const handleSubmitAsync = async (
values: z.infer<typeof validation.user.signIn>,
) => {
setIsLoading(true);
setError(undefined);
await signIn("credentials", {
@@ -92,5 +93,3 @@ export const LoginForm = () => {
</Stack>
);
};
type FormType = z.infer<typeof validation.user.signIn>;