Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions apps/app/pages/invitations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[]>([]);
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -167,6 +188,7 @@ const OnBoard: NextPage = () => {
size="md"
onClick={submitInvitations}
disabled={isJoiningWorkspaces || invitationsRespond.length === 0}
loading={isJoiningWorkspaces}
>
Accept & Join
</PrimaryButton>
Expand Down