2024-01-24 13:42:54 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import size from "lodash/size";
|
2024-01-29 15:08:32 +00:00
|
|
|
import { useTheme } from "next-themes";
|
2024-01-24 13:42:54 +00:00
|
|
|
// hooks
|
2024-02-05 07:49:07 +00:00
|
|
|
import { useApplication, useEventTracker, useIssues, useUser } from "hooks/store";
|
2024-01-24 13:42:54 +00:00
|
|
|
// components
|
|
|
|
import { EmptyState, getEmptyStateImagePath } from "components/empty-state";
|
|
|
|
// constants
|
|
|
|
import { EUserProjectRoles } from "constants/project";
|
|
|
|
import { EIssueFilterType, EIssuesStoreType } from "constants/issue";
|
2024-02-13 11:05:20 +00:00
|
|
|
import { EMPTY_FILTER_STATE_DETAILS, EMPTY_ISSUE_STATE_DETAILS } from "constants/empty-state";
|
2024-01-24 13:42:54 +00:00
|
|
|
// types
|
|
|
|
import { IIssueFilterOptions } from "@plane/types";
|
|
|
|
|
|
|
|
interface EmptyStateProps {
|
|
|
|
title: string;
|
|
|
|
image: string;
|
|
|
|
description?: string;
|
|
|
|
comicBox?: { title: string; description: string };
|
|
|
|
primaryButton?: { text: string; icon?: React.ReactNode; onClick: () => void };
|
|
|
|
secondaryButton?: { text: string; onClick: () => void };
|
|
|
|
size?: "lg" | "sm" | undefined;
|
|
|
|
disabled?: boolean | undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ProjectEmptyState: React.FC = observer(() => {
|
|
|
|
// router
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
2024-01-29 15:08:32 +00:00
|
|
|
// theme
|
|
|
|
const { resolvedTheme } = useTheme();
|
2024-01-24 13:42:54 +00:00
|
|
|
// store hooks
|
2024-02-05 07:49:07 +00:00
|
|
|
const { commandPalette: commandPaletteStore } = useApplication();
|
|
|
|
const { setTrackElement } = useEventTracker();
|
2024-01-24 13:42:54 +00:00
|
|
|
const {
|
|
|
|
membership: { currentProjectRole },
|
|
|
|
currentUser,
|
|
|
|
} = useUser();
|
|
|
|
const { issuesFilter } = useIssues(EIssuesStoreType.PROJECT);
|
|
|
|
|
|
|
|
const userFilters = issuesFilter?.issueFilters?.filters;
|
|
|
|
const activeLayout = issuesFilter?.issueFilters?.displayFilters?.layout;
|
|
|
|
|
2024-01-29 15:08:32 +00:00
|
|
|
const isLightMode = resolvedTheme ? resolvedTheme === "light" : currentUser?.theme.theme === "light";
|
|
|
|
const currentLayoutEmptyStateImagePath = getEmptyStateImagePath("empty-filters", activeLayout ?? "list", isLightMode);
|
|
|
|
const EmptyStateImagePath = getEmptyStateImagePath("onboarding", "issues", isLightMode);
|
2024-01-24 13:42:54 +00:00
|
|
|
|
|
|
|
const issueFilterCount = size(
|
|
|
|
Object.fromEntries(
|
2024-01-30 08:29:07 +00:00
|
|
|
Object.entries(userFilters ?? {}).filter(([, value]) => value && Array.isArray(value) && value.length > 0)
|
2024-01-24 13:42:54 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleClearAllFilters = () => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
const newFilters: IIssueFilterOptions = {};
|
|
|
|
Object.keys(userFilters ?? {}).forEach((key) => {
|
|
|
|
newFilters[key as keyof IIssueFilterOptions] = null;
|
|
|
|
});
|
|
|
|
issuesFilter.updateFilters(workspaceSlug.toString(), projectId.toString(), EIssueFilterType.FILTERS, {
|
|
|
|
...newFilters,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER;
|
|
|
|
|
|
|
|
const emptyStateProps: EmptyStateProps =
|
|
|
|
issueFilterCount > 0
|
|
|
|
? {
|
2024-02-13 11:05:20 +00:00
|
|
|
title: EMPTY_FILTER_STATE_DETAILS["project"].title,
|
2024-01-24 13:42:54 +00:00
|
|
|
image: currentLayoutEmptyStateImagePath,
|
|
|
|
secondaryButton: {
|
2024-02-13 11:05:20 +00:00
|
|
|
text: EMPTY_FILTER_STATE_DETAILS["project"].secondaryButton.text,
|
2024-01-24 13:42:54 +00:00
|
|
|
onClick: handleClearAllFilters,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: {
|
2024-02-13 11:05:20 +00:00
|
|
|
title: EMPTY_ISSUE_STATE_DETAILS["project"].title,
|
|
|
|
description: EMPTY_ISSUE_STATE_DETAILS["project"].description,
|
2024-01-24 13:42:54 +00:00
|
|
|
image: EmptyStateImagePath,
|
|
|
|
comicBox: {
|
2024-02-13 11:05:20 +00:00
|
|
|
title: EMPTY_ISSUE_STATE_DETAILS["project"].comicBox.title,
|
|
|
|
description: EMPTY_ISSUE_STATE_DETAILS["project"].comicBox.description,
|
2024-01-24 13:42:54 +00:00
|
|
|
},
|
|
|
|
primaryButton: {
|
2024-02-13 11:05:20 +00:00
|
|
|
text: EMPTY_ISSUE_STATE_DETAILS["project"].primaryButton.text,
|
2024-01-24 13:42:54 +00:00
|
|
|
onClick: () => {
|
2024-02-05 07:49:07 +00:00
|
|
|
setTrackElement("Project issue empty state");
|
2024-01-24 13:42:54 +00:00
|
|
|
commandPaletteStore.toggleCreateIssueModal(true, EIssuesStoreType.PROJECT);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
size: "lg",
|
|
|
|
disabled: !isEditingAllowed,
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="relative h-full w-full overflow-y-auto">
|
|
|
|
<EmptyState {...emptyStateProps} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|