|
| 1 | +import LoadingIndicator from '../../components/LoadingIndicator'; |
| 2 | +import ErrorPage from '../ErrorPage'; |
| 3 | +import { alpha, Box, useMediaQuery, useTheme } from '@mui/system'; |
| 4 | +import PageLayout from '../../components/PageLayout'; |
| 5 | +import { useAllTeamTypes } from '../../hooks/team-types.hooks'; |
| 6 | +import { Chip, Typography } from '@mui/material'; |
| 7 | +import { useState } from 'react'; |
| 8 | +import { useAllChangeRequests } from '../../hooks/change-requests.hooks'; |
| 9 | +import { ChangeRequest, wbsPipe } from 'shared'; |
| 10 | +import { ChangeRequestTypeTextPipe, ChangeRequestStatusTextPipe } from '../../utils/enum-pipes'; |
| 11 | + |
| 12 | +const CrCard = ({ cr }: { cr: ChangeRequest }) => { |
| 13 | + const theme = useTheme(); |
| 14 | + |
| 15 | + const submitterName = |
| 16 | + cr.submitter?.firstName && cr.submitter?.lastName ? `${cr.submitter.firstName} ${cr.submitter.lastName}` : 'N/A'; |
| 17 | + const reviewerName = |
| 18 | + cr.reviewer?.firstName && cr.reviewer?.lastName ? `${cr.reviewer.firstName} ${cr.reviewer.lastName}` : 'N/A'; |
| 19 | + |
| 20 | + return ( |
| 21 | + <Box |
| 22 | + sx={{ |
| 23 | + display: 'flex', |
| 24 | + flexDirection: 'column', |
| 25 | + gap: 0.5, |
| 26 | + p: 2, |
| 27 | + mb: 1, |
| 28 | + backgroundColor: theme.palette.background.paper, |
| 29 | + width: '100%', |
| 30 | + borderRadius: 1 |
| 31 | + }} |
| 32 | + > |
| 33 | + <Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}> |
| 34 | + <Typography fontWeight="bold" fontSize={18}> |
| 35 | + CR #{cr.identifier.toLocaleString()} |
| 36 | + </Typography> |
| 37 | + <Chip |
| 38 | + size="small" |
| 39 | + variant="filled" |
| 40 | + sx={{ |
| 41 | + fontSize: 12, |
| 42 | + bgcolor: alpha(theme.palette.primary.main, 0.45), |
| 43 | + color: theme.palette.primary.light |
| 44 | + }} |
| 45 | + label={ChangeRequestStatusTextPipe(cr.status)} |
| 46 | + /> |
| 47 | + </Box> |
| 48 | + <Typography fontSize={12} color="text.secondary"> |
| 49 | + Submitter: {submitterName} {' · '} Reviewer: {reviewerName} |
| 50 | + </Typography> |
| 51 | + <Typography fontSize={12} color="text.secondary"> |
| 52 | + {cr.wbsNum ? `${wbsPipe(cr.wbsNum)} - ` : ''} |
| 53 | + {cr.wbsName ? `${cr.wbsName} · ` : ''} |
| 54 | + {ChangeRequestTypeTextPipe(cr.type)} |
| 55 | + </Typography> |
| 56 | + </Box> |
| 57 | + ); |
| 58 | +}; |
| 59 | + |
| 60 | +const GuestChangeRequestsPage: React.FC = () => { |
| 61 | + const { data: allCrs, isLoading, isError, error } = useAllChangeRequests(); |
| 62 | + const [selectedTeamTypes, setSelectedTeamTypes] = useState<string[]>([]); |
| 63 | + const isMobilePortrait = useMediaQuery('(max-width:480px)'); |
| 64 | + const { |
| 65 | + isLoading: teamTypesIsLoading, |
| 66 | + isError: teamTypesIsError, |
| 67 | + data: teamTypes, |
| 68 | + error: teamTypesError |
| 69 | + } = useAllTeamTypes(); |
| 70 | + |
| 71 | + if (isLoading || !allCrs || teamTypesIsLoading || !teamTypes) return <LoadingIndicator />; |
| 72 | + if (isError) return <ErrorPage message={error.message} />; |
| 73 | + if (teamTypesIsError) return <ErrorPage message={teamTypesError.message} />; |
| 74 | + |
| 75 | + const filteredCrs = allCrs.filter( |
| 76 | + (cr) => selectedTeamTypes.length === 0 || cr.teamTypeNames.some((name) => selectedTeamTypes.includes(name)) |
| 77 | + ); |
| 78 | + |
| 79 | + return ( |
| 80 | + <PageLayout title="Change Requests"> |
| 81 | + <Box |
| 82 | + width={'100%'} |
| 83 | + display={'flex'} |
| 84 | + justifyContent={'center'} |
| 85 | + gap={2} |
| 86 | + mb={3} |
| 87 | + sx={{ |
| 88 | + overflowX: 'auto', |
| 89 | + pb: 1 |
| 90 | + }} |
| 91 | + > |
| 92 | + {teamTypes.map((team) => ( |
| 93 | + <Chip |
| 94 | + key={team.name} |
| 95 | + label={team.name} |
| 96 | + onClick={() => |
| 97 | + setSelectedTeamTypes((prev) => |
| 98 | + prev?.includes(team.name) ? prev.filter((t: string) => t !== team.name) : [...(prev || []), team.name] |
| 99 | + ) |
| 100 | + } |
| 101 | + clickable |
| 102 | + color={selectedTeamTypes?.includes(team.name) ? 'primary' : 'default'} |
| 103 | + sx={{ flexShrink: 0 }} |
| 104 | + /> |
| 105 | + ))} |
| 106 | + </Box> |
| 107 | + <Box |
| 108 | + sx={{ |
| 109 | + display: 'grid', |
| 110 | + gridTemplateColumns: isMobilePortrait ? '1fr' : 'repeat(3, 1fr)', |
| 111 | + gap: isMobilePortrait ? 2 : 3, |
| 112 | + width: '100%', |
| 113 | + px: isMobilePortrait ? 1 : 0 |
| 114 | + }} |
| 115 | + > |
| 116 | + {filteredCrs.map((changeRequest) => ( |
| 117 | + <CrCard cr={changeRequest} /> |
| 118 | + ))} |
| 119 | + </Box> |
| 120 | + </PageLayout> |
| 121 | + ); |
| 122 | +}; |
| 123 | + |
| 124 | +export default GuestChangeRequestsPage; |
0 commit comments