2023-11-27 08:45:33 +00:00
|
|
|
import React from "react";
|
2024-04-29 06:42:33 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-03-06 13:09:14 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-11-27 08:45:33 +00:00
|
|
|
import useSWR from "swr";
|
2024-01-10 14:39:45 +00:00
|
|
|
// hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import { IssuePeekOverview } from "@/components/issues/peek-overview";
|
|
|
|
import { ActiveLoader } from "@/components/ui";
|
|
|
|
import { EIssuesStoreType } from "@/constants/issue";
|
|
|
|
import { useIssues } from "@/hooks/store";
|
2024-01-10 14:39:45 +00:00
|
|
|
// components
|
2024-03-06 13:09:14 +00:00
|
|
|
import { ProjectDraftEmptyState } from "../empty-states";
|
2023-11-27 08:45:33 +00:00
|
|
|
import { DraftIssueAppliedFiltersRoot } from "../filters/applied-filters/roots/draft-issue";
|
2024-03-06 13:09:14 +00:00
|
|
|
import { DraftKanBanLayout } from "../kanban/roots/draft-issue-root";
|
2023-11-27 08:45:33 +00:00
|
|
|
import { DraftIssueListLayout } from "../list/roots/draft-issue-root";
|
2024-01-10 14:39:45 +00:00
|
|
|
// ui
|
|
|
|
// constants
|
2023-11-27 08:45:33 +00:00
|
|
|
|
|
|
|
export const DraftIssueLayoutRoot: React.FC = observer(() => {
|
2024-01-10 14:39:45 +00:00
|
|
|
// router
|
2023-11-27 08:45:33 +00:00
|
|
|
const router = useRouter();
|
2024-01-10 14:39:45 +00:00
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
// hooks
|
|
|
|
const { issues, issuesFilter } = useIssues(EIssuesStoreType.DRAFT);
|
2023-11-27 08:45:33 +00:00
|
|
|
|
2024-01-10 14:39:45 +00:00
|
|
|
useSWR(
|
|
|
|
workspaceSlug && projectId ? `DRAFT_ISSUES_${workspaceSlug.toString()}_${projectId.toString()}` : null,
|
|
|
|
async () => {
|
|
|
|
if (workspaceSlug && projectId) {
|
|
|
|
await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString());
|
|
|
|
await issues?.fetchIssues(
|
|
|
|
workspaceSlug.toString(),
|
|
|
|
projectId.toString(),
|
|
|
|
issues?.groupedIssueIds ? "mutation" : "init-loader"
|
|
|
|
);
|
|
|
|
}
|
2024-02-28 09:48:11 +00:00
|
|
|
},
|
|
|
|
{ revalidateIfStale: false, revalidateOnFocus: false }
|
2024-01-10 14:39:45 +00:00
|
|
|
);
|
2023-11-27 08:45:33 +00:00
|
|
|
|
2024-01-10 14:39:45 +00:00
|
|
|
const activeLayout = issuesFilter?.issueFilters?.displayFilters?.layout || undefined;
|
2023-11-27 08:45:33 +00:00
|
|
|
|
2024-01-10 14:39:45 +00:00
|
|
|
if (!workspaceSlug || !projectId) return <></>;
|
2024-02-13 13:42:10 +00:00
|
|
|
|
|
|
|
if (issues?.loader === "init-loader" || !issues?.groupedIssueIds) {
|
2024-02-14 07:10:03 +00:00
|
|
|
return <>{activeLayout && <ActiveLoader layout={activeLayout} />}</>;
|
2024-02-13 13:42:10 +00:00
|
|
|
}
|
|
|
|
|
2023-11-27 08:45:33 +00:00
|
|
|
return (
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="relative flex h-full w-full flex-col overflow-hidden">
|
2023-11-27 08:45:33 +00:00
|
|
|
<DraftIssueAppliedFiltersRoot />
|
|
|
|
|
2024-02-13 15:28:44 +00:00
|
|
|
{issues?.groupedIssueIds?.length === 0 ? (
|
|
|
|
<div className="relative h-full w-full overflow-y-auto">
|
|
|
|
<ProjectDraftEmptyState />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="relative h-full w-full overflow-auto">
|
|
|
|
{activeLayout === "list" ? (
|
|
|
|
<DraftIssueListLayout />
|
|
|
|
) : activeLayout === "kanban" ? (
|
|
|
|
<DraftKanBanLayout />
|
|
|
|
) : null}
|
|
|
|
{/* issue peek overview */}
|
2024-02-27 11:28:46 +00:00
|
|
|
<IssuePeekOverview is_draft />
|
2024-02-13 15:28:44 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2023-11-27 08:45:33 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|