feat(projects): bring residential-project detail to parity with listings (4 phases)
Some checks failed
Deploy / Deploy to Production (push) Has been skipped
Deploy / Smoke Test Production (push) Has been skipped
Security Scanning / Security Gate (push) Failing after 0s
Deploy / Rollback Production (push) Has been skipped
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 9s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 53s
Deploy / Build API Image (push) Failing after 13s
Deploy / Build Web Image (push) Failing after 9s
Deploy / Build AI Services Image (push) Failing after 11s
E2E Tests / Playwright E2E (push) Failing after 10s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 4s
Security Scanning / Trivy Scan — API Image (push) Failing after 50s
Security Scanning / Trivy Scan — Web Image (push) Failing after 41s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 31s
Security Scanning / Trivy Filesystem Scan (push) Failing after 23s
Deploy / Deploy to Staging (push) Has been skipped
Deploy / Smoke Test Staging (push) Has been skipped
Deploy / Rollback Staging (push) Has been skipped

Phase 1 — live POI + neighborhood score on project detail
- du-an-detail-client fetches `/analytics/pois/nearby` + `/analytics/neighborhoods/:district/score`
- Falls back to admin-entered `project.pois` / `neighborhoodScores` when endpoint returns nothing
- Adds total-score badge next to the radar chart (matches listings)

Phase 2 — project personas derivation (`lib/project-personas.ts`)
- Derives 8 personas from project-specific signals: property-type mix, amenity keywords,
  developer reputation, completion timing, status, live score + POIs
- Merges admin-authored `suitableFor` chips (badged "Chủ đầu tư chọn") with derived chips
- `composeWhyThisProject()` narrative used as fallback when admin hasn't authored one;
  badged "Tự động tổng hợp" so users know it's derived

Phase 3 — AI advisor for projects
- Extract shared Anthropic transport + JSON parsers to
  `analytics/application/queries/_shared/ai-json-client.ts` (dual auth: x-api-key +
  Bearer for proxy gateways)
- Refactor `GetListingAiAdviceHandler` to use the shared client
- New `GetProjectAiAdviceHandler` (CQRS) pulls project detail + optional POIs + score,
  builds project-flavored prompt, returns `{ advice: { summary, pros, cons, suitableFor } }`.
  No valuation block — project price is a range, not a single unit.
- `POST /analytics/projects/:id/ai-advice` endpoint (JWT-guarded)
- `ErrorCode.PROJECT_NOT_FOUND` added
- Frontend: `ProjectAiAdviceCard` mirrors listings card minus valuation, with loading /
  not-configured (503) / error states; dedupes AI-suggested personas against existing chips

Phase 4 — Mapbox LocationPicker in project create form
- New project page now renders `<LocationPicker>` with Vietnam-scoped geocoder; click /
  drag / search autofills lat+lng and (when empty) address/ward/district/city
- Edit page notes location immutability — backend `UpdateProjectCommand` does not yet
  accept lat/lng/address mutations (follow-up needed to enable editing coords)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ho Ngoc Hai
2026-04-20 17:53:19 +07:00
parent 03f8674024
commit dd3ad4aeca
13 changed files with 1486 additions and 273 deletions

View File

