From 6539a7a69f7c3d91b46cdc8d090d39a1e512691f Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Mon, 5 Aug 2024 12:56:02 +0700 Subject: [PATCH] Only leave form if API request succeeded If the "Ask to join" request failed for any reason, we don't want to navigate away from the form. --- .../routes/(authenticated)/project/create/+page.svelte | 10 ++++++---- .../src/routes/(authenticated)/project/create/+page.ts | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/src/routes/(authenticated)/project/create/+page.svelte b/frontend/src/routes/(authenticated)/project/create/+page.svelte index eab5f7f54..acbaa9cf1 100644 --- a/frontend/src/routes/(authenticated)/project/create/+page.svelte +++ b/frontend/src/routes/(authenticated)/project/create/+page.svelte @@ -172,10 +172,12 @@ let showRelatedProjects = true; async function askToJoinProject(projectId: string, projectName: string): Promise { - await _askToJoinProject(projectId); - notifySuccess($t('project.create.join_request_sent', { projectName })) - $tainted = undefined; // Prevent "are you sure you want to leave?" warning - await goto('/'); + const joinResult = await _askToJoinProject(projectId); + if (!joinResult.error) { + notifySuccess($t('project.create.join_request_sent', { projectName })) + $tainted = undefined; // Prevent "are you sure you want to leave?" warning + await goto('/'); + } } diff --git a/frontend/src/routes/(authenticated)/project/create/+page.ts b/frontend/src/routes/(authenticated)/project/create/+page.ts index 0c72cf0d7..18a413224 100644 --- a/frontend/src/routes/(authenticated)/project/create/+page.ts +++ b/frontend/src/routes/(authenticated)/project/create/+page.ts @@ -127,5 +127,4 @@ export async function _askToJoinProject(projectId: string): $OpResult