Spaces:
Paused
Paused
File size: 9,235 Bytes
5a81b95 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | import React, { useState } from 'react';
import {
Briefcase, FileText, Download, Loader2, CheckCircle,
ArrowRight, Sparkles, Building2
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
import { API_URL } from '@/config/api';
import { cn } from '@/lib/utils';
interface GeneratedPresentation {
filename: string;
url: string;
}
export default function TDCSolutionWidget() {
const [customerName, setCustomerName] = useState('');
const [need, setNeed] = useState('');
const [isGenerating, setIsGenerating] = useState(false);
const [result, setResult] = useState<GeneratedPresentation | null>(null);
const [error, setError] = useState<string | null>(null);
const handleGenerate = async () => {
if (!customerName.trim() || !need.trim()) return;
setIsGenerating(true);
setError(null);
setResult(null);
try {
// Call the TDC Generator Tool via MCP route
const response = await fetch(`${API_URL}/api/mcp/route`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
tool: 'tdc.generate_presentation',
params: {
customerName,
need
}
})
});
const data = await response.json();
if (data.result && data.result.success) {
setResult(data.result.data);
} else {
throw new Error(data.result?.error || 'Generation failed');
}
} catch (err: any) {
console.error('Generation error:', err);
setError(err.message || 'Failed to generate presentation');
} finally {
setIsGenerating(false);
}
};
const handleReset = () => {
setResult(null);
setError(null);
setCustomerName('');
setNeed('');
};
return (
<div className="h-full flex flex-col bg-white text-slate-900 rounded-lg overflow-hidden border border-slate-200 shadow-sm relative">
{/* TDC Brand Header Bar */}
<div className="h-1.5 w-full bg-[#0000BF]" />
{/* Header */}
<div className="p-4 flex items-center justify-between border-b border-slate-100">
<div className="flex items-center gap-2">
<div className="bg-[#0000BF] p-1.5 rounded text-white">
<Building2 className="w-4 h-4" />
</div>
<div>
<h2 className="font-bold text-sm text-[#0000BF]">TDC Erhverv</h2>
<p className="text-[10px] text-slate-500 font-medium">LØSNINGSDESIGNER</p>
</div>
</div>
{result && (
<button onClick={handleReset} className="text-xs text-slate-400 hover:text-[#0000BF]">
Ny løsning
</button>
)}
</div>
{/* Content */}
<div className="flex-1 p-4 overflow-y-auto">
{!result ? (
<div className="space-y-4">
<div className="space-y-1.5">
<label className="text-xs font-semibold text-slate-600 uppercase">Kunde</label>
<Input
value={customerName}
onChange={e => setCustomerName(e.target.value)}
placeholder="Virksomhedens navn..."
className="bg-slate-50 border-slate-200 focus:ring-[#0000BF] text-slate-900 placeholder:text-slate-400"
/>
</div>
<div className="space-y-1.5">
<label className="text-xs font-semibold text-slate-600 uppercase">Behov & Udfordringer</label>
<Textarea
value={need}
onChange={e => setNeed(e.target.value)}
placeholder="Beskriv kundens behov (f.eks. 'Vi har brug for sikker hjemmearbejde til 50 ansatte og bedre mobildækning')..."
className="bg-slate-50 border-slate-200 focus:ring-[#0000BF] text-slate-900 placeholder:text-slate-400 min-h-[100px] resize-none"
/>
</div>
<div className="pt-2">
<Button
onClick={handleGenerate}
disabled={isGenerating || !customerName || !need}
className={cn(
"w-full bg-[#0000BF] hover:bg-[#000090] text-white font-medium shadow-md transition-all",
isGenerating && "opacity-80"
)}
>
{isGenerating ? (
<>
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
Designer Løsning...
</>
) : (
<>
<Sparkles className="w-4 h-4 mr-2" />
Generer Præsentation
</>
)}
</Button>
</div>
{error && (
<div className="p-3 bg-red-50 text-red-600 text-xs rounded-md border border-red-100 flex items-start gap-2">
<div className="mt-0.5">⚠️</div>
<div>{error}</div>
</div>
)}
<div className="mt-4 p-3 bg-slate-50 rounded border border-slate-100 text-[10px] text-slate-500">
<p className="font-semibold mb-1">PRODUKTKATALOG INKLUDERET:</p>
<div className="flex flex-wrap gap-1">
{['One+', '5G+', 'Sikker Fiber', 'Managed Cloud', 'Teams'].map(p => (
<span key={p} className="bg-white border border-slate-200 px-1.5 py-0.5 rounded text-slate-600">{p}</span>
))}
</div>
</div>
</div>
) : (
<div className="h-full flex flex-col items-center justify-center text-center space-y-4 animate-in fade-in zoom-in-95 duration-300">
<div className="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mb-2">
<CheckCircle className="w-8 h-8 text-green-600" />
</div>
<div>
<h3 className="text-lg font-bold text-slate-900">Løsning Designet!</h3>
<p className="text-xs text-slate-500 mt-1 max-w-[200px] mx-auto">
En skræddersyet præsentation til <span className="font-semibold text-[#0000BF]">{customerName}</span> er klar.
</p>
</div>
<div className="w-full max-w-[240px] bg-slate-50 p-3 rounded-lg border border-slate-200 flex items-center gap-3 text-left hover:border-[#0000BF]/30 transition-colors">
<div className="bg-[#0000BF]/10 p-2 rounded">
<FileText className="w-5 h-5 text-[#0000BF]" />
</div>
<div className="flex-1 min-w-0">
<div className="text-xs font-medium text-slate-900 truncate">
{result.filename}
</div>
<div className="text-[10px] text-slate-500">PowerPoint (.pptx)</div>
</div>
</div>
<a
href={`${API_URL}${result.url}`}
target="_blank"
rel="noopener noreferrer"
className="w-full max-w-[240px]"
>
<Button className="w-full bg-green-600 hover:bg-green-700 text-white shadow-md">
<Download className="w-4 h-4 mr-2" />
Download PPT
</Button>
</a>
</div>
)}
</div>
</div>
);
}
|