Skip to content

Commit

Permalink
Merge branch 'dev' into 83-final-day-planner-adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatMegamind authored Apr 27, 2024
2 parents 1da3914 + d515e50 commit e57d984
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 15 deletions.
80 changes: 74 additions & 6 deletions src/components/Events/DailyEvent.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import PropTypes from 'prop-types';
import { Box, Flex, Text, Grid, Button, Spacer } from '@chakra-ui/react';
import { Box, Flex, Text, Grid, Button, Spacer, Badge, VStack } from '@chakra-ui/react';
import { useState } from 'react';
import { NPOBackend } from '../../utils/auth_utils.js';
import AUTH_ROLES from '../../utils/auth_config.js';
import { useAuthContext } from '../../common/AuthContext.jsx';
const { USER_ROLE } = AUTH_ROLES.AUTH_ROLES;

const DailyEvent = ({ id, startTime, endTime, eventTitle, confirmed, description }) => {
const DailyEvent = ({ id, startTime, endTime, eventTitle, confirmed, description, eventId }) => {
const [confirmEvent, setConfirmEvent] = useState(confirmed);
const [cohort, setCohort] = useState(undefined);
const [cohortBadgeColor, setCohortBadgeColor] = useState(undefined);
const [cohortTextColor, setCohortTextColor] = useState(undefined);
const [cohortBorderColor, setCohortBorderColor] = useState(undefined);
const [cohortBorder, setCohortBorder] = useState(undefined);
const {currentUser} = useAuthContext();

let border_color = '#2B93D1';
Expand All @@ -17,6 +22,42 @@ const DailyEvent = ({ id, startTime, endTime, eventTitle, confirmed, description
background_color = '#FEF1DC';
}

const getCohort = async () => {
if (eventId) {
try {
const { data } = await NPOBackend.get(`/catalog/${eventId}`);
let year = data[0].year;
if( year.length == 2)
{
setCohort('Both');
setCohortBadgeColor("#FFFFFF");
setCohortTextColor("#4A5568");
setCohortBorderColor("#4A5568");
setCohortBorder("outline");
}
else if(year[0] == 'junior')
{
setCohort('Junior');
setCohortBadgeColor("#CBD5E0");
setCohortTextColor("#171923");
setCohortBorderColor("#CBD5E0");
setCohortBorder("simple");
}
else {
setCohort('Senior');
setCohortBadgeColor("#4A5568");
setCohortTextColor("#FFFFFF");
setCohortBorderColor("#4A5568");
setCohortBorder("simple");
}
} catch (error) {
console.error('Error fetching data:', error);
}
}
}

getCohort();

const handleConfirm = async () => {
const date = new Date();
try {
Expand Down Expand Up @@ -54,17 +95,43 @@ const DailyEvent = ({ id, startTime, endTime, eventTitle, confirmed, description

<Spacer />

<VStack align="flex-end">
<Badge
key={eventId}
variant={cohortBorder}
backgroundColor={cohortBadgeColor}
color={cohortTextColor}
textTransform="capitalize"
borderRadius="10rem"
borderColor={cohortBorderColor}
fontWeight="normal"
px="0.5rem"
mr="0.125rem"
>
{cohort}
</Badge>

{!confirmEvent && (
<Box w="15vh" alignItems="top">
<Box w="4rem" alignItems="top">
<Grid gap={2}>
<div></div>
<div></div>
<Button bg="#FBD38D" textColor="#2D3748" size="sm" onClick={handleConfirm} visibility={currentUser.type == USER_ROLE ? 'hidden' : 'visible'}>
<Button
variant="outline"
bg="#FEF1DC"
textColor="#F69052"
borderColor="#F69052"
_hover={{ bg: "#F6AD55", color: "#2D3748" }}
size="xs"
onClick={handleConfirm}
visibility={currentUser.type == USER_ROLE ? 'hidden' : 'visible'}
>
Confirm
</Button>
</Grid>
</Box>
</Grid>
</Box>
)}
</VStack>
</Flex>
</Box>
);
Expand All @@ -77,6 +144,7 @@ DailyEvent.propTypes = {
eventTitle: PropTypes.string.isRequired,
description: PropTypes.string,
confirmed: PropTypes.bool.isRequired,
eventId: PropTypes.number.isRequired,
};

export default DailyEvent;
5 changes: 3 additions & 2 deletions src/components/Events/EventInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ const EventInfo = ({ dayId, eventDate, day, startTime, endTime, location, notes,
{day} {startTime} - {endTime}
</Text>

<Text mb="1.5rem">{location}</Text>
<Text as="b" mb="0.5rem">Location: </Text>
<Text whiteSpace="pre-wrap" mb="2rem">{location}</Text>

<Text mb="0.5rem">Details:</Text>
<Text as="b" mb="0.5rem">Details:</Text>
<Text whiteSpace="pre-wrap" mb="2rem">{notes ? notes : 'No notes.'}</Text>

<HStack mt="auto">
Expand Down
3 changes: 3 additions & 0 deletions src/components/Events/Events.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Grid } from '@chakra-ui/react';

const Events = ({ eventData }) => {

// console.log("Event Data", eventData);

const formatDate = (date) => {
let time = date.split(":");
let hours = time[0];
Expand Down Expand Up @@ -72,6 +74,7 @@ const Events = ({ eventData }) => {
eventTitle={item.title}
description={item.description}
confirmed={item.confirmed}
eventId={item.eventId}
/>
))}
</Grid>
Expand Down
35 changes: 30 additions & 5 deletions src/components/Events/PublishedScheduleTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ import PropTypes from 'prop-types';
import { useEffect, useState } from 'react';
import { Table, Thead, Tbody, Tr, Th, Td, TableContainer, Box, IconButton, useDisclosure } from '@chakra-ui/react';
import AddDayModal from '../../pages/PublishedSchedule/AddDayModal.jsx'
import StatModal from '../../pages/PublishedSchedule/StatisticsModal.jsx';
import { AddIcon } from '@chakra-ui/icons';
import { IoStatsChart } from "react-icons/io5";
import { useAuthContext } from '../../common/AuthContext.jsx';
import AUTH_ROLES from '../../utils/auth_config.js';
const { ADMIN_ROLE } = AUTH_ROLES.AUTH_ROLES;


const PublishedScheduleTable = ({ season }) => {
const PublishedScheduleTable = ({ season, allSeasons }) => {
const {currentUser} = useAuthContext();

const [eventsInDay, setEventsInDay] = useState([]);
const seasonType = season.split(' ')[0];
const seasonYear = season.split(' ')[1];
const [dataShouldRevalidate, setShouldDataRevalidate] = useState(false);
const { isOpen: isOpenDay, onOpen: onOpenDay, onClose: onCloseDay } = useDisclosure();
const { isOpen: isOpenStats, onOpen: onOpenStats, onClose: onCloseStats } = useDisclosure();

const renderTable = async () => {
const { data } = await NPOBackend.get(
Expand Down Expand Up @@ -58,6 +60,24 @@ const PublishedScheduleTable = ({ season }) => {
return (
<Box>
{currentUser.type === ADMIN_ROLE &&
<>
<IconButton
bgColor="grey.700"
color="blue.700"
borderRadius="10rem"
position="fixed"
bottom="6rem"
right={{ base: '1rem', lg: '2rem', xl: '3rem' }}
fontSize="1.25rem"
w="3.25rem"
h="3.25rem"
_hover={{ bgColor: 'blue.500' }}
onClick={onOpenStats}
icon={<IoStatsChart />}
>
Stats
</IconButton>

<IconButton
bgColor="blue.700"
color="gray.50"
Expand All @@ -66,19 +86,23 @@ const PublishedScheduleTable = ({ season }) => {
bottom="2rem"
right={{ base: '1rem', lg: '2rem', xl: '3rem' }}
fontSize="0.75rem"
w="3rem"
h="3rem"
w="3.25rem"
h="3.25rem"
_hover={{ bgColor: 'blue.500' }}
onClick={onOpenDay}
icon={<AddIcon />}
>
Create
</IconButton>
</>
}

<AddDayModal isOpenDay={isOpenDay} onCloseDay={onCloseDay} setShouldDataRevalidate={setShouldDataRevalidate}/>
{ season && allSeasons &&
<StatModal isOpen={isOpenStats} onClose={onCloseStats} season={season} allSeasons={allSeasons}/>
}

<TableContainer borderWidth={1} borderRadius="10px">
<TableContainer borderWidth={1} borderRadius="10px" mr="2rem">
<Table variant="simple">
<Thead>
<Tr>
Expand Down Expand Up @@ -115,6 +139,7 @@ const PublishedScheduleTable = ({ season }) => {

PublishedScheduleTable.propTypes = {
season: PropTypes.string.isRequired,
allSeasons: PropTypes.array.isRequired,
};

export default PublishedScheduleTable;
57 changes: 57 additions & 0 deletions src/components/StatTable/StatTable.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.container {
display: flex;
flex-direction: column;
align-items: center;
}

.select-container {
margin-top: 20px;
margin-bottom: 20px;
display: flex;
justify-content: center;
}

.table-container {
margin-top: 20px;
margin-bottom: 20px;
border: 1px solid #e1e4e8;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.table-container th {
background-color: #0e509c;
color: white;
padding: 15px;
text-align: center;
}

.table-container tbody td {
border-bottom: 1px solid #e1e4e8;
padding: 15px;
text-align: center;
}

.table-container tbody tr:last-child td:not(:first-child) {
background-color: #f0f8ff;
color: blue;
}

.table-container tbody tr:not(:last-child) td:last-child {
background-color: #f0f8ff;
color: blue;
}

.table-container tbody tr:last-child td:last-child {
border: none;
}

.table-body tr:nth-child(even) {
background-color: #f8f9fa;
}

.table-body tr:hover {
background-color: #e2f3ff;
transition: background-color 0.3s ease;
}
100 changes: 100 additions & 0 deletions src/components/StatTable/StatTable.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { useState, useEffect } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import { NPOBackend } from '../../utils/auth_utils';
import { Box, Select } from '@chakra-ui/react';
import './StatTable.css';

const StatTable = ({ season, allSeasons }) => {
const [stats, setStats] = useState([]);
const [selectedSeason, setSelectedSeason] = useState(season);

useEffect(() => {
const fetchStats = async () => {
try {
const curSeason = selectedSeason.split(' ')[0];
const curYear = selectedSeason.split(' ')[1];
const response = await NPOBackend.get(`/published-schedule/stats?season=${curSeason.toLowerCase()}&year=${curYear}`);
const data = response.data;
setStats(data);
} catch (error) {
console.error('Error fetching statistics:', error);
}
};

fetchStats();
}, [selectedSeason]);

const transformData = () => {
const transformedData = {};

stats.forEach(stat => {
const eventType = stat.eventType;
const subject = stat.subject;
const totalCount = parseInt(stat.totalCount);

if (!transformedData[eventType]) {
transformedData[eventType] = {};
}

transformedData[eventType][subject] = totalCount;
});

return transformedData;
};

const transformedStats = transformData();

return (
<Box>
<Box mt="1rem">
<Select
textColor="black"
value={selectedSeason}
onChange={(e) => setSelectedSeason(e.target.value)}
width="max-content"
>
{allSeasons.map(item => (
<option key={item} value={item}>
{item}
</option>
))
}
</Select>
</Box>
<div className='table-container'>
<table>
<thead>
<tr>
<th>Event Type</th>
{Object.keys(transformedStats).length > 0 &&
Object.keys(transformedStats[Object.keys(transformedStats)[0]]).map(subject => (
<th key={subject} style={{ textTransform: 'capitalize' }}>{subject}</th>
))}
</tr>
</thead>
<tbody className='table-body'>
{Object.keys(transformedStats).map((eventType) => (
<React.Fragment key={eventType}>
<tr className='table-data'>
<td style={{ textTransform: 'capitalize' }}>{eventType}</td>
{Object.keys(transformedStats[eventType]).map(subject => (
<td key={`${eventType}-${subject}`} >{transformedStats[eventType][subject]}</td>
))}
</tr>
</React.Fragment>
))}
</tbody>
</table>
</div>
</Box>
);
};

StatTable.propTypes = {
season: PropTypes.string,
year: PropTypes.string,
allSeasons: PropTypes.array,
};

export default StatTable;
Loading

0 comments on commit e57d984

Please sign in to comment.