import React from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // services import issuesService from "services/issues.service"; // components import { CommentCard } from "components/issues/comment"; // ui import { Icon, Loader } from "components/ui"; // helpers import { timeAgo } from "helpers/date-time.helper"; import { activityDetails } from "helpers/activity.helper"; // types import { ICurrentUserResponse, IIssueComment } from "types"; // fetch-keys import { PROJECT_ISSUES_ACTIVITY } from "constants/fetch-keys"; type Props = { issueId: string; user: ICurrentUserResponse | undefined; }; export const IssueActivitySection: React.FC = ({ issueId, user }) => { const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { data: issueActivities, mutate: mutateIssueActivities } = useSWR( workspaceSlug && projectId ? PROJECT_ISSUES_ACTIVITY(issueId) : null, workspaceSlug && projectId ? () => issuesService.getIssueActivities(workspaceSlug as string, projectId as string, issueId) : null ); const handleCommentUpdate = async (comment: IIssueComment) => { if (!workspaceSlug || !projectId || !issueId) return; await issuesService .patchIssueComment( workspaceSlug as string, projectId as string, issueId as string, comment.id, comment, user ) .then((res) => mutateIssueActivities()); }; const handleCommentDelete = async (commentId: string) => { if (!workspaceSlug || !projectId || !issueId) return; mutateIssueActivities((prevData) => prevData?.filter((p) => p.id !== commentId), false); await issuesService .deleteIssueComment( workspaceSlug as string, projectId as string, issueId as string, commentId, user ) .then(() => mutateIssueActivities()); }; if (!issueActivities) { return (
); } return (
); };