2024-01-10 14:39:45 +00:00
|
|
|
import { FC } from "react";
|
|
|
|
import { X } from "lucide-react";
|
|
|
|
// types
|
2024-04-08 13:41:47 +00:00
|
|
|
import { useLabel } from "@/hooks/store";
|
2024-03-06 13:09:14 +00:00
|
|
|
import { TLabelOperations } from "./root";
|
2024-01-10 14:39:45 +00:00
|
|
|
|
|
|
|
type TLabelListItem = {
|
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
|
|
|
issueId: string;
|
|
|
|
labelId: string;
|
2024-04-08 13:41:47 +00:00
|
|
|
values: string[];
|
2024-01-10 14:39:45 +00:00
|
|
|
labelOperations: TLabelOperations;
|
2024-01-11 12:56:58 +00:00
|
|
|
disabled: boolean;
|
2024-01-10 14:39:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const LabelListItem: FC<TLabelListItem> = (props) => {
|
2024-04-08 13:41:47 +00:00
|
|
|
const { workspaceSlug, projectId, issueId, labelId, values, labelOperations, disabled } = props;
|
2024-01-10 14:39:45 +00:00
|
|
|
// hooks
|
|
|
|
const { getLabelById } = useLabel();
|
|
|
|
|
|
|
|
const label = getLabelById(labelId);
|
|
|
|
|
|
|
|
const handleLabel = async () => {
|
2024-04-08 13:41:47 +00:00
|
|
|
if (values && !disabled) {
|
|
|
|
const currentLabels = values.filter((_labelId) => _labelId !== labelId);
|
2024-01-10 14:39:45 +00:00
|
|
|
await labelOperations.updateIssue(workspaceSlug, projectId, issueId, { label_ids: currentLabels });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!label) return <></>;
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
key={labelId}
|
2024-02-25 17:06:33 +00:00
|
|
|
className={`transition-all relative flex items-center gap-1 truncate border border-custom-border-100 rounded-full text-xs p-0.5 px-1 group ${
|
2024-01-11 12:56:58 +00:00
|
|
|
!disabled ? "cursor-pointer hover:border-red-500/50 hover:bg-red-500/20" : "cursor-not-allowed"
|
|
|
|
} `}
|
2024-01-10 14:39:45 +00:00
|
|
|
onClick={handleLabel}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className="rounded-full h-2 w-2 flex-shrink-0"
|
|
|
|
style={{
|
|
|
|
backgroundColor: label.color ?? "#000000",
|
|
|
|
}}
|
|
|
|
/>
|
2024-02-25 17:06:33 +00:00
|
|
|
<div className="truncate">{label.name}</div>
|
2024-01-11 12:56:58 +00:00
|
|
|
{!disabled && (
|
|
|
|
<div className="flex-shrink-0">
|
|
|
|
<X className="transition-all h-2.5 w-2.5 group-hover:text-red-500" />
|
|
|
|
</div>
|
|
|
|
)}
|
2024-01-10 14:39:45 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|