import { useEffect } from "react"; import { observer } from "mobx-react-lite"; import Link from "next/link"; import { Plus } from "lucide-react"; import { TRecentProjectsWidgetResponse } from "@plane/types"; // hooks import { Avatar, AvatarGroup } from "@plane/ui"; import { WidgetLoader, WidgetProps } from "@/components/dashboard/widgets"; import { ProjectLogo } from "@/components/project"; import { PROJECT_BACKGROUND_COLORS } from "@/constants/dashboard"; import { EUserWorkspaceRoles } from "@/constants/workspace"; import { useApplication, useEventTracker, useDashboard, useProject, useUser } from "@/hooks/store"; // components // ui // helpers // types // constants 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 { commandPalette: { toggleCreateProjectModal }, } = useApplication(); 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) => ( ))}
); });