'use client'; import { useState } from 'react'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Select } from '@/components/ui/select'; import { apiClient } from '@/lib/api-client'; import { useAuthStore } from '@/lib/auth-store'; const KYC_STATUS_MAP: Record = { NONE: { label: 'Chưa xác minh', variant: 'outline', description: 'Bạn chưa gửi hồ sơ xác minh danh tính. Hoàn tất KYC để mở khóa đầy đủ tính năng.' }, PENDING: { label: 'Đang chờ duyệt', variant: 'secondary', description: 'Hồ sơ của bạn đã được gửi và đang chờ đội ngũ quản trị xem xét. Vui lòng chờ 1-3 ngày làm việc.' }, VERIFIED: { label: 'Đã xác minh', variant: 'default', description: 'Danh tính của bạn đã được xác minh thành công. Bạn có thể sử dụng đầy đủ tính năng.' }, REJECTED: { label: 'Bị từ chối', variant: 'destructive', description: 'Hồ sơ xác minh bị từ chối. Vui lòng kiểm tra lại và gửi lại hồ sơ.' }, }; const DOCUMENT_TYPES = [ { value: 'CCCD', label: 'Căn cước công dân (CCCD)' }, { value: 'CMND', label: 'Chứng minh nhân dân (CMND)' }, { value: 'PASSPORT', label: 'Hộ chiếu' }, { value: 'BUSINESS_LICENSE', label: 'Giấy phép kinh doanh' }, ]; const KYC_STEPS = [ { step: 1, title: 'Loại giấy tờ', description: 'Chọn loại giấy tờ tùy thân' }, { step: 2, title: 'Tải ảnh', description: 'Tải ảnh mặt trước, mặt sau và ảnh selfie' }, { step: 3, title: 'Xác nhận', description: 'Kiểm tra và gửi hồ sơ' }, ]; export default function KycPage() { const { user, fetchProfile } = useAuthStore(); const [currentStep, setCurrentStep] = useState(1); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); const [documentType, setDocumentType] = useState('CCCD'); const [documentNumber, setDocumentNumber] = useState(''); const [frontImage, setFrontImage] = useState(null); const [backImage, setBackImage] = useState(null); const [selfieImage, setSelfieImage] = useState(null); const kycStatus = user?.kycStatus ?? 'NONE'; const kycInfo = KYC_STATUS_MAP[kycStatus] ?? { label: 'Chưa xác minh', variant: 'outline' as const, description: 'Bạn chưa gửi hồ sơ xác minh danh tính.' }; const canSubmit = kycStatus === 'NONE' || kycStatus === 'REJECTED'; const handleSubmit = async () => { if (!documentNumber.trim()) { setError('Vui lòng nhập số giấy tờ'); return; } if (!frontImage) { setError('Vui lòng tải ảnh mặt trước'); return; } setSubmitting(true); setError(null); try { await apiClient.patch('/auth/profile', { kycData: { documentType, documentNumber: documentNumber.trim(), submittedAt: new Date().toISOString(), }, }); await fetchProfile(); setSuccess(true); } catch (e) { setError(e instanceof Error ? e.message : 'Gửi hồ sơ thất bại'); } finally { setSubmitting(false); } }; return (

Xác minh danh tính (KYC)

Xác minh danh tính để sử dụng đầy đủ tính năng của GoodGo

{/* KYC Status */}
Trạng thái xác minh {kycInfo.label}

{kycInfo.description}

{error && (
{error}
)} {success && (
Hồ sơ KYC đã được gửi thành công. Vui lòng chờ 1-3 ngày làm việc để được xem xét.
)} {/* KYC Form */} {canSubmit && !success && ( <> {/* Step indicator */}
{KYC_STEPS.map((s, i) => (
= s.step ? 'bg-primary text-primary-foreground' : 'bg-muted text-muted-foreground' }`} > {s.step}
{s.title} {i < KYC_STEPS.length - 1 && (
)}
))}
{KYC_STEPS[currentStep - 1]?.title} {KYC_STEPS[currentStep - 1]?.description} {/* Step 1: Document type */} {currentStep === 1 && ( <>
setDocumentNumber(e.target.value)} placeholder="Nhập số CCCD/CMND/Hộ chiếu" />
)} {/* Step 2: Upload images */} {currentStep === 2 && ( <>
setFrontImage(e.target.files?.[0] ?? null)} /> {frontImage && (

{frontImage.name}

)}
setBackImage(e.target.files?.[0] ?? null)} /> {backImage && (

{backImage.name}

)}
setSelfieImage(e.target.files?.[0] ?? null)} /> {selfieImage && (

{selfieImage.name}

)}
)} {/* Step 3: Confirm */} {currentStep === 3 && (

Kiểm tra thông tin

Loại giấy tờ {DOCUMENT_TYPES.find((d) => d.value === documentType)?.label}
Số giấy tờ {documentNumber}
Ảnh mặt trước {frontImage ? frontImage.name : 'Chưa tải'}
Ảnh mặt sau {backImage ? backImage.name : 'Không có'}
Ảnh selfie {selfieImage ? selfieImage.name : 'Không có'}
)} {/* Navigation buttons */}
{currentStep > 1 ? ( ) : (
)} {currentStep < 3 ? ( ) : ( )}
)} {/* Already verified */} {kycStatus === 'VERIFIED' && (

Danh tính đã được xác minh

Tài khoản của bạn đã được xác minh đầy đủ. Bạn có thể sử dụng tất cả tính năng của GoodGo.

)} {/* Pending status */} {kycStatus === 'PENDING' && !success && (

Đang xem xét hồ sơ

Đội ngũ quản trị đang xem xét hồ sơ của bạn. Thời gian dự kiến: 1-3 ngày làm việc.

)}
); }