mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: weird redirection in index page (#801)
This commit is contained in:
parent
9196fb4562
commit
db488338fb
@ -67,19 +67,17 @@ export const WorkspaceSidebarDropdown = () => {
|
||||
};
|
||||
|
||||
const handleSignOut = async () => {
|
||||
await authenticationService
|
||||
.signOut()
|
||||
.catch(() =>
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: "Failed to sign out. Please try again.",
|
||||
})
|
||||
)
|
||||
.finally(() => {
|
||||
router.push("/signin");
|
||||
mutateUser();
|
||||
});
|
||||
router.push("/signin").then(() => {
|
||||
mutateUser();
|
||||
});
|
||||
|
||||
await authenticationService.signOut().catch(() =>
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: "Failed to sign out. Please try again.",
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -19,46 +19,55 @@ import { USER_WORKSPACE_INVITATIONS } from "constants/fetch-keys";
|
||||
const Home: NextPage = () => {
|
||||
const router = useRouter();
|
||||
|
||||
const { user } = useUser();
|
||||
const { workspaces } = useWorkspaces();
|
||||
const { user, isUserLoading } = useUser();
|
||||
const { workspaces, error: workspacesError } = useWorkspaces();
|
||||
|
||||
const lastActiveWorkspace =
|
||||
user && workspaces.find((workspace) => workspace.id === user.last_workspace_id);
|
||||
|
||||
const { data: invitations } = useSWR(USER_WORKSPACE_INVITATIONS, () =>
|
||||
const { data: invitations, error: invitationsError } = useSWR(USER_WORKSPACE_INVITATIONS, () =>
|
||||
workspaceService.userWorkspaceInvitations()
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (isUserLoading) return;
|
||||
|
||||
if (!user) {
|
||||
router.push("/signin");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.is_onboarded) {
|
||||
} else if (!user.is_onboarded) {
|
||||
router.push("/onboarding");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user || (!workspaces && !workspacesError)) return;
|
||||
|
||||
if (lastActiveWorkspace) {
|
||||
router.push(`/${lastActiveWorkspace.slug}`);
|
||||
return;
|
||||
} else if (workspaces.length > 0) {
|
||||
router.push(`/${workspaces[0].slug}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (invitations && invitations.length > 0) {
|
||||
} else if (!invitationsError && invitations && invitations.length > 0) {
|
||||
router.push("/invitations");
|
||||
return;
|
||||
} else {
|
||||
router.push("/create-workspace");
|
||||
return;
|
||||
}
|
||||
}, [user, router, lastActiveWorkspace, workspaces, invitations]);
|
||||
}, [
|
||||
invitations,
|
||||
invitationsError,
|
||||
isUserLoading,
|
||||
lastActiveWorkspace,
|
||||
user,
|
||||
workspaces,
|
||||
router,
|
||||
workspacesError,
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className="h-screen grid place-items-center">
|
||||
<div className="grid h-screen place-items-center">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user