gendesign/tradein-mvp/frontend/src/components/trade-in/RecentSoldList.tsx
lekss361 80850a591e
All checks were successful
Deploy Trade-In / build-backend (push) Successful in 43s
Deploy Trade-In / changes (push) Successful in 6s
Deploy Trade-In / build-frontend (push) Successful in 2m34s
Deploy Trade-In / deploy (push) Successful in 39s
feat(tradein): house analytics section (chart + KPI + sold list) (#546)
2026-05-24 18:09:45 +00:00

91 lines
3.1 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.

"use client";
import type { RecentSoldEntry } from "@/types/trade-in";
type Props = { items: RecentSoldEntry[] };
const fmtPrice = (n: number | null): string =>
n == null ? "—" : `${(n / 1_000_000).toFixed(2)} М`;
const fmtDate = (d: string | null): string => {
if (!d) return "—";
try {
return new Date(d).toLocaleDateString("ru-RU");
} catch {
return d;
}
};
export function RecentSoldList({ items }: Props) {
const suffix = items.length === 1 ? "" : "ов";
return (
<article className="card" style={{ marginTop: 12 }}>
<header className="card-head">
<h4 style={{ margin: 0, fontSize: 14, fontWeight: 600 }}>
Недавно снятые (12 мес)
</h4>
<small style={{ color: "var(--muted, #6b7280)" }}>
{items.length} лот{suffix}
</small>
</header>
<div style={{ padding: "8px 16px 16px" }}>
<table
style={{ width: "100%", fontSize: 13, borderCollapse: "collapse" }}
>
<thead>
<tr
style={{
borderBottom: "1px solid var(--border, #e5e7eb)",
textAlign: "left",
}}
>
<th style={{ padding: "6px 8px" }}>Лот</th>
<th style={{ padding: "6px 8px" }}>Цена</th>
<th style={{ padding: "6px 8px" }}>Торг</th>
<th style={{ padding: "6px 8px" }}>Снято</th>
<th style={{ padding: "6px 8px" }}>Экспозиция</th>
</tr>
</thead>
<tbody>
{items.map((it) => {
const hasDiscount =
it.discount_pct != null && it.discount_pct !== 0;
const discountColor =
it.discount_pct != null && it.discount_pct > 0
? "#16a34a"
: "var(--muted, #6b7280)";
return (
<tr
key={it.id}
style={{
borderBottom: "1px solid var(--border-soft, #f3f4f6)",
}}
>
<td style={{ padding: "6px 8px" }}>
{it.rooms ?? "?"}к, {it.area_m2 ?? "?"} м²
{it.floor != null ? `, эт. ${it.floor}` : ""}
</td>
<td style={{ padding: "6px 8px", whiteSpace: "nowrap" }}>
{fmtPrice(it.last_price)}
</td>
<td style={{ padding: "6px 8px", color: discountColor }}>
{hasDiscount
? `${it.discount_pct! > 0 ? "" : "+"}${Math.abs(it.discount_pct!).toFixed(1)}%`
: "—"}
</td>
<td style={{ padding: "6px 8px", whiteSpace: "nowrap" }}>
{fmtDate(it.removed_date)}
</td>
<td style={{ padding: "6px 8px" }}>
{it.exposure_days ?? "—"} дн.
</td>
</tr>
);
})}
</tbody>
</table>
</div>
</article>
);
}