feat(listings-frontend): add create/edit form, detail page, and listing components

- Multi-step wizard for listing creation (basic info, location, details, pricing, images)
- Listing detail page with image gallery, property specs, seller/agent info, stats
- Listings index page with filters (transaction type, property type) and pagination
- Edit page with tab-based form (read-only until backend PATCH endpoint available)
- Drag & drop image upload component with preview and multi-file support
- Dashboard layout with navigation bar
- New UI primitives: textarea, select, badge, tabs
- Listings API client with typed endpoints matching backend contract
- Zod validation schemas for all form steps
- Status badges with Vietnamese labels for all listing states
- Responsive design across all pages

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-08 01:54:08 +07:00
parent 8a33aae026
commit 207a2013f3
18 changed files with 1834 additions and 8 deletions

View File

@@ -0,0 +1,61 @@
'use client';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { cn } from '@/lib/utils';
import { useAuthStore } from '@/lib/auth-store';
import { Button } from '@/components/ui/button';
const navItems = [
{ href: '/', label: 'Trang chủ', icon: '🏠' },
{ href: '/listings', label: 'Tin đăng', icon: '📋' },
{ href: '/listings/new', label: 'Đăng tin', icon: '' },
];
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
const pathname = usePathname();
const { user, logout } = useAuthStore();
return (
<div className="min-h-screen bg-background">
<header className="sticky top-0 z-50 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
<div className="mx-auto flex h-14 max-w-7xl items-center px-4">
<Link href="/" className="mr-6 flex items-center space-x-2">
<span className="text-lg font-bold text-primary">GoodGo</span>
</Link>
<nav className="flex items-center space-x-1">
{navItems.map((item) => (
<Link
key={item.href}
href={item.href}
className={cn(
'rounded-md px-3 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground',
pathname === item.href
? 'bg-accent text-accent-foreground'
: 'text-muted-foreground',
)}
>
<span className="mr-1.5">{item.icon}</span>
{item.label}
</Link>
))}
</nav>
<div className="ml-auto flex items-center space-x-3">
{user && (
<span className="text-sm text-muted-foreground">
{user.fullName}
</span>
)}
<Button variant="ghost" size="sm" onClick={logout}>
Đăng xuất
</Button>
</div>
</div>
</header>
<main className="mx-auto max-w-7xl px-4 py-6">{children}</main>
</div>
);
}

View File

@@ -0,0 +1,131 @@
'use client';
import * as React from 'react';
import { useParams, useRouter } from 'next/navigation';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import {
StepBasicInfo,
StepLocation,
StepDetails,
StepPricing,
} from '@/components/listings/listing-form-steps';
import {
createListingSchema,
type CreateListingFormData,
} from '@/lib/validations/listings';
import { listingsApi, type ListingDetail } from '@/lib/listings-api';
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs';
export default function EditListingPage() {
const { id } = useParams<{ id: string }>();
const router = useRouter();
const [listing, setListing] = React.useState<ListingDetail | null>(null);
const [loading, setLoading] = React.useState(true);
const [activeTab, setActiveTab] = React.useState('basic');
const {
register,
reset,
formState: { errors },
} = useForm<CreateListingFormData>({
resolver: zodResolver(createListingSchema),
mode: 'onTouched',
});
React.useEffect(() => {
listingsApi
.getById(id)
.then((data) => {
setListing(data);
const { property } = data;
reset({
transactionType: data.transactionType,
propertyType: property.propertyType,
title: property.title,
description: property.description,
address: property.address,
ward: property.ward,
district: property.district,
city: property.city,
areaM2: String(property.areaM2),
bedrooms: property.bedrooms != null ? String(property.bedrooms) : '',
bathrooms: property.bathrooms != null ? String(property.bathrooms) : '',
floors: property.floors != null ? String(property.floors) : '',
direction: property.direction ?? '',
yearBuilt: property.yearBuilt != null ? String(property.yearBuilt) : '',
legalStatus: property.legalStatus ?? '',
projectName: property.projectName ?? '',
amenities: property.amenities?.join(', ') ?? '',
priceVND: data.priceVND,
rentPriceMonthly: data.rentPriceMonthly ?? '',
commissionPct: data.commissionPct != null ? String(data.commissionPct) : '',
});
})
.catch(() => setListing(null))
.finally(() => setLoading(false));
}, [id, reset]);
if (loading) {
return (
<div className="flex min-h-[400px] items-center justify-center">
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" />
</div>
);
}
if (!listing) {
return (
<div className="flex min-h-[400px] flex-col items-center justify-center space-y-4">
<p className="text-destructive">Không tìm thấy tin đăng</p>
<Button variant="outline" onClick={() => router.push('/listings')}>
Quay lại
</Button>
</div>
);
}
return (
<div className="mx-auto max-w-3xl space-y-6">
<div className="flex items-center justify-between">
<h1 className="text-2xl font-bold">Chỉnh sửa tin đăng</h1>
<Button variant="outline" onClick={() => router.push(`/listings/${id}`)}>
Xem tin
</Button>
</div>
<p className="text-sm text-muted-foreground">
Chức năng chỉnh sửa sẽ đưc hoàn thiện khi backend API hỗ trợ PATCH /listings/:id.
Hiện tại bạn thể xem lại thông tin đã nhập.
</p>
<Tabs value={activeTab} onValueChange={setActiveTab}>
<TabsList className="grid w-full grid-cols-4">
<TabsTrigger value="basic"> bản</TabsTrigger>
<TabsTrigger value="location">Vị trí</TabsTrigger>
<TabsTrigger value="details">Chi tiết</TabsTrigger>
<TabsTrigger value="pricing">Giá cả</TabsTrigger>
</TabsList>
<Card className="mt-4">
<CardContent className="pt-6">
<TabsContent value="basic">
<StepBasicInfo register={register} errors={errors} />
</TabsContent>
<TabsContent value="location">
<StepLocation register={register} errors={errors} />
</TabsContent>
<TabsContent value="details">
<StepDetails register={register} errors={errors} />
</TabsContent>
<TabsContent value="pricing">
<StepPricing register={register} errors={errors} />
</TabsContent>
</CardContent>
</Card>
</Tabs>
</div>
);
}

