import React, { useEffect, useState } from "react"; import { useRouter } from "next/router"; import Image from "next/image"; import Link from "next/link"; import useSWR, { mutate } from "swr"; // next-themes import { useTheme } from "next-themes"; // layouts import { WorkspaceAuthorizationLayout } from "layouts/auth-layout"; // services import userService from "services/user.service"; // hooks import useUser from "hooks/use-user"; import useProjects from "hooks/use-projects"; // components import { CompletedIssuesGraph, IssuesList, IssuesPieChart, IssuesStats, } from "components/workspace"; import { TourRoot } from "components/onboarding"; // ui import { PrimaryButton, ProductUpdatesModal } from "components/ui"; // icons import { BoltOutlined, GridViewOutlined } from "@mui/icons-material"; // images import emptyDashboard from "public/empty-state/dashboard.svg"; import githubBlackImage from "/public/logos/github-black.png"; import githubWhiteImage from "/public/logos/github-white.png"; // types import { ICurrentUserResponse } from "types"; import type { NextPage } from "next"; // fetch-keys import { CURRENT_USER, USER_WORKSPACE_DASHBOARD } from "constants/fetch-keys"; const Greeting = ({ user }: { user: ICurrentUserResponse | undefined }) => { const currentTime = new Date(); const hour = new Intl.DateTimeFormat("en-US", { hour12: false, hour: "numeric", }).format(currentTime); const date = new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", }).format(currentTime); const weekDay = new Intl.DateTimeFormat("en-US", { weekday: "long", }).format(currentTime); const timeString = new Intl.DateTimeFormat("en-US", { timeZone: user?.user_timezone, hour12: false, // Use 24-hour format hour: "2-digit", minute: "2-digit", }).format(currentTime); const greeting = parseInt(hour, 10) < 12 ? "morning" : parseInt(hour, 10) < 18 ? "afternoon" : "evening"; return (

Good {greeting}, {user?.first_name} {user?.last_name}

{greeting === "morning" ? "🌤️" : greeting === "afternoon" ? "🌥️" : "🌙️"}
{weekDay}, {date} {timeString}
); }; const WorkspacePage: NextPage = () => { const [month, setMonth] = useState(new Date().getMonth() + 1); const [isProductUpdatesModalOpen, setIsProductUpdatesModalOpen] = useState(false); const router = useRouter(); const { workspaceSlug } = router.query; const { theme } = useTheme(); const { user } = useUser(); const { projects } = useProjects(); const { data: workspaceDashboardData } = useSWR( workspaceSlug ? USER_WORKSPACE_DASHBOARD(workspaceSlug as string) : null, workspaceSlug ? () => userService.userWorkspaceDashboard(workspaceSlug as string, month) : null ); useEffect(() => { if (!workspaceSlug) return; mutate(USER_WORKSPACE_DASHBOARD(workspaceSlug as string)); }, [month, workspaceSlug]); return ( Dashboard } right={
GitHub Logo Star us on GitHub
} > {isProductUpdatesModalOpen && ( )} {user && !user.is_tour_completed && (
{ mutate( CURRENT_USER, (prevData) => { if (!prevData) return prevData; return { ...prevData, is_tour_completed: true, }; }, false ); userService.updateUserTourCompleted(user).catch(() => mutate(CURRENT_USER)); }} />
)}
{projects ? ( projects.length > 0 ? (
) : (
Create a project

Manage your projects by creating issues, cycles, modules, views and pages.

{ const e = new KeyboardEvent("keydown", { key: "p", }); document.dispatchEvent(e); }} > Create Project
Empty Dashboard
) ) : null}
); }; export default WorkspacePage;