2024-01-24 15:03:54 +00:00
|
|
|
import { ReactElement } from "react";
|
2024-03-06 13:09:14 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-01-24 15:03:54 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import useSWR from "swr";
|
|
|
|
// hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import { ProjectInboxHeader } from "@/components/headers";
|
|
|
|
import { InboxLayoutLoader } from "@/components/ui";
|
|
|
|
import { useInbox, useProject } from "@/hooks/store";
|
2024-01-24 15:03:54 +00:00
|
|
|
// layouts
|
2024-03-19 14:38:35 +00:00
|
|
|
import { AppLayout } from "@/layouts/app-layout";
|
2024-02-19 15:37:43 +00:00
|
|
|
// ui
|
2024-01-24 15:03:54 +00:00
|
|
|
// components
|
|
|
|
// types
|
2024-03-19 14:38:35 +00:00
|
|
|
import { NextPageWithLayout } from "@/lib/types";
|
2024-01-24 15:03:54 +00:00
|
|
|
|
|
|
|
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 (
|
|
|
|
<div className="flex h-full flex-col">
|
2024-02-19 15:37:43 +00:00
|
|
|
{currentProjectDetails?.inbox_view ? <InboxLayoutLoader /> : <div>You don{"'"}t have access to inbox</div>}
|
2024-01-24 15:03:54 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
ProjectInboxPage.getLayout = function getLayout(page: ReactElement) {
|
|
|
|
return (
|
|
|
|
<AppLayout header={<ProjectInboxHeader />} withProjectWrapper>
|
|
|
|
{page}
|
|
|
|
</AppLayout>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProjectInboxPage;
|