diff --git a/client/src/App.tsx b/client/src/App.tsx index 34a4aaa..f180478 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -2,6 +2,7 @@ import { Route, Routes } from "react-router-dom"; import HomePage from "./pages/HomePage"; import SignUpPage from "./pages/SignUpPage"; import SignInPage from "./pages/SignInPage"; +import SpringboardPage from "./pages/SpringboardPage"; function App() { return ( @@ -9,6 +10,7 @@ function App() { } path="/" /> } path="/signup" /> } path="/signin" /> + } path="/springboard/:accessToken" /> ); } diff --git a/client/src/components/SignInModule.tsx b/client/src/components/SignInModule.tsx index 0068dd8..a190c40 100644 --- a/client/src/components/SignInModule.tsx +++ b/client/src/components/SignInModule.tsx @@ -39,7 +39,7 @@ export default function SignInModule() { config.serverAddress + "/users/login", values ); - console.log(response.data.accessToken); + navigate("/springboard/" + response.data.accessToken); } catch (error) { console.error("Error logging in:", error); } diff --git a/client/src/components/SpringboardButton.tsx b/client/src/components/SpringboardButton.tsx new file mode 100644 index 0000000..5ae8bd8 --- /dev/null +++ b/client/src/components/SpringboardButton.tsx @@ -0,0 +1,18 @@ +import { Button } from "@nextui-org/react"; + +export default function SpringboardButton({ + title, + subtitle, +}: { + title: string; + subtitle: string; +}) { + return ( + + ); +} diff --git a/client/src/icons.tsx b/client/src/icons.tsx index 94b8540..da1746a 100644 --- a/client/src/icons.tsx +++ b/client/src/icons.tsx @@ -16,3 +16,22 @@ export const ChevronLeftIcon = () => { ); }; + +export const PencilSquareIcon = () => { + return ( + + + + ); +}; diff --git a/client/src/pages/SpringboardPage.tsx b/client/src/pages/SpringboardPage.tsx new file mode 100644 index 0000000..8417737 --- /dev/null +++ b/client/src/pages/SpringboardPage.tsx @@ -0,0 +1,106 @@ +import { useParams } from "react-router-dom"; +import DefaultLayout from "../layouts/default"; +import { useEffect, useState } from "react"; +import axios from "axios"; +import config from "../config"; +import { Button, Link } from "@nextui-org/react"; +import { PencilSquareIcon } from "../icons"; +import SpringboardButton from "../components/SpringboardButton"; +import { getTimeOfDay } from "../utilities"; + +export default function SpringboardPage() { + let { accessToken } = useParams(); // TODO: Replace AT from props with AT from localstorage + let [userInformation, setUserInformation] = useState(); + let timeOfDay = getTimeOfDay(); + + let greeting = ""; + if (timeOfDay === 0) { + greeting = "Good morning"; + } else if (timeOfDay === 1) { + greeting = "Good afternoon"; + } else if (timeOfDay === 2) { + greeting = "Good evening"; + } + + const retrieveUserInformation = () => { + axios + .get(`${config.serverAddress}/users/auth`, { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }) + .then((response) => { + axios + .get(`${config.serverAddress}/users/individual/${response.data.id}`, { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }) + .then((response) => { + setUserInformation(response.data); + }) + .catch((error) => { + console.error("Error retrieving user information:", error); + }); + }) + .catch((error) => { + console.error("Error retrieving user ID:", error); + }); + }; + + useEffect(() => { + retrieveUserInformation(); + }, []); + + return ( + + {userInformation && ( +
+
+
+

+ {greeting}, {userInformation.firstName}. +

+

+ Resident of Bishan-Toa Payoh Town Council +

+
+ } + > + Manage your account + +
+
+
+
+ + + + +
+
+ + )} +
+ ); +} diff --git a/client/src/utilities.ts b/client/src/utilities.ts new file mode 100644 index 0000000..59d8bcc --- /dev/null +++ b/client/src/utilities.ts @@ -0,0 +1,11 @@ +export function getTimeOfDay(): number { + const currentHour = new Date().getHours(); + + if (currentHour >= 6 && currentHour < 12) { + return 0; // Morning + } else if (currentHour >= 12 && currentHour < 18) { + return 1; // Afternoon + } else { + return 2; // Evening + } +} diff --git a/server/routes/users.js b/server/routes/users.js index dd61a80..d53a6a5 100644 --- a/server/routes/users.js +++ b/server/routes/users.js @@ -67,7 +67,7 @@ router.get("/all", async (req, res) => { res.json(list); }); -router.get("/individual/:id", async (req, res) => { +router.get("/individual/:id", validateToken, async (req, res) => { let id = req.params.id; let user = await User.findByPk(id); if (!user) { @@ -77,7 +77,7 @@ router.get("/individual/:id", async (req, res) => { res.json(user); }); -router.put("/individual/:id", async (req, res) => { +router.put("/individual/:id", validateToken, async (req, res) => { let id = req.params.id; let user = await User.findByPk(id); @@ -109,7 +109,7 @@ router.put("/individual/:id", async (req, res) => { } }); -router.delete("/individual/:id", async (req, res) => { +router.delete("/individual/:id", validateToken, async (req, res) => { let id = req.params.id; let user = await User.findByPk(id);