All files / src/components/features/admin/dev/DevSprintManagement DevSprintBoard.tsx

0% Statements 0/249
100% Branches 0/0
0% Functions 0/1
0% Lines 0/249

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
'use client';

/**
 * DevSprintBoard - Kanban-style sprint board view
 */

import React from 'react';
import Link from 'next/link';
import { DevTicketWithRelations } from '@/types/dev-ticket';
import {
  DEV_TICKET_TYPE_CONFIG,
  DEV_TICKET_STATUS_CONFIG,
  DEV_TICKET_PRIORITY_CONFIG } from '@/constants/dev-ticket';
import Image from 'next/image';

interface SprintWithStats {
  id: string;
  name: string;
  goal: string | null;
  status: string;
  startDate: string;
  endDate: string;
  project: {
    id: string;
    name: string;
    key: string;
    color: string;
  };
  tickets: DevTicketWithRelations[];
  stats: {
    totalTickets: number;
    completedTickets: number;
    completionPercentage: number;
    totalStoryPoints: number;
    completedStoryPoints: number;
    pointsPercentage: number;
    byStatus?: Record<string, number>;
  };
}

export interface DevSprintBoardProps {
  /** Sprint data with tickets */
  sprint: SprintWithStats;
  /** Handler for ticket status change */
  onTicketStatusChange: (ticketId: string, newStatus: string) => void;
}

// Define board columns
const BOARD_COLUMNS = [
  { key: 'OPEN', label: 'To Do' },
  { key: 'IN_PROGRESS', label: 'In Progress' },
  { key: 'IN_REVIEW', label: 'In Review' },
  { key: 'TESTING', label: 'Testing' },
  { key: 'COMPLETED', label: 'Done' },
];

