Files
Train/apps/web/src/components/RevisionList.tsx
T
2026-06-16 00:55:20 +08:00

68 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Revision } from '../types';
import { labelOf } from '../lib/fieldLabels';
import { Button } from './ui';
const STATUS_LABEL: Record<string, string> = {
pending: '待审核',
approved: '已通过',
rejected: '已驳回',
};
const STATUS_CLS: Record<string, string> = {
pending: 'tag tag-amber',
approved: 'tag tag-green',
rejected: 'tag tag-gray',
};
export function RevisionList({
revisions,
onApprove,
onReject,
}: {
revisions: Revision[];
onApprove?: (id: number) => void;
onReject?: (id: number) => void;
}) {
if (revisions.length === 0)
return <p className="muted"></p>;
return (
<ul className="rev-list">
{revisions.map((r) => (
<li key={r.id} className="rev-item">
<div className="rev-head">
<span className={STATUS_CLS[r.status]}>{STATUS_LABEL[r.status]}</span>
<span className="rev-author">{r.author_name}</span>
<span className="muted rev-date">
{new Date(r.created_at + 'Z').toLocaleString('zh-CN')}
</span>
</div>
{r.note && <p className="rev-note">{r.note}</p>}
<ul className="rev-changes">
{r.changes.map((c) => (
<li key={c.field}>
<b>{labelOf(c.field)}</b>
<span className="old">{c.old_value || '—'}</span>
{' → '}
<span className="new">{c.new_value || '—'}</span>
</li>
))}
</ul>
{r.status === 'pending' && (onApprove || onReject) && (
<div className="rev-actions">
{onApprove && (
<Button variant="primary" size="sm" onClick={() => onApprove(r.id)}>
</Button>
)}
{onReject && (
<Button variant="danger" size="sm" onClick={() => onReject(r.id)}>
</Button>
)}
</div>
)}
</li>
))}
</ul>
);
}