import { useEffect } from "react"; import { observer } from "mobx-react"; import Link from "next/link"; import { Plus } from "lucide-react"; // types import { TRecentProjectsWidgetResponse } from "@plane/types"; // ui import { Avatar, AvatarGroup } from "@plane/ui"; // components import { Logo } from "@/components/common"; import { WidgetLoader, WidgetProps } from "@/components/dashboard/widgets"; // constants import { PROJECT_BACKGROUND_COLORS } from "@/constants/dashboard"; import { EUserWorkspaceRoles } from "@/constants/workspace"; // hooks import { useEventTracker, useDashboard, useProject, useUser, useCommandPalette } from "@/hooks/store"; const WIDGET_KEY = "recent_projects"; type ProjectListItemProps = { projectId: string; workspaceSlug: string; }; const ProjectListItem: React.FC = observer((props) => { const { projectId, workspaceSlug } = props; // store hooks const { getProjectById } = useProject(); const projectDetails = getProjectById(projectId); const randomBgColor = PROJECT_BACKGROUND_COLORS[Math.floor(Math.random() * PROJECT_BACKGROUND_COLORS.length)]; if (!projectDetails) return null; return (
{projectDetails.name}
{projectDetails.members?.map((member) => ( ))}
); }); export const RecentProjectsWidget: React.FC = observer((props) => { const { dashboardId, workspaceSlug } = props; // store hooks const { toggleCreateProjectModal } = useCommandPalette(); const { setTrackElement } = useEventTracker(); const { membership: { currentWorkspaceRole }, } = useUser(); const { fetchWidgetStats, getWidgetStats } = useDashboard(); // derived values const widgetStats = getWidgetStats(workspaceSlug, dashboardId, WIDGET_KEY); const canCreateProject = currentWorkspaceRole && currentWorkspaceRole >= EUserWorkspaceRoles.MEMBER; useEffect(() => { fetchWidgetStats(workspaceSlug, dashboardId, { widget_key: WIDGET_KEY, }); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); if (!widgetStats) return ; return (
Recent projects
{canCreateProject && ( )} {widgetStats.map((projectId) => ( ))}
); });