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 { user } = useUserAuth("onboarding");
const { user, mutateUser } = useUserAuth("onboarding");
return (
<UserAuthorizationLayout>
@ -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) {