-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: home page redirection logic (#752)
* fix: dashboard workspace activity mutation * fix: home page redirection logic * chore: add homePageRedirect function back
- Loading branch information
Showing
6 changed files
with
72 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,67 @@ | ||
// lib | ||
import { homePageRedirect } from "lib/auth"; | ||
import { useEffect } from "react"; | ||
|
||
import { useRouter } from "next/router"; | ||
|
||
import useSWR from "swr"; | ||
|
||
// services | ||
import workspaceService from "services/workspace.service"; | ||
// hooks | ||
import useUser from "hooks/use-user"; | ||
import useWorkspaces from "hooks/use-workspaces"; | ||
// ui | ||
import { Spinner } from "components/ui"; | ||
// types | ||
import type { NextPage, NextPageContext } from "next"; | ||
import type { NextPage } from "next"; | ||
// fetch-keys | ||
import { USER_WORKSPACE_INVITATIONS } from "constants/fetch-keys"; | ||
|
||
const Home: NextPage = () => { | ||
const router = useRouter(); | ||
|
||
const { user } = useUser(); | ||
const { workspaces } = useWorkspaces(); | ||
|
||
const lastActiveWorkspace = | ||
user && workspaces.find((workspace) => workspace.id === user.last_workspace_id); | ||
|
||
const { data: invitations } = useSWR(USER_WORKSPACE_INVITATIONS, () => | ||
workspaceService.userWorkspaceInvitations() | ||
); | ||
|
||
useEffect(() => { | ||
if (!user) { | ||
router.push("/signin"); | ||
return; | ||
} | ||
|
||
if (!user.is_onboarded) { | ||
router.push("/onboarding"); | ||
return; | ||
} | ||
|
||
if (lastActiveWorkspace) { | ||
router.push(`/${lastActiveWorkspace.slug}`); | ||
return; | ||
} else if (workspaces.length > 0) { | ||
router.push(`/${workspaces[0].slug}`); | ||
return; | ||
} | ||
|
||
const Home: NextPage = () => null; | ||
if (invitations && invitations.length > 0) { | ||
router.push("/invitations"); | ||
return; | ||
} else { | ||
router.push("/create-workspace"); | ||
return; | ||
} | ||
}, [user, router, lastActiveWorkspace, workspaces, invitations]); | ||
|
||
export const getServerSideProps = (ctx: NextPageContext) => { | ||
const cookies = ctx.req?.headers.cookie; | ||
return homePageRedirect(cookies); | ||
return ( | ||
<div className="h-screen grid place-items-center"> | ||
<Spinner /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Home; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
08e77cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
plane-dev – ./apps/app
plane-dev.vercel.app
plane-dev-caravel.vercel.app
plane-dev-git-develop-caravel.vercel.app