2023-02-06 09:48:57 +00:00
|
|
|
import React, { useCallback } from "react";
|
2023-01-26 18:12:20 +00:00
|
|
|
|
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
2023-02-08 04:43:07 +00:00
|
|
|
import { mutate } from "swr";
|
2023-02-06 09:48:57 +00:00
|
|
|
|
|
|
|
// services
|
|
|
|
import issuesService from "services/issues.service";
|
2023-01-26 18:12:20 +00:00
|
|
|
// components
|
2023-02-08 04:43:07 +00:00
|
|
|
import {
|
|
|
|
ViewDueDateSelect,
|
|
|
|
ViewPrioritySelect,
|
|
|
|
ViewStateSelect,
|
|
|
|
} from "components/issues/view-select";
|
2023-02-06 09:48:57 +00:00
|
|
|
// ui
|
2023-01-26 18:12:20 +00:00
|
|
|
import { AssigneesList } from "components/ui/avatar";
|
2023-02-23 11:16:52 +00:00
|
|
|
import { CustomMenu, Tooltip } from "components/ui";
|
2023-01-26 18:12:20 +00:00
|
|
|
// types
|
|
|
|
import { IIssue, Properties } from "types";
|
2023-02-06 09:48:57 +00:00
|
|
|
// fetch-keys
|
2023-02-08 04:43:07 +00:00
|
|
|
import { USER_ISSUE } from "constants/fetch-keys";
|
2023-02-23 12:42:43 +00:00
|
|
|
import { copyTextToClipboard } from "helpers/string.helper";
|
|
|
|
import useToast from "hooks/use-toast";
|
2023-01-26 18:12:20 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issue: IIssue;
|
|
|
|
properties: Properties;
|
2023-02-06 09:48:57 +00:00
|
|
|
projectId: string;
|
|
|
|
handleDeleteIssue: () => void;
|
2023-01-26 18:12:20 +00:00
|
|
|
};
|
|
|
|
|
2023-02-06 09:48:57 +00:00
|
|
|
export const MyIssuesListItem: React.FC<Props> = ({
|
|
|
|
issue,
|
|
|
|
properties,
|
|
|
|
projectId,
|
|
|
|
handleDeleteIssue,
|
|
|
|
}) => {
|
2023-01-26 18:12:20 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
2023-02-23 12:42:43 +00:00
|
|
|
const { setToastAlert } = useToast();
|
2023-01-26 18:12:20 +00:00
|
|
|
|
2023-02-06 09:48:57 +00:00
|
|
|
const partialUpdateIssue = useCallback(
|
|
|
|
(formData: Partial<IIssue>) => {
|
|
|
|
if (!workspaceSlug) return;
|
|
|
|
|
|
|
|
mutate<IIssue[]>(
|
|
|
|
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]
|
|
|
|
);
|
|
|
|
|
2023-02-23 12:42:43 +00:00
|
|
|
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.",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-02-06 09:48:57 +00:00
|
|
|
const isNotAllowed = false;
|
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
return (
|
|
|
|
<div key={issue.id} className="flex items-center justify-between gap-2 px-4 py-3 text-sm">
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<span
|
|
|
|
className={`block h-1.5 w-1.5 flex-shrink-0 rounded-full`}
|
|
|
|
style={{
|
|
|
|
backgroundColor: issue.state_detail.color,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Link href={`/${workspaceSlug}/projects/${issue?.project_detail?.id}/issues/${issue.id}`}>
|
|
|
|
<a className="group relative flex items-center gap-2">
|
|
|
|
{properties?.key && (
|
2023-02-23 11:16:52 +00:00
|
|
|
<Tooltip
|
|
|
|
tooltipHeading="ID"
|
|
|
|
tooltipContent={`${issue.project_detail?.identifier}-${issue.sequence_id}`}
|
|
|
|
>
|
|
|
|
<span className="flex-shrink-0 text-xs text-gray-500">
|
|
|
|
{issue.project_detail?.identifier}-{issue.sequence_id}
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
2023-01-26 18:12:20 +00:00
|
|
|
)}
|
2023-02-23 11:16:52 +00:00
|
|
|
<Tooltip tooltipHeading="Title" tooltipContent={issue.name}>
|
2023-03-05 17:54:50 +00:00
|
|
|
<span className="w-auto max-w-lg overflow-hidden text-ellipsis whitespace-nowrap">
|
2023-02-23 11:16:52 +00:00
|
|
|
{issue.name}
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
2023-01-26 18:12:20 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-shrink-0 flex-wrap items-center gap-x-1 gap-y-2 text-xs">
|
|
|
|
{properties.priority && (
|
2023-02-08 04:43:07 +00:00
|
|
|
<ViewPrioritySelect
|
2023-02-06 09:48:57 +00:00
|
|
|
issue={issue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
|
|
|
isNotAllowed={isNotAllowed}
|
|
|
|
/>
|
2023-01-26 18:12:20 +00:00
|
|
|
)}
|
|
|
|
{properties.state && (
|
2023-02-08 04:43:07 +00:00
|
|
|
<ViewStateSelect
|
2023-02-06 09:48:57 +00:00
|
|
|
issue={issue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
|
|
|
isNotAllowed={isNotAllowed}
|
|
|
|
/>
|
2023-01-26 18:12:20 +00:00
|
|
|
)}
|
|
|
|
{properties.due_date && (
|
2023-02-08 04:43:07 +00:00
|
|
|
<ViewDueDateSelect
|
2023-02-06 09:48:57 +00:00
|
|
|
issue={issue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
|
|
|
isNotAllowed={isNotAllowed}
|
|
|
|
/>
|
2023-01-26 18:12:20 +00:00
|
|
|
)}
|
|
|
|
{properties.sub_issue_count && (
|
2023-03-05 17:54:50 +00:00
|
|
|
<div className="flex flex-shrink-0 items-center gap-1 rounded-md border px-3 py-1.5 text-xs shadow-sm">
|
2023-01-26 18:12:20 +00:00
|
|
|
{issue?.sub_issues_count} {issue?.sub_issues_count === 1 ? "sub-issue" : "sub-issues"}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-02-23 05:24:54 +00:00
|
|
|
{properties.labels && (
|
|
|
|
<div className="flex flex-wrap gap-1">
|
|
|
|
{issue.label_details.map((label) => (
|
|
|
|
<span
|
|
|
|
key={label.id}
|
|
|
|
className="group flex items-center gap-1 rounded-2xl border px-2 py-0.5 text-xs"
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
className="h-1.5 w-1.5 flex-shrink-0 rounded-full"
|
|
|
|
style={{
|
|
|
|
backgroundColor: label?.color && label.color !== "" ? label.color : "#000",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{label.name}
|
|
|
|
</span>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-01-26 18:12:20 +00:00
|
|
|
{properties.assignee && (
|
2023-02-23 11:16:52 +00:00
|
|
|
<Tooltip
|
|
|
|
position="top-right"
|
|
|
|
tooltipHeading="Assignees"
|
|
|
|
tooltipContent={
|
|
|
|
issue.assignee_details.length > 0
|
|
|
|
? issue.assignee_details
|
|
|
|
.map((assignee) =>
|
|
|
|
assignee?.first_name !== "" ? assignee?.first_name : assignee?.email
|
|
|
|
)
|
|
|
|
.join(", ")
|
|
|
|
: "No Assignee"
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<div className="flex items-center gap-1">
|
|
|
|
<AssigneesList userIds={issue.assignees ?? []} />
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
2023-01-26 18:12:20 +00:00
|
|
|
)}
|
2023-02-06 09:48:57 +00:00
|
|
|
<CustomMenu width="auto" ellipsis>
|
2023-02-23 12:42:43 +00:00
|
|
|
<CustomMenu.MenuItem onClick={handleDeleteIssue}>Delete issue</CustomMenu.MenuItem>
|
|
|
|
<CustomMenu.MenuItem onClick={handleCopyText}>Copy issue link</CustomMenu.MenuItem>
|
2023-02-06 09:48:57 +00:00
|
|
|
</CustomMenu>
|
2023-01-26 18:12:20 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|