mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: home page redirection logic (#752)
* fix: dashboard workspace activity mutation * fix: home page redirection logic * chore: add homePageRedirect function back
This commit is contained in:
parent
03e74415f2
commit
08e77cb19e
@ -29,7 +29,7 @@ export const UserAuthorizationLayout: React.FC<Props> = ({ children }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error?.status === 401) {
|
if (error) {
|
||||||
const redirectTo = router.asPath;
|
const redirectTo = router.asPath;
|
||||||
|
|
||||||
router.push(`/signin?next=${redirectTo}`);
|
router.push(`/signin?next=${redirectTo}`);
|
||||||
|
@ -109,9 +109,6 @@ export const homePageRedirect = async (cookie?: string) => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: backend is returning object of user and workspace.
|
|
||||||
// Get KT if it's required to send user and workspace and if
|
|
||||||
// yes change below accordingly
|
|
||||||
if (!user.is_onboarded)
|
if (!user.is_onboarded)
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
@ -1,13 +1,67 @@
|
|||||||
// lib
|
import { useEffect } from "react";
|
||||||
import { homePageRedirect } from "lib/auth";
|
|
||||||
|
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
|
// 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 = () => null;
|
const Home: NextPage = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
export const getServerSideProps = (ctx: NextPageContext) => {
|
const { user } = useUser();
|
||||||
const cookies = ctx.req?.headers.cookie;
|
const { workspaces } = useWorkspaces();
|
||||||
return homePageRedirect(cookies);
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (invitations && invitations.length > 0) {
|
||||||
|
router.push("/invitations");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
router.push("/create-workspace");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}, [user, router, lastActiveWorkspace, workspaces, invitations]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="h-screen grid place-items-center">
|
||||||
|
<Spinner />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Home;
|
export default Home;
|
||||||
|
@ -12,6 +12,7 @@ interface IGithuPostInstallationProps {
|
|||||||
provider: string;
|
provider: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO:Change getServerSideProps to router.query
|
||||||
const AppPostInstallation = ({
|
const AppPostInstallation = ({
|
||||||
installation_id,
|
installation_id,
|
||||||
setup_action,
|
setup_action,
|
||||||
|
@ -22,6 +22,8 @@ import { CubeIcon, PlusIcon } from "@heroicons/react/24/outline";
|
|||||||
// types
|
// types
|
||||||
import type { NextPage } from "next";
|
import type { NextPage } from "next";
|
||||||
import type { IWorkspaceMemberInvitation } from "types";
|
import type { IWorkspaceMemberInvitation } from "types";
|
||||||
|
// fetch-keys
|
||||||
|
import { USER_WORKSPACE_INVITATIONS } from "constants/fetch-keys";
|
||||||
|
|
||||||
const OnBoard: NextPage = () => {
|
const OnBoard: NextPage = () => {
|
||||||
const [invitationsRespond, setInvitationsRespond] = useState<string[]>([]);
|
const [invitationsRespond, setInvitationsRespond] = useState<string[]>([]);
|
||||||
@ -32,9 +34,8 @@ const OnBoard: NextPage = () => {
|
|||||||
|
|
||||||
const { setToastAlert } = useToast();
|
const { setToastAlert } = useToast();
|
||||||
|
|
||||||
const { data: invitations, mutate: mutateInvitations } = useSWR(
|
const { data: invitations, mutate: mutateInvitations } = useSWR(USER_WORKSPACE_INVITATIONS, () =>
|
||||||
"USER_WORKSPACE_INVITATIONS",
|
workspaceService.userWorkspaceInvitations()
|
||||||
() => workspaceService.userWorkspaceInvitations()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data: workspaces, mutate: mutateWorkspaces } = useSWR("USER_WORKSPACES", () =>
|
const { data: workspaces, mutate: mutateWorkspaces } = useSWR("USER_WORKSPACES", () =>
|
||||||
|
@ -3,6 +3,8 @@ import { useState } from "react";
|
|||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
|
import { mutate } from "swr";
|
||||||
|
|
||||||
// services
|
// services
|
||||||
import userService from "services/user.service";
|
import userService from "services/user.service";
|
||||||
// hooks
|
// hooks
|
||||||
@ -20,6 +22,8 @@ import { ONBOARDING_CARDS } from "constants/workspace";
|
|||||||
import Logo from "public/onboarding/logo.svg";
|
import Logo from "public/onboarding/logo.svg";
|
||||||
// types
|
// types
|
||||||
import type { NextPage } from "next";
|
import type { NextPage } from "next";
|
||||||
|
// fetch-keys
|
||||||
|
import { CURRENT_USER } from "constants/fetch-keys";
|
||||||
|
|
||||||
const Onboarding: NextPage = () => {
|
const Onboarding: NextPage = () => {
|
||||||
const [step, setStep] = useState(1);
|
const [step, setStep] = useState(1);
|
||||||
@ -72,6 +76,7 @@ const Onboarding: NextPage = () => {
|
|||||||
userService
|
userService
|
||||||
.updateUserOnBoard({ userRole })
|
.updateUserOnBoard({ userRole })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
mutate(CURRENT_USER);
|
||||||
router.push("/");
|
router.push("/");
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user