import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { useTranslation } from "react-i18next"; import { useForm, Controller } from "react-hook-form"; import { useTheme } from "@mui/material/styles"; import { TextInput } from "@/Components/Inputs/TextInput/indexV2.tsx"; import Button from "@mui/material/Button"; import Stack from "@mui/material/Stack"; import { usePost } from "@/Hooks/v2/UseApi"; const schema = z.object({ email: z.email("Invalid email address"), password: z.string().min(6, "Password must be at least 6 characters"), }); type FormData = z.infer; const Login = () => { const { t } = useTranslation(); const theme = useTheme(); const { post, loading, error } = usePost("/auth/login"); const { handleSubmit, control, formState: { errors }, } = useForm({ resolver: zodResolver(schema), // ⬅️ connect Zod defaultValues: { email: "", password: "", }, }); const onSubmit = async (data: FormData) => { const result = await post(data); if (result) { console.log(result.message); } else { console.error("Login failed:", error); } }; return ( ( )} /> ( )} /> ); }; export default Login;