Skip to content

Commit d3964d9

Browse files
committed
#4087 Fixing ErrorPage when no teams found, renaming TeamTypeCardProps and destucturing teamTypes in Teams.tsx
1 parent fc8fec9 commit d3964d9

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

src/frontend/src/pages/GuestDivisionPage/GuestSubteamCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { TeamPreview } from 'shared';
33
import { NERButton } from '../../components/NERButton';
44
import { Link as RouterLink } from 'react-router-dom';
55

6-
interface TeamTypeCardProps {
6+
interface GuestSubteamCardProps {
77
team: TeamPreview;
88
}
99

10-
const GuestSubteamCard: React.FC<TeamTypeCardProps> = ({ team }) => {
10+
const GuestSubteamCard: React.FC<GuestSubteamCardProps> = ({ team }) => {
1111
const theme = useTheme();
1212

1313
return (

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { Box, useMediaQuery } from '@mui/system';
44
import PageLayout from '../../components/PageLayout';
55
import GuestSubteamCard from './GuestSubteamCard';
66
import { useAllTeams } from '../../hooks/teams.hooks';
7+
import { useAllTeamTypes } from '../../hooks/team-types.hooks';
8+
import { Typography } from '@mui/material';
79

810
interface GuestTeamPageProps {
911
teamTypeId: string;
@@ -12,15 +14,39 @@ interface GuestTeamPageProps {
1214
const GuestTeamPage: React.FC<GuestTeamPageProps> = ({ teamTypeId }) => {
1315
const isMobilePortrait = useMediaQuery('(max-width:480px)');
1416
const { isLoading: teamsIsLoading, isError: teamsIsError, data: allTeams, error: teamsError } = useAllTeams();
15-
const teams = allTeams?.filter((team) => team.teamType?.teamTypeId === teamTypeId);
17+
const {
18+
isLoading: teamTypesIsLoading,
19+
isError: teamTypesIsError,
20+
data: allTeamTypes,
21+
error: teamTypesError
22+
} = useAllTeamTypes();
1623

17-
if (teamsIsLoading || !teams) return <LoadingIndicator />;
24+
if (teamsIsLoading || !allTeams || teamTypesIsLoading || !allTeamTypes) return <LoadingIndicator />;
1825
if (teamsIsError) return <ErrorPage message={teamsError.message} />;
26+
if (teamTypesIsError) return <ErrorPage message={teamTypesError.message} />;
1927

20-
if (teams.length === 0) return <ErrorPage message="No teams found for this division" />;
28+
const teams = allTeams.filter((team) => team.teamType?.teamTypeId === teamTypeId);
29+
const teamTypeName = allTeamTypes.find((tt) => tt.teamTypeId === teamTypeId)?.name ?? '';
30+
31+
if (teams.length === 0) {
32+
return (
33+
<PageLayout title={teamTypeName}>
34+
<Box
35+
sx={{
36+
display: 'flex',
37+
justifyContent: 'center',
38+
alignItems: 'center',
39+
height: '70vh'
40+
}}
41+
>
42+
<Typography>No Teams found for this Division</Typography>
43+
</Box>
44+
</PageLayout>
45+
);
46+
}
2147

2248
return (
23-
<PageLayout title={teams[0].teamType!.name}>
49+
<PageLayout title={teamTypeName}>
2450
<Box
2551
sx={{
2652
display: 'grid',

src/frontend/src/pages/TeamsPage/Teams.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ import { useCurrentUser } from '../../hooks/users.hooks';
1212
import { isGuest } from 'shared';
1313
import { useAllTeamTypes } from '../../hooks/team-types.hooks';
1414
import GuestTeamPage from '../GuestDivisionPage/GuestTeamPage';
15+
import LoadingIndicator from '../../components/LoadingIndicator';
16+
import ErrorPage from '../ErrorPage';
1517

1618
const TeamOrDivisionPage: React.FC = () => {
1719
const { teamId } = useParams<{ teamId: string }>();
1820
const user = useCurrentUser();
19-
const { data: teamTypes } = useAllTeamTypes();
21+
const { isLoading: teamsLoading, isError: isTeamsError, data: teamTypes, error: teamsError } = useAllTeamTypes();
22+
23+
if (teamsLoading || !teamTypes) return <LoadingIndicator />;
24+
if (isTeamsError) return <ErrorPage message={teamsError.message} />;
2025

2126
if (isGuest(user.role) && teamTypes?.some((t) => t.teamTypeId === teamId)) {
2227
return <GuestTeamPage teamTypeId={teamId} />;

0 commit comments

Comments
 (0)