Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

1.8 KB
Raw Blame
import { memo } from 'react';
import { useDraggable } from '@dnd-kit/core';
import type { ProjectDetail } from '@/lib/api/endpoints/projects';
import type { Issue } from '@/lib/api/endpoints/issues';
import { useIsPhone } from '@/hooks/useIsPhone';
import { usePermissions } from '@/hooks/usePermissions';
import { cn } from '@/lib/utils';
import IssueContextMenu from '@/features/issue/components/actions/IssueContextMenu';

// A draggable card in the unscheduled panel. Memoized because the panel renders
// again on every scroll step.
export const CalendarUnscheduledCard = memo(function CalendarUnscheduledCard({
  project,
  issue,
  color,
  onOpen,
}: {
  project: ProjectDetail;
  issue: Issue;
  color: string;
  onOpen: (id: number) => void;
}) {
  // Drag is disabled on phones, and without work_items edit (scheduling an issue
  // by dropping it on a day is an issue edit).
  const { can } = usePermissions();
  const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
    id: issue.id,
    disabled: useIsPhone() || !can('work_items', 'edit'),
  });
  return (
    <IssueContextMenu project={project} issue={issue}>
      <div
        ref={setNodeRef}
        {...attributes}
        {...listeners}
        onClick={(e) => {
          e.preventDefault();
          onOpen(issue.id);
        }}
        className={cn(
          'kanban-card flex cursor-pointer items-center gap-2 rounded-md p-2 text-xs',
          isDragging && 'opacity-40',
        )}
      >
        <span
          className="inline-block size-1.5 shrink-0 rounded-full"
          style={{ backgroundColor: color }}
        />
        <span className="shrink-0 text-muted-foreground tabular-nums">{issue.identifier}</span>
        <span className="truncate text-foreground">{issue.title}</span>
      </div>
    </IssueContextMenu>
  );
});