Skip to content

Commit 1173c25

Browse files
committed
#2131 - hook up getAllTeamTypes
1 parent 00280db commit 1173c25

11 files changed

Lines changed: 309 additions & 210 deletions

File tree

src/backend/src/controllers/design-reviews.controllers.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ export default class DesignReviewsController {
1313
}
1414
}
1515

16+
static async getAllTeamTypes(req: Request, res: Response, next: NextFunction) {
17+
try {
18+
const teamTypes = await DesignReviewsService.getAllTeamTypes();
19+
return res.status(200).json(teamTypes);
20+
} catch (error: unknown) {
21+
next(error);
22+
}
23+
}
24+
1625
static async deleteDesignReview(req: Request, res: Response, next: NextFunction) {
1726
try {
1827
const drId: string = req.params.designReviewId;

src/backend/src/routes/design-reviews.routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const designReviewsRouter = express.Router();
77

88
designReviewsRouter.get('/', DesignReviewsController.getAllDesignReviews);
99

10+
designReviewsRouter.get('/teamType/all', DesignReviewsController.getAllTeamTypes);
11+
1012
designReviewsRouter.delete('/:designReviewId/delete', DesignReviewsController.deleteDesignReview);
1113
designReviewsRouter.get('/:designReviewId', DesignReviewsController.getSingleDesignReview);
1214

src/backend/src/services/design-reviews.services.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Design_Review_Status, User } from '@prisma/client';
2-
import { DesignReview, WbsNumber, isAdmin, isLeadership, isNotLeadership } from 'shared';
2+
import { DesignReview, TeamType, WbsNumber, isAdmin, isLeadership, isNotLeadership } from 'shared';
33
import prisma from '../prisma/prisma';
44
import {
55
NotFoundException,
@@ -27,6 +27,11 @@ export default class DesignReviewsService {
2727
return designReviews.map(designReviewTransformer);
2828
}
2929

30+
static async getAllTeamTypes(): Promise<TeamType[]> {
31+
const teamTypes = await prisma.teamType.findMany();
32+
return teamTypes;
33+
}
34+
3035
/**
3136
* Deletes a design review
3237
* @param submitter the user who deleted the design review

src/frontend/src/apis/design-reviews.api.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import axios from 'axios';
1+
/*
2+
* This file is part of NER's FinishLine and licensed under GNU AGPLv3.
3+
* See the LICENSE file in the repository root folder for details.
4+
*/
5+
import axios from '../utils/axios';
26
import { DesignReview } from 'shared';
37
import { apiUrls } from '../utils/urls';
48
import { CreateDesignReviewsPayload } from '../hooks/design-reviews.hooks';
@@ -19,3 +23,12 @@ export const getAllDesignReviews = () => {
1923
transformResponse: (data) => JSON.parse(data)
2024
});
2125
};
26+
27+
/**
28+
* Gets all the team types
29+
*/
30+
export const getAllTeamTypes = () => {
31+
return axios.get(apiUrls.teamTypes(), {
32+
transformResponse: (data) => JSON.parse(data)
33+
});
34+
};

src/frontend/src/components/DesignReviewCreateModal.tsx

Lines changed: 0 additions & 176 deletions
This file was deleted.

src/frontend/src/hooks/design-reviews.hooks.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
/*
2+
* This file is part of NER's FinishLine and licensed under GNU AGPLv3.
3+
* See the LICENSE file in the repository root folder for details.
4+
*/
15
import { useMutation, useQuery, useQueryClient } from 'react-query';
2-
import { DesignReview, WbsNumber } from 'shared';
3-
import { createDesignReviews, getAllDesignReviews } from '../apis/design-reviews.api';
6+
import { DesignReview, TeamType, WbsNumber } from 'shared';
7+
import { createDesignReviews, getAllDesignReviews, getAllTeamTypes } from '../apis/design-reviews.api';
48

59
export interface CreateDesignReviewsPayload {
610
dateScheduled: Date;
@@ -43,3 +47,15 @@ export const useAllDesignReviews = () => {
4347
return data;
4448
});
4549
};
50+
51+
/**
52+
* Custom react hook to get all team types
53+
*
54+
* @returns all the team types
55+
*/
56+
export const useAllTeamTypes = () => {
57+
return useQuery<TeamType[], Error>(['teamTypes'], async () => {
58+
const { data } = await getAllTeamTypes();
59+
return data;
60+
});
61+
};

