import React from "react"; // next import { useRouter } from "next/router"; import Image from "next/image"; // swr import useSWR from "swr"; // constants import { PROJECT_ISSUES_ACTIVITY } from "constants/fetch-keys"; import { addSpaceIfCamelCase, timeAgo } from "constants/common"; // services import issuesServices from "lib/services/issues.service"; // hooks import useUser from "lib/hooks/useUser"; // ui import { Spinner } from "ui"; // icons import { CalendarDaysIcon, ChartBarIcon, ChatBubbleBottomCenterTextIcon, Squares2X2Icon, UserIcon, } from "@heroicons/react/24/outline"; // types import { IssueResponse, IState } from "types"; const activityIcons: { [key: string]: JSX.Element; } = { state: , priority: , name: , description: , target_date: , parent: , }; const IssueActivitySection: React.FC = () => { const router = useRouter(); const { issueId, projectId } = router.query; const { activeWorkspace, states, issues } = useUser(); const { data: issueActivities } = useSWR( activeWorkspace && projectId && issueId ? PROJECT_ISSUES_ACTIVITY : null, activeWorkspace && projectId && issueId ? () => issuesServices.getIssueActivities( activeWorkspace.slug, projectId as string, issueId as string ) : null ); return ( <> {issueActivities ? ( {issueActivities.map((activity, index) => { if (activity.field !== "updated_by") return ( {issueActivities.length > 1 && index !== issueActivities.length - 1 ? ( ) : null} {activity.field ? ( {activityIcons[activity.field as keyof typeof activityIcons]} ) : ( {activity.actor_detail.avatar && activity.actor_detail.avatar !== "" ? ( ) : ( {activity.actor_detail.first_name.charAt(0)} )} )} {activity.actor_detail.first_name} {activity.actor_detail.last_name} {activity.verb} {activity.verb !== "created" ? ( {activity.field ?? "commented"} ) : ( " this issue" )} {timeAgo(activity.created_at)} {activity.verb !== "created" && ( From: {activity.field === "state" ? activity.old_value ? addSpaceIfCamelCase( states?.find((s) => s.id === activity.old_value)?.name ?? "" ) : "None" : activity.field === "parent" ? activity.old_value ? issues?.results.find((i) => i.id === activity.old_value)?.name : "None" : activity.old_value ?? "None"} To: {activity.field === "state" ? activity.new_value ? addSpaceIfCamelCase( states?.find((s) => s.id === activity.new_value)?.name ?? "" ) : "None" : activity.field === "parent" ? activity.new_value ? issues?.results.find((i) => i.id === activity.new_value)?.name : "None" : activity.new_value ?? "None"} )} ); })} ) : ( )} > ); }; export default IssueActivitySection;
{activity.actor_detail.first_name} {activity.actor_detail.last_name} {activity.verb} {activity.verb !== "created" ? ( {activity.field ?? "commented"} ) : ( " this issue" )} {timeAgo(activity.created_at)}