From 011d57f5c186d989142052f1813a568bd854d03e Mon Sep 17 00:00:00 2001 From: Justin Lau Date: Thu, 28 Nov 2024 16:16:37 -0500 Subject: [PATCH] Add AccountPage and navigation from ProfilePage --- frontend/src/App.tsx | 7 ++ frontend/src/components/auth/PrivateRoute.tsx | 64 +++++++++---------- frontend/src/components/pages/AccountPage.tsx | 28 ++++++++ frontend/src/components/pages/ProfilePage.tsx | 44 ++++++++----- frontend/src/constants/Routes.ts | 2 + 5 files changed, 97 insertions(+), 48 deletions(-) create mode 100644 frontend/src/components/pages/AccountPage.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 522f9bf..0edff81 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -31,6 +31,7 @@ import NotificationsPage from "./components/pages/NotificationsPage"; import ProfilePage from "./components/pages/ProfilePage"; import UserManagementPage from "./components/pages/UserManagementPage"; import AdminPage from "./components/pages/AdminPage"; +import AccountPage from "./components/pages/AccountPage"; import { AuthenticatedUser } from "./types/AuthTypes"; @@ -139,6 +140,12 @@ const App = (): React.ReactElement => { component={ProfilePage} allowedRoles={AuthConstants.ALL_ROLES} /> + ; -}; - -const PrivateRoute: React.FC = ({ - component, - exact, - path, - allowedRoles, -}: PrivateRouteProps) => { - const { authenticatedUser } = useContext(AuthContext); - - if (!authenticatedUser) { - return ; - } - if (!allowedRoles.has(authenticatedUser.role)) { - return ; - } - - return ; -}; - -export default PrivateRoute; +import React, { useContext } from "react"; +import { Route, Redirect } from "react-router-dom"; + +import AuthContext from "../../contexts/AuthContext"; +import { LOGIN_PAGE } from "../../constants/Routes"; + +type PrivateRouteProps = { + component: React.FC; + path: string; + exact: boolean; + allowedRoles: Set; +}; + +const PrivateRoute: React.FC = ({ + component, + exact, + path, + allowedRoles, +}: PrivateRouteProps) => { + const { authenticatedUser } = useContext(AuthContext); + + if (!authenticatedUser) { + return ; + } + if (!allowedRoles.has(authenticatedUser.role)) { + return ; + } + + return ; +}; + +export default PrivateRoute; diff --git a/frontend/src/components/pages/AccountPage.tsx b/frontend/src/components/pages/AccountPage.tsx new file mode 100644 index 0000000..c7a6b05 --- /dev/null +++ b/frontend/src/components/pages/AccountPage.tsx @@ -0,0 +1,28 @@ +import React from "react"; +import { Text } from "@chakra-ui/react"; +import { useHistory } from "react-router-dom"; +import NavBar from "../common/navbar/NavBar"; +import { PROFILE_PAGE } from "../../constants/Routes"; + +const AccountPage = (): React.ReactElement => { + const history = useHistory(); + const navigateTo = () => history.push(PROFILE_PAGE); + return ( +
+ + + Account Page ⚙️ + + +
+ ); +}; + +export default AccountPage; diff --git a/frontend/src/components/pages/ProfilePage.tsx b/frontend/src/components/pages/ProfilePage.tsx index a0f24d3..bb6b9e6 100644 --- a/frontend/src/components/pages/ProfilePage.tsx +++ b/frontend/src/components/pages/ProfilePage.tsx @@ -1,16 +1,28 @@ -import React from "react"; -import { Text } from "@chakra-ui/react"; -import NavBar from "../common/navbar/NavBar"; - -const ProfilePage = (): React.ReactElement => { - return ( -
- - - Profile Page 🫨 - -
- ); -}; - -export default ProfilePage; +import React from "react"; +import { Text } from "@chakra-ui/react"; +import { useHistory } from "react-router-dom"; +import NavBar from "../common/navbar/NavBar"; +import { ACCOUNT_PAGE } from "../../constants/Routes"; + +const ProfilePage = (): React.ReactElement => { + const history = useHistory(); + const navigateTo = () => history.push(ACCOUNT_PAGE); + return ( +
+ + + Profile Page 🫨 + + +
+ ); +}; + +export default ProfilePage; diff --git a/frontend/src/constants/Routes.ts b/frontend/src/constants/Routes.ts index ac46e9e..8a8a7b4 100644 --- a/frontend/src/constants/Routes.ts +++ b/frontend/src/constants/Routes.ts @@ -26,6 +26,8 @@ export const NOTIFICATIONS_PAGE = "/notifications"; export const PROFILE_PAGE = "/profile"; +export const ACCOUNT_PAGE = "/account/:id"; + export const DEV_UTILITY_PAGE = "/dev-utility"; // TODO: This is only here for development purposes export const USER_MANAGEMENT_PAGE = "/admin/users";