Spaces:
Running
Running
axeronis
fix: resolve z-index collisions and optimize AI summary scroll performance via Portals and hardware acceleration
33757b5 Download frontend/components/ClientCard.tsx from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 14.2 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/2c5de26c1a17aff6794de780c66253fd5bb2f22b/frontend/components/ClientCard.tsx
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api@2c5de26c1a17aff6794de780c66253fd5bb2f22b/frontend/components/ClientCard.tsx
-
curl -L -o ClientCard.tsx https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/2c5de26c1a17aff6794de780c66253fd5bb2f22b/frontend/components/ClientCard.tsx
14.2 kB
| 'use client' | |
| import { useState, useEffect } from 'react' | |
| import { Lead } from '@/lib/api' | |
| import { cn } from '@/lib/utils' | |
| import { | |
| Brain, TrendingUp, DollarSign, Target, Clock, AlertCircle, | |
| Lightbulb, User as UserIcon, CheckCircle2, Phone, Check, | |
| Loader2, RefreshCw, Bot, Zap, Database, Shield, MessageSquare, | |
| AlertTriangle, ThumbsUp, PenTool, Copy, ChevronDown, ChevronUp, | |
| Mail, Archive, PhoneCall, MapPin, Briefcase, Flame | |
| } from 'lucide-react' | |
| import { useToast } from '@/contexts/ToastContext' | |
| import { motion, AnimatePresence } from 'framer-motion' | |
| import { useTranslation } from '@/lib/i18n' | |
| interface ClientCardProps { | |
| lead: Lead | |
| onTakeover: () => void | |
| isAnalyzing?: boolean | |
| onRefresh?: () => void | |
| conversationId?: string | |
| tenantId?: string | |
| } | |
| export function ClientCard({ lead, onTakeover, isAnalyzing, onRefresh, conversationId, tenantId }: ClientCardProps) { | |
| const { success, error } = useToast() | |
| const { t } = useTranslation() | |
| const summary = (lead.ai_summary_json || {}) as any | |
| const [expandedSection, setExpandedSection] = useState<string | null>(null) | |
| const [isReanalyzing, setIsReanalyzing] = useState(false) | |
| const [currentStage, setCurrentStage] = useState<any>(null) | |
| useEffect(() => { | |
| if (!lead.current_stage_id) return | |
| fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/playbook/stages`, { | |
| headers: { 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` } | |
| }) | |
| .then(r => r.ok ? r.json() : []) | |
| .then(stages => { | |
| const stage = stages.find((s: any) => s.id === lead.current_stage_id) | |
| if (stage) setCurrentStage(stage) | |
| }) | |
| .catch(console.error) | |
| }, [lead.current_stage_id]) | |
| const handleReanalyze = async () => { | |
| setIsReanalyzing(true) | |
| try { | |
| // 1. Trigger analysis | |
| const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/leads/${lead.id}/analyze`, { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` | |
| } | |
| }) | |
| if (!res.ok) throw new Error('Failed') | |
| // 2. Wait a bit for analysis to complete | |
| await new Promise(resolve => setTimeout(resolve, 2000)) | |
| // 3. Fetch updated lead data | |
| const updatedRes = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/leads/${lead.id}`, { | |
| headers: { | |
| 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` | |
| } | |
| }) | |
| if (updatedRes.ok) { | |
| const updatedLead = await updatedRes.json() | |
| // Trigger parent refresh with new data | |
| onRefresh?.() | |
| success(t('clientCard.analysisComplete'), t('clientCard.summaryUpdated')) | |
| } else { | |
| throw new Error('Failed to fetch updated data') | |
| } | |
| } catch { | |
| error(t('common.error'), t('clientCard.failedToAnalyze')) | |
| } finally { | |
| setIsReanalyzing(false) | |
| } | |
| } | |
| // Helper to clean values | |
| const cleanValue = (value: any, fallback: string): string => { | |
| if (!value || typeof value !== 'string') return fallback | |
| const errorPatterns = ['unknown', 'error', 'failed', 'undefined'] | |
| return errorPatterns.some(p => value.toLowerCase().includes(p)) ? fallback : value | |
| } | |
| // Structured Data | |
| const data = { | |
| intent: cleanValue(summary.intent, t('clientCard.notDetermined')), | |
| need: cleanValue(summary.need || lead.need, t('clientCard.notDetermined')), | |
| budget: cleanValue(summary.budget || lead.budget, t('clientCard.notDefined')), | |
| authority: cleanValue(summary.authority || lead.authority, t('common.unknown')), | |
| timeline: cleanValue(summary.timeline || lead.timeline, t('clientCard.notSpecified')), | |
| industry: cleanValue(summary.niche || summary.industry || (lead as any).industry || summary.business_type, t('clientCard.notSpecified')), | |
| pain_points: Array.isArray(summary.pain_points) ? summary.pain_points : [], | |
| objections: Array.isArray(summary.objections) ? summary.objections : [], | |
| psychotype: cleanValue(summary.psychotype || lead.psychotype, 'unknown'), | |
| hidden_signals: summary.hidden_signals, | |
| recommendation: summary.recommendation, | |
| draft_reply: summary.draft_reply, | |
| heat_score: typeof summary.heat_score === 'number' ? summary.heat_score : (lead.heat_score || 0) | |
| } | |
| // Psychotype Colors & Labels | |
| const getPsychotypeInfo = (type: string) => { | |
| const map: Record<string, { label: string; color: string; bg: string; icon: any }> = { | |
| 'dominant': { label: t('psychotypes.dominant'), color: 'text-red-600', bg: 'bg-red-50', icon: Zap }, | |
| 'influential': { label: t('psychotypes.influential'), color: 'text-amber-600', bg: 'bg-amber-50', icon: StarIcon }, | |
| 'steady': { label: t('psychotypes.steady'), color: 'text-emerald-600', bg: 'bg-emerald-50', icon: Shield }, | |
| 'conscientious': { label: t('psychotypes.conscientious'), color: 'text-blue-600', bg: 'bg-blue-50', icon: Database }, | |
| 'unknown': { label: t('clientCard.notDetermined'), color: 'text-slate-500', bg: 'bg-slate-50', icon: UserIcon } | |
| } | |
| return map[type.toLowerCase()] || map['unknown'] | |
| } | |
| const psychotype = getPsychotypeInfo(data.psychotype) | |
| // Score Color | |
| const getScoreColor = (score: number) => { | |
| if (score >= 80) return 'text-red-500' | |
| if (score >= 40) return 'text-orange-500' | |
| return 'text-blue-500' | |
| } | |
| const getHeatVisuals = (score: number) => { | |
| if (score >= 80) return { | |
| gradient: 'from-red-600 to-orange-500', | |
| bulb: 'bg-red-500', | |
| glow: 'bg-red-500/10', | |
| shadow: 'rgba(239,68,68,0.5)' | |
| } | |
| if (score >= 40) return { | |
| gradient: 'from-orange-600 to-amber-500', | |
| bulb: 'bg-orange-500', | |
| glow: 'bg-orange-500/10', | |
| shadow: 'rgba(249,115,22,0.5)' | |
| } | |
| return { | |
| gradient: 'from-blue-600 to-cyan-500', | |
| bulb: 'bg-blue-500', | |
| glow: 'bg-blue-500/10', | |
| shadow: 'rgba(59,130,246,0.5)' | |
| } | |
| } | |
| const visuals = getHeatVisuals(data.heat_score) | |
| const copyToClipboard = (text: string, label: string) => { | |
| navigator.clipboard.writeText(text) | |
| success(t('common.copied'), `${label} ${t('clientCard.copiedToClipboard')}`) | |
| } | |
| const toggleSection = (section: string) => { | |
| setExpandedSection(expandedSection === section ? null : section) | |
| } | |
| // Construct real summary points from 11-point AI data | |
| const realSummaryPoints = [ | |
| `${t('clientCard.name')}: ${lead.name || t('common.unknown')}`, | |
| data.intent && `${t('clientCard.goals')}: ${data.intent}`, | |
| data.industry && `${t('clientCard.niche')}: ${data.industry}`, | |
| data.need !== t('clientCard.notDetermined') && `${t('clientCard.need')}: ${data.need}`, | |
| data.budget !== t('clientCard.notDefined') && `${t('clientCard.budget')}: ${data.budget}`, | |
| data.authority !== t('common.unknown') && `${t('clientCard.decisionMaker')}: ${data.authority}`, | |
| data.timeline !== t('clientCard.notSpecified') && `${t('clientCard.timeline')}: ${data.timeline}`, | |
| (data.pain_points.length > 0) && `${t('clientCard.painPoints')}: ${data.pain_points.join(', ')}`, | |
| (data.objections.length > 0) && `${t('clientCard.objections')}: ${data.objections.join(', ')}`, | |
| data.hidden_signals && `${t('clientCard.signals')}: ${data.hidden_signals}`, | |
| data.psychotype !== 'unknown' && `${t('clientCard.psychotype')}: ${getPsychotypeInfo(data.psychotype).label}`, | |
| data.recommendation && `${t('clientCard.recommendation')}: ${data.recommendation}`, | |
| ].filter(Boolean) as string[] | |
| const summaryPoints = realSummaryPoints.length > 0 ? realSummaryPoints : [ | |
| t('clientCard.analysisNotDone'), | |
| t('clientCard.waitingFirstMessage') | |
| ] | |
| return ( | |
| <div className="h-full flex flex-col bg-[#0D0E18] font-['Inter'] relative"> | |
| {/* Content */} | |
| <div | |
| className="flex-1 overflow-y-auto p-5 space-y-5 scrollbar-thin scrollbar-thumb-white/10" | |
| style={{ willChange: 'transform, scroll-position', transform: 'translateZ(0)' }} | |
| > | |
| {/* Header Title with Icon */} | |
| <div className="flex items-center gap-3 mb-2 p-1"> | |
| <div className="w-10 h-10 rounded-xl bg-indigo-500/10 flex items-center justify-center text-indigo-400 border border-indigo-500/20"> | |
| <Brain className="w-5 h-5" /> | |
| </div> | |
| <div> | |
| <h2 className="text-base font-bold text-white tracking-tight">{t('clientCard.chatSummary')}</h2> | |
| <p className="text-[10px] text-slate-500 uppercase tracking-widest font-semibold">{t('common.aiGenerated') || 'AI Generated'}</p> | |
| </div> | |
| </div> | |
| {/* QUALIFICATION CARD - Quick Info */} | |
| {(lead as any).qualification_data && Object.keys((lead as any).qualification_data).length > 0 && ( | |
| <div className={cn( | |
| "rounded-xl p-4 mb-4 border transition-all", | |
| (lead as any).qualification_complete | |
| ? "bg-emerald-500/5 border-emerald-500/20" | |
| : "bg-white/5 border-white/10" | |
| )}> | |
| <div className="flex items-center justify-between mb-3"> | |
| <div className="flex items-center gap-2"> | |
| <div className={cn( | |
| "w-6 h-6 rounded-full flex items-center justify-center", | |
| (lead as any).qualification_complete | |
| ? "bg-emerald-500/20 text-emerald-400" | |
| : "bg-amber-500/20 text-amber-400" | |
| )}> | |
| {(lead as any).qualification_complete | |
| ? <CheckCircle2 className="w-4 h-4" /> | |
| : <Target className="w-4 h-4" />} | |
| </div> | |
| <span className="text-sm font-medium text-white"> | |
| {(lead as any).qualification_complete ? 'Квалифицирован' : 'Квалификация'} | |
| </span> | |
| </div> | |
| {(lead as any).qualification_complete && ( | |
| <span className="text-[10px] uppercase tracking-wider text-emerald-400 font-semibold"> | |
| ✓ Полная | |
| </span> | |
| )} | |
| </div> | |
| <div className="space-y-2"> | |
| {Object.entries((lead as any).qualification_data).map(([field, value]: [string, any]) => { | |
| const isNotFound = !value || value.toLowerCase?.().includes('не выявлено') || value.toLowerCase?.().includes('не указано') | |
| return ( | |
| <div key={field} className="flex justify-between items-center"> | |
| <span className="text-xs text-slate-400">{field}:</span> | |
| <span className={cn( | |
| "text-xs font-medium", | |
| isNotFound ? "text-slate-500 italic" : "text-white" | |
| )}> | |
| {isNotFound ? 'Не выявлено' : String(value)} | |
| </span> | |
| </div> | |
| ) | |
| })} | |
| </div> | |
| </div> | |
| )} | |
| {/* Numbered Summary List */} | |
| <div className="space-y-4 px-1"> | |
| {summaryPoints.map((point, i) => ( | |
| <div key={i} className="flex gap-4 items-start group/point"> | |
| <div className="flex flex-col items-center gap-1 mt-1"> | |
| <span className="text-[11px] font-bold text-slate-500 bg-white/5 w-6 h-6 rounded-md flex items-center justify-center group-hover/point:text-indigo-400 group-hover/point:bg-indigo-500/10 transition-colors"> | |
| {i + 1} | |
| </span> | |
| {i < summaryPoints.length - 1 && <div className="w-[1px] h-4 bg-white/5" />} | |
| </div> | |
| <p className="text-slate-300 text-sm leading-relaxed flex-1 group-hover/point:text-white transition-colors">{point}</p> | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| <div className="p-5 pb-8 mt-auto"> | |
| <div className="bg-[#1A1B26] rounded-2xl p-5 border border-white/5 relative overflow-hidden group"> | |
| {/* Glow Effect */} | |
| <div className={cn( | |
| "absolute top-0 right-0 w-32 h-32 blur-[40px] rounded-full pointer-events-none group-hover:opacity-100 opacity-50 transition-all duration-500", | |
| visuals.glow | |
| )} /> | |
| <h3 className="text-sm font-medium text-slate-300 mb-4 relative z-10">{t('clientCard.heatLevel')}</h3> | |
| <div className="flex items-center gap-4 relative z-10"> | |
| {/* Thermometer Icon Placeholder (Custom Graphic) */} | |
| <div className="h-16 w-8 bg-slate-800 rounded-full relative overflow-hidden ring-1 ring-white/10"> | |
| <div | |
| className={cn( | |
| "absolute bottom-0 left-0 right-0 bg-gradient-to-t transition-all duration-1000", | |
| visuals.gradient | |
| )} | |
| style={{ height: `${data.heat_score}%` }} | |
| /> | |
| {/* Bulb */} | |
| <div | |
| className={cn("absolute bottom-1 left-1.5 right-1.5 h-5 w-5 rounded-full transition-colors duration-500", visuals.bulb)} | |
| style={{ boxShadow: `0 0 10px ${visuals.shadow}` }} | |
| /> | |
| </div> | |
| <div> | |
| <div className="flex items-baseline gap-2"> | |
| <span className="text-4xl font-bold text-white tracking-tight">{data.heat_score}%</span> | |
| <Flame className={cn("w-6 h-6 animate-pulse", getScoreColor(data.heat_score))} /> | |
| </div> | |
| <p className={cn("text-sm font-medium mt-1", getScoreColor(data.heat_score))}> | |
| {data.heat_score >= 80 ? t('clientCard.high') : data.heat_score >= 40 ? t('clientCard.medium') : t('clientCard.low')} | |
| </p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| ) | |
| } | |
| // Helper icon for Influential type | |
| function StarIcon(props: any) { | |
| return ( | |
| <svg | |
| {...props} | |
| xmlns="http://www.w3.org/2000/svg" | |
| width="24" | |
| height="24" | |
| viewBox="0 0 24 24" | |
| fill="none" | |
| stroke="currentColor" | |
| strokeWidth="2" | |
| strokeLinecap="round" | |
| strokeLinejoin="round" | |
| > | |
| <polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" /> | |
| </svg> | |
| ) | |
| } | |