generated from ctc-uci/npo-frontend-vite-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into 83-final-day-planner-adjustments
- Loading branch information
Showing
8 changed files
with
303 additions
and
15 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
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,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; | ||
} |
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,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; |
Oops, something went wrong.