src/frontend/src/pages/CalendarPage/CalendarComponents/CalendarDayCard.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Box, Card, CardContent, Grid, IconButton, Stack, Typography } from '@mui/material';
22
import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline';
3-
import { DesignReview } from 'shared';
3+
import { DesignReview, TeamType } from 'shared';
44
import { meetingStartTimePipe } from '../../../utils/pipes';
55
import ConstructionIcon from '@mui/icons-material/Construction';
66
import WorkOutlineIcon from '@mui/icons-material/WorkOutline';
77
import ElectricalServicesIcon from '@mui/icons-material/ElectricalServices';
88
import TerminalIcon from '@mui/icons-material/Terminal';
99
import { useState } from 'react';
1010
import DRCSummaryModal from '../DesignReviewSummaryModal';
11+
import { DesignReviewCreateModal } from '../DesignReviewCreateModal';
1112

1213
export const getTeamTypeIcon = (teamTypeId: string, isLarge?: boolean) => {
1314
const teamIcons: Map<string, JSX.Element> = new Map([
@@ -22,13 +23,16 @@ export const getTeamTypeIcon = (teamTypeId: string, isLarge?: boolean) => {
2223
interface CalendarDayCardProps {
2324
cardDate: Date;
2425
events: DesignReview[];
26+
teamTypes: TeamType[];
2527
}
2628

27-
const CalendarDayCard: React.FC<CalendarDayCardProps> = ({ cardDate, events }) => {
29+
const CalendarDayCard: React.FC<CalendarDayCardProps> = ({ cardDate, events, teamTypes }) => {
30+
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
31+
2832
const DayCardTitle = () => (
2933
<Grid container alignItems="center" margin={0} padding={0}>
3034
<Grid item>
31-
<IconButton>
35+
<IconButton onClick={() => setIsCreateModalOpen(true)}>
3236
<AddCircleOutlineIcon fontSize="small" />
3337
</IconButton>
3438
</Grid>
@@ -74,6 +78,13 @@ const CalendarDayCard: React.FC<CalendarDayCardProps> = ({ cardDate, events }) =
7478

7579
return (
7680
<Card sx={{ borderRadius: 2, minWidth: 150, maxWidth: 150, minHeight: 90, maxHeight: 90 }}>
81+
<DesignReviewCreateModal
82+
showModal={isCreateModalOpen}
83+
handleClose={() => {
84+
setIsCreateModalOpen(false);
85+
}}
86+
teamTypes={teamTypes}
87+
/>
7788
<CardContent sx={{ padding: 0 }}>
7889
<DayCardTitle />
7990
{events.length < 3 ? (

src/frontend/src/pages/CalendarPage/CalendarPage.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ import {
1818
testDesignReview1
1919
} from '../../utils/design-review.utils';
2020
import ActionsMenu from '../../components/ActionsMenu';
21+
import { useAllTeamTypes } from '../../hooks/design-reviews.hooks';
22+
import LoadingIndicator from '../../components/LoadingIndicator';
23+
import ErrorPage from '../ErrorPage';
2124

2225
const CalendarPage = () => {
2326
const theme = useTheme();
27+
const { data, isLoading, isError, error } = useAllTeamTypes();
2428

2529
const [displayMonthYear, setDisplayMonthYear] = useState<Date>(new Date());
2630

@@ -67,6 +71,9 @@ const CalendarPage = () => {
6771
</ActionsMenu>
6872
);
6973

74+
if (!data || isLoading) return <LoadingIndicator />;
75+
if (isError) return <ErrorPage error={error} message={error?.message} />;
76+
7077
return (
7178
<PageLayout
7279
title="Design Review Calendar"
@@ -98,7 +105,11 @@ const CalendarPage = () => {
98105
{isDayInDifferentMonth(day, week) ? (
99106
<FillerCalendarDayCard day={day} />
100107
) : (
101-
<CalendarDayCard cardDate={cardDate} events={EventDict.get(cardDate.getDate()) ?? []} />
108+
<CalendarDayCard
109+
cardDate={cardDate}
110+
events={EventDict.get(cardDate.getDate()) ?? []}
111+
teamTypes={data}
112+
/>
102113
)}
103114
</Box>
104115
</Grid>

0 commit comments

Comments
 (0)