All files / src/components/features/admin/dev/DevProjectManagement DevProjectList.tsx

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

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                                                                                                                                                                                                                                                                                                                                                                           
'use client';

/**
 * DevProjectList - Table display of dev projects
 */

import React from 'react';
import Link from 'next/link';
import Image from 'next/image';
import { Icon } from '@/components/ui/icons';

interface ProjectWithStats {
  id: string;
  name: string;
  key: string;
  description: string | null;
  color: string;
  isActive: boolean;
  lead: {
    id: number;
    name: string | null;
    email: string;
    image: string | null;
  } | null;
  createdAt: string;
  updatedAt: string;
  _count: {
    tickets: number;
    milestones: number;
    sprints: number;
  };
}

export interface DevProjectListProps {
  /** List of projects to display */
  projects: ProjectWithStats[];
  /** Loading state */
  loading: boolean;
  /** Handler for delete */
  onDelete: (id: string) => void;
}

export default function DevProjectList({
  projects,
  loading,
  onDelete}: DevProjectListProps) {
  if (loading) {
    return (
      <div className="bg-white rounded-lg border border-gray-200 p-8 text-center">
        <div className="animate-spin h-8 w-8 border-4 border-indigo-600 border-t-transparent rounded-full mx-auto" />
        <p className="text-gray-500 mt-4">Loading projects...</p>
      </div>
    );
  }

  if (!projects || projects.length === 0) {
    return (
      <div className="bg-white rounded-lg border border-gray-200 p-8 text-center">
        <Icon name="archive" size={48} className="text-gray-400 mx-auto mb-4" />
        <p className="text-gray-500">No projects found</p>
      </div>
    );
  }

  return (
    <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
      {projects.map((project) => (
        <div
          key={project.id}
          className="bg-white rounded-lg border border-gray-200 overflow-hidden hover:shadow-lg transition-shadow"
        >
          {/* Header */}
          <div
            className="h-2"
            style={{ backgroundColor: project.color }}
          />
          <div className="p-5">
            <div className="flex items-start justify-between mb-4">
              <div>
                <div className="flex items-center gap-2">
                  <span
                    className="inline-flex items-center px-2 py-0.5 text-xs font-bold rounded"
                    style={{
                      backgroundColor: `${project.color}20`,
                      color: project.color}}
                  >
                    {project.key}
                  </span>
                  {!project.isActive && (
                    <span className="inline-flex items-center px-2 py-0.5 text-xs font-medium bg-gray-100 text-gray-600 rounded">
                      Inactive
                    </span>
                  )}
                </div>
                <h3 className="text-lg font-semibold text-gray-900 mt-2">
                  {project.name}
                </h3>
              </div>
              <div className="flex items-center gap-1">
                <Link
                  href={`/admin/dev/projects/${project.id}/edit`}
                  className="p-1.5 text-gray-400 hover:text-indigo-600 hover:bg-indigo-50 rounded-lg transition-colors"
                >
                  <Icon name="edit" size={16} />
                </Link>
                <button
                  onClick={() => onDelete(project.id)}
                  className="p-1.5 text-gray-400 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors"
                >
                  <Icon name="trash" size={16} />
                </button>
              </div>
            </div>

            {project.description && (
              <p className="text-sm text-gray-600 mb-4 line-clamp-2">
                {project.description}
              </p>
            )}

            {/* Lead */}
            {project.lead && (
              <div className="flex items-center mb-4">
                {project.lead.image ? (
                  <Image
                    src={project.lead.image}
                    alt={project.lead.name || ''}
                    width={24}
                    height={24}
                    className="w-6 h-6 rounded-full mr-2"
                  />
                ) : (
                  <div className="w-6 h-6 rounded-full bg-gray-200 flex items-center justify-center mr-2">
                    <span className="text-xs text-gray-600">
                      {project.lead.name?.charAt(0) || '?'}
                    </span>
                  </div>
                )}
                <span className="text-sm text-gray-600">
                  Lead: {project.lead.name}
                </span>
              </div>
            )}

            {/* Stats */}
            <div className="grid grid-cols-3 gap-3 pt-4 border-t border-gray-100">
              <div className="text-center">
                <p className="text-lg font-semibold text-gray-900">
                  {project._count.tickets}
                </p>
                <p className="text-xs text-gray-500">Tickets</p>
              </div>
              <div className="text-center">
                <p className="text-lg font-semibold text-gray-900">
                  {project._count.sprints}
                </p>
                <p className="text-xs text-gray-500">Sprints</p>
              </div>
              <div className="text-center">
                <p className="text-lg font-semibold text-gray-900">
                  {project._count.milestones}
                </p>
                <p className="text-xs text-gray-500">Milestones</p>
              </div>
            </div>
          </div>

          {/* Footer */}
          <div className="px-5 py-3 bg-gray-50 border-t border-gray-100">
            <Link
              href={`/admin/dev/tickets?projectId=${project.id}`}
              className="text-sm text-indigo-600 hover:text-indigo-800 font-medium"
            >
              View Tickets &rarr;
            </Link>
          </div>
        </div>
      ))}
    </div>
  );
}