From f9cd1b13527045a18bc3627cedf5242179989eda Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Wed, 7 Jun 2023 13:18:45 +0530 Subject: [PATCH] fix: last workspace id (#1237) --- apps/app/pages/onboarding.tsx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/app/pages/onboarding.tsx b/apps/app/pages/onboarding.tsx index db056cf5c..285071b1a 100644 --- a/apps/app/pages/onboarding.tsx +++ b/apps/app/pages/onboarding.tsx @@ -39,7 +39,7 @@ const Onboarding: NextPage = () => { const router = useRouter(); - const { user } = useUserAuth("onboarding"); + const { user, mutateUser } = useUserAuth("onboarding"); return ( @@ -99,16 +99,24 @@ const Onboarding: NextPage = () => { ); const userWorkspaces = await workspaceService.userWorkspaces(); - const lastActiveWorkspace = userWorkspaces.find( - (workspace) => workspace.id === user?.last_workspace_id - ); + const lastActiveWorkspace = + userWorkspaces.find( + (workspace) => workspace.id === user?.last_workspace_id + ) ?? userWorkspaces[0]; if (lastActiveWorkspace) { + userService + .updateUser({ + last_workspace_id: lastActiveWorkspace.id, + }) + .then((res) => { + mutateUser(); + }) + .catch((err) => { + console.log(err); + }); Router.push(`/${lastActiveWorkspace.slug}`); return; - } else if (userWorkspaces.length > 0) { - Router.push(`/${userWorkspaces[0].slug}`); - return; } else { const invitations = await workspaceService.userWorkspaceInvitations(); if (invitations.length > 0) {