From 33ae5f533089217e7aabbbaacb4ed374b8268657 Mon Sep 17 00:00:00 2001 From: sosokker Date: Mon, 13 Nov 2023 00:29:24 +0700 Subject: [PATCH] Link new nav to other page --- frontend/src/App.jsx | 23 +- frontend/src/components/Nav/Navbar.jsx | 239 ++++-------------- .../components/authentication/LoginPage.jsx | 134 +++++----- frontend/src/main.jsx | 3 + 4 files changed, 131 insertions(+), 268 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index cbd3257..d2bcd8d 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,10 +1,10 @@ import "./App.css"; -import { BrowserRouter, Route, Routes } from "react-router-dom"; +import { Route, Routes, useLocation } from "react-router-dom"; import TestAuth from "./components/testAuth"; import LoginPage from "./components/authentication/LoginPage"; import SignUpPage from "./components/authentication/SignUpPage"; -import NavBar from "./components/nav/Navbar"; +import NavBar from "./components/Nav/Navbar"; import Home from "./components/Home"; import ProfileUpdate from "./components/ProfileUpdatePage"; import Calendar from "./components/calendar/calendar"; @@ -13,16 +13,16 @@ import IconSideNav from "./components/IconSideNav"; import Eisenhower from "./components/eisenhowerMatrix/Eisenhower"; const App = () => { - const currentPath = window.location.pathname; + const location = useLocation(); const prevention = ["/login", "/signup"]; + const isLoginPageOrSignUpPage = prevention.some(_ => location.pathname.includes(_)); return ( - -
- {!prevention.some(_ => currentPath.includes(_)) && } -
+
+ {!isLoginPageOrSignUpPage && } +
-
+
} /> } /> @@ -30,15 +30,12 @@ const App = () => { } /> } /> } /> + } /> + } />
- - } /> - } /> - - ); }; diff --git a/frontend/src/components/Nav/Navbar.jsx b/frontend/src/components/Nav/Navbar.jsx index 5fee6cf..3f42689 100644 --- a/frontend/src/components/Nav/Navbar.jsx +++ b/frontend/src/components/Nav/Navbar.jsx @@ -1,204 +1,69 @@ -import * as React from 'react'; -import { Link, useNavigate } from 'react-router-dom'; -import IsAuthenticated from '../authentication/IsAuthenticated'; -import axiosapi from '../../api/AuthenticationApi'; -import AppBar from '@mui/material/AppBar'; -import Box from '@mui/material/Box'; -import Toolbar from '@mui/material/Toolbar'; -import IconButton from '@mui/material/IconButton'; -import Typography from '@mui/material/Typography'; -import Menu from '@mui/material/Menu'; -import MenuIcon from '@mui/icons-material/Menu'; -import Container from '@mui/material/Container'; -import Avatar from '@mui/material/Avatar'; -import Button from '@mui/material/Button'; -import Tooltip from '@mui/material/Tooltip'; -import MenuItem from '@mui/material/MenuItem'; -import AdbIcon from '@mui/icons-material/Adb'; -import Stack from '@mui/material/Stack'; +import * as React from "react"; +import { useNavigate } from "react-router-dom"; +import IsAuthenticated from "../authentication/IsAuthenticated"; +import axiosapi from "../../api/AuthenticationApi"; -const pages = { - TestAuth: '/testAuth', - -}; const settings = { - Profile: '/profile', - Account: '/account', - Dashboard: '/dashboard', - }; + Profile: '/profile', + Account: '/account', +}; function NavBar() { const Navigate = useNavigate(); - const [anchorElNav, setAnchorElNav] = React.useState(null); - const [anchorElUser, setAnchorElUser] = React.useState(null); - - const handleOpenNavMenu = (event) => { - setAnchorElNav(event.currentTarget); - }; - const handleOpenUserMenu = (event) => { - setAnchorElUser(event.currentTarget); - }; - - const handleCloseNavMenu = () => { - setAnchorElNav(null); - }; - - const handleCloseUserMenu = () => { - setAnchorElUser(null); - }; const isAuthenticated = IsAuthenticated(); const logout = () => { - // Log out the user, clear tokens, and navigate to the "/testAuth" route axiosapi.apiUserLogout(); - Navigate('/'); -} + Navigate("/"); + }; return ( - - - - - - LOGO - - - - - - - - {Object.entries(pages).map(([page, path]) => ( - - - {page} - - - ))} - - - - - LOGO - - - {Object.entries(pages).map(([page, path]) => ( - - ))} - - +
+ +
+
+ +
{isAuthenticated ? ( - - - - - - - - {Object.entries(settings).map(([setting, path]) => ( - - - {setting} - - - ))} - - - Logout - - - - +
+ + +
) : ( - - - - +
+ + +
)} - - - +
+
); } -export default NavBar; \ No newline at end of file +export default NavBar; diff --git a/frontend/src/components/authentication/LoginPage.jsx b/frontend/src/components/authentication/LoginPage.jsx index b28e274..6bba8f8 100644 --- a/frontend/src/components/authentication/LoginPage.jsx +++ b/frontend/src/components/authentication/LoginPage.jsx @@ -1,9 +1,9 @@ import React, { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; -import { useGoogleLogin } from "@react-oauth/google" +import { useGoogleLogin } from "@react-oauth/google"; -import refreshAccessToken from './refreshAcesstoken'; -import axiosapi from '../../api/AuthenticationApi'; +import refreshAccessToken from "./refreshAcesstoken"; +import axiosapi from "../../api/AuthenticationApi"; function LoginPage() { const Navigate = useNavigate(); @@ -68,75 +68,73 @@ function LoginPage() { }); return ( - -
- {/* Left Section (Login Box) */} -
-
-

Log in to your account

- {/* Email Input */} -
- - -
- {/* Password Input */} -
- - -
- {/* Login Button */} - -
OR
- {/* Login with Google Button */} - - {/* Forgot Password Link */} - +
+ {/* Left Section (Login Box) */} +
+
+

Log in to your account

+ {/* Email Input */} +
+ +
-
- - {/* Right Section (Blurred Image Background) */} -
-
- -
- Text Overlay + {/* Password Input */} +
+ + +
+ {/* Login Button */} + +
OR
+ {/* Login with Google Button */} + + {/* Forgot Password Link */} +
- + + {/* Right Section (Blurred Image Background) */} +
+
+ +
+ Text Overlay +
+
+
); } diff --git a/frontend/src/main.jsx b/frontend/src/main.jsx index 7aa4bf4..f5430b9 100644 --- a/frontend/src/main.jsx +++ b/frontend/src/main.jsx @@ -2,11 +2,14 @@ import React from "react"; import ReactDOM from "react-dom/client"; import App from "./App"; import { GoogleOAuthProvider} from '@react-oauth/google'; +import { BrowserRouter } from 'react-router-dom'; const GOOGLE_CLIENT_ID = import.meta.env.VITE_GOOGLE_CLIENT_ID ReactDOM.createRoot(document.getElementById("root")).render( + + ); \ No newline at end of file