import React, { useCallback } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { mutate } from "swr"; // components import { ViewAssigneeSelect, ViewDueDateSelect, ViewEstimateSelect, ViewPrioritySelect, ViewStateSelect, } from "components/issues"; // icons import { CustomMenu, Icon } from "components/ui"; import { LinkIcon, PencilIcon, TrashIcon, XMarkIcon } from "@heroicons/react/24/outline"; // hooks import useSpreadsheetIssuesView from "hooks/use-spreadsheet-issues-view"; import useToast from "hooks/use-toast"; // services import issuesService from "services/issues.service"; // constant import { CYCLE_ISSUES_WITH_PARAMS, MODULE_ISSUES_WITH_PARAMS, PROJECT_ISSUES_LIST_WITH_PARAMS, VIEW_ISSUES, } from "constants/fetch-keys"; // types import { ICurrentUserResponse, IIssue, Properties, UserAuth } from "types"; // helper import { copyTextToClipboard } from "helpers/string.helper"; type Props = { issue: IIssue; expanded: boolean; handleToggleExpand: (issueId: string) => void; properties: Properties; handleEditIssue: (issue: IIssue) => void; handleDeleteIssue: (issue: IIssue) => void; gridTemplateColumns: string; user: ICurrentUserResponse | undefined; userAuth: UserAuth; nestingLevel: number; }; export const SingleSpreadsheetIssue: React.FC = ({ issue, expanded, handleToggleExpand, properties, handleEditIssue, handleDeleteIssue, gridTemplateColumns, user, userAuth, nestingLevel, }) => { const router = useRouter(); const { workspaceSlug, projectId, cycleId, moduleId, viewId } = router.query; const { params } = useSpreadsheetIssuesView(); const { setToastAlert } = useToast(); const partialUpdateIssue = useCallback( (formData: Partial, issueId: string) => { if (!workspaceSlug || !projectId) return; const fetchKey = cycleId ? CYCLE_ISSUES_WITH_PARAMS(cycleId.toString(), params) : moduleId ? MODULE_ISSUES_WITH_PARAMS(moduleId.toString(), params) : viewId ? VIEW_ISSUES(viewId.toString(), params) : PROJECT_ISSUES_LIST_WITH_PARAMS(projectId.toString(), params); mutate( fetchKey, (prevData) => (prevData ?? []).map((p) => { if (p.id === issueId) { return { ...p, ...formData, }; } return p; }), false ); issuesService .patchIssue(workspaceSlug as string, projectId as string, issueId as string, formData, user) .then(() => { mutate(fetchKey); }) .catch((error) => { console.log(error); }); }, [workspaceSlug, projectId, cycleId, moduleId, viewId, params, 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 paddingLeft = `${nestingLevel * 68}px`; const isNotAllowed = userAuth.isGuest || userAuth.isViewer; return (
{properties.key && ( {issue.project_detail?.identifier}-{issue.sequence_id} )}
{issue.sub_issues_count > 0 && ( )}
{issue.name}
{properties.state && (
)} {properties.priority && (
)} {properties.assignee && (
)} {properties.labels ? ( issue.label_details.length > 0 ? (
{issue.label_details.slice(0, 4).map((label, index) => (
))} {issue.label_details.length > 4 ? +{issue.label_details.length - 4} : null}
) : (
No Labels
) ) : ( "" )} {properties.due_date && (
)} {properties.estimate && (
)}
{!isNotAllowed && ( handleEditIssue(issue)}>
Edit issue
handleDeleteIssue(issue)}>
Delete issue
Copy issue link
)}
); };