'use client'; import { useState, type FormEvent } from 'react'; import { useRouter } from 'next/navigation'; import type { Project } from '@/lib/types'; export function ProjectSettingsForm({ project, canManage, }: { project: Project; canManage: boolean; }) { const router = useRouter(); const [name, setName] = useState(project.name); const [description, setDescription] = useState(project.description ?? ''); const [status, setStatus] = useState(project.status); const [error, setError] = useState(null); const [saved, setSaved] = useState(false); const [loading, setLoading] = useState(false); async function onSubmit(event: FormEvent) { event.preventDefault(); setLoading(true); setError(null); setSaved(false); const res = await fetch(`/api/projects/${project.id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name, description: description || undefined, status, }), }); setLoading(false); if (res.ok) { setSaved(true); router.refresh(); } else { const body = (await res.json().catch(() => null)) as { error?: { message?: string }; } | null; setError(body?.error?.message ?? '更新に失敗しました'); } } if (!canManage) { return (

プロジェクトの設定変更には管理者権限が必要です。

); } return (
setName(e.target.value)} className="mt-1 w-full rounded border px-3 py-2" />