import * as React from "react"; import { Box, Button, Checkbox, FormControlLabel, FormLabel, FormControl, TextField, Typography, Grid, IconButton, Link, } from "@mui/material"; import { useForm, Controller, SubmitHandler } from "react-hook-form"; import { useDispatch } from "react-redux"; import { loginUser } from "../../../redux/slices/authSlice.ts"; import AppTheme from "../../../shared-theme/AppTheme.tsx"; import ForgotPassword from "./ForgotPassword.tsx"; import { toast } from "sonner"; import { useNavigate } from "react-router-dom"; import { Visibility, VisibilityOff } from "@mui/icons-material"; import { Card, SignInContainer } from "./styled.css.tsx"; interface ILoginForm { email: string; password: string; } export default function Login(props: { disableCustomTheme?: boolean }) { const [open, setOpen] = React.useState(false); const [showPassword, setShowPassword] = React.useState(false); const { control, handleSubmit, formState: { errors }, } = useForm(); const dispatch = useDispatch(); const router = useNavigate(); const handleClickOpen = () => { setOpen(true); }; const handleClose = () => { setOpen(false); }; const onSubmit: SubmitHandler = async (data: ILoginForm) => { try { const response = await dispatch(loginUser(data)).unwrap(); if (response?.data?.token) { router("/panel/dashboard"); } } catch (error: any) { console.log("Login failed:", error); toast.error("Login failed: " + error); } }; return ( {/* Image Section */} {/* Form Section */} Welcome Back! Login Log in with your email and password Email ( )} /> Password ( setShowPassword( (prev) => !prev ) } > {showPassword ? ( ) : ( )} )} /> } label="Remember me" /> Forgot password? ); }