import React, { useCallback } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { mutate } from "swr"; // services import issuesService from "services/issues.service"; // components import { ViewDueDateSelect, ViewPrioritySelect, ViewStateSelect, } from "components/issues/view-select"; // ui import { AssigneesList } from "components/ui/avatar"; import { CustomMenu, Tooltip } from "components/ui"; // types import { IIssue, Properties } from "types"; // fetch-keys import { USER_ISSUE } from "constants/fetch-keys"; import { copyTextToClipboard, truncateText } from "helpers/string.helper"; import useToast from "hooks/use-toast"; type Props = { issue: IIssue; properties: Properties; projectId: string; }; export const MyIssuesListItem: React.FC = ({ issue, properties, projectId }) => { const router = useRouter(); const { workspaceSlug } = router.query; const { setToastAlert } = useToast(); const partialUpdateIssue = useCallback( (formData: Partial) => { 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) .then((res) => { mutate(USER_ISSUE(workspaceSlug as string)); }) .catch((error) => { console.log(error); }); }, [workspaceSlug, projectId, issue] ); 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 && ( )} {properties.sub_issue_count && (
{issue?.sub_issues_count} {issue?.sub_issues_count === 1 ? "sub-issue" : "sub-issues"}
)} {properties.labels && issue.label_details.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" } >
)} Copy issue link
); };