View File

@@ -0,0 +1,226 @@
'use client';
import * as React from 'react';
import Link from 'next/link';
import { useParams } from 'next/navigation';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { ImageGallery } from '@/components/listings/image-gallery';
import { ListingStatusBadge } from '@/components/listings/listing-status-badge';
import { listingsApi, type ListingDetail } from '@/lib/listings-api';
import { PROPERTY_TYPES, DIRECTIONS, TRANSACTION_TYPES } from '@/lib/validations/listings';
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)} triệu`;
return num.toLocaleString('vi-VN');
}
function getLabel(list: readonly { value: string; label: string }[], value: string | null) {
if (!value) return '—';
return list.find((item) => item.value === value)?.label ?? value;
}
export default function ListingDetailPage() {
const { id } = useParams<{ id: string }>();
const [listing, setListing] = React.useState<ListingDetail | null>(null);
const [loading, setLoading] = React.useState(true);
const [error, setError] = React.useState<string | null>(null);
React.useEffect(() => {
listingsApi
.getById(id)
.then(setListing)
.catch((err) => setError(err instanceof Error ? err.message : 'Không tải được tin đăng'))
.finally(() => setLoading(false));
}, [id]);
if (loading) {
return (
<div className="flex min-h-[400px] items-center justify-center">
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" />
</div>
);
}
if (error || !listing) {
return (
<div className="flex min-h-[400px] flex-col items-center justify-center space-y-4">
<p className="text-destructive">{error || 'Không tìm thấy tin đăng'}</p>
<Link href="/listings">
<Button variant="outline">Quay lại danh sách</Button>
</Link>
</div>
);
}
const { property, seller, agent } = listing;
return (
<div className="mx-auto max-w-5xl space-y-6">
{/* Header */}
<div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
<div>
<div className="mb-2 flex items-center gap-2">
<ListingStatusBadge status={listing.status} />
<Badge variant="outline">
{getLabel(TRANSACTION_TYPES, listing.transactionType)}
</Badge>
<Badge variant="outline">
{getLabel(PROPERTY_TYPES, property.propertyType)}
</Badge>
</div>
<h1 className="text-2xl font-bold">{property.title}</h1>
<p className="mt-1 text-muted-foreground">
{property.address}, {property.ward}, {property.district}, {property.city}
</p>
</div>
<div className="text-right">
<p className="text-2xl font-bold text-primary">{formatPrice(listing.priceVND)} VNĐ</p>
{listing.pricePerM2 && (
<p className="text-sm text-muted-foreground">
~{listing.pricePerM2.toLocaleString('vi-VN')} VNĐ/m²
</p>
)}
{listing.rentPriceMonthly && (
<p className="text-sm text-muted-foreground">
Thuê: {formatPrice(listing.rentPriceMonthly)}/tháng
</p>
)}
</div>
</div>
{/* Image gallery */}
<ImageGallery media={property.media} />
<div className="grid gap-6 lg:grid-cols-3">
{/* Main content */}
<div className="space-y-6 lg:col-span-2">
{/* Key specs */}
<Card>
<CardHeader>
<CardTitle>Thông tin chung</CardTitle>
</CardHeader>
<CardContent>
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3">
<InfoItem label="Diện tích" value={`${property.areaM2}`} />
<InfoItem label="Phòng ngủ" value={property.bedrooms != null ? `${property.bedrooms}` : '—'} />
<InfoItem label="Phòng tắm" value={property.bathrooms != null ? `${property.bathrooms}` : '—'} />
<InfoItem label="Số tầng" value={property.floors != null ? `${property.floors}` : '—'} />
<InfoItem label="Hướng" value={getLabel(DIRECTIONS, property.direction)} />
<InfoItem label="Năm xây" value={property.yearBuilt ? `${property.yearBuilt}` : '—'} />
<InfoItem label="Pháp lý" value={property.legalStatus || '—'} />
<InfoItem label="Dự án" value={property.projectName || '—'} />
</div>
</CardContent>
</Card>
{/* Description */}
<Card>
<CardHeader>
<CardTitle> tả</CardTitle>
</CardHeader>
<CardContent>
<p className="whitespace-pre-wrap text-sm leading-relaxed">{property.description}</p>
</CardContent>
</Card>
{/* Amenities */}
{property.amenities && property.amenities.length > 0 && (
<Card>
<CardHeader>
<CardTitle>Tiện ích</CardTitle>
</CardHeader>
<CardContent>
<div className="flex flex-wrap gap-2">
{property.amenities.map((a) => (
<Badge key={a} variant="secondary">
{a}
</Badge>
))}
</div>
</CardContent>
</Card>
)}
</div>
{/* Sidebar */}
<div className="space-y-6">
{/* Seller info */}
<Card>
<CardHeader>
<CardTitle>Liên hệ</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div>
<p className="font-medium">{seller.fullName}</p>
<p className="text-sm text-muted-foreground">{seller.phone}</p>
</div>
<Button className="w-full">Gọi ngay</Button>
<Button variant="outline" className="w-full">
Nhắn tin
</Button>
</CardContent>
</Card>
{/* Agent info */}
{agent && (
<Card>
<CardHeader>
<CardTitle>Môi giới</CardTitle>
</CardHeader>
<CardContent>
{agent.agency && <p className="text-sm text-muted-foreground">{agent.agency}</p>}
{listing.commissionPct != null && (
<p className="mt-1 text-sm">Hoa hồng: {listing.commissionPct}%</p>
)}
</CardContent>
</Card>
)}
{/* Stats */}
<Card>
<CardHeader>
<CardTitle>Thống </CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-2 text-sm">
<div className="flex justify-between">
<span className="text-muted-foreground">Lượt xem</span>
<span className="font-medium">{listing.viewCount}</span>
</div>
<div className="flex justify-between">
<span className="text-muted-foreground">Lượt lưu</span>
<span className="font-medium">{listing.saveCount}</span>
</div>
<div className="flex justify-between">
<span className="text-muted-foreground">Liên hệ</span>
<span className="font-medium">{listing.inquiryCount}</span>
</div>
{listing.publishedAt && (
<div className="flex justify-between">
<span className="text-muted-foreground">Đăng ngày</span>
<span className="font-medium">
{new Date(listing.publishedAt).toLocaleDateString('vi-VN')}
</span>
</div>
)}
</div>
</CardContent>
</Card>
</div>
</div>
</div>
);
}
function InfoItem({ label, value }: { label: string; value: string }) {
return (
<div>
<p className="text-xs text-muted-foreground">{label}</p>
<p className="font-medium">{value}</p>
</div>
);
}

View File

@@ -0,0 +1,228 @@
'use client';
import * as React from 'react';
import { useRouter } from 'next/navigation';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import { ImageUpload, type ImageFile } from '@/components/listings/image-upload';
import {
StepBasicInfo,
StepLocation,
StepDetails,
StepPricing,
} from '@/components/listings/listing-form-steps';
import {
createListingSchema,
listingBasicSchema,
listingLocationSchema,
listingDetailsSchema,
listingPricingSchema,
type CreateListingFormData,
} from '@/lib/validations/listings';
import { listingsApi, type CreateListingPayload, type Direction } from '@/lib/listings-api';
import { useAuthStore } from '@/lib/auth-store';
import { cn } from '@/lib/utils';
const STEPS = [
{ title: 'Thông tin', schemaKeys: Object.keys(listingBasicSchema.shape) },
{ title: 'Vị trí', schemaKeys: Object.keys(listingLocationSchema.shape) },
{ title: 'Chi tiết', schemaKeys: Object.keys(listingDetailsSchema.shape) },
{ title: 'Giá cả', schemaKeys: Object.keys(listingPricingSchema.shape) },
{ title: 'Hình ảnh', schemaKeys: null },
];
function toNum(val: string | undefined): number | undefined {
if (!val) return undefined;
const n = Number(val);
return isNaN(n) ? undefined : n;
}
export default function CreateListingPage() {
const router = useRouter();
const { tokens } = useAuthStore();
const [currentStep, setCurrentStep] = React.useState(0);
const [images, setImages] = React.useState<ImageFile[]>([]);
const [isSubmitting, setIsSubmitting] = React.useState(false);
const [error, setError] = React.useState<string | null>(null);
const {
register,
handleSubmit,
trigger,
formState: { errors },
} = useForm<CreateListingFormData>({
resolver: zodResolver(createListingSchema),
mode: 'onTouched',
});
const goNext = async () => {
const step = STEPS[currentStep];
if (step?.schemaKeys) {
const valid = await trigger(step.schemaKeys as Array<keyof CreateListingFormData>);
if (!valid) return;
}
setCurrentStep((s) => Math.min(s + 1, STEPS.length - 1));
};
const goBack = () => setCurrentStep((s) => Math.max(s - 1, 0));
const onSubmit = async (data: CreateListingFormData) => {
if (!tokens?.accessToken) {
setError('Vui lòng đăng nhập để đăng tin');
return;
}
setIsSubmitting(true);
setError(null);
try {
const payload: CreateListingPayload = {
transactionType: data.transactionType,
propertyType: data.propertyType,
title: data.title,
description: data.description,
address: data.address,
ward: data.ward,
district: data.district,
city: data.city,
latitude: toNum(data.latitude) ?? 0,
longitude: toNum(data.longitude) ?? 0,
areaM2: Number(data.areaM2),
priceVND: data.priceVND,
};
const usableAreaM2 = toNum(data.usableAreaM2);
if (usableAreaM2 != null) payload.usableAreaM2 = usableAreaM2;
const bedrooms = toNum(data.bedrooms);
if (bedrooms != null) payload.bedrooms = bedrooms;
const bathrooms = toNum(data.bathrooms);
if (bathrooms != null) payload.bathrooms = bathrooms;
const floors = toNum(data.floors);
if (floors != null) payload.floors = floors;
const floor = toNum(data.floor);
if (floor != null) payload.floor = floor;
const totalFloors = toNum(data.totalFloors);
if (totalFloors != null) payload.totalFloors = totalFloors;
if (data.direction) payload.direction = data.direction as Direction;
const yearBuilt = toNum(data.yearBuilt);
if (yearBuilt != null) payload.yearBuilt = yearBuilt;
if (data.legalStatus) payload.legalStatus = data.legalStatus;
if (data.projectName) payload.projectName = data.projectName;
if (data.amenities) {
payload.amenities = data.amenities.split(',').map((s) => s.trim()).filter(Boolean);
}
if (data.rentPriceMonthly) payload.rentPriceMonthly = data.rentPriceMonthly;
const commissionPct = toNum(data.commissionPct);
if (commissionPct != null) payload.commissionPct = commissionPct;
const result = await listingsApi.create(tokens.accessToken, payload);
for (const img of images) {
try {
await listingsApi.uploadMedia(tokens.accessToken, result.listingId, img.file);
} catch {
// Continue with remaining images
}
}
router.push(`/listings/${result.listingId}`);
} catch (err) {
setError(err instanceof Error ? err.message : 'Có lỗi xảy ra');
} finally {
setIsSubmitting(false);
}
};
return (
<div className="mx-auto max-w-3xl">
<h1 className="mb-6 text-2xl font-bold">Đăng tin mới</h1>
{/* Step indicators */}
<div className="mb-8 flex items-center justify-between">
{STEPS.map((step, index) => (
<div key={step.title} className="flex items-center">
<button
type="button"
onClick={() => index < currentStep && setCurrentStep(index)}
className={cn(
'flex h-8 w-8 items-center justify-center rounded-full text-sm font-medium transition-colors',
index === currentStep
? 'bg-primary text-primary-foreground'
: index < currentStep
? 'bg-primary/20 text-primary cursor-pointer'
: 'bg-muted text-muted-foreground',
)}
>
{index < currentStep ? '\u2713' : index + 1}
</button>
<span
className={cn(
'ml-2 hidden text-sm sm:inline',
index === currentStep ? 'font-medium' : 'text-muted-foreground',
)}
>
{step.title}
</span>
{index < STEPS.length - 1 && (
<div
className={cn(
'mx-3 h-px w-8 sm:w-12',
index < currentStep ? 'bg-primary' : 'bg-muted',
)}
/>
)}
</div>
))}
</div>
{error && (
<div className="mb-4 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive">
{error}
<button className="ml-2 font-medium underline" onClick={() => setError(null)}>
Đóng
</button>
</div>
)}
<form onSubmit={handleSubmit(onSubmit)}>
<Card>
<CardContent className="pt-6">
{currentStep === 0 && <StepBasicInfo register={register} errors={errors} />}
{currentStep === 1 && <StepLocation register={register} errors={errors} />}
{currentStep === 2 && <StepDetails register={register} errors={errors} />}
{currentStep === 3 && <StepPricing register={register} errors={errors} />}
{currentStep === 4 && (
<div className="space-y-4">
<h3 className="text-lg font-semibold">Hình nh</h3>
<ImageUpload images={images} onChange={setImages} />
</div>
)}
</CardContent>
</Card>
<div className="mt-6 flex justify-between">
<Button
type="button"
variant="outline"
onClick={goBack}
disabled={currentStep === 0}
>
Quay lại
</Button>
{currentStep < STEPS.length - 1 ? (
<Button type="button" onClick={goNext}>
Tiếp theo
</Button>
) : (
<Button type="submit" disabled={isSubmitting}>
{isSubmitting ? 'Đang đăng...' : 'Đăng tin'}
</Button>
)}
</div>
</form>
</div>
);
}

View File

@@ -0,0 +1,172 @@
'use client';
import * as React from 'react';
import Link from 'next/link';
import { Card, CardContent } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { Select } from '@/components/ui/select';
import { ListingStatusBadge } from '@/components/listings/listing-status-badge';
import { listingsApi, type ListingDetail, type PaginatedResult } from '@/lib/listings-api';
import { PROPERTY_TYPES, TRANSACTION_TYPES } from '@/lib/validations/listings';
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)} triệu`;
return num.toLocaleString('vi-VN');
}
export default function ListingsPage() {
const [result, setResult] = React.useState<PaginatedResult<ListingDetail> | null>(null);
const [loading, setLoading] = React.useState(true);
const [filters, setFilters] = React.useState({
transactionType: '',
propertyType: '',
page: 1,
});
React.useEffect(() => {
setLoading(true);
const params: Record<string, string | number> = { page: filters.page, limit: 12 };
if (filters.transactionType) params['transactionType'] = filters.transactionType;
if (filters.propertyType) params['propertyType'] = filters.propertyType;
listingsApi
.search(params)
.then(setResult)
.catch(() => setResult(null))
.finally(() => setLoading(false));
}, [filters]);
return (
<div className="space-y-6">
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
<h1 className="text-2xl font-bold">Tin đăng</h1>
<Link href="/listings/new">
<Button>Đăng tin mới</Button>
</Link>
</div>
{/* Filters */}
<div className="flex flex-wrap gap-3">
<Select
value={filters.transactionType}
onChange={(e) => setFilters((f) => ({ ...f, transactionType: e.target.value, page: 1 }))}
className="w-40"
>
<option value="">Tất cả giao dịch</option>
{TRANSACTION_TYPES.map((t) => (
<option key={t.value} value={t.value}>
{t.label}
</option>
))}
</Select>
<Select
value={filters.propertyType}
onChange={(e) => setFilters((f) => ({ ...f, propertyType: e.target.value, page: 1 }))}
className="w-44"
>
<option value="">Tất cả loại BĐS</option>
{PROPERTY_TYPES.map((t) => (
<option key={t.value} value={t.value}>
{t.label}
</option>
))}
</Select>
</div>
{/* Listing grid */}
{loading ? (
<div className="flex min-h-[300px] items-center justify-center">
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" />
</div>
) : !result || result.data.length === 0 ? (
<div className="flex min-h-[300px] flex-col items-center justify-center text-muted-foreground">
<p>Chưa tin đăng nào</p>
<Link href="/listings/new" className="mt-2">
<Button variant="outline" size="sm">
Đăng tin đu tiên
</Button>
</Link>
</div>
) : (
<>
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
{result.data.map((listing) => (
<Link key={listing.id} href={`/listings/${listing.id}`}>
<Card className="h-full overflow-hidden transition-shadow hover:shadow-md">
<div className="relative aspect-[4/3] bg-muted">
{listing.property.media.length > 0 ? (
<img
src={listing.property.media[0]?.url}
alt={listing.property.title}
className="h-full w-full object-cover"
/>
) : (
<div className="flex h-full items-center justify-center text-muted-foreground">
Chưa nh
</div>
)}
<div className="absolute left-2 top-2">
<ListingStatusBadge status={listing.status} />
</div>
</div>
<CardContent className="p-4">
<p className="text-lg font-bold text-primary">
{formatPrice(listing.priceVND)} VNĐ
</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.district}, {listing.property.city}
</p>
<div className="mt-3 flex flex-wrap gap-1.5">
<Badge variant="secondary" className="text-xs">
{listing.property.areaM2} m²
</Badge>
{listing.property.bedrooms != null && (
<Badge variant="secondary" className="text-xs">
{listing.property.bedrooms} PN
</Badge>
)}
{listing.property.bathrooms != null && listing.property.bathrooms > 0 && (
<Badge variant="secondary" className="text-xs">
{listing.property.bathrooms} PT
</Badge>
)}
</div>
</CardContent>
</Card>
</Link>
))}
</div>
{/* Pagination */}
{result.totalPages > 1 && (
<div className="flex items-center justify-center gap-2">
<Button
variant="outline"
size="sm"
disabled={filters.page <= 1}
onClick={() => setFilters((f) => ({ ...f, page: f.page - 1 }))}
>
Trước
</Button>
<span className="text-sm text-muted-foreground">
Trang {result.page} / {result.totalPages}
</span>
<Button
variant="outline"
size="sm"
disabled={filters.page >= result.totalPages}
onClick={() => setFilters((f) => ({ ...f, page: f.page + 1 }))}
>
Tiếp
</Button>
</div>
)}
</>
)}
</div>
);
}

