Skip to content

Commit aba1b0c

Browse files
committed
Adding route and hook for page
1 parent 6bc8f3a commit aba1b0c

6 files changed

Lines changed: 31 additions & 12 deletions

File tree

src/frontend/src/app/AppAuthenticated.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Settings from '../pages/SettingsPage/SettingsPage';
1313
import InfoPage from '../pages/InfoPage';
1414
import GanttChartPage from '../pages/GanttPage/ProjectGanttChart/ProjectGanttChartPage';
1515
import Teams from '../pages/TeamsPage/Teams';
16+
import GuestTeamPage from '../pages/GuestDivisionPage/GuestTeamPage';
1617
import AdminTools from '../pages/AdminToolsPage/AdminTools';
1718
import Credits from '../pages/CreditsPage/Credits';
1819
import AppContextUser from './AppContextUser';
@@ -121,6 +122,7 @@ const AppAuthenticated: React.FC<AppAuthenticatedProps> = ({ userId, userRole })
121122
<Route path={routes.CHANGE_REQUESTS} component={ChangeRequests} />
122123
<Route path={routes.GANTT} component={GanttChartPage} />
123124
<Route path={routes.TEAMS} component={Teams} />
125+
<Route path={routes.DIVISIONS_BY_ID} component={GuestTeamPage} />
124126
<Route path={routes.SETTINGS} component={Settings} />
125127
<Route path={routes.ADMIN_TOOLS} component={AdminTools} />
126128
<Route path={routes.INFO} component={InfoPage} />

src/frontend/src/hooks/teams.hooks.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,10 @@ export const useMyTeamAsHead = () => {
199199
return data;
200200
});
201201
};
202+
203+
export const useTeamsByTypeId = (teamTypeId: string) => {
204+
return useQuery<TeamPreview[], Error>(['teams', 'type', teamTypeId], async () => {
205+
const { data } = await getAllTeams();
206+
return data.filter((team) => team.teamType?.teamTypeId === teamTypeId);
207+
});
208+
};

src/frontend/src/layouts/Sidebar/Sidebar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import QueryStatsIcon from '@mui/icons-material/QueryStats';
3838
import CurrencyExchangeIcon from '@mui/icons-material/CurrencyExchange';
3939
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
4040
import { useState } from 'react';
41+
import { sub } from 'date-fns';
4142

4243
interface SidebarProps {
4344
drawerOpen: boolean;
@@ -59,7 +60,7 @@ const Sidebar = ({ drawerOpen, setDrawerOpen, moveContent, setMoveContent }: Sid
5960
return {
6061
name: team.name,
6162
icon: <IconComponent />,
62-
route: routes.TEAMS + '/' + team.teamTypeId
63+
route: routes.DIVISIONS + '/' + team.teamTypeId
6364
};
6465
});
6566

src/frontend/src/pages/GuestDivisionPage/GuestTeamPage.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,25 @@ import ErrorPage from '../ErrorPage';
33
import { Box, useMediaQuery } from '@mui/system';
44
import PageLayout from '../../components/PageLayout';
55
import GuestSubteamCard from './GuestSubteamCard';
6-
import { useAllTeams } from '../../hooks/teams.hooks';
6+
import { useTeamsByTypeId } from '../../hooks/teams.hooks';
77
import { useParams } from 'react-router-dom';
88

99
interface ParamTypes {
10-
teamId: string;
10+
teamTypeId: string;
1111
}
1212

1313
const GuestTeamPage: React.FC = () => {
1414
const isMobilePortrait = useMediaQuery('(max-width:480px)');
15-
const { teamId } = useParams<ParamTypes>();
16-
const { isLoading: teamsIsLoading, isError: teamsIsError, data: allTeams, error: teamsError } = useAllTeams();
15+
const { teamTypeId } = useParams<ParamTypes>();
16+
const { isLoading: teamsIsLoading, isError: teamsIsError, data: teams, error: teamsError } = useTeamsByTypeId(teamTypeId);
1717

18-
if (teamsIsLoading || !allTeams) return <LoadingIndicator />;
18+
if (teamsIsLoading || !teams) return <LoadingIndicator />;
1919
if (teamsIsError) return <ErrorPage message={teamsError.message} />;
2020

21-
const filteredTeams = allTeams.filter((team) => team.teamType?.teamTypeId === teamId);
22-
23-
if (filteredTeams.length === 0) return <ErrorPage message="No teams found for this division" />;
21+
if (teams.length === 0) return <ErrorPage message="No teams found for this division" />;
2422

2523
return (
26-
<PageLayout title={filteredTeams[0].teamType!.name}>
24+
<PageLayout title={teams[0].teamType!.name}>
2725
<Box
2826
sx={{
2927
display: 'grid',
@@ -33,7 +31,7 @@ const GuestTeamPage: React.FC = () => {
3331
px: isMobilePortrait ? 1 : 0
3432
}}
3533
>
36-
{filteredTeams.map((team) => (
34+
{teams.map((team) => (
3735
<GuestSubteamCard key={team.teamId} team={team} />
3836
))}
3937
</Box>

src/frontend/src/pages/TeamsPage/TeamSpecificPage.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ const TeamSpecificPage: React.FC = () => {
194194
</Box>
195195
) : null
196196
}
197-
previousPages={[{ name: 'Teams', route: routes.TEAMS }]}
197+
previousPages={
198+
isGuest(user.role) && data.teamType
199+
? [{ name: data.teamType.name, route: `${routes.DIVISIONS}/${data.teamType.teamTypeId}` }]
200+
: [{ name: 'Teams', route: routes.TEAMS }]
201+
}
198202
>
199203
<Grid container spacing={2}>
200204
<Grid item xs={12}>

src/frontend/src/utils/routes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ const PROJECT_PART = PROJECTS_BY_WBS + '/part/:indexNum';
4141
const TEAMS = `/teams`;
4242
const TEAMS_BY_ID = TEAMS + `/:teamId`;
4343

44+
/**************** Divisions Section ***************/
45+
const DIVISIONS = `/divisions`;
46+
const DIVISIONS_BY_ID = DIVISIONS + `/:teamTypeId`;
47+
4448
/**************** Change Requests Section ****************/
4549
const CHANGE_REQUESTS = `/change-requests`;
4650
const ALL_CHANGE_REQUESTS = CHANGE_REQUESTS + `/all`;
@@ -96,6 +100,9 @@ export const routes = {
96100
TEAMS,
97101
TEAMS_BY_ID,
98102

103+
DIVISIONS,
104+
DIVISIONS_BY_ID,
105+
99106
GANTT,
100107

101108
PROJECTS,

0 commit comments

Comments
 (0)