fix lint warnings

This commit is contained in:
Taehee Choi 2022-03-13 11:58:14 -07:00
parent 3320d0d932
commit 52f76f8209
5 changed files with 65 additions and 41 deletions

View File

@ -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";

View File

@ -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,9 +37,7 @@ 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 /> <Navbar />
<Box id="drawer-container" sx={{ display: "flex", height: "100%" }}> <Box id="drawer-container" sx={{ display: "flex", height: "100%" }}>
@ -52,7 +49,8 @@ const ProtectedRoute = () => {
</Box> </Box>
</Box> </Box>
</> </>
: <Navigate to="/login" state={{ from: location }} replace /> ) : (
<Navigate to="/login" state={{ from: location }} replace />
); );
}; };

View File

@ -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,20 +43,47 @@ 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>

View File

@ -9,7 +9,7 @@ export const AuthProvider = ({ children }: {children: any}) => {
<AuthContext.Provider value={{ auth, setAuth }}> <AuthContext.Provider value={{ auth, setAuth }}>
{children} {children}
</AuthContext.Provider> </AuthContext.Provider>
) );
} };
export default AuthContext; export default AuthContext;

View File

@ -3,6 +3,6 @@ import AuthContext from "../context/AuthProvider";
const useAuth = () => { const useAuth = () => {
return useContext(AuthContext); return useContext(AuthContext);
} };
export default useAuth; export default useAuth;