import { useNavigate } from "react-router-dom"; import { useEffect } from "react"; import { useHasUserPermission } from "./useHasUserPermission"; import { useAllProjectLevelPermissions } from "./useProfile"; import { VIEW_PROJECTS } from "../utils/constants"; import showToast from "../services/toastService"; export const useProjectAccess = (projectId) => { const navigate = useNavigate(); const { data: projectPermissions, isLoading, isFetched } = useAllProjectLevelPermissions(projectId); const canView = useHasUserPermission(VIEW_PROJECTS); const loading = isLoading || !isFetched; debugger useEffect(() => { if (projectId && !loading && !canView) { showToast("You don't have permission to view project details", "warning"); navigate("/projects"); } }, [projectId, loading, canView, navigate]); return { canView, loading, }; };