refactor(web): dedup tỷ/triệu compact formatters (GOO-206)
- Add `formatCompact` as an exported alias for `formatPrice` in lib/currency.ts - Replace 5 inline copies of the tỷ/triệu compact formatter: - components/map/listing-map.tsx (local `formatPrice` fn) - components/agents/agent-profile-client.tsx (local `fmtVND` fn) - app/(dashboard)/dashboard/saved-searches/page.tsx (local `formatPrice` fn) - app/(public)/page.tsx (local `formatVnd` fn + `vndFmt` Intl instance) - components/listings/price-history-chart.tsx (local `formatMillions` + `priceToMillions`) All call sites now import from the canonical lib/currency module. PriceHistoryChart now stores raw VND in chart data (was: millions) so formatCompact emits correct tỷ/triệu labels using canonical thresholds. Pre-existing test failures in inquiry/lead/AVM specs are unrelated to this change. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -11,21 +11,13 @@ import {
|
||||
} from 'recharts';
|
||||
|
||||
import type { PriceHistoryItem } from '@/lib/listings-api';
|
||||
import { formatCompact } from '@/lib/currency';
|
||||
|
||||
interface PriceHistoryChartProps {
|
||||
data: PriceHistoryItem[];
|
||||
height?: number;
|
||||
}
|
||||
|
||||
function priceToMillions(priceStr: string): number {
|
||||
return Math.round(Number(priceStr) / 1_000_000);
|
||||
}
|
||||
|
||||
function formatMillions(value: number): string {
|
||||
if (value >= 1000) return `${(value / 1000).toFixed(1)} tỷ`;
|
||||
return `${value} tr`;
|
||||
}
|
||||
|
||||
export function PriceHistoryChart({ data, height = 280 }: PriceHistoryChartProps) {
|
||||
if (data.length === 0) return null;
|
||||
|
||||
@@ -37,7 +29,7 @@ export function PriceHistoryChart({ data, height = 280 }: PriceHistoryChartProps
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
}),
|
||||
price: priceToMillions(item.newPrice),
|
||||
price: Number(item.newPrice),
|
||||
}));
|
||||
|
||||
return (
|
||||
@@ -48,7 +40,7 @@ export function PriceHistoryChart({ data, height = 280 }: PriceHistoryChartProps
|
||||
<YAxis
|
||||
tick={{ fontSize: 11 }}
|
||||
className="fill-muted-foreground"
|
||||
tickFormatter={(v: number) => formatMillions(v)}
|
||||
tickFormatter={(v: number) => formatCompact(v)}
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={{
|
||||
@@ -57,7 +49,7 @@ export function PriceHistoryChart({ data, height = 280 }: PriceHistoryChartProps
|
||||
borderRadius: '0.5rem',
|
||||
fontSize: '0.875rem',
|
||||
}}
|
||||
formatter={(value) => [formatMillions(Number(value)), 'Giá']}
|
||||
formatter={(value) => [formatCompact(Number(value)), 'Giá']}
|
||||
/>
|
||||
<Line
|
||||
type="monotone"
|
||||
|
||||
Reference in New Issue
Block a user