import { ReactElement } from "react"; import { observer } from "mobx-react"; import { useRouter } from "next/router"; import useSWR from "swr"; // hooks import { ProjectInboxHeader } from "@/components/headers"; import { InboxLayoutLoader } from "@/components/ui"; import { useInbox, useProject } from "@/hooks/store"; // layouts import { AppLayout } from "@/layouts/app-layout"; // ui // components // types import { NextPageWithLayout } from "@/lib/types"; const ProjectInboxPage: NextPageWithLayout = observer(() => { const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { currentProjectDetails } = useProject(); const { fetchInboxes } = useInbox(); useSWR( workspaceSlug && projectId && currentProjectDetails && currentProjectDetails?.inbox_view ? `INBOX_${workspaceSlug.toString()}_${projectId.toString()}` : null, async () => { if (workspaceSlug && projectId && currentProjectDetails && currentProjectDetails?.inbox_view) { const inboxes = await fetchInboxes(workspaceSlug.toString(), projectId.toString()); if (inboxes && inboxes.length > 0) router.push(`/${workspaceSlug}/projects/${projectId}/inbox/${inboxes[0].id}`); } } ); return (
{currentProjectDetails?.inbox_view ? :
You don{"'"}t have access to inbox
}
); }); ProjectInboxPage.getLayout = function getLayout(page: ReactElement) { return ( } withProjectWrapper> {page} ); }; export default ProjectInboxPage;