fix lint warnings
This commit is contained in:
parent
3320d0d932
commit
52f76f8209
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from "react";
|
import React from "react";
|
||||||
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
|
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
|
||||||
import "./styles.css";
|
import "./styles.css";
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,18 @@
|
|||||||
import {useLocation, Outlet, Navigate, Routes, Route} from "react-router-dom";
|
import { useLocation, Outlet, Navigate } from "react-router-dom";
|
||||||
import useAuth from "./hooks/useAuth";
|
import useAuth from "./hooks/useAuth";
|
||||||
import Navbar from "./components/navbar/Navbar";
|
import Navbar from "./components/navbar/Navbar";
|
||||||
import Sidebar from "./components/sidebar/Sidebar";
|
import Sidebar from "./components/sidebar/Sidebar";
|
||||||
import React, {useState} from "react";
|
import React, { useState } from "react";
|
||||||
import {
|
import {
|
||||||
MeetingStatus,
|
MeetingStatus,
|
||||||
SidebarUserObj,
|
SidebarUserObj,
|
||||||
} from "./components/sidebar/SidebarUser";
|
} from "./components/sidebar/SidebarUser";
|
||||||
import {Box} from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
|
|
||||||
const ProtectedRoute = () => {
|
const ProtectedRoute = () => {
|
||||||
const { auth }: any = useAuth();
|
const { auth }: any = useAuth();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
const [meetingInfoOpen, setMeetingInfoOpen] = useState(false);
|
|
||||||
/* Temporary data */
|
/* Temporary data */
|
||||||
const [sidebarUsers] = useState<SidebarUserObj[]>([
|
const [sidebarUsers] = useState<SidebarUserObj[]>([
|
||||||
{ id: 0, name: "Jincheng L.", meetingStatus: MeetingStatus.ONLINE },
|
{ id: 0, name: "Jincheng L.", meetingStatus: MeetingStatus.ONLINE },
|
||||||
@ -38,22 +37,21 @@ const ProtectedRoute = () => {
|
|||||||
{ id: 19, name: "Bob Q.", meetingStatus: MeetingStatus.ONLINE },
|
{ id: 19, name: "Bob Q.", meetingStatus: MeetingStatus.ONLINE },
|
||||||
{ id: 20, name: "Bob R.", meetingStatus: MeetingStatus.ONLINE },
|
{ id: 20, name: "Bob R.", meetingStatus: MeetingStatus.ONLINE },
|
||||||
]);
|
]);
|
||||||
return (
|
return auth?.isLoggedIn ? (
|
||||||
auth?.isLoggedIn
|
<>
|
||||||
?
|
<Navbar />
|
||||||
<>
|
<Box id="drawer-container" sx={{ display: "flex", height: "100%" }}>
|
||||||
<Navbar />
|
<Box sx={{ flexGrow: 1 }}>
|
||||||
<Box id="drawer-container" sx={{ display: "flex", height: "100%" }}>
|
<Outlet />
|
||||||
<Box sx={{ flexGrow: 1 }}>
|
|
||||||
<Outlet />
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Sidebar users={sidebarUsers} />
|
|
||||||
</Box>
|
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
<Box>
|
||||||
: <Navigate to="/login" state={{ from: location }} replace />
|
<Sidebar users={sidebarUsers} />
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Navigate to="/login" state={{ from: location }} replace />
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ProtectedRoute;
|
export default ProtectedRoute;
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { useRef, useState, useEffect, useContext } from "react";
|
import { useState } from "react";
|
||||||
import { useLocation, Link, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import { Stack, Typography } from "@mui/material";
|
import { Stack, Typography } from "@mui/material";
|
||||||
import Container from "@mui/material/Container";
|
import Container from "@mui/material/Container";
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
@ -10,7 +10,6 @@ import LoginIcon from "@mui/icons-material/Login";
|
|||||||
import useAuth from "../../hooks/useAuth";
|
import useAuth from "../../hooks/useAuth";
|
||||||
|
|
||||||
const Login: React.FC = () => {
|
const Login: React.FC = () => {
|
||||||
|
|
||||||
const { setAuth }: any = useAuth();
|
const { setAuth }: any = useAuth();
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@ -34,8 +33,8 @@ const Login: React.FC = () => {
|
|||||||
|
|
||||||
const handleLogin = () => {
|
const handleLogin = () => {
|
||||||
if (username === "" && password === "") {
|
if (username === "" && password === "") {
|
||||||
setAuth({username: username, isLoggedIn: true});
|
setAuth({ username: username, isLoggedIn: true });
|
||||||
navigate(from, {replace: true});
|
navigate(from, { replace: true });
|
||||||
}
|
}
|
||||||
setUsername("");
|
setUsername("");
|
||||||
setPassword("");
|
setPassword("");
|
||||||
@ -44,25 +43,52 @@ const Login: React.FC = () => {
|
|||||||
return (
|
return (
|
||||||
<Container className="login">
|
<Container className="login">
|
||||||
<Stack className="grid-container" spacing={2}>
|
<Stack className="grid-container" spacing={2}>
|
||||||
<img className="login-logo" src={hsbcLogo} alt="HSBC Logo"/>
|
<img className="login-logo" src={hsbcLogo} alt="HSBC Logo" />
|
||||||
{/* <p ref={errRef} className={errMsg ? "errmsg" : "offscreen"} aria-live="assertive">{errMsg}</p> */}
|
{/* <p ref={errRef} className={errMsg ? "errmsg" : "offscreen"} aria-live="assertive">{errMsg}</p> */}
|
||||||
<TextField className="username-input" id="outlined-basic" label="Username" variant="outlined" placeholder="Username" onChange={(event) => {setUsername(event.target.value)}}/>
|
<TextField
|
||||||
<TextField className="password-input" id="outlined-basic" label="Password" variant="outlined" placeholder="Password" type="password" onChange={(event) => {setPassword(event.target.value)}}/>
|
className="username-input"
|
||||||
|
id="outlined-basic"
|
||||||
|
label="Username"
|
||||||
|
variant="outlined"
|
||||||
|
placeholder="Username"
|
||||||
|
onChange={(event) => {
|
||||||
|
setUsername(event.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
className="password-input"
|
||||||
|
id="outlined-basic"
|
||||||
|
label="Password"
|
||||||
|
variant="outlined"
|
||||||
|
placeholder="Password"
|
||||||
|
type="password"
|
||||||
|
onChange={(event) => {
|
||||||
|
setPassword(event.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<Stack direction="row" justifyContent="space-between" spacing={2}>
|
<Stack direction="row" justifyContent="space-between" spacing={2}>
|
||||||
<a className="register-btn" href="#">
|
<a className="register-btn" href="#">
|
||||||
<Typography sx={{ ml: 1, mb: 1 }}>Forgot your password?</Typography>
|
<Typography sx={{ ml: 1, mb: 1 }}>Forgot your password?</Typography>
|
||||||
</a>
|
</a>
|
||||||
<Button endIcon={<LoginIcon />} className="login-btn" variant="contained" type="submit" onClick={handleLogin}>Login</Button>
|
<Button
|
||||||
|
endIcon={<LoginIcon />}
|
||||||
|
className="login-btn"
|
||||||
|
variant="contained"
|
||||||
|
type="submit"
|
||||||
|
onClick={handleLogin}
|
||||||
|
>
|
||||||
|
Login
|
||||||
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack direction="row" justifyContent="space-between" spacing={2}>
|
<Stack direction="row" justifyContent="space-between" spacing={2}>
|
||||||
<Typography sx={{ ml: 1 }}>Login with</Typography>
|
<Typography sx={{ ml: 1 }}>Login with</Typography>
|
||||||
<a className="zoom-logo" href="#">
|
<a className="zoom-logo" href="#">
|
||||||
<img src={zoomLogo} alt="Zoom Logo"/>
|
<img src={zoomLogo} alt="Zoom Logo" />
|
||||||
</a>
|
</a>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Login;
|
export default Login;
|
||||||
|
|||||||
@ -3,13 +3,13 @@ import { createContext, useState } from "react";
|
|||||||
const AuthContext = createContext({});
|
const AuthContext = createContext({});
|
||||||
|
|
||||||
export const AuthProvider = ({ children }: {children: any}) => {
|
export const AuthProvider = ({ children }: {children: any}) => {
|
||||||
const [auth, setAuth] = useState({});
|
const [auth, setAuth] = useState({});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthContext.Provider value={{ auth, setAuth }}>
|
<AuthContext.Provider value={{ auth, setAuth }}>
|
||||||
{children}
|
{children}
|
||||||
</AuthContext.Provider>
|
</AuthContext.Provider>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default AuthContext;
|
export default AuthContext;
|
||||||
@ -2,7 +2,7 @@ import { useContext } from "react";
|
|||||||
import AuthContext from "../context/AuthProvider";
|
import AuthContext from "../context/AuthProvider";
|
||||||
|
|
||||||
const useAuth = () => {
|
const useAuth = () => {
|
||||||
return useContext(AuthContext);
|
return useContext(AuthContext);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default useAuth;
|
export default useAuth;
|
||||||
Reference in New Issue
Block a user