2024-04-10 14:25:16 +00:00
|
|
|
import { FC, MouseEvent } from "react";
|
2024-01-24 15:03:54 +00:00
|
|
|
import { observer } from "mobx-react";
|
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { Tooltip, PriorityIcon } from "@plane/ui";
|
2024-04-08 13:41:47 +00:00
|
|
|
// components
|
2024-05-07 08:40:27 +00:00
|
|
|
import { ButtonAvatars } from "@/components/dropdowns/member/avatar";
|
2024-04-08 13:41:47 +00:00
|
|
|
import { InboxIssueStatus } from "@/components/inbox";
|
2024-01-24 15:03:54 +00:00
|
|
|
// helpers
|
2024-04-08 13:41:47 +00:00
|
|
|
import { cn } from "@/helpers/common.helper";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { renderFormattedDate } from "@/helpers/date-time.helper";
|
2024-04-08 13:41:47 +00:00
|
|
|
// hooks
|
2024-05-07 08:40:27 +00:00
|
|
|
import { useLabel, useMember, useProjectInbox } from "@/hooks/store";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { usePlatformOS } from "@/hooks/use-platform-os";
|
2024-04-08 13:41:47 +00:00
|
|
|
// store
|
|
|
|
import { IInboxIssueStore } from "@/store/inbox/inbox-issue.store";
|
2024-01-24 15:03:54 +00:00
|
|
|
|
2024-04-08 13:41:47 +00:00
|
|
|
type InboxIssueListItemProps = {
|
2024-01-24 15:03:54 +00:00
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
2024-04-08 13:41:47 +00:00
|
|
|
projectIdentifier?: string;
|
|
|
|
inboxIssue: IInboxIssueStore;
|
2024-04-29 14:08:46 +00:00
|
|
|
setIsMobileSidebar: (value: boolean) => void;
|
2024-01-24 15:03:54 +00:00
|
|
|
};
|
|
|
|
|
2024-04-08 13:41:47 +00:00
|
|
|
export const InboxIssueListItem: FC<InboxIssueListItemProps> = observer((props) => {
|
2024-04-29 14:08:46 +00:00
|
|
|
const { workspaceSlug, projectId, inboxIssue, projectIdentifier, setIsMobileSidebar } = props;
|
2024-01-24 15:03:54 +00:00
|
|
|
// router
|
|
|
|
const router = useRouter();
|
|
|
|
const { inboxIssueId } = router.query;
|
2024-04-08 13:41:47 +00:00
|
|
|
// store
|
2024-04-10 10:38:31 +00:00
|
|
|
const { currentTab } = useProjectInbox();
|
2024-04-08 13:41:47 +00:00
|
|
|
const { projectLabels } = useLabel();
|
2024-03-12 15:09:36 +00:00
|
|
|
const { isMobile } = usePlatformOS();
|
2024-05-07 08:40:27 +00:00
|
|
|
const { getUserDetails } = useMember();
|
2024-04-08 13:41:47 +00:00
|
|
|
const issue = inboxIssue.issue;
|
2024-01-24 15:03:54 +00:00
|
|
|
|
2024-04-08 13:41:47 +00:00
|
|
|
const handleIssueRedirection = (event: MouseEvent, currentIssueId: string | undefined) => {
|
|
|
|
if (inboxIssueId === currentIssueId) event.preventDefault();
|
2024-04-29 14:08:46 +00:00
|
|
|
setIsMobileSidebar(false);
|
2024-04-08 13:41:47 +00:00
|
|
|
};
|
2024-01-24 15:03:54 +00:00
|
|
|
|
2024-04-08 13:41:47 +00:00
|
|
|
if (!issue) return <></>;
|
2024-05-07 08:40:27 +00:00
|
|
|
|
|
|
|
const createdByDetails = issue?.created_by ? getUserDetails(issue?.created_by) : undefined;
|
|
|
|
|
2024-01-24 15:03:54 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Link
|
|
|
|
id={`inbox-issue-list-item-${issue.id}`}
|
2024-04-08 13:41:47 +00:00
|
|
|
key={`${projectId}_${issue.id}`}
|
2024-04-10 10:38:31 +00:00
|
|
|
href={`/${workspaceSlug}/projects/${projectId}/inbox?currentTab=${currentTab}&inboxIssueId=${issue.id}`}
|
2024-04-08 13:41:47 +00:00
|
|
|
onClick={(e) => handleIssueRedirection(e, issue.id)}
|
2024-01-24 15:03:54 +00:00
|
|
|
>
|
|
|
|
<div
|
2024-04-08 13:41:47 +00:00
|
|
|
className={cn(
|
|
|
|
`flex flex-col gap-2 relative border border-t-transparent border-l-transparent border-r-transparent border-b-custom-border-200 p-4 hover:bg-custom-primary/5 cursor-pointer transition-all`,
|
2024-04-30 11:51:24 +00:00
|
|
|
{ "border-custom-primary-100 border": inboxIssueId === issue.id }
|
2024-04-08 13:41:47 +00:00
|
|
|
)}
|
2024-01-24 15:03:54 +00:00
|
|
|
>
|
2024-04-08 13:41:47 +00:00
|
|
|
<div className="space-y-1">
|
|
|
|
<div className="relative flex items-center justify-between gap-2">
|
|
|
|
<div className="flex-shrink-0 text-xs font-medium text-custom-text-300">
|
|
|
|
{projectIdentifier}-{issue.sequence_id}
|
|
|
|
</div>
|
|
|
|
{inboxIssue.status !== -2 && <InboxIssueStatus inboxIssue={inboxIssue} iconSize={12} />}
|
2024-01-24 15:03:54 +00:00
|
|
|
</div>
|
2024-04-08 13:41:47 +00:00
|
|
|
<h3 className="truncate w-full text-sm">{issue.name}</h3>
|
2024-01-24 15:03:54 +00:00
|
|
|
</div>
|
|
|
|
|
2024-05-07 08:40:27 +00:00
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
|
|
<Tooltip
|
|
|
|
tooltipHeading="Created on"
|
|
|
|
tooltipContent={`${renderFormattedDate(issue.created_at ?? "")}`}
|
|
|
|
isMobile={isMobile}
|
|
|
|
>
|
|
|
|
<div className="text-xs text-custom-text-200">{renderFormattedDate(issue.created_at ?? "")}</div>
|
|
|
|
</Tooltip>
|
2024-04-08 13:41:47 +00:00
|
|
|
|
2024-05-07 08:40:27 +00:00
|
|
|
<div className="border-2 rounded-full border-custom-border-400" />
|
2024-04-08 13:41:47 +00:00
|
|
|
|
2024-05-07 08:40:27 +00:00
|
|
|
{issue.priority && (
|
|
|
|
<Tooltip tooltipHeading="Priority" tooltipContent={`${issue.priority ?? "None"}`}>
|
|
|
|
<PriorityIcon priority={issue.priority} withContainer className="w-3 h-3" />
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
2024-04-08 13:41:47 +00:00
|
|
|
|
2024-05-07 08:40:27 +00:00
|
|
|
{issue.label_ids && issue.label_ids.length > 3 ? (
|
|
|
|
<div className="relative !h-[17.5px] flex items-center gap-1 rounded border border-custom-border-300 px-1 text-xs">
|
|
|
|
<span className="h-2 w-2 rounded-full bg-orange-400" />
|
|
|
|
<span className="normal-case max-w-28 truncate">{`${issue.label_ids.length} labels`}</span>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{(issue.label_ids ?? []).map((labelId) => {
|
|
|
|
const labelDetails = projectLabels?.find((l) => l.id === labelId);
|
|
|
|
if (!labelDetails) return null;
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
key={labelId}
|
|
|
|
className="relative !h-[17.5px] flex items-center gap-1 rounded border border-custom-border-300 px-1 text-xs"
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
className="h-2 w-2 rounded-full"
|
|
|
|
style={{
|
|
|
|
backgroundColor: labelDetails.color,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<span className="normal-case max-w-28 truncate">{labelDetails.name}</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
{/* created by */}
|
|
|
|
{createdByDetails && <ButtonAvatars showTooltip={false} userIds={createdByDetails?.id} />}
|
2024-01-24 15:03:54 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|