'use client' import { useState, useEffect } from 'react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { useToast } from '@/components/ui/use-toast' import { BookOpen, Plus, X } from 'lucide-react' import { apiFetch, ApiError } from '@/lib/api' interface DictWord { id: string word: string scope: string } export function DictionaryTab() { const { toast } = useToast() const [globalDictWords, setGlobalDictWords] = useState([]) const [newGlobalWord, setNewGlobalWord] = useState('') const [dictLoading, setDictLoading] = useState(false) const fetchGlobalDict = async () => { try { const data = await apiFetch<{ words: DictWord[] }>('/api/dictionary?scope=GLOBAL', { silent: true }) if (data?.words) setGlobalDictWords(data.words) } catch {} } useEffect(() => { fetchGlobalDict() }, []) const handleAdd = async () => { if (!newGlobalWord.trim()) return setDictLoading(true) try { await apiFetch('/api/dictionary', { method: 'POST', body: JSON.stringify({ word: newGlobalWord.trim(), scope: 'GLOBAL' }), }) setNewGlobalWord('') fetchGlobalDict() toast({ title: 'Begriff hinzugefügt' }) } catch (err) { toast({ title: 'Fehler', description: err instanceof ApiError ? err.message : 'Fehler', variant: 'destructive' }) } finally { setDictLoading(false) } } return (

Globales Wörterbuch

Globale Begriffe, die allen Mandanten als Journal-Vorschläge zur Verfügung stehen. Mandanten können zusätzlich eigene Begriffe über ihre Wörterliste hinzufügen.

{/* Add new word */}
setNewGlobalWord(e.target.value)} onKeyDown={async (e) => { if (e.key === 'Enter' && newGlobalWord.trim()) handleAdd() }} className="flex-1" disabled={dictLoading} />
{/* List of global words */} {globalDictWords.length === 0 ? (
Noch keine globalen Begriffe hinterlegt.
) : (
{globalDictWords.map((w) => ( {w.word} ))}
)}

{globalDictWords.length} globale(r) Begriff(e). Diese erscheinen bei allen Mandanten als Vorschläge im Journal.

) }