From a61e8370b5d12d7f4e9e16157599c90c8aba3129 Mon Sep 17 00:00:00 2001 From: sriram veeraghanta Date: Mon, 28 Aug 2023 13:25:09 +0530 Subject: [PATCH] fix: workspace accepted invitation redirects to the workspace (#1971) * fix: workspace accepted invitation redirects to the workspace * chore: removing logs * fix: updating user last workspace id with newly joined one * adding error toast --- apps/app/pages/invitations.tsx | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/apps/app/pages/invitations.tsx b/apps/app/pages/invitations.tsx index 34aeca8f3..8e823b450 100644 --- a/apps/app/pages/invitations.tsx +++ b/apps/app/pages/invitations.tsx @@ -33,6 +33,7 @@ import type { IWorkspaceMemberInvitation } from "types"; import { USER_WORKSPACE_INVITATIONS } from "constants/fetch-keys"; // constants import { ROLE } from "constants/workspace"; +import userService from "services/user.service"; const OnBoard: NextPage = () => { const [invitationsRespond, setInvitationsRespond] = useState([]); @@ -78,12 +79,32 @@ const OnBoard: NextPage = () => { workspaceService .joinWorkspaces({ invitations: invitationsRespond }) .then(() => { - mutateInvitations(); mutate("USER_WORKSPACES"); - - setIsJoiningWorkspaces(false); + const firstInviteId = invitationsRespond[0]; + const redirectWorkspace = invitations?.find((i) => i.id === firstInviteId)?.workspace; + userService + .updateUser({ last_workspace_id: redirectWorkspace?.id }) + .then(() => { + setIsJoiningWorkspaces(false); + router.push(`/${redirectWorkspace?.slug}`); + }) + .catch(() => { + setToastAlert({ + type: "error", + title: "Error!", + message: "Something went wrong, Please try again.", + }); + setIsJoiningWorkspaces(false); + }); }) - .catch(() => setIsJoiningWorkspaces(false)); + .catch(() => { + setToastAlert({ + type: "error", + title: "Error!", + message: "Something went wrong, Please try again.", + }); + setIsJoiningWorkspaces(false); + }); }; return ( @@ -167,6 +188,7 @@ const OnBoard: NextPage = () => { size="md" onClick={submitInvitations} disabled={isJoiningWorkspaces || invitationsRespond.length === 0} + loading={isJoiningWorkspaces} > Accept & Join