fix: CustomerAssign in WindowsPanel identisch mit AgentPanel (onChange direkt, kein OK-Button)
This commit is contained in:
parent
1f8fda6a83
commit
5eae071bf9
@ -7,7 +7,7 @@ import ScriptModal from './ScriptModal'
|
|||||||
import {
|
import {
|
||||||
X, Cpu, MemoryStick, HardDrive, Monitor, Server, Settings,
|
X, Cpu, MemoryStick, HardDrive, Monitor, Server, Settings,
|
||||||
Download, Trash2, RefreshCw, Package, Search, Play,
|
Download, Trash2, RefreshCw, Package, Search, Play,
|
||||||
ShieldCheck, Bot, Cable, CalendarClock, ChevronRight,
|
ShieldCheck, Bot, Cable, CalendarClock,
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
|
|
||||||
// ── Navigation ────────────────────────────────────────────────────────────────
|
// ── Navigation ────────────────────────────────────────────────────────────────
|
||||||
@ -48,32 +48,52 @@ function Panel({ onClose, children }) {
|
|||||||
|
|
||||||
function CustomerAssign({ agent, customers, current, onReload }) {
|
function CustomerAssign({ agent, customers, current, onReload }) {
|
||||||
const [editing, setEditing] = useState(false)
|
const [editing, setEditing] = useState(false)
|
||||||
const [val, setVal] = useState(current?.id?.toString() || '')
|
const [saving, setSaving] = useState(false)
|
||||||
|
|
||||||
const save = async () => {
|
const handleChange = async (e) => {
|
||||||
if (val === '') await api.unassignAgentCustomer(agent.id)
|
const val = e.target.value
|
||||||
else await api.assignAgentCustomer(agent.id, parseInt(val))
|
setSaving(true)
|
||||||
setEditing(false)
|
try {
|
||||||
if (onReload) onReload()
|
if (val === '') await api.unassignCustomer(agent.id)
|
||||||
|
else await api.assignCustomer(agent.id, parseInt(val))
|
||||||
|
if (onReload) onReload()
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
} finally {
|
||||||
|
setSaving(false)
|
||||||
|
setEditing(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!editing) return (
|
if (editing) return (
|
||||||
<button onClick={() => setEditing(true)}
|
<div className="flex items-center gap-2 mt-0.5">
|
||||||
className="text-xs text-gray-500 hover:text-orange-400 transition-colors mt-0.5 flex items-center gap-1">
|
<select
|
||||||
{current ? `${current.number} — ${current.name}` : 'Kein Kunde'}
|
value={agent.customer_id || ''}
|
||||||
<ChevronRight className="w-3 h-3" />
|
onChange={handleChange}
|
||||||
</button>
|
disabled={saving}
|
||||||
|
className="bg-gray-900 border border-gray-700 rounded px-2 py-1 text-sm text-white focus:outline-none focus:border-sky-500"
|
||||||
|
autoFocus
|
||||||
|
onBlur={() => !saving && setEditing(false)}
|
||||||
|
>
|
||||||
|
<option value="">— Nicht zugewiesen —</option>
|
||||||
|
{customers.sort((a, b) => a.number.localeCompare(b.number)).map(c => (
|
||||||
|
<option key={c.id} value={c.id}>{c.number} — {c.name}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
{saving && <span className="text-xs text-gray-500">Speichere...</span>}
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2 mt-1">
|
<div
|
||||||
<select value={val} onChange={e => setVal(e.target.value)}
|
className="text-sm mt-0.5 cursor-pointer hover:underline"
|
||||||
className="bg-gray-800 border border-gray-700 rounded px-2 py-0.5 text-xs text-white focus:outline-none">
|
onClick={() => setEditing(true)}
|
||||||
<option value="">Kein Kunde</option>
|
title="Kunde aendern"
|
||||||
{customers.map(c => <option key={c.id} value={c.id}>{c.number} — {c.name}</option>)}
|
>
|
||||||
</select>
|
{current
|
||||||
<button onClick={save} className="text-green-400 text-xs">OK</button>
|
? <span className="text-sky-400">{current.number} — {current.name}</span>
|
||||||
<button onClick={() => setEditing(false)} className="text-gray-500 text-xs">Abbrechen</button>
|
: <span className="text-gray-500 italic">Kein Kunde zugewiesen (klicken zum Zuweisen)</span>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user