diff --git a/client/src/Hooks/v2/UseApi.tsx b/client/src/Hooks/v2/UseApi.tsx index 7cef2bf2e..eab661793 100644 --- a/client/src/Hooks/v2/UseApi.tsx +++ b/client/src/Hooks/v2/UseApi.tsx @@ -34,19 +34,16 @@ export const useGet = ( }; }; -export const usePost = (endpoint: string) => { +export const usePost = (endpoint: string) => { const [loading, setLoading] = useState(false); const [error, setError] = useState(null); - const postFn = async ( - body: B, - config?: AxiosRequestConfig - ): Promise => { + const postFn = async (body: B, config?: AxiosRequestConfig): Promise => { setLoading(true); setError(null); try { - const res = await post(endpoint, body, config); + const res = await post(endpoint, body, config); return res.data; } catch (err: any) { const errMsg = err?.response?.data?.msg || err.message || "An error occurred"; diff --git a/client/src/Pages/v2/Auth/Login.tsx b/client/src/Pages/v2/Auth/Login.tsx index 16c40d5d9..58eec01dc 100644 --- a/client/src/Pages/v2/Auth/Login.tsx +++ b/client/src/Pages/v2/Auth/Login.tsx @@ -8,6 +8,8 @@ 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"; +import type { ApiResponse } 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"), @@ -18,14 +20,14 @@ type FormData = z.infer; const Login = () => { const { t } = useTranslation(); const theme = useTheme(); - const { post, loading, error } = usePost("/auth/login"); + const { post, loading, error } = usePost("/auth/login"); const { handleSubmit, control, formState: { errors }, } = useForm({ - resolver: zodResolver(schema), // ⬅️ connect Zod + resolver: zodResolver(schema), defaultValues: { email: "", password: "",