From 5382dbd4a7ee9fb30cd778e8c6303947a69c5d4f Mon Sep 17 00:00:00 2001 From: Rory Doak <138574807+RODO94@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:34:56 +0100 Subject: [PATCH] feat: Flow Name Duplicate Validation (#3445) --- editor.planx.uk/src/pages/Team.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/editor.planx.uk/src/pages/Team.tsx b/editor.planx.uk/src/pages/Team.tsx index d3851ed023..58e0238ccf 100644 --- a/editor.planx.uk/src/pages/Team.tsx +++ b/editor.planx.uk/src/pages/Team.tsx @@ -325,12 +325,20 @@ const Team: React.FC = () => { const newFlowName = prompt("Service name"); if (newFlowName) { const newFlowSlug = slugify(newFlowName); - useStore - .getState() - .createFlow(teamId, newFlowSlug, newFlowName) - .then((newId: string) => { - navigation.navigate(`/${slug}/${newId}`); - }); + const duplicateFlowName = flows?.find( + (flow) => flow.slug === newFlowSlug, + ); + + !duplicateFlowName + ? useStore + .getState() + .createFlow(teamId, newFlowSlug, newFlowName) + .then((newId: string) => { + navigation.navigate(`/${slug}/${newId}`); + }) + : alert( + `The flow "${newFlowName}" already exists. Enter a unique flow name to continue`, + ); } }} >