Skip to content

Commit

Permalink
Merge pull request #26 from Geethika-Kancharla/main
Browse files Browse the repository at this point in the history
Completed members page #12
  • Loading branch information
SkySingh04 authored Aug 16, 2024
2 parents 3d7f1a1 + efb8f98 commit 8ce2494
Show file tree
Hide file tree
Showing 18 changed files with 521 additions and 116 deletions.
2 changes: 1 addition & 1 deletion app/(default)/achievements/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ export default function AchievementsPage() {
</div>
</div>
);
}
}
29 changes: 29 additions & 0 deletions app/(default)/api/membersData/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { NextResponse } from 'next/server';
import { db } from '@/Firebase';
import { collection, addDoc } from 'firebase/firestore';

export async function POST(request: Request) {
try {
const data = await request.json();

if (!Array.isArray(data)) {
return NextResponse.json({ message: 'Expected an array of JSON objects', error: true });
}

const savedData = [];
for (const item of data) {
// Save each item to Firebase Firestore
const docRef = await addDoc(collection(db, "members"), item);
console.log("Document written with ID: ", docRef.id);

// Collect saved data for response
savedData.push({ id: docRef.id, ...item });
}

// Return a success response
return NextResponse.json({ message: 'Registration successful', data: savedData });
} catch (error) {
console.error('An error occurred:', error);
return NextResponse.json({ message: 'An error occurred', error });
}
}
18 changes: 9 additions & 9 deletions app/(default)/api/registration/sih/route.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { db } from '@/Firebase';
import { sihValidate } from '@/lib/utils';
import { addDoc, collection, getDocs } from 'firebase/firestore';
import { NextResponse } from 'next/server';
import { NextResponse } from 'next/server';

// Add a new registration
export async function POST(request: Request) {
const data = await request.json();
export async function POST(request: Request) {
const data = await request.json();
// Validate the data
const val = sihValidate(data);

if(val.error){
if (val.error) {
return NextResponse.json({ message: 'Validation error', error: val.error });
}

try{
try {
// Save to Firebase
const docRef = await addDoc(collection(db, "sih2024"), data);
console.log("Document written with ID: ", docRef.id);
Expand All @@ -22,12 +22,12 @@ export async function POST(request: Request) {
return NextResponse.json({ message: 'An error occurred', error });
}
// Return a response
return NextResponse.json({ message: 'Registration successful', data });
}
return NextResponse.json({ message: 'Registration successful', data });
}

//get all registrations
export async function GET() {
try{
export async function GET() {
try {
// Get all registrations in sih2024 collection
const querySnapshot = await getDocs(collection(db, "sih2024"));
// Map the data to get only the data
Expand Down
2 changes: 1 addition & 1 deletion app/(default)/events/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const metadata = {
title: 'Events',
description: 'Events page',
}
export default function Events() {
export default function Events() {
return (
<>
</>
Expand Down
2 changes: 1 addition & 1 deletion app/(default)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function DefaultLayout({
children,
}: {
children: React.ReactNode
}) {
}) {

useEffect(() => {
AOS.init({
Expand Down
3 changes: 2 additions & 1 deletion app/(default)/leads/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export const metadata = {
description: 'Leads page',
}

export default function Leads() {
export default function Leads() {

return (
<>
</>
Expand Down
13 changes: 13 additions & 0 deletions app/(default)/members/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Members from "@/components/Members"

export const metadata = {
title: 'Members',
description: 'Members page',
}
export default function Events() {
return (
<>
<Members />
</>
)
}
99 changes: 99 additions & 0 deletions components/Members.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"use client";

import React, { useState, useEffect } from 'react';
import Card from '@/components/ui/Card';
import CollapsibleSection from '@/components/ui/CollapsibleSection';
import { db } from "@/Firebase";
import { collection, query, where, getDocs } from "firebase/firestore";

interface Member {
id: string;
name: string;
domain: string;
company?: string;
year: string;
}

const headings = ["Alumni", "Fourth Year", "Third Year", "Second Year", "First Year"];

export default function Members() {
// Set default open index to the index of "Alumni"
const [openIndex, setOpenIndex] = useState<number>(headings.indexOf("Alumni"));
const [data, setData] = useState<{ [key: string]: Member[] }>({});

const handleToggle = (index: number) => {
setOpenIndex(openIndex === index ? -1 : index);
};

useEffect(() => {
const fetchData = async () => {
try {
const fetchedData: { [key: string]: Member[] } = {};

for (const heading of headings) {
const membersCollection = collection(db, "members");
const q = query(membersCollection, where("year", "==", heading));
const querySnapshot = await getDocs(q);

// Collect all documents
const allMembers = querySnapshot.docs.map(doc => ({
id: doc.id,
...(doc.data() as Omit<Member, 'id'>)
})) as Member[];

// Remove duplicates based on name, domain, and year
const uniqueMembers = Array.from(
new Map(
allMembers.map(member => [
`${member.name}-${member.domain}-${member.year}`,
member
])
).values()
);

// Sort members alphabetically by name
const sortedMembers = uniqueMembers.sort((a, b) => a.name.localeCompare(b.name));

fetchedData[heading] = sortedMembers;
}

setData(fetchedData);
} catch (error) {
console.error("Error fetching data: ", error);
}
};
fetchData();
}, []);

return (
<div className="flex flex-col justify-center items-center w-full space-y-4 mt-20 pb-8 bg-black">
<h1 className="text-center font-bold text-4xl text-white"></h1>
<div className="w-full max-w-6xl px-2 ">
<div className="space-y-2">
{headings.map((heading, index) => (
<CollapsibleSection
key={index}
heading={heading}
content={
<div className='flex justify-center'>
<div className="grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-16">
{data[heading]?.map((profile, cardIndex) => (
<Card
key={cardIndex}
name={profile.name}
domain={profile.domain}
company={profile.company || ""}
/>
))}
</div>
</div>
}
isOpen={openIndex === index}
onToggle={() => handleToggle(index)}
/>
))}
</div>
</div>
</div>
);
}
Loading

0 comments on commit 8ce2494

Please sign in to comment.