Skip to content

Commit

Permalink
Commented frontend
Browse files Browse the repository at this point in the history
Signed-off-by: Bennett-Wendorf <bennettwendorf@gmail.com>
  • Loading branch information
Bennett-Wendorf committed Dec 12, 2022
1 parent ba04d16 commit c6ff352
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 6 deletions.
1 change: 1 addition & 0 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const themeDependentContextStyle = (theme) => ({

const toolbarStyle = (theme) => theme.mixins.toolbar

// Generate the base page layout with the navdrawer
const getBasePageLayout = (useNavElements, element) => {
return (
<Box sx={rootStyle}>
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/components/AppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const readMessageStyles = (theme) => ({
color: theme.palette.text.disabled,
})

// Build the account menu component
function AccountMenu() {
const [menuAnchorEl, setMenuAnchorEl] = React.useState(null);
const menuOpen = Boolean(menuAnchorEl);
Expand Down Expand Up @@ -171,8 +172,10 @@ function AccountMenu() {
)
}

// Build the message component
function Message({ message, updateMessages, setErrorSnackbarMessage, setIsErrorSnackbarOpen, setSelectedMessage, setIsMessageDetailsDialogOpen }) {

// Toggle if a message is read or unread
const toggleMessageRead = () => {
api.put(`api/messages/${message.MessageID}`)
.then(() => {
Expand Down Expand Up @@ -227,6 +230,7 @@ function Message({ message, updateMessages, setErrorSnackbarMessage, setIsErrorS
)
}

// Build the messages menu
function MessagesMenu() {
const [menuAnchorEl, setMenuAnchorEl] = React.useState(null);
const menuOpen = Boolean(menuAnchorEl);
Expand All @@ -250,6 +254,7 @@ function MessagesMenu() {
setMenuAnchorEl(null)
}

// Delete the currently selected message
const deleteSelectedMessage = () => {
api.delete(`api/messages/${selectedMessage.MessageID}`)
.then(() => {
Expand All @@ -268,6 +273,7 @@ function MessagesMenu() {
setUnreadMessagesCount(messages.filter(m => !m.Read).length)
}, [messages])

// Obtain an updated list of messages from the API
const updateMessages = () => {
api.get("/api/messages/me")
.then((response) => {
Expand Down Expand Up @@ -334,6 +340,7 @@ function MessagesMenu() {
}
</Menu>

{/* The message details dialog */}
<Dialog open={isMessageDetailsDialogOpen} onClose={() => setIsMessageDetailsDialogOpen(false)} maxWidth={'xs'} fullWidth>
<DialogTitle>
Viewing Message
Expand Down Expand Up @@ -366,6 +373,7 @@ function MessagesMenu() {
</DialogActions>
</Dialog>

{/* The delete confirmation dialog */}
<Dialog open={isDeleteConfirmationDialogOpen} onClose={() => setIsDeleteConfirmationDialogOpen(false)}>
<DialogTitle>
Delete?
Expand All @@ -379,6 +387,7 @@ function MessagesMenu() {
</DialogActions>
</Dialog>

{/* The error snackbar */}
<Portal> {/* This shouldn't be needed, but it prevents the snackbar from rendering behind the nav drawer */}
<Snackbar open={isErrorSnackbarOpen} autoHideDuration={6000} onClose={() => setIsErrorSnackbarOpen(false)}>
<Alert onClose={() => setIsErrorSnackbarOpen(false)} severity="error" sx={{ width: '100%' }} variant="outlined">
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/components/Carousel/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import CarouselCard from "./CarouselCard"
const drawerWidth = 220
const eventListMargin = 40

/**
* The card carousel component
* @param {Object} props
*/
export default function Carousel({ events, eventClick, eventClickView }) {

/**
* A callback function that is used to add a wheel event listener to the image list
*/
const scrollRef = useCallback(node => {
if (node !== null) {
const onWheel = (e) => {
Expand All @@ -29,6 +37,7 @@ export default function Carousel({ events, eventClick, eventClickView }) {

const [paperWidth, setPaperWidth] = useState(window.innerWidth - drawerWidth - eventListMargin)

// Update the paper width when the window is resized
useEffect(() => {
function handleWindowResize() {
setPaperWidth(window.innerWidth - drawerWidth - eventListMargin)
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Carousel/CarouselCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const dividerStyles = {
mb: 1.75
}

// A card component for the carousel
export default function CarouselCard({ event, eventClick, eventClickView }) {

const userIsAdmin = AuthService.useHasPermissions(["Administrator"])
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/components/Event/ModifyEventDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default function ModifyEventDialog(props) {
setModifyStates(selectedEvent)
}, [selectedEvent])

// Set up pieces of state for modifying an event
const setModifyStates = (event) => {
setUpdateSummary(event.Summary ?? defaultUpdateSummary)
setUpdateDescription(event.Description ?? defaultUpdateDescription)
Expand Down Expand Up @@ -159,6 +160,7 @@ export default function ModifyEventDialog(props) {

const addRole = useUserStore(state => state.addRole)

// Handle adding a volunteer role to the user if they attempt to volunteer for an event without being a volunteer
const handleAddVolunteerRole = () => {
api.post('/api/users/role', {
roles: ["Volunteer"]
Expand All @@ -177,6 +179,7 @@ export default function ModifyEventDialog(props) {
})
}

// Handle adding a donor role to the user if they attempt to donate to an event without being a donor
const handleAddDonorRole = () => {
api.post('/api/users/role', {
roles: ["Donor"]
Expand Down Expand Up @@ -260,6 +263,7 @@ export default function ModifyEventDialog(props) {
}
}

// Complete the volunteer process
const completeVolunteer = async () => {
await api.post(`/api/events/${selectedEvent.EventID}/volunteer`)
.then(response => {
Expand All @@ -273,6 +277,7 @@ export default function ModifyEventDialog(props) {
})
}

// Handle canceling a volunteer slot
const handleCancelVolunteer = () => {
api.delete(`/api/events/${selectedEvent.EventID}/volunteer`)
.then(response => {
Expand All @@ -298,6 +303,7 @@ export default function ModifyEventDialog(props) {
}
}

// Complete the donation process
const completeDonate = async () => {
let newDonation = {
amount: donationAmount
Expand All @@ -315,6 +321,7 @@ export default function ModifyEventDialog(props) {
})
}

// Update the list of donations for the selected event
const updateEventDonations = async (event) => {
return api.get(`/api/events/${event.EventID}/donations`)
.then(response => {
Expand Down Expand Up @@ -846,6 +853,7 @@ export default function ModifyEventDialog(props) {
</DialogActions>
</Dialog >

{/* The success snackbar */}
<Snackbar open={isActionSuccessOpen} autoHideDuration={6000} onClose={() => setIsActionSuccessOpen(false)}>
<Alert onClose={() => setIsActionSuccessOpen(false)} severity="success" sx={{ width: '100%' }} variant="outlined">
{actionSuccessMessage}
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/Program/Programs.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default function Programs({ selectedEvent, open, onClose }) {

const [selectedProgram, setSelectedProgram] = useState({});

// Handle the submission of the add program form
const handleAddProgramSubmit = () => {
api.post(`/api/events/${selectedEvent.EventID}/programs`, {
summary: newProgramSummary,
Expand Down Expand Up @@ -81,6 +82,7 @@ export default function Programs({ selectedEvent, open, onClose }) {
}

// TODO: Handle errors better here if they are on certain fields
// Handle the submission of the update program form
const handleUpdateProgramSubmit = () => {
api.put(`/api/events/${selectedEvent.EventID}/programs/${selectedProgram.ProgramID}`, {
summary: updateProgramSummary,
Expand Down Expand Up @@ -121,6 +123,7 @@ export default function Programs({ selectedEvent, open, onClose }) {
setUpdateProgramError(false);
}

// Handle the deletion of a program
const handleDelete = () => {
api.delete(`/api/events/${selectedEvent.EventID}/programs/${selectedProgram.ProgramID}`)
.then(res => {
Expand Down Expand Up @@ -342,6 +345,7 @@ export default function Programs({ selectedEvent, open, onClose }) {
</DialogActions>
</Dialog >

{/* Snackbar for success */}
<Snackbar open={isSuccessSnackbarOpen} autoHideDuration={6000} onClose={() => setIsSuccessSnackbarOpen(false)}>
<Alert onClose={() => setIsSuccessSnackbarOpen(false)} severity="success" sx={{ width: '100%' }} variant='outlined'>
{successSnackbarMessage}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/Statistics/DateRangeDonationsGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default function DateRangeDonationsGraph() {

const [paperWidth, setPaperWidth] = useState(window.innerWidth - drawerWidth - eventListMargin)

// Update the paper width when the window is resized
useEffect(() => {
function handleWindowResize() {
setPaperWidth(window.innerWidth - drawerWidth - eventListMargin)
Expand All @@ -101,6 +102,7 @@ export default function DateRangeDonationsGraph() {
};
}, [])

// Convert the data retrieved from the api into useable data for the graph by grouping totals for each day
const convertToDailyAmounts = (data, startDate, endDate) => {
const dailyAmounts = []

Expand Down Expand Up @@ -132,6 +134,7 @@ export default function DateRangeDonationsGraph() {
return dailyAmounts
}

// Update the graph data when the start or end date is changed
const updateDonations = () => {
api.get('/api/donations', { params: { startDate: startDate.toISOString(), endDate: endDate.toISOString() } })
.then(response => {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/Dashboard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function Dashboard() {
setIsModifyDialogOpen(true)
}

// Handle opening the view dialog when an event is selected
const handleEventClickView = async (event) => {
setSelectedEvent(event)
checkIfVolunteered(event)
Expand All @@ -65,6 +66,7 @@ export function Dashboard() {
})
}

// Check if the user has volunteered for the event
const checkIfVolunteered = async (event) => {
return api.get(`/api/events/${event.EventID}/volunteer`)
.then(response => {
Expand All @@ -76,6 +78,7 @@ export function Dashboard() {
)
}

// Check if the user has donated to the event
const checkIfDonated = async (event) => {
return api.get(`/api/events/${event.EventID}/donate`)
.then(response => {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/pages/Events/EventTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function EventTable({ rows, eventUpdate }) {
setIsModifyDialogOpen(true)
}

// Handle a row click by setting state as needed
const handleRowClickView = async (event) => {
setSelectedEvent(event)
checkIfVolunteered(event)
Expand All @@ -81,6 +82,7 @@ export function EventTable({ rows, eventUpdate }) {
})
}

// Check if the current user has volunteered
const checkIfVolunteered = async (event) => {
return api.get(`/api/events/${event.EventID}/volunteer`)
.then(response => {
Expand All @@ -92,6 +94,7 @@ export function EventTable({ rows, eventUpdate }) {
)
}

// Check if the current user has donated
const checkIfDonated = async (event) => {
return api.get(`/api/events/${event.EventID}/donate`)
.then(response => {
Expand All @@ -104,6 +107,7 @@ export function EventTable({ rows, eventUpdate }) {

const [containerHeight, setContainerHeight] = useState(window.innerHeight - barHeight - margin)

// Update the container height when the window is resized
useEffect(() => {
function handleWindowResize() {
setContainerHeight(window.innerHeight - barHeight - margin)
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function Login() {

const navigate = useNavigate()

// Handle the submission of a login form
const handleSubmit = (event) => {
event.preventDefault()
const data = new FormData(event.currentTarget)
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/Login/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function Register() {

const navigate = useNavigate()

// Handle the submission of a registration form
const handleSubmit = (event) => {
event.preventDefault()
resetErrors()
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/pages/Users/UserAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function UserAdvanced() {

const userIsAdmin = AuthService.useHasPermissions(["Administrator"])

// Handle the deletion of a user
const handleDelete = (user) => {
api.delete(`/api/users/${user.UserID}`)
.then(res => {
Expand All @@ -92,6 +93,7 @@ export function UserAdvanced() {
})
}

// Handle the restoration of a user
const handleRestore = (user) => {
api.put(`/api/users/${user.UserID}`)
.then(res => {
Expand All @@ -109,6 +111,7 @@ export function UserAdvanced() {
})
}

// Update the user data
const updateUser = async () => {
api.get(`/api/users/${id}`)
.then((res) => {
Expand Down Expand Up @@ -141,6 +144,7 @@ export function UserAdvanced() {

const [containerHeight, setContainerHeight] = useState(window.innerHeight - barHeight - margin - userInfoCardHeight)

// Update the container height when the window is resized
useEffect(() => {
function handleWindowResize() {
setContainerHeight(window.innerHeight - barHeight - margin - userInfoCardHeight)
Expand All @@ -157,6 +161,7 @@ export function UserAdvanced() {

return (
<>
{/* Generate the bar for this page */}
<Bar title={`User: ${user.FullName ?? "N/A"}`}>
{user?.Active ?
<Tooltip title="Delete User">
Expand Down Expand Up @@ -344,6 +349,7 @@ export function UserAdvanced() {
</Grid2>
</>}

{/* Create the dialog for confirming user deletion */}
<Dialog open={isDeleteConfirmationDialogOpen} onClose={() => setIsDeleteConfirmationDialogOpen(false)}>
<DialogTitle>
<Typography variant="h6" component="h2">
Expand All @@ -366,6 +372,7 @@ export function UserAdvanced() {
</DialogActions>
</Dialog>

{/* Create the dialog for confirming user restoration */}
<Dialog open={isRestoreConfirmationDialogOpen} onClose={() => setIsRestoreConfirmationDialogOpen(false)}>
<DialogTitle>
<Typography variant="h6" component="h2">
Expand All @@ -383,6 +390,7 @@ export function UserAdvanced() {
</DialogActions>
</Dialog>

{/* Create the alert snackbar */}
<Snackbar open={isSnackbarOpen} autoHideDuration={6000} onClose={() => setIsSnackbarOpen(false)}>
<Alert onClose={() => setIsSnackbarOpen(false)} severity={snackbarError ? "error" : "success"} sx={{ width: '100%' }} variant='outlined'>
{snackbarMessage}
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/pages/Users/UserTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { useState, useEffect } from "react";
import { useNavigate } from "react-router-dom";

// Import utilities and components
import api from "../../utils/api";
import AuthService from '../../services/auth.service'

// Import general mui stuff
Expand All @@ -17,7 +16,6 @@ import {
Paper,
Typography,
Tooltip,
IconButton,
} from '@mui/material';
import Grid2 from '@mui/material/Unstable_Grid2'

Expand Down
5 changes: 1 addition & 4 deletions frontend/src/pages/Users/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ import AuthService from '../../services/auth.service';
import UserTable from './UserTable';

// Import general mui stuff
import { Button, IconButton, Tooltip, Grid, Alert } from '@mui/material';
import { IconButton, Tooltip } from '@mui/material';

// Import icons from mui
import AddIcon from '@mui/icons-material/AddCircle'

// Import dialog stuff from mui
import { TextField, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle } from '@mui/material';

export function Users() {
const [users, setUsers] = useState([]);
const [unauthorizedError, setUnauthorizedError] = useState(false);
Expand Down
Loading

0 comments on commit c6ff352

Please sign in to comment.