Skip to content

Commit

Permalink
fix(team): error null-properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jonassimoen committed Oct 22, 2023
1 parent 645a619 commit e8f420a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/pages/Team/Team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export const _Team = (props: AbstractTeamType) => {
}, [clubsSuccess, teamSuccess, matchesSuccess, deadlineInfoSuccess]);

const getTeamInfo = (weekId: number) => {
if(!teamResult) {
return;
}
const playerProps = ["id", "name", "short", "positionId", "clubId", "value", "ban", "injury", "form", "forename", "surname", "points", "portraitUrl", "externalId"];
const selectionProps: any[] = [];
const starting = teamResult.players.filter((p: Player) => p.selection?.starting === 1)
Expand All @@ -62,7 +65,7 @@ export const _Team = (props: AbstractTeamType) => {
return Object.assign({ inStarting: false, upcomingMatches: displayWeekMatches }, pick(p, playerProps), pick(p.selection, selectionProps));
});

const teamName = teamResult.team.name;
const teamName = teamResult.team?.name;
const captainPlayer = teamResult.players.find((p: Player) => p && p.selection && p.selection.captain === 1);
const captainId = captainPlayer && captainPlayer.id;

Expand All @@ -72,7 +75,7 @@ export const _Team = (props: AbstractTeamType) => {
const budget = teamResult.players.reduce((acc: any, player: Player) => acc - player.value, application.competition.budget);
// const boosters = undefined; // todo

const isTeamOwner = !!(teamResult.team.userId === user?.id);
const isTeamOwner = !!(teamResult.team?.userId === user?.id);

props.initTeamState(starting, bench, teamName, budget, captainId, viceCaptainId, true);
};
Expand Down

0 comments on commit e8f420a

Please sign in to comment.