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
This commit is contained in:
sriram veeraghanta 2023-08-28 13:25:09 +05:30 committed by GitHub
parent 9f420a00d7
commit a61e8370b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<string[]>([]);
@ -78,12 +79,32 @@ const OnBoard: NextPage = () => {
workspaceService
.joinWorkspaces({ invitations: invitationsRespond })
.then(() => {
mutateInvitations();
mutate("USER_WORKSPACES");
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(() => setIsJoiningWorkspaces(false));
.catch(() => {
setToastAlert({
type: "error",
title: "Error!",
message: "Something went wrong, Please try again.",
});
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
</PrimaryButton>