Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analytics tab (wip) #507

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions components/Organizer/AnalyticsTab/AnalyticsTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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<DietaryData[]>({
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 (
<>
<Table columns={columns} dataSource={formattedDietaryData}></Table>
</>
);
}
10 changes: 8 additions & 2 deletions components/Organizer/OrganizerDash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -100,13 +101,18 @@ export default function OrganizerDash() {
children: <EventsTab />,
},
{
label: 'Bug Reports',
label: `Analytics`,
key: '7',
children: <AnalyticsTab />,
},
{
label: 'Bug Reports',
key: '8',
children: <BugReportsTab />,
},
{
label: `Settings`,
key: '8',
key: '9',
children: <SettingsTab />,
},
]}
Expand Down
31 changes: 31 additions & 0 deletions pages/api/dietary-restrictions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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<any>) {
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');
}
}
3 changes: 3 additions & 0 deletions public/darkmode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/noun-light-mode-6724406.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions types/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,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
Expand Down
Loading