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-03-09 17:20:34 +00:00
|
|
|
import { copyTextToClipboard, truncateText } from "helpers/string.helper";
|
2023-02-23 12:42:43 +00:00
|
|
|
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;
|
2023-01-26 18:12:20 +00:00
|
|
|
};
|
|
|
|
|
2023-03-09 17:20:34 +00:00
|
|
|
export const MyIssuesListItem: React.FC<Props> = ({ issue, properties, projectId }) => {
|
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 (
|
2023-03-09 17:20:34 +00:00
|
|
|
<div className="border-b border-gray-300 last:border-b-0">
|
2023-03-14 06:48:14 +00:00
|
|
|
<div key={issue.id} className="flex items-center justify-between gap-2 px-4 py-3">
|
2023-01-26 18:12:20 +00:00
|
|
|
<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
|
2023-03-14 06:48:14 +00:00
|
|
|
tooltipHeading="Issue ID"
|
2023-02-23 11:16:52 +00:00
|
|
|
tooltipContent={`${issue.project_detail?.identifier}-${issue.sequence_id}`}
|
|
|
|
>
|
2023-03-14 06:48:14 +00:00
|
|
|
<span className="flex-shrink-0 text-xs text-gray-400">
|
2023-02-23 11:16:52 +00:00
|
|
|
{issue.project_detail?.identifier}-{issue.sequence_id}
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
2023-01-26 18:12:20 +00:00
|
|
|
)}
|
2023-03-21 07:17:10 +00:00
|
|
|
<Tooltip position="top-left" tooltipHeading="Title" tooltipContent={issue.name}>
|
2023-03-14 06:48:14 +00:00
|
|
|
<span className="break-all text-sm text-gray-800">
|
|
|
|
{truncateText(issue.name, 50)}
|
|
|
|
</span>
|
2023-02-23 11:16:52 +00:00
|
|
|
</Tooltip>
|
2023-01-26 18:12:20 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
2023-03-09 17:20:34 +00:00
|
|
|
|
2023-03-14 06:48:14 +00:00
|
|
|
<div className="flex flex-wrap items-center gap-2 text-xs">
|
2023-03-09 17:20:34 +00:00
|
|
|
{properties.priority && (
|
|
|
|
<ViewPrioritySelect
|
|
|
|
issue={issue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
|
|
|
isNotAllowed={isNotAllowed}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{properties.state && (
|
|
|
|
<ViewStateSelect
|
|
|
|
issue={issue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
|
|
|
isNotAllowed={isNotAllowed}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{properties.due_date && (
|
|
|
|
<ViewDueDateSelect
|
|
|
|
issue={issue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
|
|
|
isNotAllowed={isNotAllowed}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{properties.sub_issue_count && (
|
|
|
|
<div className="flex items-center gap-1 rounded-md border px-3 py-1.5 text-xs shadow-sm">
|
|
|
|
{issue?.sub_issues_count} {issue?.sub_issues_count === 1 ? "sub-issue" : "sub-issues"}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{properties.labels && issue.label_details.length > 0 ? (
|
|
|
|
<div className="flex flex-wrap gap-1">
|
|
|
|
{issue.label_details.map((label) => (
|
2023-02-23 05:24:54 +00:00
|
|
|
<span
|
2023-03-09 17:20:34 +00:00
|
|
|
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>
|
|
|
|
))}
|
2023-02-23 11:16:52 +00:00
|
|
|
</div>
|
2023-03-09 17:20:34 +00:00
|
|
|
) : (
|
|
|
|
""
|
|
|
|
)}
|
|
|
|
{properties.assignee && (
|
|
|
|
<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>
|
|
|
|
)}
|
|
|
|
<CustomMenu width="auto" ellipsis>
|
|
|
|
<CustomMenu.MenuItem onClick={handleCopyText}>Copy issue link</CustomMenu.MenuItem>
|
|
|
|
</CustomMenu>
|
|
|
|
</div>
|
2023-01-26 18:12:20 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|