Files
goodgo-platform/apps/web/components/listings/listing-form-steps.tsx
Ho Ngoc Hai 88429a1e51
Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 6s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 1m8s
Deploy / Build API Image (push) Failing after 29s
E2E Tests / Playwright E2E (push) Failing after 13s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 2s
Security Scanning / Trivy Scan — API Image (push) Failing after 1m9s
Security Scanning / Trivy Scan — Web Image (push) Failing after 37s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 1m2s
Security Scanning / Trivy Filesystem Scan (push) Failing after 51s
Deploy / Smoke Test Staging (push) Has been skipped
Deploy / Smoke Test Production (push) Has been skipped
Security Scanning / Security Gate (push) Failing after 1s
Deploy / Rollback Staging (push) Has been skipped
Deploy / Rollback Production (push) Has been skipped
Deploy / Build Web Image (push) Failing after 14s
Deploy / Build AI Services Image (push) Failing after 12s
Deploy / Deploy to Staging (push) Has been skipped
Deploy / Deploy to Production (push) Has been skipped
feat(listings): phase B — rich property fields + admin-authored personas
Schema (prisma/migrations/20260419000000_property_rich_fields)
--------------------------------------------------------------
New Prisma enums:
- Furnishing: FULLY_FURNISHED / BASIC_FURNISHED / UNFURNISHED
- PropertyCondition: NEW / LIKE_NEW / RENOVATED / USED

New Property columns (all optional / default empty, no data loss):
- furnishing, propertyCondition — enums above
- balconyDirection — reuses existing Direction enum
- maintenanceFeeVND BigInt (phí quản lý/tháng)
- parkingSlots Int
- viewType String[] (e.g. ["Sông","Thành phố"])
- petFriendly Boolean (null = unknown)
- suitableFor String[] — admin-chosen persona labels
- whyThisLocation Text — admin narrative

Backend wiring end-to-end
-------------------------
- Create/Update DTOs: @IsEnum/@IsString/@IsNumber/@IsBoolean/@IsArray
  validators; maintenanceFeeVND accepted as a numeric string, cast to
  BigInt on the way to Prisma. whyThisLocation capped at 2000 chars.
- Introduced a small `PropertyExtras` interface on the create/update
  commands so the constructor signature stays readable instead of
  ballooning to 30+ positional args. Handlers forward it to the repo.
- Prisma property repository writes all new columns via raw SQL
  INSERT/UPDATE and reads them on findById.
- ListingDetailData + findByIdWithProperty expose the 9 new fields
  (maintenanceFeeVND serialised as decimal string to avoid BigInt JSON).

Frontend
--------
- listings-api.ts: ListingDetail.property + CreateListingPayload carry
  the 9 new fields; Furnishing + PropertyCondition exported as string
  unions.
- validations/listings.ts: zod schema extended; FURNISHING_OPTIONS,
  PROPERTY_CONDITION_OPTIONS, VIEW_TYPE_OPTIONS label arrays added in
  the existing DIRECTIONS style (Vietnamese labels).
- listing-form-steps.tsx StepDetails: new "Nội thất & điều kiện"
  fieldset with selects/inputs for each field. viewType + suitableFor
  are comma-separated text (same convention as amenities).
  petFriendly is a 3-way select (không chọn / Có / Không).
- new/page.tsx + [id]/edit/page.tsx: submit handlers split CSV inputs
  into arrays, coerce petFriendly, prune empty selects.
- listing-detail-client.tsx Details card: new rows for furnishing,
  propertyCondition, balconyDirection, maintenanceFeeVND (VND
  formatted), parkingSlots, viewType (joined · ), petFriendly
  (Cho phép / Không cho phép / hide when null).
- PersonaFitCard now takes the listing directly and MERGES admin
  suitableFor (rendered first with a "Người đăng chọn" badge in primary
  accent) with the derived personas (deduped by label). When
  whyThisLocation is non-empty it overrides the derived narrative.

Tests
-----
- listing-detail-client.spec.tsx fixture gains all 9 nullable/empty
  defaults.
- listing-form-steps.spec.tsx direction-options duplication fixed.
- pnpm --filter @goodgo/api test --run: 1975/1975 pass.
- pnpm --filter @goodgo/web test --run: 624/624 pass.

Phase B of 4. Next: Phase E AI advisor via Anthropic Opus (URL+key to
be provided by the user).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 15:08:04 +07:00

342 lines
12 KiB
TypeScript

