diff --git a/client/src/App.tsx b/client/src/App.tsx index 9558f5d..53d2192 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -8,7 +8,7 @@ import ManageUserAccountPage from "./pages/ManageUserAccountPage"; import CommunityPage from "./pages/CommunityPage"; import CreatePostPage from "./pages/CreatePostPage"; import EditPostPage from "./pages/EditPostPage"; -import PostPage from './pages/PostPage'; +import PostPage from "./pages/PostPage"; import SchedulePage from "./pages/SchedulePage"; import EventsPage from "./pages/EventsPage"; import CreateEventsPage from "./pages/CreateEventsPage"; @@ -17,28 +17,57 @@ import AdministratorSpringboard from "./pages/AdministratorSpringboard"; import HBContestPage from "./pages/HBContestPage"; import HBFormPage from "./pages/HBFormPage"; import EditEventsPage from "./pages/EditEventsPage"; +import DefaultLayout from "./layouts/default"; +import AdministratorLayout from "./layouts/administrator"; function App() { return ( - } path="/" /> - } path="/signup" /> - } path="/signin" /> - } path="/springboard" /> - } path="/manage-account" /> - } path="/admin" /> + {/* User Routes */} + }> + {/* General Routes */} + } /> + } path="signup" /> + } path="signin" /> + } path="springboard" /> + } path="manage-account" /> - } path="/community" /> - } path="/createPost" /> - } path="/editPost/:id" /> - } path="/post/:id" /> - } path="/schedule" /> - } path="/events" /> - } path="/contest" /> - } path="/hbcform" /> - } path="/createEvent" /> - } path="/manageEvent" /> - } path="/editEvent/:id" /> + {/* Events Route */} + + } /> + + + {/* Karang Guni Schedules Route */} + + } /> + + + {/* Home Bill Contest Route */} + + } /> + } path="new-submission" /> + + + {/* Community Posts Route */} + + } /> + } path="create" /> + } path="post/:id" /> + } path="edit/:id" /> + + + + {/* Admin Routes */} + }> + } /> + + {/* Events */} + + } /> + } path="create" /> + } path="edit/:id" /> + + ); } diff --git a/client/src/components/AdministratorNavigationPanel.tsx b/client/src/components/AdministratorNavigationPanel.tsx index 991b9e2..ec42e12 100644 --- a/client/src/components/AdministratorNavigationPanel.tsx +++ b/client/src/components/AdministratorNavigationPanel.tsx @@ -26,19 +26,30 @@ import { useEffect, useState } from "react"; import config from "../config"; import AdministratorNavigationPanelNavigationButton from "./AdministratorNavigationPanelNavigationButton"; import EcoconnectLogo from "./EcoconnectLogo"; +import { useNavigate } from "react-router-dom"; export default function AdministratorNavigationPanel() { const [userInformation, setUserInformation] = useState(); const [userProfileImageURL, setUserProfileImageURL] = useState(""); const [panelVisible, setPanelVisible] = useState(true); const [isScrolled, setIsScrolled] = useState(false); + + const navigate = useNavigate(); + useEffect(() => { - retrieveUserInformation().then((value) => { - setUserInformation(value); - setUserProfileImageURL( - `${config.serverAddress}/users/profile-image/${value.id}` - ); - }); + retrieveUserInformation() + .then((value) => { + if (!value || value.accountType != 2) { + navigate("/"); + } + setUserInformation(value); + setUserProfileImageURL( + `${config.serverAddress}/users/profile-image/${value.id}` + ); + }) + .catch(() => { + navigate("/signin"); + }); const handleScroll = () => { setIsScrolled(window.scrollY > 10); }; diff --git a/client/src/components/NavigationBar.tsx b/client/src/components/NavigationBar.tsx index c23bb75..8d030c2 100644 --- a/client/src/components/NavigationBar.tsx +++ b/client/src/components/NavigationBar.tsx @@ -21,23 +21,23 @@ import { useNavigate } from "react-router-dom"; import EcoconnectFullLogo from "./EcoconnectFullLogo"; export default function NavigationBar() { - let [userProfileImageURL, setUserProfileImageURL] = useState(""); - let [userInformation, setUserInformation] = useState(); - let [doneLoading, setDoneLoading] = useState(false); + const [userProfileImageURL, setUserProfileImageURL] = useState(""); + const [userInformation, setUserInformation] = useState(); + const [doneLoading, setDoneLoading] = useState(false); const [isScrolled, setIsScrolled] = useState(false); - let navigate = useNavigate(); + const navigate = useNavigate(); useEffect(() => { retrieveUserInformation() .then((value) => { + if (value.accountType == 2) navigate("/admin"); setUserProfileImageURL( `${config.serverAddress}/users/profile-image/${value.id}` ); setUserInformation(value); }) - .catch((err) => { - console.log(err); - return; + .catch(() => { + navigate("/signin"); }) .finally(() => { setDoneLoading(true); @@ -86,7 +86,7 @@ export default function NavigationBar() { variant="light" size="sm" onPress={() => { - navigate("/schedule"); + navigate("/karang-guni-schedules"); }} >

Schedules

@@ -95,7 +95,7 @@ export default function NavigationBar() { variant="light" size="sm" onPress={() => { - navigate("/contest"); + navigate("/home-bill-contest"); }} >

HB Contest

@@ -104,7 +104,7 @@ export default function NavigationBar() { variant="light" size="sm" onPress={() => { - navigate("/community"); + navigate("/community-posts"); }} >

Community Forums

diff --git a/client/src/components/SignInModule.tsx b/client/src/components/SignInModule.tsx index 9437c40..b95536c 100644 --- a/client/src/components/SignInModule.tsx +++ b/client/src/components/SignInModule.tsx @@ -8,6 +8,7 @@ import { useNavigate } from "react-router-dom"; import { ChevronLeftIcon } from "../icons"; import { popErrorToast } from "../utilities"; import { retrieveUserInformation } from "../security/users"; +import instance from "../security/http"; const validationSchema = Yup.object({ email: Yup.string() @@ -36,7 +37,7 @@ export default function SignInModule() { }; const handleSubmit = (values: any): void => { - axios + instance .post(config.serverAddress + "/users/login", values) .then((response) => { localStorage.setItem("accessToken", response.data.accessToken); @@ -44,7 +45,7 @@ export default function SignInModule() { if (value.accountType == 2) { navigate("/admin"); } else { - navigate("/springboard/"); + navigate("/springboard"); } }); }) diff --git a/client/src/components/SignedInStatusVerifier.tsx b/client/src/components/SignedInStatusVerifier.tsx index 052b3b2..c6b8e77 100644 --- a/client/src/components/SignedInStatusVerifier.tsx +++ b/client/src/components/SignedInStatusVerifier.tsx @@ -8,8 +8,8 @@ export default function SignedInStatusVerifier({ }: { children: React.JSX.Element; }) { - let navigate = useNavigate(); - let [isLoading, setIsLoading] = useState(true); + const navigate = useNavigate(); + const [isLoading, setIsLoading] = useState(true); useEffect(() => { retrieveUserInformation() .then((value) => { diff --git a/client/src/components/UpdateAccountModule.tsx b/client/src/components/UpdateAccountModule.tsx index e16f878..690fcbf 100644 --- a/client/src/components/UpdateAccountModule.tsx +++ b/client/src/components/UpdateAccountModule.tsx @@ -23,7 +23,7 @@ import instance from "../security/http"; export default function UpdateAccountModule() { const navigate = useNavigate(); - let [userInformation, setUserInformation] = useState(); + const [userInformation, setUserInformation] = useState(); const { isOpen, onOpen, onOpenChange } = useDisclosure(); @@ -33,7 +33,7 @@ export default function UpdateAccountModule() { setUserInformation(response); }) .catch(() => { - navigate("/springboard/"); + navigate("/signin"); }); }, []); @@ -72,7 +72,7 @@ export default function UpdateAccountModule() { values ); console.log("User updated successfully:", response.data); - navigate("/springboard/"); + navigate("/springboard"); } catch (error) { popErrorToast(error); } @@ -127,7 +127,7 @@ export default function UpdateAccountModule() { +
+
+
+

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

+
+

A staff member of

+
- +

{userInformation.email}

+
+ } + onPress={() => { + navigate("/manage-account"); + }} + > + Manage your account +
-
- -
-

Statistics Overview

-
-
-
-

User Count

-

(past 30 days)

-
-

- Total: 2139 users -

-
-
- {/* TODO: Graph */} -

GRAPH HERE

+ +
+
+ +
+

Statistics Overview

+
+
+
+

User Count

+

(past 30 days)

+

+ Total: 2139 users +

-
-
-

Population Distribution

-
-
- {/* TODO: Graph */} -

GRAPH HERE

-
+
+ {/* TODO: Graph */} +

GRAPH HERE

- -
- +
+
+

Population Distribution

+
+
+ {/* TODO: Graph */} +

GRAPH HERE

+
+
+
+
+
)}
); diff --git a/client/src/pages/CommunityPage.tsx b/client/src/pages/CommunityPage.tsx index 0f17262..7babcf0 100644 --- a/client/src/pages/CommunityPage.tsx +++ b/client/src/pages/CommunityPage.tsx @@ -1,5 +1,4 @@ // import { title } from "@/components/primitives"; -import DefaultLayout from "../layouts/default"; import { SetStateAction, useEffect, useState } from "react"; import { Button, @@ -117,20 +116,12 @@ export default function CommunityPage() { } }; - // useEffect(() => { - // retrieveUserInformation() - // .then((response) => { - // setUserInformation(response); - // }) - // return; - // }, []); - const handlePostClick = (id: number) => { - navigate(`/post/${id}`); + navigate(`post/${id}`); }; return ( - +
@@ -163,8 +154,10 @@ export default function CommunityPage() {
- e.stopPropagation()}> + e.stopPropagation()} + > @@ -174,7 +167,7 @@ export default function CommunityPage() { { - navigate(`/editPost/${post.id}`); + navigate(`edit/${post.id}`); }} > Edit @@ -196,12 +189,6 @@ export default function CommunityPage() {

Image

- {/* {userInformation && ( - - )} */}
@@ -210,19 +197,30 @@ export default function CommunityPage() { Tag 2
- - -
- ); })} @@ -234,7 +232,7 @@ export default function CommunityPage() { className=" bg-primary-500 dark:bg-primary-700 text-white" size="lg" onPress={() => { - navigate("/createPost"); + navigate("create"); }} >

Create a post!

@@ -280,6 +278,6 @@ export default function CommunityPage() { )} - +
); } diff --git a/client/src/pages/CreateEventsPage.tsx b/client/src/pages/CreateEventsPage.tsx index 088a798..c85acc8 100644 --- a/client/src/pages/CreateEventsPage.tsx +++ b/client/src/pages/CreateEventsPage.tsx @@ -1,4 +1,3 @@ -import DefaultLayout from "../layouts/default"; import { Button } from "@nextui-org/react"; import { Formik, Form } from "formik"; import * as Yup from "yup"; @@ -32,8 +31,12 @@ const validationSchema = Yup.object({ time: Yup.string().required("Time is required"), location: Yup.string().required("Location is required"), category: Yup.string().required("Category is required"), - slotsAvailable: Yup.number().integer().required("Slots Available is required"), - imageUrl: Yup.string().url("Invalid URL format").required("Image URL is required") + slotsAvailable: Yup.number() + .integer() + .required("Slots Available is required"), + imageUrl: Yup.string() + .url("Invalid URL format") + .required("Image URL is required"), }); const CreateEventsPage = () => { @@ -47,7 +50,7 @@ const CreateEventsPage = () => { location: "", category: "", slotsAvailable: "", - imageUrl: "" + imageUrl: "", }; const handleSubmit = async ( @@ -56,12 +59,15 @@ const CreateEventsPage = () => { ) => { console.log("Submitting form with values:", values); // Debug log try { - const response = await axios.post(config.serverAddress + "/events", values); + const response = await axios.post( + config.serverAddress + "/events", + values + ); console.log("Server response:", response); // Debug log if (response.status === 200 || response.status === 201) { console.log("Event created successfully:", response.data); resetForm(); // Clear form after successful submit - navigate("/manageEvent"); + navigate(-1); } else { console.error("Error creating event:", response.statusText); } @@ -77,7 +83,7 @@ const CreateEventsPage = () => { }; return ( - +
- +
); }; diff --git a/client/src/pages/CreatePostPage.tsx b/client/src/pages/CreatePostPage.tsx index a35e501..b23593c 100644 --- a/client/src/pages/CreatePostPage.tsx +++ b/client/src/pages/CreatePostPage.tsx @@ -1,4 +1,3 @@ -import DefaultLayout from "../layouts/default"; import { Button } from "@nextui-org/react"; import { Formik, Form } from "formik"; import * as Yup from "yup"; @@ -48,7 +47,7 @@ function CreatePostPage() { if (response.status === 200) { console.log("Post created successfully:", response.data); resetForm(); // Clear form after successful submit - navigate("/community"); + navigate(-1); } else { console.error("Error creating post:", response.statusText); } @@ -62,9 +61,9 @@ function CreatePostPage() { setSubmitting(false); } }; - + return ( - +
- +
); } diff --git a/client/src/pages/EditEventsPage.tsx b/client/src/pages/EditEventsPage.tsx index b7cd688..8748847 100644 --- a/client/src/pages/EditEventsPage.tsx +++ b/client/src/pages/EditEventsPage.tsx @@ -1,5 +1,4 @@ -import React, { useState, useEffect } from 'react'; -import DefaultLayout from "../layouts/default"; +import React, { useState, useEffect } from "react"; import { Button } from "@nextui-org/react"; import { Formik, Form } from "formik"; import * as Yup from "yup"; @@ -33,8 +32,12 @@ const validationSchema = Yup.object({ time: Yup.string().required("Time is required"), location: Yup.string().required("Location is required"), category: Yup.string().required("Category is required"), - slotsAvailable: Yup.number().integer().required("Slots Available is required"), - imageUrl: Yup.string().url("Invalid URL format").required("Image URL is required") + slotsAvailable: Yup.number() + .integer() + .required("Slots Available is required"), + imageUrl: Yup.string() + .url("Invalid URL format") + .required("Image URL is required"), }); const EditEventsPage = () => { @@ -48,13 +51,15 @@ const EditEventsPage = () => { location: "", category: "", slotsAvailable: "", - imageUrl: "" + imageUrl: "", }); useEffect(() => { const fetchEvent = async () => { try { - const response = await axios.get(`${config.serverAddress}/events/${id}`); + const response = await axios.get( + `${config.serverAddress}/events/${id}` + ); console.log("Fetched event data:", response.data); // Debug log setInitialValues(response.data); } catch (error) { @@ -71,12 +76,15 @@ const EditEventsPage = () => { ) => { console.log("Submitting form with values:", values); // Debug log try { - const response = await axios.put(`${config.serverAddress}/events/${id}`, values); + const response = await axios.put( + `${config.serverAddress}/events/${id}`, + values + ); console.log("Server response:", response); // Debug log if (response.status === 200 || response.status === 201) { console.log("Event updated successfully:", response.data); resetForm(); // Clear form after successful submit - navigate("/manageEvent"); + navigate(-1); } else { console.error("Error updating event:", response.statusText); } @@ -92,7 +100,7 @@ const EditEventsPage = () => { }; return ( - +
- +
); }; diff --git a/client/src/pages/EditPostPage.tsx b/client/src/pages/EditPostPage.tsx index d837ab2..f891d0b 100644 --- a/client/src/pages/EditPostPage.tsx +++ b/client/src/pages/EditPostPage.tsx @@ -1,4 +1,3 @@ -import DefaultLayout from "../layouts/default"; import { Button } from "@nextui-org/react"; import { Formik, Form } from "formik"; import * as Yup from "yup"; @@ -60,7 +59,7 @@ function editPost() { if (response.status === 200) { console.log("Post updated successfully:", response.data); resetForm(); - navigate("/community"); + navigate(-1); } else { console.error("Error updating post:", response.statusText); } @@ -76,7 +75,7 @@ function editPost() { }; return ( - +
- +
); } diff --git a/client/src/pages/EventsPage.tsx b/client/src/pages/EventsPage.tsx index 32503fc..1225bf9 100644 --- a/client/src/pages/EventsPage.tsx +++ b/client/src/pages/EventsPage.tsx @@ -1,9 +1,15 @@ -import React, { useState, useEffect } from 'react'; -import DefaultLayout from "../layouts/default"; +import React, { useState, useEffect } from "react"; import { useNavigate } from "react-router-dom"; import instance from "../security/http"; import config from "../config"; -import { Card, CardHeader, CardBody, CardFooter, Image, Button } from "@nextui-org/react"; +import { + Card, + CardHeader, + CardBody, + CardFooter, + Image, + Button, +} from "@nextui-org/react"; const EventsPage = () => { const [events, setEvents] = useState([]); @@ -24,7 +30,7 @@ const EventsPage = () => { }, []); return ( - +

Events

@@ -34,8 +40,8 @@ const EventsPage = () => {

No events available.

) : ( events.map((event) => ( - @@ -53,7 +59,7 @@ const EventsPage = () => {

{event.description}

-
- +
); }; diff --git a/client/src/pages/HBContestPage.tsx b/client/src/pages/HBContestPage.tsx index e0a445b..b62ce9b 100644 --- a/client/src/pages/HBContestPage.tsx +++ b/client/src/pages/HBContestPage.tsx @@ -1,54 +1,64 @@ -import { Card, CardHeader, CardBody, CardFooter, Divider, Button } from "@nextui-org/react"; -import DefaultLayout from '../layouts/default'; -import { useNavigate } from 'react-router-dom'; - +import { + Card, + CardHeader, + CardBody, + CardFooter, + Divider, + Button, +} from "@nextui-org/react"; +import { useNavigate } from "react-router-dom"; export default function HBContestPage() { + const navigate = useNavigate(); - let navigate = useNavigate(); - - return ( - -
- - -
-

Home Bill Contest

-
-
- - -

This contest is to encourage residents to reduce the use of electricity and water usage. - This contest would be won by the person with the lowest overall bill average. - Join us in this important effort to create a more sustainable future for everyone. - Participants would be required to input and upload their bills into the form to ensure integrity and honesty.

-
- - -
-
-

Winners

-

There will 3 winners for each month. Each winner will receive random food vouchers.

-

1st: 3 vouchers

-

2nd: 2 vouchers

-

3rd: 1 voucher

-
-
- -
-
-
-
-
-
- ) + return ( +
+
+ + +
+

Home Bill Contest

+
+
+ + +

+ This contest is to encourage residents to reduce the use of + electricity and water usage. This contest would be won by the + person with the lowest overall bill average. Join us in this + important effort to create a more sustainable future for everyone. + Participants would be required to input and upload their bills + into the form to ensure integrity and honesty.{" "} +

+
+ + +
+
+

Winners

+

+ There will 3 winners for each month. Each winner will receive + random food vouchers. +

+

1st: 3 vouchers

+

2nd: 2 vouchers

+

3rd: 1 voucher

+
+
+ +
+
+
+
+
+
+ ); } - diff --git a/client/src/pages/HBFormPage.tsx b/client/src/pages/HBFormPage.tsx index e4d9bbb..5e36184 100644 --- a/client/src/pages/HBFormPage.tsx +++ b/client/src/pages/HBFormPage.tsx @@ -1,183 +1,182 @@ -import DefaultLayout from '../layouts/default'; -import { Button } from '@nextui-org/react'; -import { ArrowUTurnLeftIcon } from '../icons'; -import { useNavigate } from 'react-router-dom'; -import { Formik, Form } from 'formik'; -import * as Yup from 'yup'; -import config from '../config'; -import NextUIFormikInput from '../components/NextUIFormikInput'; +import { Button } from "@nextui-org/react"; +import { ArrowUTurnLeftIcon } from "../icons"; +import { useNavigate } from "react-router-dom"; +import { Formik, Form } from "formik"; +import * as Yup from "yup"; +import config from "../config"; +import NextUIFormikInput from "../components/NextUIFormikInput"; import axios from "axios"; -import InsertImage from '../components/InsertImage'; +import InsertImage from "../components/InsertImage"; const validationSchema = Yup.object({ - electricalBill: Yup.number() - .typeError('Must be a number') - .positive("Must be a positive value") - .max(99999.99, "Value is too large") - .required(), - waterBill: Yup.number() - .typeError('Must be a number') - .positive("Must be a positive value") - .max(99999.99, "Value is too large") - .required(), - totalBill: Yup.number() - .typeError('Must be a number') - .positive("Must be a positive value") - .max(99999.99, "Value is too large") - .required(), - noOfDependents: Yup.number() - .typeError('Must be a number') - .integer("Must be a whole number") - .positive("Must be a positive value") - .required(), + electricalBill: Yup.number() + .typeError("Must be a number") + .positive("Must be a positive value") + .max(99999.99, "Value is too large") + .required(), + waterBill: Yup.number() + .typeError("Must be a number") + .positive("Must be a positive value") + .max(99999.99, "Value is too large") + .required(), + totalBill: Yup.number() + .typeError("Must be a number") + .positive("Must be a positive value") + .max(99999.99, "Value is too large") + .required(), + noOfDependents: Yup.number() + .typeError("Must be a number") + .integer("Must be a whole number") + .positive("Must be a positive value") + .required(), }); export default function HBFormPage() { - let navigate = useNavigate(); + const navigate = useNavigate(); - const initialValues: { - id: string; - electricalBill: string; - waterBill: string; - totalBill: string; - noOfDependents: string; - ebPicture: File | null; - wbPicture: File | null; - } = { - id: '', - electricalBill: '', - waterBill: '', - totalBill: '', - noOfDependents: '', - ebPicture: null, - wbPicture: null, - }; + const initialValues: { + id: string; + electricalBill: string; + waterBill: string; + totalBill: string; + noOfDependents: string; + ebPicture: File | null; + wbPicture: File | null; + } = { + id: "", + electricalBill: "", + waterBill: "", + totalBill: "", + noOfDependents: "", + ebPicture: null, + wbPicture: null, + }; + const handleSubmit = async ( + values: any, + { setSubmitting, resetForm, setFieldError, setFieldValue }: any + ) => { + const formData = new FormData(); + formData.append("electricalBill", values.electricalBill); + formData.append("waterBill", values.waterBill); + formData.append("totalBill", values.totalBill); + formData.append("noOfDependents", values.noOfDependents); - const handleSubmit = async ( - values: any, - { setSubmitting, resetForm, setFieldError, setFieldValue }: any - ) => { - const formData = new FormData(); - formData.append('electricalBill', values.electricalBill); - formData.append('waterBill', values.waterBill); - formData.append('totalBill', values.totalBill); - formData.append('noOfDependents', values.noOfDependents); + if (values.ebPicture) { + formData.append("ebPicture", values.ebPicture); + } - if (values.ebPicture) { - formData.append('ebPicture', values.ebPicture); + if (values.wbPicture) { + formData.append("wbPicture", values.wbPicture); + } + + try { + const response = await axios.post( + config.serverAddress + "/hbcform", + formData, + { + headers: { + "Content-Type": "multipart/form-data", + }, } + ); + if (response.status === 200) { + console.log("Form created successfully:", response.data); + resetForm(); // Clear form after successful submit + setFieldValue("ebPicture", null); + setFieldValue("wbPicture", null); + navigate(-1); + } else { + console.error("Error creating form:", response.statusText); + } + } catch (error: any) { + if (error.response && error.response.data && error.response.data.errors) { + const errors = error.response.data.errors; + Object.keys(errors).forEach((key) => { + setFieldError(key, errors[key]); + }); + } else { + console.error("Unexpected error:", error); + } + } finally { + setSubmitting(false); + } + }; - if (values.wbPicture) { - formData.append('wbPicture', values.wbPicture); - } - - try { - const response = await axios.post(config.serverAddress + "/hbcform", formData, { - headers: { - 'Content-Type': 'multipart/form-data' - } - }); - if (response.status === 200) { - console.log("Form created successfully:", response.data); - resetForm(); // Clear form after successful submit - setFieldValue('ebPicture', null); - setFieldValue('wbPicture', null); - navigate("/contest"); - } else { - console.error("Error creating form:", response.statusText); - } - } catch (error: any) { - if (error.response && error.response.data && error.response.data.errors) { - const errors = error.response.data.errors; - Object.keys(errors).forEach((key) => { - setFieldError(key, errors[key]); - }); - } else { - console.error("Unexpected error:", error); - } - } finally { - setSubmitting(false); - } - }; - - return ( - -
- -
-
- - {({ isValid, dirty, isSubmitting, setFieldValue }) => ( -
-
-
-
- - - - -
-
- { - setFieldValue('ebPicture', file); - }} - /> - { - setFieldValue('wbPicture', file); - }} - /> -
-
-
- -
-
-
- )} -
-
-
- ); + return ( +
+
+ +
+
+ + {({ isValid, dirty, isSubmitting, setFieldValue }) => ( +
+
+
+
+ + + + +
+
+ { + setFieldValue("ebPicture", file); + }} + /> + { + setFieldValue("wbPicture", file); + }} + /> +
+
+
+ +
+
+
+ )} +
+
+
+ ); } diff --git a/client/src/pages/HomePage.tsx b/client/src/pages/HomePage.tsx index e1a926d..7566fcb 100644 --- a/client/src/pages/HomePage.tsx +++ b/client/src/pages/HomePage.tsx @@ -1,11 +1,9 @@ import { Button } from "@nextui-org/react"; import { useNavigate } from "react-router-dom"; -import DefaultLayout from "../layouts/default"; - export default function HomePage() { const navigate = useNavigate(); return ( - +

Home

- +
); } diff --git a/client/src/pages/ManageEventsPage.tsx b/client/src/pages/ManageEventsPage.tsx index 1f1a485..7b5b3f0 100644 --- a/client/src/pages/ManageEventsPage.tsx +++ b/client/src/pages/ManageEventsPage.tsx @@ -1,6 +1,14 @@ -import React, { useEffect, useState } from 'react'; -import DefaultLayout from "../layouts/default"; -import { Table, TableHeader, TableColumn, TableBody, TableRow, TableCell, Avatar, Button } from "@nextui-org/react"; +import React, { useEffect, useState } from "react"; +import { + Table, + TableHeader, + TableColumn, + TableBody, + TableRow, + TableCell, + Avatar, + Button, +} from "@nextui-org/react"; import { useNavigate } from "react-router-dom"; import { PencilSquareIcon, TrashIcon } from "../icons"; import axios from "axios"; @@ -38,7 +46,7 @@ const ManageEventsPage = () => { }; return ( - +

Manage Events

@@ -57,7 +65,10 @@ const ManageEventsPage = () => {
- + {event.title}
@@ -92,13 +103,12 @@ const ManageEventsPage = () => { - +
); }; export default ManageEventsPage; - diff --git a/client/src/pages/ManageUserAccountPage.tsx b/client/src/pages/ManageUserAccountPage.tsx index e841a4c..35cad02 100644 --- a/client/src/pages/ManageUserAccountPage.tsx +++ b/client/src/pages/ManageUserAccountPage.tsx @@ -1,4 +1,3 @@ -import DefaultLayout from "../layouts/default"; import UpdateAccountModule from "../components/UpdateAccountModule"; import { useNavigate } from "react-router-dom"; @@ -10,12 +9,12 @@ export default function ManageUserAccountPage() { } return ( - +
- +
); } diff --git a/client/src/pages/PostPage.tsx b/client/src/pages/PostPage.tsx index d94dda5..bcc7079 100644 --- a/client/src/pages/PostPage.tsx +++ b/client/src/pages/PostPage.tsx @@ -1,196 +1,200 @@ -import { useParams, useNavigate } from 'react-router-dom'; -import { useEffect, useState } from 'react'; -import DefaultLayout from "../layouts/default"; +import { useParams, useNavigate } from "react-router-dom"; +import { useEffect, useState } from "react"; import instance from "../security/http"; import config from "../config"; import { - Button, - Avatar, - Dropdown, - DropdownTrigger, - DropdownMenu, - DropdownItem, - Chip, - Modal, - ModalContent, - ModalHeader, - ModalBody, - ModalFooter, - useDisclosure, - Spinner, - } from "@nextui-org/react"; + Button, + Avatar, + Dropdown, + DropdownTrigger, + DropdownMenu, + DropdownItem, + Chip, + Modal, + ModalContent, + ModalHeader, + ModalBody, + ModalFooter, + useDisclosure, + Spinner, +} from "@nextui-org/react"; import { -ChatBubbleOvalLeftEllipsisIcon, -EllipsisHorizontalIcon, -HandThumbsUpIcon, -ArrowUTurnLeftIcon, + ChatBubbleOvalLeftEllipsisIcon, + EllipsisHorizontalIcon, + HandThumbsUpIcon, + ArrowUTurnLeftIcon, } from "../icons"; interface Post { - title: string; - postImage: Blob; - content: string; - tags: string; - id: number; + title: string; + postImage: Blob; + content: string; + tags: string; + id: number; } const PostPage: React.FC = () => { - const navigate = useNavigate(); - const { id } = useParams<{ id: string }>(); - const [post, setPost] = useState(null); - const { isOpen, onOpen, onOpenChange } = useDisclosure(); - const [selectedPost, setSelectedPost] = useState(null); + const navigate = useNavigate(); + const { id } = useParams<{ id: string }>(); + const [post, setPost] = useState(null); + const { isOpen, onOpen, onOpenChange } = useDisclosure(); + const [selectedPost, setSelectedPost] = useState(null); - useEffect(() => { - if (id) { - instance.get(`${config.serverAddress}/post/${id}`).then((res) => { - setPost(res.data); - }); - } - }, [id]); - - if (!post) { - return
; + useEffect(() => { + if (id) { + instance.get(`${config.serverAddress}/post/${id}`).then((res) => { + setPost(res.data); + }); } - - const handleDeleteClick = (post: Post) => { - setSelectedPost(post); - onOpen(); - }; - const handleDeleteConfirm = async () => { - if (selectedPost) { - try { - await instance.delete( - config.serverAddress + `/post/${selectedPost.id}` - ); - onOpenChange(); - } catch (error) { - console.error("Error deleting post:", error); - } - } - }; + }, [id]); + if (!post) { return ( - -
-
- +
+ +
+ ); + } + + const handleDeleteClick = (post: Post) => { + setSelectedPost(post); + onOpen(); + }; + const handleDeleteConfirm = async () => { + if (selectedPost) { + try { + await instance.delete( + config.serverAddress + `/post/${selectedPost.id}` + ); + onOpenChange(); + } catch (error) { + console.error("Error deleting post:", error); + } + } + }; + + return ( +
+
+
+ +
+
+
+
+
+
+
-
-
-
-
-
- -
-
-
-
-
-

{post.title}

-

Adam

-
-
- - - - - - { - navigate(`/editPost/${post.id}`); - }}> - Edit - - handleDeleteClick(post)} - > - Delete - - - -
-
-
-

{post.content}

-
-
-

Image

- {/* {userInformation && ( +
+
+
+
+

{post.title}

+

Adam

+
+
+ + + + + + { + navigate(`edit/${post.id}`); + }} + > + Edit + + handleDeleteClick(post)} + > + Delete + + + +
+
+
+

{post.content}

+
+
+

Image

+ {/* {userInformation && ( )} */} -
-
-
-
- Tag 1 - Tag 2 -
-
- - - -
-
-
-
-
+
+
+
+
+ Tag 1 + Tag 2 +
+
+ + + +
+
+
-
-
-
- - - {(onClose) => ( - <> - - Confirm Delete - - -

Are you sure you want to delete this post?

-
- - - - - - )} -
-
-
- ); - } +
+
+
+ + + + {(onClose) => ( + <> + + Confirm Delete + + +

Are you sure you want to delete this post?

+
+ + + + + + )} +
+
+ + ); +}; -export default PostPage; \ No newline at end of file +export default PostPage; diff --git a/client/src/pages/SchedulePage.tsx b/client/src/pages/SchedulePage.tsx index 516809a..e0705da 100644 --- a/client/src/pages/SchedulePage.tsx +++ b/client/src/pages/SchedulePage.tsx @@ -12,7 +12,6 @@ import { TableHeader, TableRow, } from "@nextui-org/react"; -import DefaultLayout from "../layouts/default"; import { useEffect, useState } from "react"; import config from "../config"; import instance from "../security/http"; @@ -30,7 +29,7 @@ interface Schedule { const statusColorMap: Record = { "On going": "success", "Up coming": "danger", - "Ended": "default", + Ended: "default", }; const getStatusColor = (status: string): ChipProps["color"] => { @@ -97,7 +96,7 @@ export default function SchedulePage() { }; return ( - +

Karang Guni Schedule

@@ -201,6 +200,6 @@ export default function SchedulePage() {
-
+ ); } diff --git a/client/src/pages/SignInPage.tsx b/client/src/pages/SignInPage.tsx index 1203788..9c9c593 100644 --- a/client/src/pages/SignInPage.tsx +++ b/client/src/pages/SignInPage.tsx @@ -1,11 +1,10 @@ import SignInModule from "../components/SignInModule"; -import DefaultLayout from "../layouts/default"; import SignedInStatusVerifier from "../components/SignedInStatusVerifier"; export default function SignInPage() { return ( - +
@@ -33,7 +32,7 @@ export default function SignInPage() {
- +
); } diff --git a/client/src/pages/SignUpPage.tsx b/client/src/pages/SignUpPage.tsx index c63d308..00a51d5 100644 --- a/client/src/pages/SignUpPage.tsx +++ b/client/src/pages/SignUpPage.tsx @@ -1,11 +1,10 @@ import SignUpModule from "../components/SignUpModule"; -import DefaultLayout from "../layouts/default"; import SignedInStatusVerifier from "../components/SignedInStatusVerifier"; export default function SignUpPage() { return ( - +
@@ -33,7 +32,7 @@ export default function SignUpPage() {
- +
); } diff --git a/client/src/pages/SpringboardPage.tsx b/client/src/pages/SpringboardPage.tsx index 22f6a5d..5a06038 100644 --- a/client/src/pages/SpringboardPage.tsx +++ b/client/src/pages/SpringboardPage.tsx @@ -1,5 +1,4 @@ import { useNavigate } from "react-router-dom"; -import DefaultLayout from "../layouts/default"; import { useEffect, useState } from "react"; import { Button, Card, Link } from "@nextui-org/react"; import { LockClosedIcon, PencilSquareIcon } from "../icons"; @@ -14,8 +13,8 @@ export default function SpringboardPage() { if (!accessToken) { navigate("/signin"); } - let [userInformation, setUserInformation] = useState(); - let [accountUnavailable, setAccountUnavaliable] = useState(false); + const [userInformation, setUserInformation] = useState(); + const [accountUnavailable, setAccountUnavaliable] = useState(false); let timeOfDay = getTimeOfDay(); let greeting = ""; @@ -42,7 +41,7 @@ export default function SpringboardPage() { }, []); return ( - +
{userInformation && (
@@ -165,6 +164,6 @@ export default function SpringboardPage() {
)}
- +
); } diff --git a/client/src/security/http.ts b/client/src/security/http.ts index 22d566a..ef9a818 100644 --- a/client/src/security/http.ts +++ b/client/src/security/http.ts @@ -9,7 +9,7 @@ const instance = axios.create({ instance.interceptors.request.use( function (config) { // Do something before request is sent - let accessToken = localStorage.getItem("accessToken"); + const accessToken = localStorage.getItem("accessToken"); if (accessToken) { config.headers["Authorization"] = `Bearer ${accessToken}`; }