Skip to content

Commit 9b047c9

Browse files
#3872 used different hook for subdivisions
1 parent c635232 commit 9b047c9

2 files changed

Lines changed: 16 additions & 42 deletions

File tree

src/backend/src/prisma/seed.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,21 +350,15 @@ const performSeed: () => Promise<void> = async () => {
350350
const mechanical = await TeamsService.createTeamType(
351351
batman,
352352
'Mechanical',
353-
'YouTubeIcon',
353+
'Construction',
354354
'This is the mechanical team',
355355
ner
356356
);
357-
const software = await TeamsService.createTeamType(
358-
thomasEmrax,
359-
'Software',
360-
'InstagramIcon',
361-
'This is the software team',
362-
ner
363-
);
357+
const software = await TeamsService.createTeamType(thomasEmrax, 'Software', 'Code', 'This is the software team', ner);
364358
const electrical = await TeamsService.createTeamType(
365359
cyborg,
366360
'Electrical',
367-
'SettingsIcon',
361+
'ElectricBolt',
368362
'This is the electrical team',
369363
ner
370364
);

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

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@ import DrawerHeader from '../../components/DrawerHeader';
2525
import { Cached, ChevronLeft, ChevronRight } from '@mui/icons-material';
2626
import { useHomePageContext } from '../../app/HomePageContext';
2727
import { isGuest, TeamType } from 'shared';
28-
import { getAllTeamTypes } from '../../apis/team-types.api';
29-
import ConstructionIcon from '@mui/icons-material/Construction';
30-
import ElectricBoltIcon from '@mui/icons-material/ElectricBolt';
31-
import CodeIcon from '@mui/icons-material/Code';
32-
import WorkIcon from '@mui/icons-material/Work';
28+
import * as MuiIcons from '@mui/icons-material';
29+
import { useAllTeamTypes } from '../../hooks/team-types.hooks';
30+
import ErrorPage from '../../pages/ErrorPage';
3331
import BarChartIcon from '@mui/icons-material/BarChart';
3432
import { useCurrentUser } from '../../hooks/users.hooks';
3533
import QueryStatsIcon from '@mui/icons-material/QueryStats';
3634
import CurrencyExchangeIcon from '@mui/icons-material/CurrencyExchange';
3735
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
38-
import { useState, useEffect } from 'react';
36+
import { useState } from 'react';
3937

4038
interface SidebarProps {
4139
drawerOpen: boolean;
@@ -49,36 +47,18 @@ const Sidebar = ({ drawerOpen, setDrawerOpen, moveContent, setMoveContent }: Sid
4947
const { onPNMHomePage, onOnboardingHomePage } = useHomePageContext();
5048
const user = useCurrentUser();
5149
const { onGuestHomePage } = useHomePageContext();
52-
const [allTeams, setAllTeams] = useState<LinkItem[]>([]);
50+
const { isError: teamsError, error: teamsErrorMsg, data: teams } = useAllTeamTypes();
5351

54-
const getIcon = (iconName: string) => {
55-
const icons: { [key: string]: React.ComponentType } = {
56-
ConstructionIcon,
57-
CodeIcon,
58-
ElectricBoltIcon,
59-
WorkIcon
52+
const allTeams: LinkItem[] = (teams ?? []).map((team: TeamType) => {
53+
const IconComponent = MuiIcons[(team.iconName in MuiIcons ? team.iconName : 'Circle') as keyof typeof MuiIcons];
54+
return {
55+
name: team.name,
56+
icon: <IconComponent />,
57+
route: routes.TEAMS + '/' + team.teamTypeId
6058
};
61-
const Icon = icons[iconName];
62-
return Icon ? <Icon /> : undefined;
63-
};
64-
65-
useEffect(() => {
66-
getAllTeamTypes()
67-
.then((response) => {
68-
console.log('All teams from API:', response.data);
69-
setAllTeams(
70-
response.data.map((team: TeamType) => ({
71-
name: team.name,
72-
icon: getIcon(team.iconName),
73-
route: routes.TEAMS + '/' + team.teamTypeId
74-
}))
75-
);
76-
})
77-
.catch((error) => {
78-
console.log("Teams couldn't load " + error);
79-
});
80-
}, []);
59+
});
8160

61+
if (teamsError) return <ErrorPage error={teamsErrorMsg} />;
8262
const memberLinkItems: LinkItem[] = [
8363
{
8464
name: 'Home',

0 commit comments

Comments
 (0)