2024-05-14 20:55:38 +00:00
|
|
|
"use client";
|
2023-09-01 11:12:30 +00:00
|
|
|
import { FC } from "react";
|
2023-08-11 11:48:33 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
2024-06-10 06:46:23 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
import { useSearchParams } from "next/navigation";
|
2023-08-11 11:48:33 +00:00
|
|
|
// components
|
2024-06-10 06:46:23 +00:00
|
|
|
import { IssueBlockDueDate, IssueBlockLabels, IssueBlockPriority, IssueBlockState } from "@/components/issues";
|
2024-05-16 11:47:04 +00:00
|
|
|
// helpers
|
|
|
|
import { queryParamGenerator } from "@/helpers/query-param-generator";
|
|
|
|
// hook
|
2024-06-10 06:46:23 +00:00
|
|
|
import { useIssueDetails, usePublish } from "@/hooks/store";
|
|
|
|
// types
|
2024-05-14 08:56:54 +00:00
|
|
|
import { IIssue } from "@/types/issue";
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2024-05-14 08:56:54 +00:00
|
|
|
type IssueListBlockProps = {
|
2024-06-10 06:46:23 +00:00
|
|
|
anchor: string;
|
2024-05-14 08:56:54 +00:00
|
|
|
issue: IIssue;
|
|
|
|
};
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
export const IssueListLayoutBlock: FC<IssueListBlockProps> = observer((props) => {
|
|
|
|
const { anchor, issue } = props;
|
2024-05-16 07:44:36 +00:00
|
|
|
// query params
|
2024-06-10 06:46:23 +00:00
|
|
|
const searchParams = useSearchParams();
|
2024-05-16 07:44:36 +00:00
|
|
|
const board = searchParams.get("board") || undefined;
|
|
|
|
const state = searchParams.get("state") || undefined;
|
|
|
|
const priority = searchParams.get("priority") || undefined;
|
|
|
|
const labels = searchParams.get("labels") || undefined;
|
2024-06-10 06:46:23 +00:00
|
|
|
// store hooks
|
2024-05-14 08:56:54 +00:00
|
|
|
const { setPeekId } = useIssueDetails();
|
2024-06-10 06:46:23 +00:00
|
|
|
const { project_details } = usePublish(anchor);
|
2023-09-01 11:12:30 +00:00
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
const { queryParam } = queryParamGenerator({ board, peekId: issue.id, priority, state, labels });
|
2023-09-01 11:12:30 +00:00
|
|
|
const handleBlockClick = () => {
|
2024-05-14 08:56:54 +00:00
|
|
|
setPeekId(issue.id);
|
2023-09-01 11:12:30 +00:00
|
|
|
};
|
|
|
|
|
2023-08-11 11:48:33 +00:00
|
|
|
return (
|
2024-06-10 06:46:23 +00:00
|
|
|
<Link
|
|
|
|
href={`/issues/${anchor}?${queryParam}`}
|
|
|
|
onClick={handleBlockClick}
|
|
|
|
className="relative flex items-center gap-10 bg-custom-background-100 p-3"
|
|
|
|
>
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="relative flex w-full flex-grow items-center gap-3 overflow-hidden">
|
2023-08-11 11:48:33 +00:00
|
|
|
{/* id */}
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="flex-shrink-0 text-xs font-medium text-custom-text-300">
|
2024-06-10 06:46:23 +00:00
|
|
|
{project_details?.identifier}-{issue?.sequence_id}
|
2023-08-11 11:48:33 +00:00
|
|
|
</div>
|
|
|
|
{/* name */}
|
2024-06-10 06:46:23 +00:00
|
|
|
<div onClick={handleBlockClick} className="flex-grow cursor-pointer truncate text-sm">
|
2023-09-01 11:12:30 +00:00
|
|
|
{issue.name}
|
|
|
|
</div>
|
2023-08-11 11:48:33 +00:00
|
|
|
</div>
|
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
<div className="inline-flex flex-shrink-0 items-center gap-2 text-xs">
|
|
|
|
{/* priority */}
|
|
|
|
{issue?.priority && (
|
|
|
|
<div className="flex-shrink-0">
|
|
|
|
<IssueBlockPriority priority={issue?.priority} />
|
|
|
|
</div>
|
|
|
|
)}
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
{/* state */}
|
|
|
|
{issue?.state_detail && (
|
|
|
|
<div className="flex-shrink-0">
|
|
|
|
<IssueBlockState state={issue?.state_detail} />
|
|
|
|
</div>
|
|
|
|
)}
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
{/* labels */}
|
|
|
|
{issue?.label_details && issue?.label_details.length > 0 && (
|
|
|
|
<div className="flex-shrink-0">
|
|
|
|
<IssueBlockLabels labels={issue?.label_details} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{/* due date */}
|
|
|
|
{issue?.target_date && (
|
|
|
|
<div className="flex-shrink-0">
|
|
|
|
<IssueBlockDueDate due_date={issue?.target_date} group={issue?.state_detail?.group} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2024-06-10 06:46:23 +00:00
|
|
|
</Link>
|
2023-08-11 11:48:33 +00:00
|
|
|
);
|
2023-09-01 11:12:30 +00:00
|
|
|
});
|