import { useEffect } from "react"; import { useTheme } from "next-themes"; import { observer } from "mobx-react-lite"; // hooks import { useApplication, useEventTracker, useDashboard, useProject, useUser } from "hooks/store"; // components import { TourRoot } from "components/onboarding"; import { UserGreetingsView } from "components/user"; import { IssuePeekOverview } from "components/issues"; import { DashboardWidgets } from "components/dashboard"; import { EmptyState, getEmptyStateImagePath } from "components/empty-state"; // ui import { Spinner } from "@plane/ui"; // constants import { EUserWorkspaceRoles } from "constants/workspace"; export const WorkspaceDashboardView = observer(() => { // theme const { resolvedTheme } = useTheme(); // store hooks const { captureEvent, setTrackElement } = useEventTracker(); const { commandPalette: { toggleCreateProjectModal }, router: { workspaceSlug }, } = useApplication(); const { currentUser, updateTourCompleted, membership: { currentWorkspaceRole }, } = useUser(); const { homeDashboardId, fetchHomeDashboardWidgets } = useDashboard(); const { joinedProjectIds } = useProject(); const isLightMode = resolvedTheme ? resolvedTheme === "light" : currentUser?.theme.theme === "light"; const emptyStateImage = getEmptyStateImagePath("onboarding", "dashboard", isLightMode); const handleTourCompleted = () => { updateTourCompleted() .then(() => { captureEvent("User tour complete", { user_id: currentUser?.id, email: currentUser?.email, state: "SUCCESS", }); }) .catch((error) => { console.error(error); }); }; // fetch home dashboard widgets on workspace change useEffect(() => { if (!workspaceSlug) return; fetchHomeDashboardWidgets(workspaceSlug); }, [fetchHomeDashboardWidgets, workspaceSlug]); const isEditingAllowed = currentWorkspaceRole === EUserWorkspaceRoles.ADMIN; return ( <> {homeDashboardId && joinedProjectIds ? ( <> {joinedProjectIds.length > 0 ? ( <>
{currentUser && } {currentUser && !currentUser.is_tour_completed && (
)}
) : ( { setTrackElement("Dashboard"); toggleCreateProjectModal(true); }, }} comicBox={{ title: "Everything starts with a project in Plane", description: "A project could be a product’s roadmap, a marketing campaign, or launching a new car.", }} size="lg" disabled={!isEditingAllowed} /> )} ) : (
)} ); });