From 5106be7723dd2fb6215d0ad7e68f410e93652ab4 Mon Sep 17 00:00:00 2001 From: Stanley Zheng Date: Mon, 16 Sep 2024 11:25:28 -0500 Subject: [PATCH] hope this works --- .../Organizer/AnalyticsTab/AnalyticsTab.tsx | 54 +++++++++++++++++++ components/Organizer/OrganizerDash.tsx | 10 +++- pages/api/dietary-restrictions.ts | 34 ++++++++++++ public/darkmode.svg | 3 ++ public/noun-light-mode-6724406.svg | 3 ++ types/database.ts | 5 ++ 6 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 components/Organizer/AnalyticsTab/AnalyticsTab.tsx create mode 100644 pages/api/dietary-restrictions.ts create mode 100644 public/darkmode.svg create mode 100644 public/noun-light-mode-6724406.svg diff --git a/components/Organizer/AnalyticsTab/AnalyticsTab.tsx b/components/Organizer/AnalyticsTab/AnalyticsTab.tsx new file mode 100644 index 00000000..6f4a8c51 --- /dev/null +++ b/components/Organizer/AnalyticsTab/AnalyticsTab.tsx @@ -0,0 +1,54 @@ +import {Table} from 'antd'; + +import useSWR from 'swr'; +import {DietaryData, ResponseError} from '../../../types/database'; +import { RequestType, useCustomSWR } from '../../../utils/request-utils'; +import React, { useState, useRef, useEffect } from 'react'; + + +export default function Analytics() { + + const { data: dietaryData, error: dietaryError } = useCustomSWR({ + url: '/api/dietary-restrictions', + method: RequestType.GET, + errorMessage: 'Failed to get list of dietary data.', + }); + console.log('dietaryData:', dietaryData); // Add this to debug + + const columns = [ + { + title: 'Dietary Restriction', + dataIndex: '_id', // Corresponds to the _id field in the data + key: '_id', + }, + { + title: 'Count', + dataIndex: 'count', // Corresponds to the count field in the data + key: 'count', + }, + ]; + + // Format the dietary data to add a unique 'key' for each row + const formattedDietaryData = dietaryData + ? dietaryData.map((restriction: DietaryData) => ({ + ...restriction, + key: restriction._id , // Use _id as key or fallback to index + + })) + : undefined; + + + + + return ( + <> + + +
+ + ); + + + +} + diff --git a/components/Organizer/OrganizerDash.tsx b/components/Organizer/OrganizerDash.tsx index b3081570..65cd4fe9 100644 --- a/components/Organizer/OrganizerDash.tsx +++ b/components/Organizer/OrganizerDash.tsx @@ -6,6 +6,7 @@ import ManageUsersTab from './ManageUsersTab/ManageUsersTab'; import PreAddUsersTab from './PreAddUsersTab/PreAddUsersTab'; import ApplicantsTab from './ApplicantsTab/ApplicantsTab'; import EventsTab from './EventsTab/EventsTab'; +import AnalyticsTab from './AnalyticsTab/AnalyticsTab'; import styles from '../../styles/Organizer.module.css'; import { AccentColor, Theme, ThemeContext, getAccentColor, getThemedClass } from '../../theme/themeProvider'; import { useContext, useEffect } from 'react'; @@ -100,13 +101,18 @@ export default function OrganizerDash() { children: , }, { - label: 'Bug Reports', + label: `Analytics`, key: '7', + children: , + }, + { + label: 'Bug Reports', + key: '8', children: , }, { label: `Settings`, - key: '8', + key: '9', children: , }, ]} diff --git a/pages/api/dietary-restrictions.ts b/pages/api/dietary-restrictions.ts new file mode 100644 index 00000000..23664214 --- /dev/null +++ b/pages/api/dietary-restrictions.ts @@ -0,0 +1,34 @@ +import type { NextApiRequest, NextApiResponse } from 'next'; +import dbConnect from '../../middleware/database'; +import { getSession } from 'next-auth/react'; +import Application from '../../models/application'; + +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + const session = await getSession({req}); + + + + await dbConnect(); + + switch (req.method) { + case 'GET': + const count = await Application.aggregate([ + { + $unwind: "$dietaryRestrictions" + }, + { + $group: { + _id: "$dietaryRestrictions", + count: { $sum: 1 } + } + }, + { + $sort: { count: -1 } + } + ]); + return res.status(200).send(JSON.stringify(count)); + default: + return res.status(405).send('Method not supported brother'); + } + +} \ No newline at end of file diff --git a/public/darkmode.svg b/public/darkmode.svg new file mode 100644 index 00000000..b16284f3 --- /dev/null +++ b/public/darkmode.svg @@ -0,0 +1,3 @@ + + +Created by GlyphGenius Studiofrom Noun Project \ No newline at end of file diff --git a/public/noun-light-mode-6724406.svg b/public/noun-light-mode-6724406.svg new file mode 100644 index 00000000..21023209 --- /dev/null +++ b/public/noun-light-mode-6724406.svg @@ -0,0 +1,3 @@ + + +Created by GlyphGenius Studiofrom Noun Project \ No newline at end of file diff --git a/types/database.ts b/types/database.ts index f2ef8e0f..f6558c9e 100644 --- a/types/database.ts +++ b/types/database.ts @@ -126,6 +126,11 @@ export interface JudgingSessionData { time: String; } +export interface DietaryData { + _id: mongoose.Schema.Types.ObjectId; + count: number; +} + export interface HackathonSettingsData { _id: mongoose.Schema.Types.ObjectId; HACKATHON_START: string; // MM/DD/YYYY HH:mm A