export default function DevSprintBoard({
  sprint,
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  onTicketStatusChange}: DevSprintBoardProps) {
  const daysRemaining = Math.max(
    0,
    Math.ceil(
      (new Date(sprint.endDate).getTime() - new Date().getTime()) / (1000 * 60 * 60 * 24)
    )
  );

  const getTicketsByStatus = (status: string) => {
    return sprint.tickets.filter((t) => t.status === status);
  };

  return (
    <div className="space-y-6">
      {/* Sprint Header */}
      <div className="bg-white rounded-lg border border-gray-200 p-6">
        <div className="flex items-start justify-between mb-4">
          <div>
            <div className="flex items-center gap-2 mb-2">
              <span
                className="inline-flex items-center px-2 py-0.5 text-xs font-bold rounded"
                style={{
                  backgroundColor: `${sprint.project.color}20`,
                  color: sprint.project.color}}
              >
                {sprint.project.key}
              </span>
              <span
                className={`inline-flex px-2 py-0.5 text-xs font-medium rounded-full ${
                  sprint.status === 'ACTIVE'
                    ? 'bg-green-100 text-green-700'
                    : sprint.status === 'COMPLETED'
                      ? 'bg-blue-100 text-blue-700'
                      : 'bg-gray-100 text-gray-700'
                }`}
              >
                {sprint.status}
              </span>
            </div>
            <h2 className="text-xl font-bold text-gray-900">{sprint.name}</h2>
            {sprint.goal && (
              <p className="text-sm text-gray-600 mt-1">{sprint.goal}</p>
            )}
          </div>
          <div className="text-right">
            <p className="text-sm text-gray-500">
              {new Date(sprint.startDate).toLocaleDateString()} -{' '}
              {new Date(sprint.endDate).toLocaleDateString()}
            </p>
            {sprint.status === 'ACTIVE' && (
              <p className="text-sm font-medium text-indigo-600">
                {daysRemaining} day{daysRemaining !== 1 ? 's' : ''} remaining
              </p>
            )}
          </div>
        </div>

        {/* Progress Bar */}
        <div className="mt-4">
          <div className="flex justify-between text-sm mb-2">
            <span className="text-gray-600">
              {sprint.stats.completedTickets} / {sprint.stats.totalTickets} tickets
            </span>
            <span className="text-gray-600">
              {sprint.stats.completedStoryPoints} / {sprint.stats.totalStoryPoints} points
            </span>
          </div>
          <div className="h-2 bg-gray-200 rounded-full overflow-hidden">
            <div
              className="h-full bg-indigo-600 transition-all duration-500"
              style={{ width: `${sprint.stats.pointsPercentage}%` }}
            />
          </div>
          <p className="text-xs text-gray-500 mt-1 text-right">
            {sprint.stats.pointsPercentage}% complete
          </p>
        </div>
      </div>

      {/* Board Columns */}
      <div className="grid grid-cols-5 gap-4">
        {BOARD_COLUMNS.map((column) => {
          const tickets = getTicketsByStatus(column.key);
          const statusConfig = DEV_TICKET_STATUS_CONFIG[column.key as keyof typeof DEV_TICKET_STATUS_CONFIG];

          return (
            <div
              key={column.key}
              className="bg-gray-50 rounded-lg p-3 min-h-[400px]"
            >
              {/* Column Header */}
              <div className="flex items-center justify-between mb-3">
                <div className="flex items-center gap-2">
                  <span
                    className={`w-2 h-2 rounded-full ${statusConfig?.bgColor.replace('/10', '').replace('bg-', 'bg-') || 'bg-gray-400'}`}
                  />
                  <h3 className="text-sm font-semibold text-gray-700">
                    {column.label}
                  </h3>
                </div>
                <span className="inline-flex items-center justify-center w-5 h-5 text-xs font-medium text-gray-500 bg-white rounded-full">
                  {tickets.length}
                </span>
              </div>

              {/* Ticket Cards */}
              <div className="space-y-2">
                {tickets.map((ticket) => {
                  const typeConfig =
                    DEV_TICKET_TYPE_CONFIG[ticket.type as keyof typeof DEV_TICKET_TYPE_CONFIG];
                  const priorityConfig =
                    DEV_TICKET_PRIORITY_CONFIG[
                      ticket.priority as keyof typeof DEV_TICKET_PRIORITY_CONFIG
                    ];

                  return (
                    <Link
                      key={ticket.id}
                      href={`/admin/dev/tickets/${ticket.id}`}
                      className="block bg-white rounded-lg border border-gray-200 p-3 hover:shadow-md transition-shadow"
                    >
                      {/* Type & Priority */}
                      <div className="flex items-center gap-1 mb-2">
                        <span
                          className={`inline-flex items-center px-1.5 py-0.5 text-xs rounded ${typeConfig?.bgColor || 'bg-gray-100'} ${typeConfig?.color || 'text-gray-600'}`}
                        >
                          {typeConfig?.icon && (
                            <span className="mr-0.5">{typeConfig.icon}</span>
                          )}
                          {typeConfig?.label || ticket.type}
                        </span>
                        <span
                          className={`inline-flex px-1.5 py-0.5 text-xs rounded ${priorityConfig?.bgColor || 'bg-gray-100'} ${priorityConfig?.color || 'text-gray-600'}`}
                        >
                          {priorityConfig?.label || ticket.priority}
                        </span>
                      </div>

                      {/* Title */}
                      <p className="text-sm font-medium text-gray-900 line-clamp-2 mb-2">
                        {ticket.title}
                      </p>

                      {/* Footer */}
                      <div className="flex items-center justify-between mt-2 pt-2 border-t border-gray-100">
                        <span className="text-xs text-gray-500">
                          {ticket.ticketNumber}
                        </span>
                        <div className="flex items-center gap-2">
                          {ticket.storyPoints !== null && (
                            <span className="inline-flex items-center justify-center w-5 h-5 text-xs font-medium text-gray-600 bg-gray-100 rounded-full">
                              {ticket.storyPoints}
                            </span>
                          )}
                          {ticket.assignee && (
                            ticket.assignee.image ? (
                              <Image
                                src={ticket.assignee.image}
                                alt={ticket.assignee.name || ''}
                                width={20}
                                height={20}
                                className="w-5 h-5 rounded-full"
                              />
                            ) : (
                              <div className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center">
                                <span className="text-xs text-gray-600">
                                  {ticket.assignee.name?.charAt(0) || '?'}
                                </span>
                              </div>
                            )
                          )}
                        </div>
                      </div>
                    </Link>
                  );
                })}

                {tickets.length === 0 && (
                  <div className="text-center py-8 text-sm text-gray-400">
                    No tickets
                  </div>
                )}
              </div>
            </div>
          );
        })}
      </div>
    </div>
  );
}