import { useState, useEffect } from 'react' // import { useSelector } from 'react-redux'; // import AuthWrapper from 'sections/auth/AuthWrapper'; import { Box, Grid, Card, CardContent, // CardHeader, Stack, // Divider, // InputLabel, // OutlinedInput, TextField, Button, Typography, CardHeader, Container, Link } from '@mui/material' import { useTheme } from '@mui/material/styles'; import AnimateButton from 'components/@extended/AnimateButton'; import logo from 'assets/images/logo-nearle.png' import axios from 'axios' import { useNavigate } from 'react-router-dom' // import { openSnackbar } from 'store/reducers/snackbar'; // import { useDispatch } from 'react-redux'; import Loader from 'components/Loader'; import { enqueueSnackbar } from 'notistack'; const Login = () => { const theme = useTheme(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [alertmessage, setAlertmessage] = useState(''); const [checkusername, setCheckusername] = useState(false); // const [toast, setToast] = useState(false); const [loading, setLoading] = useState(false); let navigate = useNavigate(); // let dispatch = useDispatch(); const [submitting, setSubmitting] = useState(false) // let loginuserid = useSelector((state)=>state.logininfo); // useEffect(() => { // if (alertmessage) { // dispatch( // openSnackbar({ // open: true, // message: alertmessage, // variant: 'alert', // anchorOrigin: { vertical: 'top', horizontal: 'right' }, // alert: { // // variant:'info', // color: 'error', // } // }) // ) // } // }, [toast]) useEffect(() => { if (localStorage.getItem("authname") // || localStorage.getItem("appuserid") ) { navigate('/dashboard') } // console.log(alertmessage) }, []) const usernamecheck = async (e) => { e.preventDefault(); setUsername(e.target.value) if (e.target.value) { try { // await axios.post(`${process.env.REACT_APP_URL}/auth/login`, { // "authname": e.target.value // }) await axios.post(`${process.env.REACT_APP_URL}/users/login`, { "authname": e.target.value, "configid": 1, "password": 'admin' }) .then((res) => { console.log(res.data) if (res.data.details.authname === e.target.value) { setUsername(e.target.value); setCheckusername(false); } else { setCheckusername(true); } // if (res.data.authname === e.target.value) { // setUsername(e.target.value); // setCheckusername(false); // } }).catch((err) => { // if (err.response.data.message === 'No user found') { setCheckusername(true); // } }) } catch (err) { console.log(err) } } } const loginsend = async () => { // e.preventDefault(); setLoading(true) if (password && username) { setSubmitting(true) try { await axios.post(`${process.env.REACT_APP_URL}/users/login`, { "authname": username, "configid": 1, "password": password }).then((res) => { console.log(res.data) if (res.data.details.authname === username) { // setAlertmessage('login Successfull'); setLoading(false) // dispatch( // openSnackbar({ // open: true, // message: 'login Successfull', // variant: 'alert', // anchorOrigin: { vertical: 'top', horizontal: 'right' }, // alert: { // color: 'success' // } // }) // ) enqueueSnackbar('login Successfull', { variant: 'success', anchorOrigin: { vertical: 'top', horizontal: 'right' }, autoHideDuration: 3000 }) setUsername(''); setPassword(''); localStorage.setItem("firstname", res.data.details.firstname); localStorage.setItem("authname", res.data.details.authname); localStorage.setItem("appuserid", res.data.details.userid); localStorage.setItem("roleid", res.data.details.roleid); localStorage.setItem("tenantid", res.data.details.tenantid); navigate('/dashboard'); setSubmitting(false) } }).catch((err) => { console.log(err); setAlertmessage('Invalid Data'); opentoast('Invalid Data'); setLoading(false) setSubmitting(false) }) } catch (err) { console.log(err) setLoading(false) setSubmitting(false) } } else { // let el2 = document.getElementById('toastid'); // el2.classList.add('d-block'); // el2.classList.remove('d-none'); setAlertmessage('Fill All required fields'); opentoast('Fill All required fields'); setLoading(false) } } // const handleClose = () => { // setToast(false) // } const opentoast = (message) => { // setToast(true) // setTimeout(() => { // // handleClose(); // setToast(false) // }, 2000); enqueueSnackbar(message, { variant: 'error', anchorOrigin: { vertical: 'top', horizontal: 'right' }, autoHideDuration: 2000 }) } return <> {/* */} {(loading) && } {/* */} legendary {/* {children} */} *': { flexGrow: 1, flexBasis: '50%' } }} > {/* Login} /> */} {/* */} {/*

eee

*/} {/* */} Login} /> {/* */}
{ e.preventDefault() }} > {/* */} {/* Email Address {touched.email && errors.email && ( {errors.email} )} */} setPassword(e.target.value)} type='password' id="password1" label="Password" variant="outlined" /> {/* */} {/* */} {/* Password */} {/* // // {showPassword ? : } // // // } placeholder="Enter password" // margin="normal" // fullWidth required autoComplete="current-password" onChange={(e) => setPassword(e.target.value)} type='password' id="password1" /> */} {/* {touched.password && errors.password && ( {errors.password} )} */} {/* */} Forgot password? {/* setChecked(event.target.checked)} name="checked" color="primary" size="small" /> } label={Keep me sign in} /> Forgot Password? */} {/* {errors.submit && ( {errors.submit} )} */} {/* */} {/* */} {/* */}
{/*
*/}
{/* */} © All rights reserved {/* Privacy Policy */} Terms and Conditions Privacy Policy {/* CA Privacy Notice */}
{/*
*/} } export default Login;