-
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.
add the frontend chapter dashboard (#19)
* adding front end * updated front end routes still not working * fixing front end * adding image, changing spacing, changing font, adding box * little errors but starting to do routes * added card popup for view button * everything donegit add .git add . * to dos for the future * toggle (#16) * checkbox (#17) * toggle * toggling * checkbox * refactor entire page * merge and add filter * fix id issues * removing isAdmin for chapter dashboard routes * fixing toggle requests route * fix deleterequest route admin --------- Co-authored-by: logbrass <[email protected]> Co-authored-by: aditighoshh <[email protected]> Co-authored-by: zoegoldman <[email protected]> Co-authored-by: Caroline Chen <[email protected]> Co-authored-by: kygchng <[email protected]>
- Loading branch information
1 parent
60385d9
commit 4483af3
Showing
36 changed files
with
39,488 additions
and
132 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
2 changes: 1 addition & 1 deletion
2
client/src/AdminDashboard/api.tsx → client/src/AdminDashboard/api.ts
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
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,41 @@ | ||
import { FormControlLabel, Switch, Typography } from '@mui/material'; | ||
import { Box } from '@mui/system'; | ||
import React from 'react'; | ||
import IUser from '../util/types/user.ts'; | ||
import { putData } from '../util/api.ts'; | ||
|
||
interface IAcceptingRequestsToggleProps { | ||
chapter: IUser; | ||
} | ||
|
||
function AcceptingRequestsToggle({ chapter }: IAcceptingRequestsToggleProps) { | ||
const [checked, setChecked] = React.useState(chapter.isAcceptingRequests); | ||
const [error, setError] = React.useState<string | null>(null); | ||
|
||
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setChecked(event.target.checked); | ||
const response = await putData(`user/toggleRequests/${chapter.id}`, {}); | ||
|
||
if (response.error) { | ||
setError(response.error.message || 'An error occurred'); | ||
} | ||
}; | ||
|
||
return ( | ||
<Box> | ||
<FormControlLabel | ||
control={ | ||
<Switch checked={checked} onChange={handleChange} color="primary" /> | ||
} | ||
label={ | ||
checked | ||
? 'Currently accepting requests' | ||
: 'Not curently accepting requests' | ||
} | ||
/> | ||
{error && <Typography sx={{ color: 'red' }}>Error: {error}</Typography>} | ||
</Box> | ||
); | ||
} | ||
|
||
export default AcceptingRequestsToggle; |
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,157 @@ | ||
import { | ||
Box, | ||
Button, | ||
Checkbox, | ||
FormControl, | ||
InputLabel, | ||
Menu, | ||
MenuItem, | ||
Select, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableRow, | ||
Typography, | ||
} from '@mui/material'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { formatDate } from '../util/date.ts'; | ||
import IBirthdayRequest from '../util/types/birthdayRequest.ts'; | ||
import RequestDetailDialog from './RequestDetailDialog.tsx'; | ||
|
||
interface IActiveRequestsTableProps { | ||
activeRequests: IBirthdayRequest[]; | ||
fulfillRequest: (request: IBirthdayRequest) => void; | ||
} | ||
|
||
function ActiveRequestsTable({ | ||
activeRequests, | ||
fulfillRequest, | ||
}: IActiveRequestsTableProps) { | ||
const [open, setOpen] = useState(false); | ||
const [selectedRequest, setSelectedRequest] = useState<IBirthdayRequest>( | ||
{} as IBirthdayRequest, | ||
); | ||
|
||
const [filterMonthOptions, setFilterMonthOptions] = useState<number[][]>([]); | ||
const [filterMonth, setFilterMonth] = useState<number[] | null | undefined>( | ||
undefined, | ||
); | ||
|
||
const viewRequest = (request: IBirthdayRequest) => { | ||
setSelectedRequest(request); | ||
setOpen(true); | ||
}; | ||
|
||
useEffect(() => { | ||
const months = activeRequests | ||
.map((request) => { | ||
const date = new Date(request.childBirthday); | ||
return [date.getMonth() + 1, date.getFullYear()]; | ||
}) | ||
.filter( | ||
(value, index, self) => | ||
index === | ||
self.findIndex((t) => JSON.stringify(t) === JSON.stringify(value)), | ||
); | ||
|
||
console.log(months); | ||
|
||
setFilterMonthOptions(months); | ||
}, [activeRequests]); | ||
|
||
const filteredRequests = activeRequests.filter((request) => { | ||
if (!filterMonth) { | ||
return true; | ||
} | ||
|
||
const date = new Date(request.childBirthday); | ||
return ( | ||
date.getMonth() + 1 === filterMonth[0] && | ||
date.getFullYear() === filterMonth[1] | ||
); | ||
}); | ||
|
||
return ( | ||
<> | ||
<Box> | ||
<Typography variant="h5" fontWeight="bold" mb={1}> | ||
Active Requests | ||
</Typography> | ||
<FormControl sx={{ m: 1, minWidth: 150, color: 'black' }}> | ||
<InputLabel>Filter by month</InputLabel> | ||
<Select | ||
label="Filter by month" | ||
value={ | ||
// eslint-disable-next-line no-nested-ternary | ||
filterMonth === undefined | ||
? undefined | ||
: filterMonth | ||
? `${filterMonth[0]}/${filterMonth[1]}` | ||
: 'None' | ||
} | ||
onChange={(event) => { | ||
if (event.target.value === 'None') { | ||
setFilterMonth(null); | ||
return; | ||
} | ||
|
||
const value = (event.target.value as string).split('/'); | ||
setFilterMonth([parseInt(value[0], 10), parseInt(value[1], 10)]); | ||
}} | ||
> | ||
<MenuItem value="None"> | ||
<em>None</em> | ||
</MenuItem> | ||
{filterMonthOptions.map((month) => ( | ||
<MenuItem | ||
value={`${month[0]}/${month[1]}`} | ||
key={`${month[0]}/${month[1]}`} | ||
> | ||
{month[0]}/{month[1]} | ||
</MenuItem> | ||
))} | ||
</Select> | ||
</FormControl> | ||
<Table> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>Child Name</TableCell> | ||
<TableCell>Child Birthday</TableCell> | ||
<TableCell>Agency Name</TableCell> | ||
<TableCell>Mark Completed</TableCell> | ||
<TableCell>{}</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{filteredRequests.map((request) => ( | ||
<TableRow key={request.id}> | ||
<TableCell>{request.childName}</TableCell> | ||
<TableCell>{formatDate(request.childBirthday)}</TableCell> | ||
<TableCell>{request.agencyOrganization}</TableCell> | ||
<TableCell> | ||
<Checkbox onClick={() => fulfillRequest(request)} /> | ||
</TableCell> | ||
<TableCell> | ||
<Button | ||
variant="contained" | ||
onClick={() => viewRequest(request)} | ||
> | ||
View | ||
</Button> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</Box> | ||
<RequestDetailDialog | ||
request={selectedRequest} | ||
open={open} | ||
onClose={() => setOpen(false)} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default ActiveRequestsTable; |
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,21 @@ | ||
import { Box, Typography } from '@mui/material'; | ||
import React from 'react'; | ||
import Logo from './Logo.tsx'; | ||
import IUser from '../util/types/chapter.ts'; | ||
|
||
interface IChapterDashboardHeaderProps { | ||
chapter: IUser; | ||
} | ||
|
||
function ChapterDashboardHeader({ chapter }: IChapterDashboardHeaderProps) { | ||
return ( | ||
<Box sx={{ textAlign: 'left' }}> | ||
<Logo /> | ||
<Typography variant="h4" fontWeight="bold" mb={1}> | ||
Welcome {chapter.city}, {chapter.state}! | ||
</Typography> | ||
</Box> | ||
); | ||
} | ||
|
||
export default ChapterDashboardHeader; |
Oops, something went wrong.