Files
goodgo-platform/apps/web/components/valuation/valuation-history.tsx
Ho Ngoc Hai 8da488711b feat(analytics): AVM v2 batch valuation, comparison, history + frontend upgrade
Add batch valuation (POST /analytics/valuation/batch, max 50 properties),
valuation comparison (POST /analytics/valuation/compare, 2-5 properties),
and history endpoint (GET /analytics/valuation/history/:propertyId) with
confidence explanation helper. Frontend: enhanced valuation form with project
autocomplete and deep analysis toggle, results with confidence badges and
price range visualization, comparables table, history chart, market context
card, and PDF export.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-16 05:08:05 +07:00

112 lines
3.5 KiB
TypeScript

'use client';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { formatPrice } from '@/lib/currency';
import type { ValuationHistoryItem } from '@/lib/valuation-api';
interface ValuationHistoryProps {
items: ValuationHistoryItem[];
total: number;
page: number;
onPageChange: (page: number) => void;
onSelect: (id: string) => void;
isLoading?: boolean;
}
const PROPERTY_TYPE_LABELS: Record<string, string> = {
APARTMENT: 'Căn hộ',
HOUSE: 'Nhà riêng',
VILLA: 'Biệt thự',
LAND: 'Đất nền',
OFFICE: 'Văn phòng',
SHOPHOUSE: 'Shophouse',
};
export function ValuationHistory({
items,
total,
page,
onPageChange,
onSelect,
isLoading,
}: ValuationHistoryProps) {
const totalPages = Math.ceil(total / 10);
return (
<Card>
<CardHeader>
<CardTitle className="text-lg">Lịch sử đnh giá</CardTitle>
<CardDescription>
{total} lần đnh giá trước đó
</CardDescription>
</CardHeader>
<CardContent>
{isLoading ? (
<div className="flex h-32 items-center justify-center text-muted-foreground">
Đang tải...
</div>
) : items.length === 0 ? (
<div className="flex h-32 items-center justify-center text-muted-foreground">
Chưa lịch sử đnh giá
</div>
) : (
<>
<div className="space-y-2">
{items.map((item) => (
<button
key={item.id}
type="button"
onClick={() => onSelect(item.id)}
className="flex w-full items-center gap-4 rounded-lg border p-3 text-left transition-colors hover:bg-accent"
>
<div className="min-w-0 flex-1">
<p className="font-medium">
{PROPERTY_TYPE_LABELS[item.propertyType] || item.propertyType}
</p>
<p className="text-sm text-muted-foreground">
{item.district}, {item.city} &middot; {item.area} m²
</p>
</div>
<div className="text-right">
<p className="font-semibold text-primary">
{formatPrice(item.estimatedPriceVND)}
</p>
<p className="text-sm text-muted-foreground">
{new Date(item.createdAt).toLocaleDateString('vi-VN')}
</p>
</div>
</button>
))}
</div>
{totalPages > 1 && (
<div className="mt-4 flex items-center justify-center gap-2">
<Button
variant="outline"
size="sm"
disabled={page <= 1}
onClick={() => onPageChange(page - 1)}
>
Trước
</Button>
<span className="text-sm text-muted-foreground">
Trang {page}/{totalPages}
</span>
<Button
variant="outline"
size="sm"
disabled={page >= totalPages}
onClick={() => onPageChange(page + 1)}
>
Tiếp
</Button>
</div>
)}
</>
)}
</CardContent>
</Card>
);
}