Skip to content

Commit

Permalink
Merge pull request #100 from acm-ucr/dev
Browse files Browse the repository at this point in the history
to main
  • Loading branch information
kavinphab authored Dec 27, 2024
2 parents 62e1ce5 + 1a52c02 commit 4297b79
Show file tree
Hide file tree
Showing 21 changed files with 406 additions and 608 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jobs:
name: build
runs-on: ubuntu-latest

env:
NEXT_PUBLIC_GOOGLE_CALENDAR_API_KEY: ${{secrets.NEXT_PUBLIC_GOOGLE_CALENDAR_API_KEY}}
NEXT_PUBLIC_CALENDAR_EMAIL: ${{secrets.NEXT_PUBLIC_CALENDAR_EMAIL}}

steps:
- uses: actions/checkout@v4
- uses: acm-ucr/build@v2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Iranian Student Association Website

![Next.js](https://img.shields.io/badge/next.js-000000?style=for-the-badge&logo=nextdotjs&logoColor=white)
![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)
![TypeScript](https://img.shields.io/badge/typescript-%23407ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)
![TailwindCSS](https://img.shields.io/badge/tailwindcss-%2338B2AC.svg?style=for-the-badge&logo=tailwind-css&logoColor=white)
![Figma](https://img.shields.io/badge/figma-%23F24E1E.svg?style=for-the-badge&logo=figma&logoColor=white)
<br/>
Expand Down
58 changes: 1 addition & 57 deletions public/philanthropy/ISCC.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 0 additions & 33 deletions src/app/api/calendar/route.ts

This file was deleted.

65 changes: 16 additions & 49 deletions src/app/join-us/page.tsx
Original file line number Diff line number Diff line change
@@ -1,63 +1,30 @@
"use client";

import React from "react";
import BackgroundComponent from "@/components/join-us/background";
import Socials from "@/components/join-us/socials";
import Calendar from "@/components/join-us/calendar/calendarWrapper";
import Title from "@/components/join-us/title";
import { motion } from "framer-motion";

const animation = {
hidden: { opacity: 0, y: 30 },
show: { opacity: 1, y: 0 },
};
import WrappedEvents from "@/components/join-us/WrappedEvents";

const page = () => {
return (
<div className="relative min-h-screen">
{/* Background */}
<div className="absolute inset-0 -z-10">
<BackgroundComponent />
</div>

<div className="flex min-h-screen flex-col">
<div className="flex flex-grow flex-col items-center space-y-8 px-4 sm:space-y-10 sm:px-8 lg:space-y-12 lg:px-16">
<motion.div
variants={animation}
initial="hidden"
whileInView="show"
transition={{ duration: 0.8 }}
className="mb-3 flex justify-center sm:mb-4 md:mb-6 lg:mb-10"
>
<Title />
</motion.div>
<div>
<div className="relative flex min-h-screen flex-col">
<div className="absolute inset-0 -z-10">
<BackgroundComponent />
</div>

{/* Socials */}
<motion.div
variants={animation}
initial="hidden"
whileInView="show"
transition={{ duration: 0.8 }}
className="mx-auto w-full max-w-sm sm:max-w-md md:max-w-2xl"
>
<div className="flex flex-grow flex-col items-center space-y-12">
<div className="mt-8 rounded-lg px-4 py-2 text-4xl tracking-widest text-black">
Join Us
</div>
<div className="mx-auto w-full max-w-2xl">
<Socials />
</motion.div>
</div>

{/* Event Calendar Heading */}
<motion.div
variants={animation}
initial="hidden"
whileInView="show"
viewport={{ once: true, margin: "-100px" }}
transition={{ duration: 1, delay: 0.4 }}
className="mt-6 rounded-lg px-4 py-2 text-center text-2xl font-bold tracking-widest text-black sm:mt-8 sm:text-3xl md:text-4xl lg:mt-10 lg:text-5xl"
>
<div className="mt-8 rounded-lg px-4 text-4xl tracking-widest text-black">
Event Calendar
</motion.div>
</div>

{/* Calendar */}
<div className="w-full max-w-2xl md:max-w-4xl">
<Calendar />
<div className="w-full max-w-4xl">
<WrappedEvents />
</div>
</div>
</div>
Expand Down
102 changes: 102 additions & 0 deletions src/components/join-us/Events.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"use client";

import { useState, useEffect } from "react";
import Calendar from "./calendar/Calendar";

type CalendarEvent = {
id: string;
name: string;
date: Date;
location?: string;
isAllDay: boolean;
details?: string;
title: string;
};

type GoogleCalendarEvent = {
id: string;
summary: string;
start: {
dateTime?: string;
date?: string;
};
location?: string;
description?: string;
};

const Events = () => {
const [currentMonth, setCurrentMonth] = useState(new Date());
const [events, setEvents] = useState<CalendarEvent[]>([]);
const [loading, setLoading] = useState(true);

const handleMonthChange = (newDate: Date) => {
setCurrentMonth(newDate);
};

useEffect(() => {
const fetchGoogleCalendarEvents = async () => {
setLoading(true);

const startDate = new Date(
currentMonth.getFullYear(),
currentMonth.getMonth(),
1,
).toISOString();
const endDate = new Date(
currentMonth.getFullYear(),
currentMonth.getMonth() + 1,
0,
).toISOString();

try {
const res = await fetch(
`https://www.googleapis.com/calendar/v3/calendars/${process.env.NEXT_PUBLIC_GOOGLE_CALENDAR_EMAIL}/events?key=${process.env.NEXT_PUBLIC_GOOGLE_CALENDAR_API_KEY}&singleEvents=true&orderBy=startTime&timeMin=${startDate}&timeMax=${endDate}&maxResults=10`,
);

const data = await res.json();

console.log("API Response:", data);

if (data.items) {
const eventsData = data.items.map((event: GoogleCalendarEvent) => ({
id: event.id,
name: event.summary,
date: new Date(event.start.dateTime ?? event.start.date ?? ""),
location: event.location,
isAllDay: !event.start.dateTime,
details: event.description,
}));

setEvents(eventsData);
} else {
console.error("No events found in the API response.");
setEvents([]);
}
} catch (error) {
console.error("Error fetching events:", error);
} finally {
setLoading(false);
}
};

fetchGoogleCalendarEvents();
}, [currentMonth]);

return (
<div className="flex min-h-screen flex-col items-center">
{loading ? (
<p className="text-center text-lg md:text-xl lg:text-2xl">
Loading events...
</p>
) : (
<Calendar
currentMonth={currentMonth}
events={events}
onMonthChange={handleMonthChange}
/>
)}
</div>
);
};

export default Events;
16 changes: 16 additions & 0 deletions src/components/join-us/WrappedEvents.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use client";

import React from "react";
import Events from "./Events";

const WrappedEvents = () => {
return (
<div className="flex min-h-screen flex-col px-1 py-1">
<div className="w-full min-w-[300px] max-w-4xl rounded-lg p-4">
<Events />
</div>
</div>
);
};

export default WrappedEvents;
39 changes: 39 additions & 0 deletions src/components/join-us/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"use client";

import React from "react";
import CustomHeader from "./CustomHeader";
import CustomToolbar from "./CustomToolbar";
import CustomEvents from "./CustomEvents";

interface Event {
id: string;
name: string;
date: Date;
location?: string;
isAllDay: boolean;
details?: string;
title: string;
}

interface CalendarProps {
currentMonth: Date;
events: Event[];
onMonthChange: (date: Date) => void;
}

const Calendar = ({ currentMonth, events, onMonthChange }: CalendarProps) => {
return (
<div className="relative mx-auto flex w-full max-w-4xl flex-col overflow-hidden rounded-3xl border-4 border-isa-dark-red bg-isa-beige-100 bg-opacity-80 p-5 text-center shadow-lg drop-shadow-md backdrop-blur-0">
<CustomHeader currentMonth={currentMonth} />
<CustomToolbar
onMonthChange={onMonthChange}
currentMonth={currentMonth}
/>
<div className="mt-4">
<CustomEvents currentMonth={currentMonth} events={events} />
</div>
</div>
);
};

export default Calendar;
Loading

0 comments on commit 4297b79

Please sign in to comment.