import React, { useEffect, useState } from 'react' import { X, Save } from 'lucide-react' import { KnowledgeGroup, UpdateGroupData } from '../types' interface EditNotebookDialogProps { isOpen: boolean onClose: () => void notebook: KnowledgeGroup onUpdate: (id: string, data: UpdateGroupData) => Promise } export const EditNotebookDialog: React.FC = ({ isOpen, onClose, notebook, onUpdate, }) => { const [name, setName] = useState(notebook.name) const [description, setDescription] = useState(notebook.description || '') const [intro, setIntro] = useState(notebook.intro || '') const [isSubmitting, setIsSubmitting] = useState(false) // Reset form when notebook changes or dialog opens useEffect(() => { if (isOpen) { setName(notebook.name) setDescription(notebook.description || '') setIntro(notebook.intro || '') } }, [isOpen, notebook]) if (!isOpen) return null const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!name.trim()) return try { setIsSubmitting(true) await onUpdate(notebook.id, { name: name.trim(), description: description.trim(), intro: intro.trim(), }) onClose() } catch (error) { console.error('Failed to update notebook:', error) alert('更新失败,请重试') } finally { setIsSubmitting(false) } } return (

编辑知识组

setName(e.target.value)} className="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="知识组名称" required />
setDescription(e.target.value)} className="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="一句话描述(可选)" />