Skip to content

Commit

Permalink
alter if condition and Store fn name
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Jul 22, 2024
1 parent 19e54f7 commit b639547
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface TeamStore {
fetchCurrentTeam: () => Promise<Team>;
updateTeamTheme: (theme: Partial<TeamTheme>) => Promise<boolean>;
updateTeamSettings: (teamSettings: Partial<TeamSettings>) => Promise<boolean>;
create: (newTeam: { name: string; slug: string }) => Promise<number>;
createTeam: (newTeam: { name: string; slug: string }) => Promise<number>;
}

export const teamStore: StateCreator<
Expand Down Expand Up @@ -66,7 +66,7 @@ export const teamStore: StateCreator<
theme: get().teamTheme,
}),

create: async (newTeam) => {
createTeam: async (newTeam) => {
const { $client } = get();
const isSuccess = await $client.team.create(newTeam);
return isSuccess;
Expand Down
26 changes: 11 additions & 15 deletions editor.planx.uk/src/pages/Teams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,19 @@ const Teams: React.FC<Props> = ({ teams, teamTheme }) => {

if (newTeamName) {
const newSlug = slugify(newTeamName);
return newSlug;
}
const teamNameDuplicate = teams.find(
(team) => team.slug === newSlug,
);
if (teamNameDuplicate === undefined) {
await useStore
.getState()
.create({
const teamSlugDuplicate = teams.find(
(team) => team.slug === newSlug,
);
if (teamSlugDuplicate !== undefined) {
alert(
`A team with the name "${teamSlugDuplicate.name}" already exists. Enter a unique team name to continue.`,
);
} else {
await createTeam({
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.`,
);
}).then(() => navigation.navigate(`/${newSlug}`));
}
}
}}
>
Expand Down

0 comments on commit b639547

Please sign in to comment.