Skip to content

Commit

Permalink
Merge pull request #17 from ubc-biztech/stats-base-page
Browse files Browse the repository at this point in the history
base page completed
  • Loading branch information
AllanT102 authored Jul 6, 2024
2 parents 5b8e67e + de63b5f commit 748a5d3
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 26 deletions.
22 changes: 22 additions & 0 deletions src/lib/dbUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export async function fetchRegistrationData(eventId: string, year: string) {
// TODO - fetch data registration data from backend. This is just returning a Mock, likely won't be the final data struct format

let data = []
for (let i = 0; i < 200; i++) {
data.push({
id: i.toString(),
regStatus: "Checked-In",
appStatus: "Accepted",
firstName: "John",
lastName: "Smith",
email: "[email protected]",
points: 0,
studentNumber: "12345678",
faculty: "Comm...",
dynamicField1: "aa...",
shouldNotDisplay: "THIS SHOULD NOT BE DISPLAYING."
})
}

return data
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DataTable } from "@/components/RegistrationTable/data-table";
import { useEffect, useState } from "react";
import { ColumnDef } from "@tanstack/react-table";
import { GetServerSideProps } from 'next'
import { fetchRegistrationData } from '@/lib/dbUtils';

// Dynamic columns
const dynamicColumns: ColumnDef<Attendee>[] = [
Expand Down Expand Up @@ -33,7 +34,7 @@ export default function AdminEvent({ initialData }: Props) {
const year = router.query.year as string;

if (eventId && year) {
fetchRegistationData(eventId, year).then(d => {
fetchRegistrationData(eventId, year).then(d => {
setData(d)
setLoading(false)
})
Expand Down Expand Up @@ -73,33 +74,10 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const { eventId, year } = context.params as { eventId: string, year: string };

try {
const data = await fetchRegistationData(eventId, year);
const data = await fetchRegistrationData(eventId, year);
return { props: { initialData: data } };
} catch (error) {
console.error("Failed to fetch initial data:", error);
return { props: { initialData: null } };
}
}

async function fetchRegistationData(eventId: string, year: string) {
// TODO - fetch data from backend. This is just returning a Mock, likely won't be the final data struct format

let data = []
for (let i = 0; i < 200; i++) {
data.push({
id: i.toString(),
regStatus: "Checked-In",
appStatus: "Accepted",
firstName: "John",
lastName: "Smith",
email: "[email protected]",
points: 0,
studentNumber: "12345678",
faculty: "Comm...",
dynamicField1: "aa...",
shouldNotDisplay: "THIS SHOULD NOT BE DISPLAYING."
})
}

return data
}
}
40 changes: 40 additions & 0 deletions src/pages/admin/event/[eventId]/[year]/stats/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { BasicInformation } from "@/types";
import { GetServerSideProps } from "next";
import { useRouter } from "next/router";
import { fetchRegistrationData } from "@/lib/dbUtils";

type Props = {
initialData: BasicInformation[] | null
}

export default function Statistics( { initialData }: Props) {
const router = useRouter()

return (
<main className="bg-primary-color min-h-screen">
<div className="container mx-auto p-10 flex flex-col">
<span>
<h2 className="text-white">Event Statistics</h2>
<p className="text-baby-blue font-poppins">Statistics {">"} {router.query.eventId} {router.query.year}</p>
{/*
insert charts here
*/}
</span>
</div>
</main>
);
}



export const getServerSideProps: GetServerSideProps = async (context) => {
const { eventId, year } = context.params as { eventId: string, year: string };

try {
const data = await fetchRegistrationData(eventId, year);
return { props: { initialData: data } };
} catch (error) {
console.error("Failed to fetch initial data:", error);
return { props: { initialData: null } };
}
}
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type BasicInformation = {
fname: string
lname: string
major: string
gender: string
year: string
diet: string
heardFrom: string
faculty: string
}

0 comments on commit 748a5d3

Please sign in to comment.