Files
goodgo-platform/apps/web/components/chuyen-nhuong/transfer-wizard-client.tsx
Ho Ngoc Hai 593d1594bd
Some checks failed
Deploy / Build API Image (push) Failing after 19s
Deploy / Build Web Image (push) Failing after 11s
Security Scanning / Trivy Filesystem Scan (push) Failing after 27s
Deploy / Deploy to Staging (push) Has been skipped
Deploy / Smoke Test Production (push) Has been skipped
Deploy / Deploy to Production (push) Has been skipped
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 11s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 37s
Deploy / Build AI Services Image (push) Failing after 10s
E2E Tests / Playwright E2E (push) Failing after 10s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 3s
Security Scanning / Trivy Scan — API Image (push) Failing after 47s
Security Scanning / Trivy Scan — Web Image (push) Failing after 31s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 32s
Deploy / Smoke Test Staging (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
refactor(web): replace emoji icons with lucide-react across the app
User directive: avoid emojis for UI chrome; keep the icon language
consistent with the rest of the design system (shadcn + lucide-react).

Swaps
-----
- lib/listing-personas.ts — Persona emojis (👨‍👩‍👧🏡🚇🧑‍💻🌳📈🛡️🏥)
  → Lucide icons (Baby, Home, TrainFront, Laptop, Trees, TrendingUp,
  Shield, HeartPulse). Persona type now carries `icon: LucideIcon`.
- components/neighborhood/types.ts — POI_CATEGORY_CONFIG emojis
  (🏫🏥🚇🛒🍽️🌳) → Lucide (GraduationCap, Stethoscope, TrainFront,
  ShoppingBag, UtensilsCrossed, Trees). Config type tightened to
  `icon: LucideIcon`.
- components/neighborhood/neighborhood-poi-map.tsx — filter pills
  now render <config.icon h-3.5 w-3.5>. Map markers were text-emoji
  (el.textContent = config.icon); replaced with hard-coded inline
  SVG strings per category (POI_MARKER_SVG) since lucide-static
  isn't installed. Marker bumped 28px → 32px for larger hit target.
  Popup now shows only the property name + category label (no
  emoji prefix). closeButton: true + closeOnClick: true for
  better dismissibility.
- listing-detail-client.tsx — PersonaFitCard now renders
  <p.icon h-4 w-4 aria-hidden>.
- transfer / chuyen-nhuong files — category icons (🛋️🧊🖥️🍳🛍️🏠)
  migrated to Lucide (Sofa, Refrigerator, Monitor, ChefHat, Store,
  Home) with type `icon: LucideIcon`.
- Small replacements: inquiries page 📭 → Inbox; kyc page ✓ → Check.

POI popup click fix
-------------------
The inner SVG inside each POI marker was capturing pointer events
before Mapbox's marker-click handler saw them, so clicking a marker
did nothing. Explicit `innerSvg.style.pointerEvents = 'none'` lets
clicks reach the wrapping .poi-marker div that setPopup() is bound
to. Verified via DOM dispatch: click → popup opens with property
name + category + distance + × close.

Verification
------------
- Grep across the 4 scoped files for emoji code points → 0 hits.
- pnpm -w test: 624/624 green.
- Typecheck: no new errors in touched files.

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

341 lines
12 KiB
TypeScript

'use client';
import { ChevronLeft, ChevronRight, Loader2, Send } from 'lucide-react';
import { useRouter } from 'next/navigation';
import * as React from 'react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import {
type TransferCategory,
type TransferCondition,
CATEGORY_ICONS,
CATEGORY_LABELS,
CONDITION_LABELS,
transferApi,
} from '@/lib/chuyen-nhuong-api';
import { cn } from '@/lib/utils';
import {
type TransferItemDraft,
useTransferWizardStore,
} from '@/lib/transfer-wizard-store';
const STEPS = [
'Danh mục',
'Sản phẩm',
'Định giá AI',
'Thông tin & Gửi',
] as const;
// ─── Step 1: Category Selection ────────────────────────
function StepCategory() {
const { category, setCategory, setStep } = useTransferWizardStore();
const categories = Object.entries(CATEGORY_LABELS) as [TransferCategory, string][];
return (
<div className="space-y-4">
<p className="text-muted-foreground text-sm">Chọn danh mục chuyển nhượng:</p>
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3">
{categories.map(([value, label]) => (
<button
key={value}
type="button"
onClick={() => {
setCategory(value);
setStep(1);
}}
className={cn(
'flex flex-col items-center gap-2 rounded-lg border p-4 text-sm transition hover:border-primary',
category === value && 'border-primary bg-primary/5 ring-1 ring-primary',
)}
>
{(() => {
const Icon = CATEGORY_ICONS[value];
return <Icon className="h-6 w-6" aria-hidden="true" />;
})()}
<span>{label}</span>
</button>
))}
</div>
</div>
);
}
// ─── Step 2: Items ─────────────────────────────────────
function StepItems() {
const { items, addItem, removeItem, category } = useTransferWizardStore();
const [name, setName] = React.useState('');
const [condition, setCondition] = React.useState<TransferCondition>('GOOD');
const [askingPrice, setAskingPrice] = React.useState('');
const handleAdd = () => {
if (!name || !askingPrice || !category) return;
addItem({
name,
condition,
askingPriceVND: Number(askingPrice),
quantity: 1,
});
setName('');
setAskingPrice('');
};
return (
<div className="space-y-4">
<div className="grid gap-3 sm:grid-cols-3">
<div>
<Label>Tên sản phẩm</Label>
<Input value={name} onChange={(e) => setName(e.target.value)} placeholder="VD: Bàn làm việc" />
</div>
<div>
<Label>Tình trạng</Label>
<select
value={condition}
onChange={(e) => setCondition(e.target.value as TransferCondition)}
className="border-input bg-background flex h-9 w-full rounded-md border px-3 py-1 text-sm"
>
{Object.entries(CONDITION_LABELS).map(([v, l]) => (
<option key={v} value={v}>{l}</option>
))}
</select>
</div>
<div>
<Label>Giá (VND)</Label>
<Input type="number" value={askingPrice} onChange={(e) => setAskingPrice(e.target.value)} placeholder="0" />
</div>
</div>
<Button type="button" variant="outline" size="sm" onClick={handleAdd} disabled={!name || !askingPrice}>
+ Thêm sản phẩm
</Button>
{items.length > 0 && (
<div className="divide-y rounded-md border">
{items.map((item) => (
<div key={item.id} className="flex items-center justify-between px-3 py-2 text-sm">
<span>{item.name} {CONDITION_LABELS[item.condition]}</span>
<div className="flex items-center gap-3">
<span className="font-medium">{new Intl.NumberFormat('vi-VN').format(item.askingPriceVND)} VND</span>
<Button type="button" variant="ghost" size="sm" onClick={() => removeItem(item.id)}>Xoá</Button>
</div>
</div>
))}
</div>
)}
</div>
);
}
// ─── Step 3: AI Estimate ───────────────────────────────
function StepAiEstimate() {
const { items, category, aiEstimate, isEstimating, setAiEstimate, setIsEstimating } = useTransferWizardStore();
const handleEstimate = async () => {
if (!category || items.length === 0) return;
setIsEstimating(true);
try {
const payload = items.map((item) => ({
category,
condition: item.condition,
originalPriceVND: item.askingPriceVND,
purchaseYear: new Date().getFullYear(),
}));
const result = await transferApi.estimate(payload);
setAiEstimate(result);
} catch {
setAiEstimate(null);
} finally {
setIsEstimating(false);
}
};
return (
<div className="space-y-4">
<p className="text-muted-foreground text-sm">
Sử dụng AI đ ưc tính giá trị chuyển nhượng dựa trên danh mục, tình trạng giá gốc.
</p>
<Button type="button" onClick={handleEstimate} disabled={isEstimating || items.length === 0}>
{isEstimating && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
{isEstimating ? 'Đang ước tính...' : 'Ước tính giá bằng AI'}
</Button>
{aiEstimate && (
<Card>
<CardContent className="pt-4">
<p className="text-lg font-semibold">
Tổng ưc tính: {new Intl.NumberFormat('vi-VN').format(Number(aiEstimate.totalEstimateVND))} VND
</p>
<p className="text-muted-foreground text-sm">
Đ tin cậy: {Math.round(aiEstimate.avgConfidence * 100)}%
</p>
</CardContent>
</Card>
)}
</div>
);
}
// ─── Step 4: Details & Submit ──────────────────────────
function StepDetails() {
const store = useTransferWizardStore();
const router = useRouter();
const [submitting, setSubmitting] = React.useState(false);
const handleSubmit = async () => {
if (!store.category) return;
setSubmitting(true);
try {
const payload = {
category: store.category,
title: store.title,
description: store.description || undefined,
address: store.address,
district: store.district,
city: store.city,
latitude: 0,
longitude: 0,
askingPriceVND: store.askingPriceVND || store.items.reduce((sum, i) => sum + i.askingPriceVND * i.quantity, 0),
pricingSource: store.pricingSource,
isNegotiable: store.isNegotiable,
items: store.items.map((i) => ({
name: i.name,
brand: i.brand,
modelName: i.modelName,
category: store.category!,
condition: i.condition,
purchaseYear: i.purchaseYear,
originalPriceVND: i.askingPriceVND,
askingPriceVND: i.askingPriceVND,
quantity: i.quantity,
notes: i.notes,
})),
};
await transferApi.create(payload);
store.reset();
router.push('/chuyen-nhuong');
} catch {
// Error handling deferred to toast integration
} finally {
setSubmitting(false);
}
};
return (
<div className="space-y-4">
<div className="grid gap-3 sm:grid-cols-2">
<div className="sm:col-span-2">
<Label>Tiêu đ</Label>
<Input
value={store.title}
onChange={(e) => store.setListingDetails({ title: e.target.value })}
placeholder="VD: Chuyển nhượng bộ nội thất văn phòng"
/>
</div>
<div className="sm:col-span-2">
<Label> tả</Label>
<Textarea
value={store.description}
onChange={(e) => store.setListingDetails({ description: e.target.value })}
rows={3}
/>
</div>
<div>
<Label>Đa chỉ</Label>
<Input
value={store.address}
onChange={(e) => store.setListingDetails({ address: e.target.value })}
/>
</div>
<div>
<Label>Quận/Huyện</Label>
<Input
value={store.district}
onChange={(e) => store.setListingDetails({ district: e.target.value })}
/>
</div>
<div>
<Label>Thành phố</Label>
<Input
value={store.city}
onChange={(e) => store.setListingDetails({ city: e.target.value })}
/>
</div>
</div>
<Button type="button" onClick={handleSubmit} disabled={submitting || !store.title || !store.address || !store.district}>
{submitting ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : <Send className="mr-2 h-4 w-4" />}
{submitting ? 'Đang gửi...' : 'Đăng tin'}
</Button>
</div>
);
}
// ─── Main Wizard ───────────────────────────────────────
export function TransferWizardClient() {
const { currentStep, setStep, items, category } = useTransferWizardStore();
const canNext = () => {
if (currentStep === 0) return !!category;
if (currentStep === 1) return items.length > 0;
return true;
};
return (
<div className="container mx-auto max-w-3xl py-8">
<Card>
<CardHeader>
<CardTitle>Đăng tin chuyển nhượng</CardTitle>
{/* Step indicator */}
<div className="mt-4 flex items-center gap-2">
{STEPS.map((label, i) => (
<React.Fragment key={label}>
{i > 0 && <div className={cn('h-px flex-1', i <= currentStep ? 'bg-primary' : 'bg-border')} />}
<button
type="button"
onClick={() => i < currentStep && setStep(i)}
className={cn(
'flex h-8 w-8 items-center justify-center rounded-full text-xs font-medium transition',
i === currentStep && 'bg-primary text-primary-foreground',
i < currentStep && 'bg-primary/20 text-primary cursor-pointer',
i > currentStep && 'bg-muted text-muted-foreground',
)}
>
{i + 1}
</button>
</React.Fragment>
))}
</div>
<div className="text-muted-foreground mt-1 text-center text-sm">{STEPS[currentStep]}</div>
</CardHeader>
<CardContent>
{currentStep === 0 && <StepCategory />}
{currentStep === 1 && <StepItems />}
{currentStep === 2 && <StepAiEstimate />}
{currentStep === 3 && <StepDetails />}
{/* Navigation */}
<div className="mt-6 flex justify-between">
<Button
type="button"
variant="outline"
onClick={() => setStep(currentStep - 1)}
disabled={currentStep === 0}
>
<ChevronLeft className="mr-1 h-4 w-4" /> Quay lại
</Button>
{currentStep < 3 && (
<Button type="button" onClick={() => setStep(currentStep + 1)} disabled={!canNext()}>
Tiếp theo <ChevronRight className="ml-1 h-4 w-4" />
</Button>
)}
</div>
</CardContent>
</Card>
</div>
);
}