|
| 1 | +import { alpha, Box, Card, CardContent, Chip, Stack, Typography, useTheme, Link } from '@mui/material'; |
| 2 | +import { wbsNamePipe, ProjectPreview, wbsPipe, WbsElementStatus } from 'shared'; |
| 3 | +import { datePipe } from '../../utils/pipes'; |
| 4 | +import { NERButton } from '../../components/NERButton'; |
| 5 | +import { useSingleProject } from '../../hooks/projects.hooks'; |
| 6 | +import LoadingIndicator from '../../components/LoadingIndicator'; |
| 7 | +import ErrorPage from '../ErrorPage'; |
| 8 | +import { Link as RouterLink } from 'react-router-dom'; |
| 9 | + |
| 10 | +interface ProjectCardProps { |
| 11 | + project: ProjectPreview; |
| 12 | +} |
| 13 | + |
| 14 | +const GuestProjectsCard: React.FC<ProjectCardProps> = ({ project }) => { |
| 15 | + const theme = useTheme(); |
| 16 | + const { data: singleProject, isLoading, isError, error } = useSingleProject(project.wbsNum); |
| 17 | + if (isError) return <ErrorPage message={error.message} />; |
| 18 | + if (isLoading || !singleProject) return <LoadingIndicator />; |
| 19 | + |
| 20 | + const activeWorkPackages = project.workPackages.filter((wp) => wp.status === WbsElementStatus.Active); |
| 21 | + |
| 22 | + return ( |
| 23 | + <Card |
| 24 | + variant="outlined" |
| 25 | + sx={{ |
| 26 | + width: '100%', |
| 27 | + height: '100%', |
| 28 | + display: 'flex', |
| 29 | + flexDirection: 'column', |
| 30 | + background: theme.palette.background.paper, |
| 31 | + borderRadius: 2 |
| 32 | + }} |
| 33 | + > |
| 34 | + <CardContent sx={{ padding: 2, display: 'flex', flexDirection: 'column', flexGrow: 1 }}> |
| 35 | + <Stack direction="row" justifyContent="space-between"> |
| 36 | + <Box width={'100%'}> |
| 37 | + <Box display="flex" justifyContent="space-between" alignItems="center"> |
| 38 | + <Typography |
| 39 | + fontWeight={'regular'} |
| 40 | + variant="h5" |
| 41 | + sx={{ marginBottom: '0.3rem', fontSize: { xs: '1.15rem', sm: '1.5rem' }, flexGrow: 1 }} |
| 42 | + > |
| 43 | + {wbsNamePipe(singleProject)} |
| 44 | + </Typography> |
| 45 | + {activeWorkPackages[0]?.stage ? ( |
| 46 | + <Chip |
| 47 | + size="medium" |
| 48 | + variant="filled" |
| 49 | + sx={{ |
| 50 | + marginLeft: 'auto', |
| 51 | + fontSize: 12, |
| 52 | + bgcolor: alpha(theme.palette.primary.main, 0.45), |
| 53 | + color: theme.palette.primary.light |
| 54 | + }} |
| 55 | + label={activeWorkPackages[0].stage} |
| 56 | + /> |
| 57 | + ) : null} |
| 58 | + </Box> |
| 59 | + <Typography fontSize={12} color="text.secondary"> |
| 60 | + Project Lead:{' '} |
| 61 | + {singleProject.lead?.firstName && singleProject.lead?.lastName |
| 62 | + ? `${singleProject.lead.firstName} ${singleProject.lead.lastName}` |
| 63 | + : 'N/A'} |
| 64 | + {' • '} |
| 65 | + Project Manager:{' '} |
| 66 | + {singleProject.manager?.firstName && singleProject.manager?.lastName |
| 67 | + ? `${singleProject.manager.firstName} ${singleProject.manager.lastName}` |
| 68 | + : 'N/A'} |
| 69 | + </Typography> |
| 70 | + <Typography fontWeight={'regular'} fontSize={{ xs: 14, sm: 16 }}> |
| 71 | + {datePipe(singleProject.startDate) + |
| 72 | + ' ⟝ ' + |
| 73 | + singleProject.duration + |
| 74 | + ' wks ⟞ ' + |
| 75 | + datePipe(singleProject.endDate)} |
| 76 | + </Typography> |
| 77 | + </Box> |
| 78 | + </Stack> |
| 79 | + <Typography |
| 80 | + sx={{ |
| 81 | + flexGrow: 1, |
| 82 | + overflow: 'hidden', |
| 83 | + textOverflow: 'ellipsis', |
| 84 | + display: '-webkit-box', |
| 85 | + WebkitLineClamp: 3, |
| 86 | + WebkitBoxOrient: 'vertical' |
| 87 | + }} |
| 88 | + > |
| 89 | + {singleProject.summary} |
| 90 | + </Typography> |
| 91 | + <Link |
| 92 | + component={RouterLink} |
| 93 | + to={`/projects/${wbsPipe(project.wbsNum)}`} |
| 94 | + sx={{ width: '100%', textDecoration: 'none' }} |
| 95 | + > |
| 96 | + <NERButton |
| 97 | + fullWidth |
| 98 | + sx={{ |
| 99 | + marginTop: 2, |
| 100 | + backgroundColor: theme.palette.error.main, |
| 101 | + color: theme.palette.error.contrastText, |
| 102 | + '&:hover': { |
| 103 | + backgroundColor: theme.palette.error.dark |
| 104 | + } |
| 105 | + }} |
| 106 | + > |
| 107 | + Learn more |
| 108 | + </NERButton> |
| 109 | + </Link> |
| 110 | + </CardContent> |
| 111 | + </Card> |
| 112 | + ); |
| 113 | +}; |
| 114 | + |
| 115 | +export default GuestProjectsCard; |
0 commit comments