import { useState } from "react";
import { useRouter } from "next/router";
import useSWR from "swr";
import { observer } from "mobx-react-lite";
// hooks
import { useApplication, useProject, useUser } from "hooks/store";
// components
import { TourRoot } from "components/onboarding";
import { UserGreetingsView } from "components/user";
import { CompletedIssuesGraph, IssuesList, IssuesPieChart, IssuesStats } from "components/workspace";
// constants
import { EUserWorkspaceRoles } from "constants/workspace";
// images
import { NewEmptyState } from "components/common/new-empty-state";
import emptyProject from "public/empty-state/dashboard_empty_project.webp";
export const WorkspaceDashboardView = observer(() => {
// states
const [month, setMonth] = useState(new Date().getMonth() + 1);
// router
const router = useRouter();
const { workspaceSlug } = router.query;
// store hooks
const {
commandPalette: commandPaletteStore,
eventTracker: { setTrackElement, postHogEventTracker },
} = useApplication();
const { currentUser, dashboardInfo: workspaceDashboardInfo, fetchUserDashboardInfo, updateTourCompleted } = useUser();
const { workspaceProjects } = useProject();
// fetch user dashboard info
useSWR(
workspaceSlug ? `USER_WORKSPACE_DASHBOARD_${workspaceSlug}_${month}` : null,
workspaceSlug ? () => fetchUserDashboardInfo(workspaceSlug.toString(), month) : null
);
const isEditingAllowed = !!userStore.currentProjectRole && userStore.currentProjectRole >= EUserWorkspaceRoles.MEMBER;
const handleTourCompleted = () => {
updateTourCompleted()
.then(() => {
postHogEventTracker("USER_TOUR_COMPLETE", {
user_id: currentUser?.id,
email: currentUser?.email,
state: "SUCCESS",
});
})
.catch((error) => {
console.log(error);
});
};
return (
<>
{/* {isProductUpdatesModalOpen && (