2024-01-18 10:19:54 +00:00
|
|
|
import { useEffect } from "react";
|
|
|
|
import { observer } from "mobx-react-lite";
|
2024-03-06 13:09:14 +00:00
|
|
|
import Link from "next/link";
|
2024-01-18 10:19:54 +00:00
|
|
|
import { History } from "lucide-react";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { TRecentActivityWidgetResponse } from "@plane/types";
|
2024-01-18 10:19:54 +00:00
|
|
|
// hooks
|
|
|
|
// components
|
2024-03-06 13:09:14 +00:00
|
|
|
import { Avatar, getButtonStyling } from "@plane/ui";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { ActivityIcon, ActivityMessage, IssueLink } from "@/components/core";
|
|
|
|
import { RecentActivityEmptyState, WidgetLoader, WidgetProps } from "@/components/dashboard/widgets";
|
2024-01-18 10:19:54 +00:00
|
|
|
// ui
|
|
|
|
// helpers
|
2024-03-19 14:38:35 +00:00
|
|
|
import { cn } from "@/helpers/common.helper";
|
|
|
|
import { calculateTimeAgo } from "@/helpers/date-time.helper";
|
|
|
|
import { useDashboard, useUser } from "@/hooks/store";
|
2024-01-18 10:19:54 +00:00
|
|
|
// types
|
|
|
|
|
|
|
|
const WIDGET_KEY = "recent_activity";
|
|
|
|
|
|
|
|
export const RecentActivityWidget: React.FC<WidgetProps> = observer((props) => {
|
|
|
|
const { dashboardId, workspaceSlug } = props;
|
|
|
|
// store hooks
|
|
|
|
const { currentUser } = useUser();
|
|
|
|
// derived values
|
2024-01-22 15:20:30 +00:00
|
|
|
const { fetchWidgetStats, getWidgetStats } = useDashboard();
|
|
|
|
const widgetStats = getWidgetStats<TRecentActivityWidgetResponse[]>(workspaceSlug, dashboardId, WIDGET_KEY);
|
2024-03-06 08:54:36 +00:00
|
|
|
const redirectionLink = `/${workspaceSlug}/profile/${currentUser?.id}/activity`;
|
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-03-06 13:09:14 +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">
|
|
|
|
<Link href={redirectionLink} className="mx-7 text-lg font-semibold text-custom-text-300 hover:underline">
|
2024-01-24 14:11:02 +00:00
|
|
|
Your issue activities
|
2024-01-22 15:20:30 +00:00
|
|
|
</Link>
|
2024-01-18 10:19:54 +00:00
|
|
|
{widgetStats.length > 0 ? (
|
2024-03-06 13:09:14 +00:00
|
|
|
<div className="mx-7 mt-4 space-y-6">
|
2024-01-18 10:19:54 +00:00
|
|
|
{widgetStats.map((activity) => (
|
|
|
|
<div key={activity.id} className="flex gap-5">
|
|
|
|
<div className="flex-shrink-0">
|
|
|
|
{activity.field ? (
|
|
|
|
activity.new_value === "restore" ? (
|
|
|
|
<History className="h-3.5 w-3.5 text-custom-text-200" />
|
|
|
|
) : (
|
2024-03-06 13:09:14 +00:00
|
|
|
<div className="flex h-6 w-6 justify-center">
|
2024-01-18 10:19:54 +00:00
|
|
|
<ActivityIcon activity={activity} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
) : activity.actor_detail.avatar && activity.actor_detail.avatar !== "" ? (
|
|
|
|
<Avatar
|
|
|
|
src={activity.actor_detail.avatar}
|
|
|
|
name={activity.actor_detail.display_name}
|
|
|
|
size={24}
|
|
|
|
className="h-full w-full rounded-full object-cover"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<div className="grid h-7 w-7 place-items-center rounded-full border-2 border-white bg-gray-700 text-xs text-white">
|
|
|
|
{activity.actor_detail.is_bot
|
|
|
|
? activity.actor_detail.first_name.charAt(0)
|
|
|
|
: activity.actor_detail.display_name.charAt(0)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2024-04-24 09:50:32 +00:00
|
|
|
<div className="-mt-2 break-words">
|
|
|
|
<p className="inline text-sm text-custom-text-200">
|
2024-01-18 10:19:54 +00:00
|
|
|
<span className="font-medium text-custom-text-100">
|
2024-03-06 15:17:38 +00:00
|
|
|
{currentUser?.id === activity.actor_detail.id ? "You" : activity.actor_detail?.display_name}{" "}
|
2024-01-18 10:19:54 +00:00
|
|
|
</span>
|
|
|
|
{activity.field ? (
|
|
|
|
<ActivityMessage activity={activity} showIssue />
|
|
|
|
) : (
|
|
|
|
<span>
|
2024-01-23 15:15:44 +00:00
|
|
|
created <IssueLink activity={activity} />
|
2024-01-18 10:19:54 +00:00
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</p>
|
2024-04-24 09:50:32 +00:00
|
|
|
<p className="text-xs text-custom-text-200 whitespace-nowrap">
|
|
|
|
{calculateTimeAgo(activity.created_at)}
|
|
|
|
</p>
|
2024-01-18 10:19:54 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
2024-03-06 08:54:36 +00:00
|
|
|
<Link
|
|
|
|
href={redirectionLink}
|
|
|
|
className={cn(
|
|
|
|
getButtonStyling("link-primary", "sm"),
|
2024-03-06 13:09:14 +00:00
|
|
|
"mx-auto w-min px-2 py-1 text-xs hover:bg-custom-primary-100/20"
|
2024-03-06 08:54:36 +00:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
View all
|
|
|
|
</Link>
|
2024-01-18 10:19:54 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
2024-03-06 13:09:14 +00:00
|
|
|
<div className="grid h-full place-items-center">
|
2024-01-18 10:19:54 +00:00
|
|
|
<RecentActivityEmptyState />
|
|
|
|
</div>
|
|
|
|
)}
|
2024-01-22 15:20:30 +00:00
|
|
|
</div>
|
2024-01-18 10:19:54 +00:00
|
|
|
);
|
|
|
|
});
|