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:
@@ -5,16 +5,10 @@ import mapboxgl from 'mapbox-gl';
|
||||
import * as React from 'react';
|
||||
import 'mapbox-gl/dist/mapbox-gl.css';
|
||||
import { ComponentErrorBoundary } from '@/components/error-boundary';
|
||||
import { formatCompact } from '@/lib/currency';
|
||||
import type { ListingDetail } from '@/lib/listings-api';
|
||||
import { useMapboxStyle } from '@/lib/mapbox-style';
|
||||
|
||||
function formatPrice(priceVND: string): string {
|
||||
const num = Number(priceVND);
|
||||
if (num >= 1_000_000_000) return `${(num / 1_000_000_000).toFixed(1)} tỷ`;
|
||||
if (num >= 1_000_000) return `${(num / 1_000_000).toFixed(0)} tr`;
|
||||
return num.toLocaleString('vi-VN');
|
||||
}
|
||||
|
||||
interface ListingMapProps {
|
||||
listings: ListingDetail[];
|
||||
onMarkerClick?: (listing: ListingDetail) => void;
|
||||
@@ -67,7 +61,7 @@ function buildGeoJSON(
|
||||
geometry: { type: 'Point', coordinates: [lng, lat] },
|
||||
properties: {
|
||||
id: listing.id,
|
||||
price: formatPrice(listing.priceVND),
|
||||
price: formatCompact(listing.priceVND),
|
||||
title: listing.property.title,
|
||||
district: listing.property.district ?? '',
|
||||
city: listing.property.city ?? '',
|
||||
@@ -100,7 +94,7 @@ function buildPopupContent(listing: ListingDetail): HTMLDivElement {
|
||||
const price = document.createElement('p');
|
||||
price.style.cssText =
|
||||
'font-weight:700;color:hsl(var(--primary));font-size:14px;margin:0 0 4px;';
|
||||
price.textContent = `${formatPrice(listing.priceVND)} VND`;
|
||||
price.textContent = `${formatCompact(listing.priceVND)} VND`;
|
||||
container.appendChild(price);
|
||||
|
||||
const title = document.createElement('p');
|
||||
|
||||
Reference in New Issue
Block a user