import React, { useCallback } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { mutate } from "swr"; // hooks import useToast from "hooks/use-toast"; import useUserAuth from "hooks/use-user-auth"; // services import issuesService from "services/issues.service"; // components import { ViewDueDateSelect, ViewPrioritySelect, ViewStateSelect, } from "components/issues/view-select"; // icon import { LinkIcon, PaperClipIcon } from "@heroicons/react/24/outline"; import { LayerDiagonalIcon } from "components/icons"; // ui import { AssigneesList } from "components/ui/avatar"; import { CustomMenu, Tooltip } from "components/ui"; // types import { IIssue, Properties } from "types"; // helper import { copyTextToClipboard, truncateText } from "helpers/string.helper"; // fetch-keys import { USER_ISSUE } from "constants/fetch-keys"; type Props = { issue: IIssue; properties: Properties; projectId: string; }; export const MyIssuesListItem: React.FC = ({ issue, properties, projectId }) => { const router = useRouter(); const { workspaceSlug } = router.query; const { user } = useUserAuth(); const { setToastAlert } = useToast(); const partialUpdateIssue = useCallback( (formData: Partial, issue: IIssue) => { if (!workspaceSlug) return; mutate( USER_ISSUE(workspaceSlug as string), (prevData) => prevData?.map((p) => { if (p.id === issue.id) return { ...p, ...formData }; return p; }), false ); issuesService .patchIssue(workspaceSlug as string, projectId as string, issue.id, formData, user) .then((res) => { mutate(USER_ISSUE(workspaceSlug as string)); }) .catch((error) => { console.log(error); }); }, [workspaceSlug, projectId, user] ); const handleCopyText = () => { const originURL = typeof window !== "undefined" && window.location.origin ? window.location.origin : ""; copyTextToClipboard( `${originURL}/${workspaceSlug}/projects/${projectId}/issues/${issue.id}` ).then(() => { setToastAlert({ type: "success", title: "Link Copied!", message: "Issue link copied to clipboard.", }); }); }; const isNotAllowed = false; return (
{properties?.key && ( {issue.project_detail?.identifier}-{issue.sequence_id} )} {truncateText(issue.name, 50)}
{properties.priority && ( )} {properties.state && ( )} {properties.due_date && issue.target_date && ( )} {properties.labels && issue.labels.length > 0 && (
{issue.label_details.map((label) => ( {label.name} ))}
)} {properties.assignee && (
0 ? issue.assignee_details .map((assignee) => assignee?.first_name !== "" ? assignee?.first_name : assignee?.email ) .join(", ") : "No Assignee" } >
)} {properties.sub_issue_count && issue.sub_issues_count > 0 && (
{issue.sub_issues_count}
)} {properties.link && issue.link_count > 0 && (
{issue.link_count}
)} {properties.attachment_count && issue.attachment_count > 0 && (
{issue.attachment_count}
)} Copy issue link
); };