diff --git a/components/capa/capa-owner-notes-form.tsx b/components/capa/capa-owner-notes-form.tsx new file mode 100644 index 0000000..b9e3cf1 --- /dev/null +++ b/components/capa/capa-owner-notes-form.tsx @@ -0,0 +1,57 @@ +'use client' + +import { useState } from 'react' + +interface Props { + capaId: string + initialNotes: string | null +} + +export function CapaOwnerNotesForm({ capaId, initialNotes }: Props) { + const [notes, setNotes] = useState(initialNotes ?? '') + const [saving, setSaving] = useState(false) + const [saved, setSaved] = useState(false) + const [error, setError] = useState(null) + + async function handleSave() { + setSaving(true) + setSaved(false) + setError(null) + const res = await fetch(`/ims/api/capa/${capaId}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ owner_notes: notes }), + }) + setSaving(false) + if (!res.ok) { + setError('Failed to save. Please try again.') + return + } + setSaved(true) + setTimeout(() => setSaved(false), 2000) + } + + return ( +
+ +