2024-01-18 10:19:54 +00:00
|
|
|
import { useEffect } from "react";
|
2024-04-29 06:42:33 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-03-06 13:09:14 +00:00
|
|
|
import Link from "next/link";
|
2024-01-18 10:19:54 +00:00
|
|
|
import { Plus } from "lucide-react";
|
2024-04-29 06:42:33 +00:00
|
|
|
// types
|
2024-03-19 14:38:35 +00:00
|
|
|
import { TRecentProjectsWidgetResponse } from "@plane/types";
|
2024-04-29 06:42:33 +00:00
|
|
|
// ui
|
2024-03-06 13:09:14 +00:00
|
|
|
import { Avatar, AvatarGroup } from "@plane/ui";
|
2024-04-29 06:42:33 +00:00
|
|
|
// components
|
2024-03-19 14:38:35 +00:00
|
|
|
import { WidgetLoader, WidgetProps } from "@/components/dashboard/widgets";
|
|
|
|
import { ProjectLogo } from "@/components/project";
|
2024-04-29 06:42:33 +00:00
|
|
|
// constants
|
2024-03-19 14:38:35 +00:00
|
|
|
import { PROJECT_BACKGROUND_COLORS } from "@/constants/dashboard";
|
|
|
|
import { EUserWorkspaceRoles } from "@/constants/workspace";
|
2024-04-29 06:42:33 +00:00
|
|
|
// hooks
|
|
|
|
import { useEventTracker, useDashboard, useProject, useUser, useCommandPalette } from "@/hooks/store";
|
2024-01-18 10:19:54 +00:00
|
|
|
|
|
|
|
const WIDGET_KEY = "recent_projects";
|
|
|
|
|
|
|
|
type ProjectListItemProps = {
|
|
|
|
projectId: string;
|
|
|
|
workspaceSlug: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
const ProjectListItem: React.FC<ProjectListItemProps> = 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 (
|
|
|
|
<Link href={`/${workspaceSlug}/projects/${projectId}/issues`} className="group flex items-center gap-8">
|
|
|
|
<div
|
2024-04-29 06:42:33 +00:00
|
|
|
className={`grid h-[3.375rem] w-[3.375rem] flex-shrink-0 place-items-center rounded border border-transparent ${randomBgColor}`}
|
2024-01-18 10:19:54 +00:00
|
|
|
>
|
2024-04-29 06:42:33 +00:00
|
|
|
<div className="grid h-7 w-7 place-items-center">
|
2024-03-06 13:45:48 +00:00
|
|
|
<ProjectLogo logo={projectDetails.logo_props} className="text-xl" />
|
|
|
|
</div>
|
2024-01-18 10:19:54 +00:00
|
|
|
</div>
|
|
|
|
<div className="flex-grow truncate">
|
2024-04-29 06:42:33 +00:00
|
|
|
<h6 className="truncate text-sm font-medium text-custom-text-300 group-hover:text-custom-text-100 group-hover:underline">
|
2024-01-18 10:19:54 +00:00
|
|
|
{projectDetails.name}
|
|
|
|
</h6>
|
|
|
|
<div className="mt-2">
|
|
|
|
<AvatarGroup>
|
|
|
|
{projectDetails.members?.map((member) => (
|
2024-01-29 15:05:23 +00:00
|
|
|
<Avatar key={member.member_id} src={member.member__avatar} name={member.member__display_name} />
|
2024-01-18 10:19:54 +00:00
|
|
|
))}
|
|
|
|
</AvatarGroup>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export const RecentProjectsWidget: React.FC<WidgetProps> = observer((props) => {
|
|
|
|
const { dashboardId, workspaceSlug } = props;
|
|
|
|
// store hooks
|
2024-04-29 06:42:33 +00:00
|
|
|
const { toggleCreateProjectModal } = useCommandPalette();
|
2024-02-05 07:49:07 +00:00
|
|
|
const { setTrackElement } = useEventTracker();
|
2024-01-18 10:19:54 +00:00
|
|
|
const {
|
|
|
|
membership: { currentWorkspaceRole },
|
|
|
|
} = useUser();
|
2024-01-22 15:20:30 +00:00
|
|
|
const { fetchWidgetStats, getWidgetStats } = useDashboard();
|
2024-01-18 10:19:54 +00:00
|
|
|
// derived values
|
2024-01-22 15:20:30 +00:00
|
|
|
const widgetStats = getWidgetStats<TRecentProjectsWidgetResponse>(workspaceSlug, dashboardId, WIDGET_KEY);
|
2024-01-25 12:30:45 +00:00
|
|
|
const canCreateProject = currentWorkspaceRole && currentWorkspaceRole >= EUserWorkspaceRoles.MEMBER;
|
2024-01-18 10:19:54 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2024-01-24 14:11:02 +00:00
|
|
|
fetchWidgetStats(workspaceSlug, dashboardId, {
|
|
|
|
widget_key: WIDGET_KEY,
|
|
|
|
});
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, []);
|
2024-01-18 10:19:54 +00:00
|
|
|
|
|
|
|
if (!widgetStats) return <WidgetLoader widgetKey={WIDGET_KEY} />;
|
|
|
|
|
|
|
|
return (
|
2024-04-29 06:42:33 +00:00
|
|
|
<div className="min-h-96 w-full rounded-xl border-[0.5px] border-custom-border-200 bg-custom-background-100 py-6 duration-300 hover:shadow-custom-shadow-4xl">
|
2024-01-22 15:20:30 +00:00
|
|
|
<Link
|
|
|
|
href={`/${workspaceSlug}/projects`}
|
2024-04-29 06:42:33 +00:00
|
|
|
className="mx-7 text-lg font-semibold text-custom-text-300 hover:underline"
|
2024-01-22 15:20:30 +00:00
|
|
|
>
|
2024-02-20 08:12:04 +00:00
|
|
|
Recent projects
|
2024-01-22 15:20:30 +00:00
|
|
|
</Link>
|
2024-04-29 06:42:33 +00:00
|
|
|
<div className="mx-7 mt-4 space-y-8">
|
2024-01-18 10:19:54 +00:00
|
|
|
{canCreateProject && (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="group flex items-center gap-8"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2024-02-05 07:49:07 +00:00
|
|
|
setTrackElement("Sidebar");
|
2024-01-18 10:19:54 +00:00
|
|
|
toggleCreateProjectModal(true);
|
|
|
|
}}
|
|
|
|
>
|
2024-04-29 06:42:33 +00:00
|
|
|
<div className="grid h-[3.375rem] w-[3.375rem] flex-shrink-0 place-items-center rounded border border-dashed border-custom-primary-60 bg-custom-primary-100/20 text-custom-primary-100">
|
2024-01-18 10:19:54 +00:00
|
|
|
<Plus className="h-6 w-6" />
|
|
|
|
</div>
|
2024-04-29 06:42:33 +00:00
|
|
|
<p className="text-sm font-medium text-custom-text-300 group-hover:text-custom-text-100 group-hover:underline">
|
2024-01-18 10:19:54 +00:00
|
|
|
Create new project
|
|
|
|
</p>
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{widgetStats.map((projectId) => (
|
|
|
|
<ProjectListItem key={projectId} projectId={projectId} workspaceSlug={workspaceSlug} />
|
|
|
|
))}
|
|
|
|
</div>
|
2024-01-22 15:20:30 +00:00
|
|
|
</div>
|
2024-01-18 10:19:54 +00:00
|
|
|
);
|
|
|
|
});
|