-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Geethika-Kancharla/main
Completed members page #12
- Loading branch information
Showing
18 changed files
with
521 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,4 +73,4 @@ export default function AchievementsPage() { | |
</div> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
Oops, something went wrong.