Compare commits

...

2 Commits

Author SHA1 Message Date
Sheen Capadngan
37a204e49e misc: addressed review comment 2024-09-16 23:27:10 +08:00
Sheen Capadngan
f49f3c926c misc: added handling of no project access for redirects 2024-09-16 20:00:54 +08:00

View File

@@ -1,6 +1,7 @@
import { createContext, ReactNode, useContext, useMemo } from "react"; import { createContext, ReactNode, useContext, useEffect, useMemo } from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { createNotification } from "@app/components/notifications";
import { useGetUserWorkspaces } from "@app/hooks/api"; import { useGetUserWorkspaces } from "@app/hooks/api";
import { Workspace } from "@app/hooks/api/workspace/types"; import { Workspace } from "@app/hooks/api/workspace/types";
@@ -31,6 +32,34 @@ export const WorkspaceProvider = ({ children }: Props): JSX.Element => {
}; };
}, [ws, workspaceId, isLoading]); }, [ws, workspaceId, isLoading]);
const shouldTriggerNoProjectAccess =
!value.isLoading &&
!value.currentWorkspace &&
router.pathname.startsWith("/project") &&
workspaceId;
// handle redirects for project-specific routes
useEffect(() => {
if (shouldTriggerNoProjectAccess) {
createNotification({
text: "You are not a member of this project.",
type: "info"
});
setTimeout(() => {
router.push("/");
}, 5000);
}
}, [shouldTriggerNoProjectAccess, router]);
if (shouldTriggerNoProjectAccess) {
return (
<div className="flex h-screen w-screen items-center justify-center bg-bunker-800 text-primary-50">
You do not have sufficient access to this project.
</div>
);
}
return <WorkspaceContext.Provider value={value}>{children}</WorkspaceContext.Provider>; return <WorkspaceContext.Provider value={value}>{children}</WorkspaceContext.Provider>;
}; };