Skip to content

Commit

Permalink
alter add a new team and store method fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Jul 22, 2024
1 parent ce9e1d1 commit 19e54f7
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions editor.planx.uk/src/pages/Teams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ const TeamColourBand = styled(Box)(({ theme }) => ({
}));

const Teams: React.FC<Props> = ({ teams, teamTheme }) => {
const canUserEditTeam = useStore.getState().canUserEditTeam;
const [canUserEditTeam, createTeam] = useStore((state) => [
state.canUserEditTeam,
state.createTeam,
]);

const isPlatformAdmin = useStore.getState().getUser()?.isPlatformAdmin;

Expand Down Expand Up @@ -97,26 +100,27 @@ const Teams: React.FC<Props> = ({ teams, teamTheme }) => {

if (newTeamName) {
const newSlug = slugify(newTeamName);
const teamNameDuplicate = teams.find(
(team) => team.slug === newSlug,
return newSlug;
}
const teamNameDuplicate = teams.find(
(team) => team.slug === newSlug,
);
if (teamNameDuplicate === undefined) {
await useStore
.getState()
.create({
name: newTeamName,
slug: newSlug,
})
.then(() => navigation.navigate(`/${newSlug}`));
} else {
alert(
`A team with the name "${teamNameDuplicate.name}" already exists. Enter a unique team name to continue.`,
);
if (teamNameDuplicate === undefined) {
await useStore
.getState()
.create({
name: newTeamName,
slug: newSlug,
})
.then(() => navigation.navigate(`/${newSlug}`));
} else {
alert(
`A team with the name "${teamNameDuplicate.name}" already exists. Enter a unique team name to continue.`,
);
}
}
}}
>
Add a new Team
Add a new team
</AddButton>
) : null}
</Box>
Expand Down

0 comments on commit 19e54f7

Please sign in to comment.