@@ -336,16 +336,26 @@ export default function EditProjectPage() {
</div>
</FormSection>
{/* Vị trí */}
{/* Vị trí (hiện tại chỉ hiển thị; backend chưa hỗ trợ sửa toạ độ sau khi tạo) */}
<FormSection title="Vị trí">
<div className="space-y-1.5 sm:col-span-2 text-sm text-muted-foreground">
{project.address}
<br />
{project.district}, {project.city}
<br />
<span className="text-xs">
(Vị trí đa không thể chỉnh sửa sau khi tạo.)
</span>
<div className="sm:col-span-2 space-y-2 text-sm">
<div className="text-muted-foreground">
<span className="font-medium text-foreground">{project.address}</span>
<br />
{project.district}, {project.city}
{typeof project.latitude === 'number' && typeof project.longitude === 'number' && (
<>
<br />
<span className="text-xs">
({project.latitude.toFixed(6)}, {project.longitude.toFixed(6)})
</span>
</>
)}
</div>
<p className="text-xs text-muted-foreground">
Vị trí đa hiện chưa thể chỉnh sửa sau khi tạo. Nếu cần cập nhật,
vui lòng xoá dự án tạo lại.
</p>
</div>
</FormSection>

View File

@@ -3,6 +3,7 @@
import { zodResolver } from '@hookform/resolvers/zod';
import { ArrowLeft } from 'lucide-react';
import Link from 'next/link';
import dynamic from 'next/dynamic';
import { useRouter } from 'next/navigation';
import * as React from 'react';
import { useForm } from 'react-hook-form';
@@ -15,6 +16,18 @@ import { Select } from '@/components/ui/select';
import { Textarea } from '@/components/ui/textarea';
import { duAnApi, type CreateProjectPayload } from '@/lib/du-an-api';
const LocationPicker = dynamic(
() => import('@/components/map/location-picker').then((m) => m.LocationPicker),
{
ssr: false,
loading: () => (
<div className="flex h-[320px] items-center justify-center rounded-lg border border-dashed bg-muted text-sm text-muted-foreground">
Đang tải bản đ
</div>
),
},
);
const SLUG_REGEX = /^[a-z0-9-]+$/;
const projectSchema = z.object({
@@ -126,6 +139,8 @@ export default function CreateProjectPage() {
const {
register,
handleSubmit,
setValue,
watch,
formState: { errors },
} = useForm<ProjectFormData>({
resolver: zodResolver(projectSchema),
@@ -135,6 +150,36 @@ export default function CreateProjectPage() {
},
});
const latStr = watch('latitude');
const lngStr = watch('longitude');
const latNum = Number.parseFloat(latStr ?? '');
const lngNum = Number.parseFloat(lngStr ?? '');
const handlePickLocation = React.useCallback(
(
coords: { lat: number; lng: number },
resolved?: { address?: string; ward?: string; district?: string; city?: string },
) => {
setValue('latitude', coords.lat.toFixed(6), { shouldValidate: true });
setValue('longitude', coords.lng.toFixed(6), { shouldValidate: true });
// Only autofill address fields when currently empty — don't clobber what
// the admin typed intentionally.
if (resolved?.address && !watch('address')) {
setValue('address', resolved.address, { shouldValidate: true });
}
if (resolved?.ward && !watch('ward')) {
setValue('ward', resolved.ward, { shouldValidate: true });
}
if (resolved?.district && !watch('district')) {
setValue('district', resolved.district, { shouldValidate: true });
}
if (resolved?.city && !watch('city')) {
setValue('city', resolved.city, { shouldValidate: true });
}
},
[setValue, watch],
);
const onSubmit = async (data: ProjectFormData) => {
setIsSubmitting(true);
setError(null);
@@ -309,6 +354,19 @@ export default function CreateProjectPage() {
{/* Vị trí */}
<FormSection title="Vị trí">
<div className="sm:col-span-2">
<Label>Chọn vị trí trên bản đ</Label>
<p className="mb-2 text-xs text-muted-foreground">
Nhấp vào bản đ hoặc kéo pin đ xác đnh toạ đ. Ô đa chỉ / phường /
quận / thành phố bên dưới sẽ tự điền nếu đang trống.
</p>
<LocationPicker
lat={Number.isFinite(latNum) ? latNum : null}
lng={Number.isFinite(lngNum) ? lngNum : null}
onChange={handlePickLocation}
height="360px"
/>
</div>
<div className="space-y-1.5 sm:col-span-2">
<Label htmlFor="address">
Đa chỉ <span className="text-destructive">*</span>