Skip to content

Commit

Permalink
Added past events feature and removed volunteers from event details s…
Browse files Browse the repository at this point in the history
…chema
  • Loading branch information
jennymar committed May 8, 2024
1 parent bdc39b4 commit 4d0acd5
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 61 deletions.
1 change: 0 additions & 1 deletion backend/src/models/eventDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const eventDetailsSchema = new Schema({
date: { type: String, required: true },
location: { type: String, required: true },
imageURI: { type: String, required: true },
volunteers: { type: [String], required: false, default: [] },
});

type EventDetails = InferSchemaType<typeof eventDetailsSchema>;
Expand Down
28 changes: 0 additions & 28 deletions frontend/src/api/eventDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export type EventDetails = {
date: string;
location: string;
imageURI: string;
volunteers: string[];
};

export async function getEventDetails(id: string): Promise<APIResult<EventDetails>> {
Expand Down Expand Up @@ -40,7 +39,6 @@ type CreateEventDetailsRequest = {
date: string;
location: string;
imageURI: string;
// volunteers: string[]; when creating an event, no volunteers are added
};

export async function createEventDetails(
Expand All @@ -63,7 +61,6 @@ type UpdateEventDetailsRequest = {
date: string;
location: string;
imageURI: string;
volunteers: string[];
};

export async function updateEventDetails(
Expand All @@ -80,28 +77,3 @@ export async function updateEventDetails(
return handleAPIError(error);
}
}

// wrap updateEventDetails to push a volunteer ID to an event
export async function addVolunteerToEvent(
eventId: string,
volunteerId: string,
): Promise<APIResult<EventDetails>> {
try {
const result = await getEventDetails(eventId);
if (!result.success) {
// if result is not successful, return the result which is APIError
return result;
}
const oldEvent = result.data;
oldEvent.volunteers.push(volunteerId);
const response = await updateEventDetails(oldEvent);

if (!response.success) {
// if response is not successful, return the response which is APIError
return response;
}
return { success: true, data: response.data };
} catch (error) {
return handleAPIError(error);
}
}
2 changes: 0 additions & 2 deletions frontend/src/api/testimonial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export type Testimonial = {
export async function getAllTestimonials(): Promise<APIResult<Testimonial[]>> {
try {
const response = await get(`/api/testimonial/get`);
//console.log(response);
const json = (await response.json()) as Testimonial[];
//console.log(json);
return { success: true, data: json };
} catch (error) {
return handleAPIError(error);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/(web app)/involved/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function Involved() {
<div className={styles.cards}>
<WhiteCard
imageUrl="/cal.svg"
buttonUrl="/events"
buttonUrl="/upcoming-events"
buttonText="Learn More"
title="Upcoming Events"
description="Lorem ipsum dolor sit amet consectetur. Et vestibulum enim nunc ultrices. Donec blandit sollicitudin vitae integer mauris sed. Mattis duis id viverra suscipit morbi."
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/(web app)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function Home() {
<div className={styles.whiteCardsContainer}>
<WhiteCard
imageUrl="/Donate.svg"
buttonUrl="/"
buttonUrl="/donations"
buttonText="Donate"
title="Help Our Cause"
description="Your support and contributions will enable us to meet our goals and improve conditions.
Expand All @@ -64,7 +64,7 @@ export default function Home() {
</div>

<div className={styles.buttonContainer}>
<Button text={see_more_text} link={"/events"} />
<Button text={see_more_text} link={"/upcoming-events"} />
</div>
<Description
title="Our Community Sponsors"
Expand Down
47 changes: 47 additions & 0 deletions frontend/src/app/(web app)/past-events/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use client";
import React, { useEffect, useState } from "react";

import EventsList from "../../../components/EventsList";

import styles from "./page.module.css";

import { BackgroundImage, BackgroundImagePages, getBackgroundImages } from "@/api/images";
import BackgroundHeader from "@/components/BackgroundHeader";

export default function PastEvents() {
const [images, setImages] = useState<BackgroundImage[]>([]);

useEffect(() => {
getBackgroundImages(BackgroundImagePages.TEAM)
.then((result) => {
if (result.success) {
setImages(result.data);
}
})
.catch((error) => {
alert(error);
});
}, []);

return (
<div className="items-center justify-center">
<BackgroundHeader
backgroundImageURIs={images.map((image) => image.imageURI)}
header="GET INVOLVED"
title="Past Events"
description="Lorem ipsum dolor sit amet consectetur. Et vestibulum enim nunc ultrices. Donec blandit sollicitudin vitae integer mauris sed. Mattis duis id viverra suscipit morbi."
/>
<div className={styles.body}>
<div className={styles.bodyTitle}>
<h1 style={{ font: "var(--font-title-l)" }}>Explore our Past Events</h1>
<p style={{ font: "var(--font-body-reg)" }}>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloremque necessitatibus
asperiores, optio quasi sit tempora in amet aut natus, similique enim explicabo id
expedita minima doloribus repellendus est? Quos, officia?
</p>
</div>
<EventsList page="past-events" />
</div>
</div>
);
}
19 changes: 19 additions & 0 deletions frontend/src/app/(web app)/upcoming-events/page.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@import url("https://fonts.googleapis.com/css2?family=Open+Sans:ital,wdth,wght@0,75..100,300..800;1,75..100,300..800&family=Roboto+Slab:wght@100..900&display=swap");

.body {
max-width: 1440px;
margin: 0 auto;
height: auto;
padding: 0px 98px 136px;
background-color: #f9f9f9;
color: black;
}
.bodyTitle {
margin: 0;
padding: 64px 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: left;
gap: 24px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function UpcomingEvents() {
expedita minima doloribus repellendus est? Quos, officia?
</p>
</div>
<EventsList page="events" />
<EventsList page="upcoming-events" />
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/admin/dashboard/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
display: flex;
justify-content: flex-start;
padding-left: 90px;
padding-top: 150px;
padding-top: 50px;
}

.gridContainer {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/admin/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ export default function Dashboard() {
<div className={styles.gridContainer}>
<DashboardCard
imageURI="/dashboard_eventcreator.png"
url="/eventcreator"
url="/event-creator"
title="Event Creator"
last_updated="Month XX, XXXX, XX:XX"
/>
<DashboardCard
imageURI="/dashboard_pageeditor.png"
url="/pageeditor"
url="/page-editor"
title="Page Editor"
last_updated="Month XX, XXXX, XX:XX"
/>

<DashboardCard
imageURI="/dashboard_newsletter.png"
url="/newslettercreator"
url="/newsletter-creator"
title="Newsletter"
last_updated="Month XX, XXXX, XX:XX"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
display: flex;
justify-content: center;
padding-left: 30px;
padding-top: 140px;
padding-top: 50px;
}

.gridContainer {
Expand Down
File renamed without changes.
21 changes: 18 additions & 3 deletions frontend/src/components/EventsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const EventsCard = ({ event, page }: CardProps) => {
<div className={styles.cardTitle}>{event.name}</div>
<div className={styles.homeCardDescription}>{event.description}</div>
</div>
<Link href={`/events/${event._id}`}>
<Link href={`/upcoming-events/${event._id}`}>
<button className={styles.homeCardButton}>Learn More</button>
</Link>
</div>
</main>
);
} else {
} else if (page === "upcoming-events") {
return (
<main className={styles.cardContainer} style={{ width: `578px`, height: `536px` }}>
<div style={{ width: "578px", height: "270px", overflow: "hidden" }}>
Expand All @@ -45,12 +45,27 @@ const EventsCard = ({ event, page }: CardProps) => {
<div className={styles.cardTitle}>{event.name}</div>
<div className={styles.cardDescription}>{event.description}</div>
</div>
<Link href={`/events/${event._id}`}>
<Link href={`/upcoming-events/${event._id}`}>
<button className={styles.cardButton}>Learn More</button>
</Link>
</div>
</main>
);
} else if (page === "past-events") {
return (
<main className={styles.cardContainer} style={{ width: `578px`, height: `450px` }}>
<div style={{ width: "578px", height: "270px", overflow: "hidden" }}>
<Image src={event.imageURI} alt="image" width={578} height={270} />
</div>

<div className={styles.cardContent}>
<div className={styles.textContainer}>
<div className={styles.cardTitle}>{event.name}</div>
<div className={styles.cardDescription}>{event.description}</div>
</div>
</div>
</main>
);
}
};

Expand Down
42 changes: 35 additions & 7 deletions frontend/src/components/EventsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,27 @@ type EventsListProps = {
};

export default function EventsList({ page }: EventsListProps) {
const [events, setEvents] = useState<EventDetails[]>([]);
const [pastEvents, setPastEvents] = useState<EventDetails[]>([]);
const [upcomingEvents, setUpcomingEvents] = useState<EventDetails[]>([]);

// Fetch events
useEffect(() => {
getAllEventDetails()
.then((response) => {
if (response.success) {
setEvents(response.data);
const currentDate = new Date();

const filteredPastEvents = response.data.filter((item) => {
const eventDate = new Date(item.date);
return eventDate < currentDate;
});
setPastEvents(filteredPastEvents);

const filteredUpcomingEvents = response.data.filter((item) => {
const eventDate = new Date(item.date);
return eventDate >= currentDate;
});
setUpcomingEvents(filteredUpcomingEvents);
} else {
alert(response.error);
}
Expand All @@ -33,25 +46,40 @@ export default function EventsList({ page }: EventsListProps) {
style={{ display: "flex", flexWrap: "wrap", columnGap: "24px", rowGap: "50px" }}
className="events"
>
{events.length === 0 ? (
{upcomingEvents.length === 0 ? (
<p>Loading...</p>
) : (
upcomingEvents.map((event: EventDetails) => (
<EventCard key={event._id} event={event} page={page} />
))
)}
</div>
);
} else if (page === "upcoming-events") {
return (
<div
style={{ display: "flex", flexWrap: "wrap", columnGap: "85px", rowGap: "85px" }}
className="events"
>
{upcomingEvents.length === 0 ? (
<p>Loading...</p>
) : (
events.map((event: EventDetails) => (
upcomingEvents.map((event: EventDetails) => (
<EventCard key={event._id} event={event} page={page} />
))
)}
</div>
);
} else {
} else if (page === "past-events") {
return (
<div
style={{ display: "flex", flexWrap: "wrap", columnGap: "85px", rowGap: "85px" }}
className="events"
>
{events.length === 0 ? (
{pastEvents.length === 0 ? (
<p>Loading...</p>
) : (
events.map((event: EventDetails) => (
pastEvents.map((event: EventDetails) => (
<EventCard key={event._id} event={event} page={page} />
))
)}
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const Footer = () => {
getInvolved: "/involved",
ourImpact: "/impact",
ourMission: "/mission",
upcomingEvents: "/events",
upcomingEvents: "/upcoming-events",
pastEvents: "/past-events",
testimonials: "/testimonials",
ourTeam: "/team",
contactUs: "/contact",
Expand Down Expand Up @@ -152,8 +153,8 @@ const Footer = () => {
<Link className={`${styles.link} ${styles.normalLink}`} href={links.ourTeam}>
Our Team
</Link>
<Link className={`${styles.link} ${styles.normalLink}`} href={links.donate}>
Donate
<Link className={`${styles.link} ${styles.normalLink}`} href={links.pastEvents}>
Past Events
</Link>
<Link className={`${styles.link} ${styles.normalLink}`} href={links.newsletter}>
Newsletter
Expand All @@ -164,6 +165,9 @@ const Footer = () => {
<Link className={`${styles.link} ${styles.normalLink}`} href={links.contactUs}>
Contact Us
</Link>
<Link className={`${styles.link} ${styles.normalLink}`} href={links.donate}>
Donate
</Link>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/HeaderBar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
z-index: 1;
width: 202px;
max-height: 104px;
max-height: 156px;
overflow-y: auto;
}

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/HeaderBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const HeaderBar = () => {
<div className={styles.getInvolved}>
<Link href="/involved">Get Involved</Link>
<div className={styles.getInvolvedDropdown}>
<Link href="/events">Upcoming Events</Link>
<Link href="/upcoming-events">Upcoming Events</Link>
<Link href="/past-events">Past Events</Link>
<Link href="/donations">Donate</Link>
</div>
</div>
Expand Down
Loading

0 comments on commit 4d0acd5

Please sign in to comment.