Files
goodgo-platform/apps/web/components/chuyen-nhuong/transfer-item-table.tsx
Ho Ngoc Hai b2490e209e fix(web): consolidate inline currency formatters into shared lib (GOO-205)
Remove 8 inline formatPrice/formatVND/formatPriceM2 functions scattered
across components and pages, replacing them with imports from
@/lib/currency. Add formatVNDFull (full locale, no compact notation) for
chuyen-nhuong pages. Fix price-history-chart off-by-1000 bug caused by
double-dividing through priceToMillions then formatMillions. Add k/m²
branch to formatPricePerM2 for sub-million values.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
2026-04-24 14:17:55 +07:00

76 lines
2.7 KiB
TypeScript

'use client';
import { Badge } from '@/components/ui/badge';
import {
type TransferItemData,
CATEGORY_LABELS,
CONDITION_COLORS,
CONDITION_LABELS,
} from '@/lib/chuyen-nhuong-api';
import { formatVNDFull } from '@/lib/currency';
interface TransferItemTableProps {
items: TransferItemData[];
}
export function TransferItemTable({ items }: TransferItemTableProps) {
if (items.length === 0) {
return <p className="text-sm text-muted-foreground">Chưa danh sách vật phẩm.</p>;
}
return (
<div className="overflow-x-auto">
<table className="w-full text-sm">
<thead>
<tr className="border-b">
<th className="px-3 py-2 text-left font-medium">Tên</th>
<th className="px-3 py-2 text-left font-medium">Loại</th>
<th className="px-3 py-2 text-left font-medium">Tình trạng</th>
<th className="px-3 py-2 text-left font-medium">Thương hiệu</th>
<th className="px-3 py-2 text-right font-medium">SL</th>
<th className="px-3 py-2 text-right font-medium">Giá yêu cầu</th>
<th className="px-3 py-2 text-right font-medium">Giá AI</th>
</tr>
</thead>
<tbody>
{items.map((item) => (
<tr key={item.id} className="border-b">
<td className="px-3 py-2">
<div>
<p className="font-medium">{item.name}</p>
{item.modelName && (
<p className="text-xs text-muted-foreground">{item.modelName}</p>
)}
</div>
</td>
<td className="px-3 py-2 text-muted-foreground">
{CATEGORY_LABELS[item.category]}
</td>
<td className="px-3 py-2">
<Badge className={CONDITION_COLORS[item.condition]} variant="secondary">
{CONDITION_LABELS[item.condition]}
</Badge>
</td>
<td className="px-3 py-2 text-muted-foreground">
{item.brand ?? '—'}
</td>
<td className="px-3 py-2 text-right">{item.quantity}</td>
<td className="px-3 py-2 text-right font-medium">
{formatVNDFull(item.askingPriceVND)}
</td>
<td className="px-3 py-2 text-right text-muted-foreground">
{item.aiEstimatePriceVND ? (
<span title={item.aiConfidence ? `Độ tin cậy: ${Math.round(item.aiConfidence * 100)}%` : undefined}>
{formatVNDFull(item.aiEstimatePriceVND)}
</span>
) : '—'}
</td>
</tr>
))}
</tbody>
</table>
</div>
);
}