Skip to content

Commit c3aa601

Browse files
committed
#1565: If multiple overdue work packages, show it as one alert instead of multiple alerts
1 parent 56547e6 commit c3aa601

2 files changed

Lines changed: 57 additions & 68 deletions

File tree

src/frontend/src/pages/HomePage/OverdueWorkPackageAlert.tsx

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,69 @@
1-
import Box from '@mui/material/Box';
1+
import React from 'react';
22
import { useAllWorkPackages } from '../../hooks/work-packages.hooks';
33
import { WbsElementStatus } from 'shared';
4-
import OverdueWorkPackageAlert from './OverdueWorkPackageAlert';
54
import { useCurrentUser } from '../../hooks/users.hooks';
5+
import { useState } from 'react';
6+
import { wbsPipe } from 'shared';
7+
import { Box, Alert, IconButton, Collapse, Link, Typography, AlertTitle } from '@mui/material';
8+
import CloseIcon from '@mui/icons-material/Close';
9+
import { routes } from '../../utils/routes';
10+
import { Link as RouterLink } from 'react-router-dom';
11+
import { datePipe } from '../../utils/pipes';
612

713
const OverdueWorkPackageAlerts: React.FC = () => {
814
const user = useCurrentUser();
915
const workPackages = useAllWorkPackages({ status: WbsElementStatus.Active });
1016
const currentDate = new Date();
17+
const [open, setOpen] = useState(true);
1118

12-
return (
13-
<Box>
14-
{workPackages.data
15-
?.filter((wp) => wp.projectLead?.userId === user.userId)
16-
?.filter((wp) => new Date(wp.endDate) < currentDate)
17-
.map((wp) => (
18-
<OverdueWorkPackageAlert wp={wp} />
19-
))}
20-
</Box>
21-
);
19+
// Filter for work packages that are overdue and the user is the project lead
20+
const userOverdueWorkPackages = workPackages.data
21+
?.filter((wp) => wp.projectLead?.userId === user.userId)
22+
?.filter((wp) => new Date(wp.endDate) < currentDate);
23+
24+
// If there are no overdue work packages, don't display anything
25+
if (!userOverdueWorkPackages || userOverdueWorkPackages.length === 0) {
26+
return null;
27+
} else {
28+
return (
29+
<Box sx={{ width: '100%', my: 2 }}>
30+
<Collapse in={open}>
31+
<Alert
32+
variant="filled"
33+
severity="warning"
34+
action={
35+
<IconButton
36+
aria-label="close"
37+
color="inherit"
38+
size="small"
39+
onClick={() => {
40+
setOpen(false);
41+
}}
42+
>
43+
<CloseIcon fontSize="inherit" />
44+
</IconButton>
45+
}
46+
>
47+
<AlertTitle>
48+
{userOverdueWorkPackages.length > 1 ? 'Overdue Work Packages:' : 'Overdue Work Package:'}
49+
</AlertTitle>
50+
{userOverdueWorkPackages.map((wp) => (
51+
<React.Fragment key={wp.id}>
52+
<Link color="inherit" component={RouterLink} to={`${routes.PROJECTS}/${wbsPipe(wp.wbsNum)}`} noWrap>
53+
<Typography fontWeight={'regular'} variant="inherit">
54+
{wbsPipe(wp.wbsNum)} - {wp.name}
55+
</Typography>
56+
</Link>
57+
<Typography fontWeight={'regular'} variant="inherit" noWrap my={0.5}>
58+
{'Due: ' + datePipe(wp.endDate)}
59+
</Typography>
60+
</React.Fragment>
61+
))}
62+
</Alert>
63+
</Collapse>
64+
</Box>
65+
);
66+
}
2267
};
2368

2469
export default OverdueWorkPackageAlerts;

0 commit comments

Comments
 (0)