'use client';
import type { UseFormRegister, FieldErrors } from 'react-hook-form';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Select } from '@/components/ui/select';
import { Textarea } from '@/components/ui/textarea';
import {
TRANSACTION_TYPES,
PROPERTY_TYPES,
DIRECTIONS,
FURNISHING_OPTIONS,
PROPERTY_CONDITION_OPTIONS,
type CreateListingFormData,
} from '@/lib/validations/listings';
interface StepProps {
register: UseFormRegister<CreateListingFormData>;
errors: FieldErrors<CreateListingFormData>;
}
function FieldError({ message }: { message?: string }) {
if (!message) return null;
return <p className="mt-1 text-xs text-destructive">{message}</p>;
}
// ─── Step 1: Basic Info ──────────────────────────────────
export function StepBasicInfo({ register, errors }: StepProps) {
return (
<div className="space-y-4">
<h3 className="text-lg font-semibold">Thông tin bản</h3>
<div className="grid gap-4 sm:grid-cols-2">
<div>
<Label htmlFor="transactionType">Loại giao dịch *</Label>
<Select id="transactionType" {...register('transactionType')}>
<option value="">-- Chọn --</option>
{TRANSACTION_TYPES.map((t) => (
<option key={t.value} value={t.value}>
{t.label}
</option>
))}
</Select>
<FieldError message={errors.transactionType?.message} />
</div>
<div>
<Label htmlFor="propertyType">Loại bất đng sản *</Label>
<Select id="propertyType" {...register('propertyType')}>
<option value="">-- Chọn --</option>
{PROPERTY_TYPES.map((t) => (
<option key={t.value} value={t.value}>
{t.label}
</option>
))}
</Select>
<FieldError message={errors.propertyType?.message} />
</div>
</div>
<div>
<Label htmlFor="title">Tiêu đ tin đăng *</Label>
<Input id="title" placeholder="VD: Bán căn hộ 2PN tại Vinhomes Central Park" {...register('title')} />
<FieldError message={errors.title?.message} />
</div>
<div>
<Label htmlFor="description"> tả chi tiết *</Label>
<Textarea
id="description"
rows={5}
placeholder="Mô tả chi tiết về bất động sản..."
{...register('description')}
/>
<FieldError message={errors.description?.message} />
</div>
</div>
);
}
// ─── Step 2: Location ────────────────────────────────────
export function StepLocation({ register, errors }: StepProps) {
return (
<div className="space-y-4">
<h3 className="text-lg font-semibold">Vị trí</h3>
<div>
<Label htmlFor="address">Đa chỉ *</Label>
<Input id="address" placeholder="Số nhà, tên đường" {...register('address')} />
<FieldError message={errors.address?.message} />
</div>
<div className="grid gap-4 sm:grid-cols-3">
<div>
<Label htmlFor="ward">Phường/ *</Label>
<Input id="ward" placeholder="Phường/Xã" {...register('ward')} />
<FieldError message={errors.ward?.message} />
</div>
<div>
<Label htmlFor="district">Quận/Huyện *</Label>
<Input id="district" placeholder="Quận/Huyện" {...register('district')} />
<FieldError message={errors.district?.message} />
</div>
<div>
<Label htmlFor="city">Tỉnh/Thành phố *</Label>
<Input id="city" placeholder="Tỉnh/Thành phố" {...register('city')} />
<FieldError message={errors.city?.message} />
</div>
</div>
<div className="grid gap-4 sm:grid-cols-2">
<div>
<Label htmlFor="latitude"> đ</Label>
<Input
id="latitude"
type="number"
step="any"
placeholder="VD: 10.7769"
{...register('latitude')}
/>
<FieldError message={errors.latitude?.message} />
</div>
<div>
<Label htmlFor="longitude">Kinh đ</Label>
<Input
id="longitude"
type="number"
step="any"
placeholder="VD: 106.7009"
{...register('longitude')}
/>
<FieldError message={errors.longitude?.message} />
</div>
</div>
<div className="rounded-lg border border-dashed p-6 text-center text-sm text-muted-foreground">
Bản đ chọn vị trí sẽ đưc tích hợp trong phiên bản tiếp theo
</div>
</div>
);
}
// ─── Step 3: Details ─────────────────────────────────────
export function StepDetails({ register, errors }: StepProps) {
return (
<div className="space-y-4">
<h3 className="text-lg font-semibold">Thông số chi tiết</h3>
<div className="grid gap-4 sm:grid-cols-2 md:grid-cols-3">
<div>
<Label htmlFor="areaM2">Diện tích (m²) *</Label>
<Input id="areaM2" type="number" step="0.1" placeholder="VD: 75" {...register('areaM2')} />
<FieldError message={errors.areaM2?.message} />
</div>
<div>
<Label htmlFor="usableAreaM2">Diện tích sử dụng (m²)</Label>
<Input id="usableAreaM2" type="number" step="0.1" {...register('usableAreaM2')} />
</div>
<div>
<Label htmlFor="bedrooms">Phòng ngủ</Label>
<Input id="bedrooms" type="number" min="0" {...register('bedrooms')} />
</div>
<div>
<Label htmlFor="bathrooms">Phòng tắm</Label>
<Input id="bathrooms" type="number" min="0" {...register('bathrooms')} />
</div>
<div>
<Label htmlFor="floors">Số tầng</Label>
<Input id="floors" type="number" min="0" {...register('floors')} />
</div>
<div>
<Label htmlFor="floor">Tầng số</Label>
<Input id="floor" type="number" min="0" {...register('floor')} />
</div>
<div>
<Label htmlFor="totalFloors">Tổng số tầng tòa nhà</Label>
<Input id="totalFloors" type="number" min="0" {...register('totalFloors')} />
</div>
<div>
<Label htmlFor="direction">Hướng nhà</Label>
<Select id="direction" {...register('direction')}>
<option value="">-- Không chọn --</option>
{DIRECTIONS.map((d) => (
<option key={d.value} value={d.value}>
{d.label}
</option>
))}
</Select>
</div>
<div>
<Label htmlFor="yearBuilt">Năm xây dựng</Label>
<Input id="yearBuilt" type="number" placeholder="VD: 2020" {...register('yearBuilt')} />
</div>
</div>
<div>
<Label htmlFor="legalStatus">Pháp </Label>
<Input id="legalStatus" placeholder="VD: Sổ hồng, sổ đỏ..." {...register('legalStatus')} />
</div>
<div>
<Label htmlFor="projectName">Tên dự án</Label>
<Input id="projectName" placeholder="VD: Vinhomes Central Park" {...register('projectName')} />
</div>
<div>
<Label htmlFor="amenities">Tiện ích (cách nhau bởi dấu phẩy)</Label>
<Input id="amenities" placeholder="VD: Hồ bơi, Gym, Công viên" {...register('amenities')} />
</div>
<fieldset className="space-y-4 rounded-lg border p-4">
<legend className="px-2 text-sm font-semibold">Nội thất & điều kiện</legend>
<div className="grid gap-4 sm:grid-cols-2 md:grid-cols-3">
<div>
<Label htmlFor="furnishing">Nội thất</Label>
<Select id="furnishing" {...register('furnishing')}>
<option value="">-- Không chọn --</option>
{FURNISHING_OPTIONS.map((o) => (
<option key={o.value} value={o.value}>
{o.label}
</option>
))}
</Select>
</div>
<div>
<Label htmlFor="propertyCondition">Tình trạng</Label>
<Select id="propertyCondition" {...register('propertyCondition')}>
<option value="">-- Không chọn --</option>
{PROPERTY_CONDITION_OPTIONS.map((o) => (
<option key={o.value} value={o.value}>
{o.label}
</option>
))}
</Select>
</div>
<div>
<Label htmlFor="balconyDirection">Hướng ban công</Label>
<Select id="balconyDirection" {...register('balconyDirection')}>
<option value="">-- Không chọn --</option>
{DIRECTIONS.map((d) => (
<option key={d.value} value={d.value}>
{d.label}
</option>
))}
</Select>
</div>
<div>
<Label htmlFor="maintenanceFeeVND">Phí quản / tháng (VNĐ)</Label>
<Input
id="maintenanceFeeVND"
type="text"
inputMode="numeric"
placeholder="VD: 2500000"
{...register('maintenanceFeeVND')}
/>
</div>
<div>
<Label htmlFor="parkingSlots">Chỗ đ xe</Label>
<Input id="parkingSlots" type="number" min="0" {...register('parkingSlots')} />
</div>
<div>
<Label htmlFor="petFriendly">Cho phép thú cưng</Label>
<Select id="petFriendly" {...register('petFriendly')}>
<option value="">-- Không chọn --</option>
<option value="true"></option>
<option value="false">Không</option>
</Select>
</div>
</div>
<div>
<Label htmlFor="viewType">View (cách nhau bởi dấu phẩy)</Label>
<Input
id="viewType"
placeholder="VD: Sông, Thành phố, Công viên"
{...register('viewType')}
/>
</div>
<div>
<Label htmlFor="suitableFor">Phù hợp với (cách nhau bởi dấu phẩy)</Label>
<Input
id="suitableFor"
placeholder="VD: Gia đình có con nhỏ, Người đi làm xa"
{...register('suitableFor')}
/>
</div>
<div>
<Label htmlFor="whyThisLocation"> sao khu vực này phù hợp</Label>
<Textarea
id="whyThisLocation"
rows={3}
placeholder="Mô tả ngắn lý do khu vực này phù hợp với người mua..."
{...register('whyThisLocation')}
/>
</div>
</fieldset>
</div>
);
}
// ─── Step 4: Pricing ─────────────────────────────────────
export function StepPricing({ register, errors }: StepProps) {
return (
<div className="space-y-4">
<h3 className="text-lg font-semibold">Giá & Hoa hồng</h3>
<div>
<Label htmlFor="priceVND">Giá bán (VNĐ) *</Label>
<Input id="priceVND" placeholder="VD: 5000000000" {...register('priceVND')} />
<FieldError message={errors.priceVND?.message} />
<p className="mt-1 text-xs text-muted-foreground">Nhập số không dấu chấm hoặc dấu phẩy</p>
</div>
<div className="grid gap-4 sm:grid-cols-2">
<div>
<Label htmlFor="rentPriceMonthly">Giá thuê/tháng (VNĐ)</Label>
<Input id="rentPriceMonthly" placeholder="Chỉ áp dụng cho thuê" {...register('rentPriceMonthly')} />
</div>
<div>
<Label htmlFor="commissionPct">Hoa hồng (%)</Label>
<Input
id="commissionPct"
type="number"
step="0.1"
min="0"
max="100"
placeholder="VD: 2.5"
{...register('commissionPct')}
/>
</div>
</div>
</div>
);
}