fix: last workspace id (#1237)

This commit is contained in:
Anmol Singh Bhatia 2023-06-07 13:18:45 +05:30 committed by GitHub
parent 18f66805cb
commit f9cd1b1352
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,7 +39,7 @@ const Onboarding: NextPage = () => {
const router = useRouter(); const router = useRouter();
const { user } = useUserAuth("onboarding"); const { user, mutateUser } = useUserAuth("onboarding");
return ( return (
<UserAuthorizationLayout> <UserAuthorizationLayout>
@ -99,16 +99,24 @@ const Onboarding: NextPage = () => {
); );
const userWorkspaces = await workspaceService.userWorkspaces(); const userWorkspaces = await workspaceService.userWorkspaces();
const lastActiveWorkspace = userWorkspaces.find( const lastActiveWorkspace =
(workspace) => workspace.id === user?.last_workspace_id userWorkspaces.find(
); (workspace) => workspace.id === user?.last_workspace_id
) ?? userWorkspaces[0];
if (lastActiveWorkspace) { if (lastActiveWorkspace) {
userService
.updateUser({
last_workspace_id: lastActiveWorkspace.id,
})
.then((res) => {
mutateUser();
})
.catch((err) => {
console.log(err);
});
Router.push(`/${lastActiveWorkspace.slug}`); Router.push(`/${lastActiveWorkspace.slug}`);
return; return;
} else if (userWorkspaces.length > 0) {
Router.push(`/${userWorkspaces[0].slug}`);
return;
} else { } else {
const invitations = await workspaceService.userWorkspaceInvitations(); const invitations = await workspaceService.userWorkspaceInvitations();
if (invitations.length > 0) { if (invitations.length > 0) {