Files
goodgo-platform/apps/web/components/valuation/ai-estimate-button.tsx
Ho Ngoc Hai 03f8674024
Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 18s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 1m15s
Deploy / Build API Image (push) Failing after 33s
Deploy / Build Web Image (push) Failing after 14s
Deploy / Build AI Services Image (push) Failing after 13s
E2E Tests / Playwright E2E (push) Failing after 11s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 3s
Security Scanning / Trivy Scan — API Image (push) Failing after 2m1s
Security Scanning / Trivy Scan — Web Image (push) Failing after 51s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 47s
Security Scanning / Trivy Filesystem Scan (push) Failing after 35s
Deploy / Deploy to Staging (push) Has been skipped
Deploy / Smoke Test Staging (push) Has been skipped
Deploy / Deploy to Production (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
fix(ai-advice,ui): Bearer auth for proxy gateways + un-pin contact card + VN diacritics
- AI advice handler now sends both `x-api-key` and `Authorization: Bearer`
  so proxy gateways (e.g. chat.trollllm.xyz) accept the request. Native
  Anthropic ignores the extra header.
- Remove `lg:sticky lg:top-20` from listing detail contact card — sidebar
  now scrolls with the page.
- Fix missing Vietnamese diacritics on AI estimate button:
  "Dinh gia AI" -> "Định giá AI", "Dang dinh gia..." -> "Đang định giá...".
  Tests updated accordingly.

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

81 lines
2.8 KiB
TypeScript

'use client';
import { useState } from 'react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { useValuationPredictForListing } from '@/lib/hooks/use-valuation';
interface AiEstimateButtonProps {
listingId: string;
}
function formatPrice(num: number): string {
if (num >= 1_000_000_000) return `${(num / 1_000_000_000).toFixed(2)} ty`;
if (num >= 1_000_000) return `${(num / 1_000_000).toFixed(0)} trieu`;
return num.toLocaleString('vi-VN');
}
export function AiEstimateButton({ listingId }: AiEstimateButtonProps) {
const [showResult, setShowResult] = useState(false);
const mutation = useValuationPredictForListing();
const handleClick = () => {
mutation.mutate(listingId, {
onSuccess: () => setShowResult(true),
});
};
if (showResult && mutation.data) {
const result = mutation.data;
const confidencePct = Math.round(result.confidence * 100);
return (
<Card className="border-primary/20 bg-primary/5">
<CardHeader className="pb-2">
<CardDescription>Gia uoc tinh AI</CardDescription>
<CardTitle className="text-xl text-primary">
{formatPrice(result.estimatedPriceVND)} VND
</CardTitle>
</CardHeader>
<CardContent className="space-y-2">
<div className="flex items-center justify-between text-sm">
<span className="text-muted-foreground">Do tin cay</span>
<span className="font-medium">{confidencePct}%</span>
</div>
<div className="h-1.5 rounded-full bg-muted">
<div
className="h-1.5 rounded-full bg-primary"
style={{ width: `${confidencePct}%` }}
/>
</div>
<div className="flex items-center justify-between text-sm">
<span className="text-muted-foreground">Khoang gia</span>
<span className="font-medium">
{formatPrice(result.priceRangeLow)} - {formatPrice(result.priceRangeHigh)}
</span>
</div>
</CardContent>
</Card>
);
}
return (
<Button
variant="outline"
className="w-full gap-2"
onClick={handleClick}
disabled={mutation.isPending}
>
<svg className="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"
/>
</svg>
{mutation.isPending ? 'Đang định giá...' : 'Định giá AI'}
</Button>
);
}