import { useEffect, useState } from 'react'; import { api } from '@renderer/api'; import { Button } from '@renderer/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@renderer/components/ui/dialog'; import { getTeamColorSet } from '@renderer/constants/teamColors'; import { cn } from '@renderer/lib/utils'; import { Loader2 } from 'lucide-react'; const TEAM_COLOR_NAMES = [ 'blue', 'green', 'red', 'yellow', 'purple', 'cyan', 'orange', 'pink', ] as const; interface EditTeamDialogProps { open: boolean; teamName: string; currentName: string; currentDescription: string; currentColor: string; onClose: () => void; onSaved: () => void; } export const EditTeamDialog = ({ open, teamName, currentName, currentDescription, currentColor, onClose, onSaved, }: EditTeamDialogProps): React.JSX.Element => { const [name, setName] = useState(currentName); const [description, setDescription] = useState(currentDescription); const [color, setColor] = useState(currentColor); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); useEffect(() => { if (open) { setName(currentName); setDescription(currentDescription); setColor(currentColor); setError(null); } }, [open, currentName, currentDescription, currentColor]); const handleSave = (): void => { if (!name.trim()) { setError('Team name cannot be empty'); return; } setSaving(true); setError(null); void (async () => { try { await api.teams.updateConfig(teamName, { name: name.trim(), description: description.trim(), color, }); onSaved(); onClose(); } catch (e) { setError(e instanceof Error ? e.message : 'Failed to save'); } finally { setSaving(false); } })(); }; return ( !nextOpen && onClose()}> Edit Team Change team name, description and color
setName(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter' && !saving && name.trim()) handleSave(); }} className="w-full rounded-md border border-[var(--color-border)] bg-[var(--color-surface)] px-3 py-1.5 text-sm text-[var(--color-text)] outline-none focus:border-[var(--color-border-emphasis)]" placeholder="Team name" />