- Rewrite prisma/seed.ts to populate all 27 models with realistic Vietnamese real estate data (8 users with login, 10 properties, 10 listings, orders, payments, reviews, notifications, etc.) - Replace all emoji icons with Lucide React SVG icons across frontend for consistent rendering, sizing, and accessibility - Redesign dashboard nav: grouped sidebar with section headers, primary/secondary split on desktop, icon-only secondary items - Replace language switcher flag emoji with Globe icon - Replace SVG theme toggle with Lucide Moon/Sun icons - Fix API startup: graceful fallback for Sentry profiling, Google OAuth, and Zalo OAuth when credentials are not configured - Relax rate limiting in development mode (10k req/min) - Fix listings API to include media[] array in search response - Add optional chaining for property.media across frontend components - Update OAuth strategy tests to match graceful fallback behavior Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
118 lines
4.9 KiB
TypeScript
118 lines
4.9 KiB
TypeScript
import Image from 'next/image';
|
|
import Link from 'next/link';
|
|
import { AddToCompareButton } from '@/components/comparison/add-to-compare-button';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { Card, CardContent } from '@/components/ui/card';
|
|
import { formatPrice } from '@/lib/currency';
|
|
import { shimmerBlurDataURL } from '@/lib/image-blur';
|
|
import type { ListingDetail } from '@/lib/listings-api';
|
|
|
|
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',
|
|
};
|
|
|
|
interface PropertyCardProps {
|
|
listing: ListingDetail;
|
|
compact?: boolean;
|
|
}
|
|
|
|
export function PropertyCard({ listing, compact }: PropertyCardProps) {
|
|
const transactionLabel = listing.transactionType === 'SALE' ? 'Bán' : 'Cho thuê';
|
|
const propertyTypeLabel = PROPERTY_TYPE_LABELS[listing.property.propertyType] || listing.property.propertyType;
|
|
|
|
return (
|
|
<article
|
|
aria-label={`${listing.property.title} — ${transactionLabel} ${propertyTypeLabel}, ${formatPrice(listing.priceVND)} VNĐ`}
|
|
>
|
|
<Link href={`/listings/${listing.id}`}>
|
|
<Card className="group h-full overflow-hidden transition-shadow hover:shadow-md">
|
|
<div className={`relative bg-muted ${compact ? 'aspect-[16/10]' : 'aspect-[4/3]'}`}>
|
|
{(listing.property.media?.length ?? 0) > 0 ? (
|
|
<Image
|
|
src={listing.property.media![0]?.url ?? ''}
|
|
alt={`Ảnh bất động sản: ${listing.property.title}`}
|
|
fill
|
|
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw"
|
|
className="object-cover transition-transform group-hover:scale-105"
|
|
placeholder="blur"
|
|
blurDataURL={shimmerBlurDataURL()}
|
|
/>
|
|
) : (
|
|
<div className="flex h-full items-center justify-center text-muted-foreground" aria-hidden="true">
|
|
Chưa có ảnh
|
|
</div>
|
|
)}
|
|
<div className="absolute left-2 top-2 flex gap-1">
|
|
<Badge variant="default" className="text-xs">
|
|
{transactionLabel}
|
|
</Badge>
|
|
<Badge variant="secondary" className="text-xs">
|
|
{propertyTypeLabel}
|
|
</Badge>
|
|
</div>
|
|
{(listing.property.media?.length ?? 0) > 1 && (
|
|
<div className="absolute bottom-2 right-2">
|
|
<Badge variant="outline" className="bg-black/50 text-xs text-white border-none" aria-label={`${listing.property.media!.length} ảnh`}>
|
|
{listing.property.media!.length} ảnh
|
|
</Badge>
|
|
</div>
|
|
)}
|
|
<div className="absolute right-2 top-2">
|
|
<AddToCompareButton listingId={listing.id} compact />
|
|
</div>
|
|
</div>
|
|
<CardContent className="p-4">
|
|
<p className="text-lg font-bold text-primary">
|
|
{formatPrice(listing.priceVND)} VNĐ
|
|
{listing.transactionType === 'RENT' && listing.rentPriceMonthly && (
|
|
<span className="text-sm font-normal text-muted-foreground">/tháng</span>
|
|
)}
|
|
</p>
|
|
<h3 className="mt-1 line-clamp-1 font-medium">{listing.property.title}</h3>
|
|
<p className="mt-1 line-clamp-1 text-sm text-muted-foreground">
|
|
{listing.property.address}, {listing.property.district}, {listing.property.city}
|
|
</p>
|
|
<ul className="mt-3 flex flex-wrap gap-1.5" aria-label="Thông tin bất động sản">
|
|
<li>
|
|
<Badge variant="secondary" className="text-xs">
|
|
{listing.property.areaM2} m²
|
|
</Badge>
|
|
</li>
|
|
{listing.property.bedrooms != null && (
|
|
<li>
|
|
<Badge variant="secondary" className="text-xs">
|
|
{listing.property.bedrooms} PN
|
|
</Badge>
|
|
</li>
|
|
)}
|
|
{listing.property.bathrooms != null && listing.property.bathrooms > 0 && (
|
|
<li>
|
|
<Badge variant="secondary" className="text-xs">
|
|
{listing.property.bathrooms} PT
|
|
</Badge>
|
|
</li>
|
|
)}
|
|
{listing.property.direction && (
|
|
<li>
|
|
<Badge variant="outline" className="text-xs">
|
|
Hướng {listing.property.direction === 'NORTH' ? 'Bắc' :
|
|
listing.property.direction === 'SOUTH' ? 'Nam' :
|
|
listing.property.direction === 'EAST' ? 'Đông' :
|
|
listing.property.direction === 'WEST' ? 'Tây' :
|
|
listing.property.direction}
|
|
</Badge>
|
|
</li>
|
|
)}
|
|
</ul>
|
|
</CardContent>
|
|
</Card>
|
|
</Link>
|
|
</article>
|
|
);
|
|
}
|