Files
ftb-project-management/apps/web/components/product/RequirementTable.tsx
Script Generator e261c3d0b8 feat(product): 实现产品需求管理模块(后端 + 前端)
后端:Product Module(CRUD)、Requirement Module(CRUD + 状态机流转)、PrismaService
前端:产品列表页、产品详情页(含需求池 Tab)、Zustand Store、API 封装

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-08 11:06:16 +08:00

102 lines
3.4 KiB
TypeScript

'use client';
import { RequirementStatus } from '@ftb/shared';
import { RequirementStatusBadge } from './RequirementStatusBadge';
import { PRIORITY_LABEL, REQUIREMENT_STATUS_LABEL } from '@/lib/constants';
interface RequirementItem {
id: string;
title: string;
description: string;
status: RequirementStatus;
priority: number;
creator?: { id: string; name: string };
createdAt: string;
}
interface Props {
requirements: RequirementItem[];
statusFilter: RequirementStatus | null;
onFilterChange: (status: RequirementStatus | null) => void;
onEdit: (req: RequirementItem) => void;
onStatusChange: (id: string, status: RequirementStatus) => void;
onDelete: (id: string) => void;
onCreate: () => void;
}
const ALL_STATUSES = Object.values(RequirementStatus);
export function RequirementTable({
requirements,
statusFilter,
onFilterChange,
onEdit,
onStatusChange,
onDelete,
onCreate,
}: Props) {
return (
<div>
<div className="mb-4 flex items-center justify-between">
<div className="flex gap-2">
<button
onClick={() => onFilterChange(null)}
className={`rounded-full px-3 py-1 text-xs ${!statusFilter ? 'bg-blue-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-gray-200'}`}
>
</button>
{ALL_STATUSES.map((s) => (
<button
key={s}
onClick={() => onFilterChange(s)}
className={`rounded-full px-3 py-1 text-xs ${statusFilter === s ? 'bg-blue-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-gray-200'}`}
>
{REQUIREMENT_STATUS_LABEL[s]}
</button>
))}
</div>
<button
onClick={onCreate}
className="rounded-md bg-blue-600 px-4 py-2 text-sm text-white hover:bg-blue-700"
>
</button>
</div>
{requirements.length === 0 ? (
<div className="py-12 text-center text-gray-400"></div>
) : (
<table className="w-full text-left text-sm">
<thead className="border-b text-xs text-gray-500">
<tr>
<th className="pb-3 font-medium"></th>
<th className="pb-3 font-medium"></th>
<th className="pb-3 font-medium"></th>
<th className="pb-3 font-medium"></th>
<th className="pb-3 font-medium"></th>
</tr>
</thead>
<tbody className="divide-y">
{requirements.map((req) => (
<tr key={req.id} className="hover:bg-gray-50">
<td className="py-3 font-medium text-gray-900">{req.title}</td>
<td className="py-3">
<RequirementStatusBadge status={req.status} />
</td>
<td className="py-3 text-gray-600">{PRIORITY_LABEL[req.priority] || '无'}</td>
<td className="py-3 text-gray-600">{req.creator?.name || '-'}</td>
<td className="py-3">
<div className="flex gap-2">
<button onClick={() => onEdit(req)} className="text-blue-600 hover:underline"></button>
<button onClick={() => onDelete(req.id)} className="text-red-500 hover:underline"></button>
</div>
</td>
</tr>
))}
</tbody>
</table>
)}
</div>
);
}