'use client'; import { useState } from 'react'; import { X } from 'lucide-react'; const COLORS = [ '#ef4444', '#f97316', '#f59e0b', '#eab308', '#7dd3a8', '#10b981', '#06b6d4', '#0ea5e9', '#6366f1', '#8b5cf6', '#a855f7', '#ec4899', ]; export default function NewGroupModal({ onClose, onCreated, }: { onClose: () => void; onCreated: () => void; }) { const [name, setName] = useState(''); const [emoji, setEmoji] = useState(''); const [color, setColor] = useState(COLORS[0]); const [busy, setBusy] = useState(false); const [err, setErr] = useState(null); const submit = async () => { if (!name.trim()) { setErr('分组名不能为空'); return; } setBusy(true); setErr(null); try { const r = await fetch('/api/groups', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ name: name.trim(), color, emoji: emoji.trim() || undefined }), }); const j = await r.json(); if (!j.ok) { setErr(j.error ?? '创建失败'); setBusy(false); return; } onCreated(); } catch (e) { setErr(e instanceof Error ? e.message : '未知错误'); setBusy(false); } }; return (
e.stopPropagation()} >
新建分组
setName(e.target.value)} placeholder="如:AI · 编程" className="control-surface mt-1 w-full rounded-md px-3 py-2 text-[13px] text-[var(--text)] outline-none focus:border-[var(--accent)]" />
setEmoji(e.target.value)} placeholder="🤖" maxLength={4} className="control-surface mt-1 w-full rounded-md px-3 py-2 text-[13px] text-[var(--text)] outline-none focus:border-[var(--accent)]" />
{COLORS.map((c) => (
{err &&
{err}
}
); }