loginpage loading added'

parent f98887e3
import React, { useState } from "react"; import React, { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import axios from 'axios'; import axios from 'axios';
import { base_url } from "../../utils/constants"; import { base_url } from "../../utils/constants";
import { loginUser } from "../../redux/reducers/userSlice"; import { loginUser } from "../../redux/reducers/userSlice";
import {useDispatch} from 'react-redux' import {useDispatch} from 'react-redux'
import Loading from '../../components/loading Component/Loading'
function Home() { function Home() {
const navigate = useNavigate(); const navigate = useNavigate();
const dispatch=useDispatch() const dispatch=useDispatch()
const [id, setId] = useState(null); const [id, setId] = useState(null);
const [errorMsg,setErrorMsg]=useState("") const [errorMsg,setErrorMsg]=useState("")
const [loading,setLoading]=useState(true)
const handleNavigate = () => { const handleNavigate = async () => {
setLoading(true)
if(id!==null){ if(id!==null){
axios.post(`${base_url}/login`,{empId:Number(id)}) await axios.post(`${base_url}/login`,{empId:Number(id)})
.then((res) => { .then((res) => {
setLoading(false)
dispatch(loginUser(res.data.user)) dispatch(loginUser(res.data.user))
navigate(`/dashboard`); navigate(`/dashboard`);
}) })
.catch((error)=>{ .catch((error)=>{
setLoading(false)
setErrorMsg("Not Authorized"); setErrorMsg("Not Authorized");
}) })
}else{ }else{
setLoading(false)
navigate(`/`); navigate(`/`);
} }
}; };
useEffect(()=>{
setLoading(false)
},[])
if(loading) {return <Loading/>}
else
return ( return (
<div className="container py-10 px-10 mx-0 min-w-full h-screen flex items-center justify-center bg-blue-100 "> <div className="container py-10 px-10 mx-0 min-w-full h-screen flex items-center justify-center bg-blue-100 ">
<div className=""> <div className="">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment