import React, { useCallback, useState } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; import { Popover2 } from "@blueprintjs/popover2"; // icons import { Icon } from "components/ui"; import { EllipsisHorizontalIcon, LinkIcon, PencilIcon, TrashIcon } from "@heroicons/react/24/outline"; // services import issuesService from "services/issue.service"; import trackEventServices from "services/track_event.service"; // hooks import useToast from "hooks/use-toast"; // components import { ViewDueDateSelect, ViewEstimateSelect, ViewStartDateSelect } from "components/issues"; import { LabelSelect, MembersSelect, PrioritySelect } from "components/project"; import { StateSelect } from "components/states"; // helpers import { copyTextToClipboard } from "helpers/string.helper"; import { renderLongDetailDateFormat } from "helpers/date-time.helper"; // types import { ICurrentUserResponse, IIssue, IState, Properties, TIssuePriorities, UserAuth } from "types"; // constant import { CYCLE_DETAILS, MODULE_DETAILS, SUB_ISSUES } from "constants/fetch-keys"; type Props = { issue: IIssue; index: number; expanded: boolean; handleToggleExpand: (issueId: string) => void; properties: Properties; handleEditIssue: (issue: IIssue) => void; handleDeleteIssue: (issue: IIssue) => void; gridTemplateColumns: string; disableUserActions: boolean; user: ICurrentUserResponse | undefined; userAuth: UserAuth; nestingLevel: number; }; export const SingleSpreadsheetIssue: React.FC = ({ issue, index, expanded, handleToggleExpand, properties, handleEditIssue, handleDeleteIssue, gridTemplateColumns, disableUserActions, user, userAuth, nestingLevel, }) => { const [isOpen, setIsOpen] = useState(false); const router = useRouter(); const { workspaceSlug, projectId, cycleId, moduleId } = router.query; const { setToastAlert } = useToast(); const partialUpdateIssue = useCallback( (formData: Partial, issue: IIssue) => { if (!workspaceSlug || !projectId) return; issuesService .patchIssue(workspaceSlug as string, projectId as string, issue.id as string, formData, user) .then(() => { if (issue.parent) { mutate(SUB_ISSUES(issue.parent as string)); } else { if (cycleId) mutate(CYCLE_DETAILS(cycleId as string)); if (moduleId) mutate(MODULE_DETAILS(moduleId as string)); } }) .catch((error) => { console.log(error); }); }, [workspaceSlug, projectId, cycleId, moduleId, user] ); const openPeekOverview = () => { const { query } = router; router.push({ pathname: router.pathname, query: { ...query, peekIssue: issue.id }, }); }; 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 handleStateChange = (data: string, states: IState[] | undefined) => { const oldState = states?.find((s) => s.id === issue.state); const newState = states?.find((s) => s.id === data); partialUpdateIssue( { state: data, state_detail: newState, }, issue ); trackEventServices.trackIssuePartialPropertyUpdateEvent( { workspaceSlug, workspaceId: issue.workspace, projectId: issue.project_detail.id, projectIdentifier: issue.project_detail.identifier, projectName: issue.project_detail.name, issueId: issue.id, }, "ISSUE_PROPERTY_UPDATE_STATE", user ); if (oldState?.group !== "completed" && newState?.group !== "completed") { trackEventServices.trackIssueMarkedAsDoneEvent( { workspaceSlug: issue.workspace_detail.slug, workspaceId: issue.workspace_detail.id, projectId: issue.project_detail.id, projectIdentifier: issue.project_detail.identifier, projectName: issue.project_detail.name, issueId: issue.id, }, user ); } }; const handlePriorityChange = (data: TIssuePriorities) => { partialUpdateIssue({ priority: data }, issue); trackEventServices.trackIssuePartialPropertyUpdateEvent( { workspaceSlug, workspaceId: issue.workspace, projectId: issue.project_detail.id, projectIdentifier: issue.project_detail.identifier, projectName: issue.project_detail.name, issueId: issue.id, }, "ISSUE_PROPERTY_UPDATE_PRIORITY", user ); }; const handleAssigneeChange = (data: any) => { const newData = issue.assignees ?? []; if (newData.includes(data)) newData.splice(newData.indexOf(data), 1); else newData.push(data); partialUpdateIssue({ assignees_list: data }, issue); trackEventServices.trackIssuePartialPropertyUpdateEvent( { workspaceSlug, workspaceId: issue.workspace, projectId: issue.project_detail.id, projectIdentifier: issue.project_detail.identifier, projectName: issue.project_detail.name, issueId: issue.id, }, "ISSUE_PROPERTY_UPDATE_ASSIGNEE", user ); }; const handleLabelChange = (data: any) => { partialUpdateIssue({ labels_list: data }, issue); }; const paddingLeft = `${nestingLevel * 68}px`; const tooltipPosition = index === 0 ? "bottom" : "top"; const isNotAllowed = userAuth.isGuest || userAuth.isViewer; return ( <>
{properties.key && ( {issue.project_detail?.identifier}-{issue.sequence_id} )} {!isNotAllowed && !disableUserActions && (
setIsOpen(nextOpenState)} content={
} placement="bottom-start" >
)}
{issue.sub_issues_count > 0 && (
)}
{properties.state && (
)} {properties.priority && (
)} {properties.assignee && (
)} {properties.labels && (
)} {properties.start_date && (
)} {properties.due_date && (
)} {properties.estimate && (
)} {properties.created_on && (
{renderLongDetailDateFormat(issue.created_at)}
)} {properties.updated_on && (
{renderLongDetailDateFormat(issue.updated_at)}
)}
); };