diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts index 22978de6b7..521ce4a38c 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts @@ -25,7 +25,7 @@ export interface TeamStore { fetchCurrentTeam: () => Promise; updateTeamTheme: (theme: Partial) => Promise; updateTeamSettings: (teamSettings: Partial) => Promise; - create: (newTeam: { name: string; slug: string }) => Promise; + createTeam: (newTeam: { name: string; slug: string }) => Promise; } export const teamStore: StateCreator< @@ -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; diff --git a/editor.planx.uk/src/pages/Teams.tsx b/editor.planx.uk/src/pages/Teams.tsx index b39d698a91..ef1da7b68c 100644 --- a/editor.planx.uk/src/pages/Teams.tsx +++ b/editor.planx.uk/src/pages/Teams.tsx @@ -100,23 +100,19 @@ const Teams: React.FC = ({ 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}`)); + } } }} >