View File

@@ -0,0 +1,54 @@
import Link from 'next/link';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
export default function HomePage() {
return (
<div className="space-y-8">
<div>
<h1 className="text-3xl font-bold">Chào mừng đến GoodGo</h1>
<p className="mt-2 text-muted-foreground">
Nền tảng bất đng sản thông minh tại Việt Nam
</p>
</div>
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
<Card>
<CardHeader>
<CardTitle>Đăng tin mới</CardTitle>
<CardDescription>Tạo tin đăng bán hoặc cho thuê bất đng sản</CardDescription>
</CardHeader>
<CardContent>
<Link href="/listings/new">
<Button className="w-full">Đăng tin ngay</Button>
</Link>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>Tin đăng của tôi</CardTitle>
<CardDescription>Quản các tin đăng đã tạo</CardDescription>
</CardHeader>
<CardContent>
<Link href="/listings">
<Button variant="outline" className="w-full">Xem danh sách</Button>
</Link>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>Tìm kiếm</CardTitle>
<CardDescription>Tìm bất đng sản phù hợp nhu cầu</CardDescription>
</CardHeader>
<CardContent>
<Link href="/listings">
<Button variant="outline" className="w-full">Tìm kiếm</Button>
</Link>
</CardContent>
</Card>
</div>
</div>
);
}

View File

@@ -1,8 +0,0 @@
export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center justify-center p-24">
<h1 className="text-4xl font-bold">GoodGo Platform</h1>
<p className="mt-4 text-lg text-gray-600">Vietnam Real Estate Platform</p>
</main>
);
}