import { Button } from "@workspace/ui/components/button"; import { Input } from "@workspace/ui/components/input"; import { PopoverClose } from "@workspace/ui/components/popover"; import { useRef, useState } from "react"; interface RemarkFormProps { initialRemark?: string | null; onSave: (remark: string) => Promise | void; } export function RemarkForm({ onSave, initialRemark }: RemarkFormProps) { const [remark, setRemark] = useState(initialRemark ?? ""); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); const closeRef = useRef(null); const handleInputChange = (event: React.ChangeEvent) => { setRemark(event.target.value); }; const handleSave = async (event: React.FormEvent) => { event.preventDefault(); setError(null); setSaving(true); try { await onSave(remark); closeRef.current?.click(); } catch { setError("备注保存失败,请重试"); } finally { setSaving(false); } }; return (
备注
{error ? (

{error}

) : null}
); }