// CreateCollectionModal.jsx — §22 S2 endpoint, §22 S4 UI. The create-collection // form the project directory's "Create your first collection" / "New // collection" control opens. S2 shipped the POST // /api/projects/:id/collections endpoint but left it UI-less; S4 surfaces it, // gated on the viewer's `can_create_collection` capability. // // The form lets the Owner choose an id (a slug, not "default"), a type, an // optional display name, and an optional visibility (defaulting to the // project's). The backend commits a `.collection.yaml`, re-mirrors the // registry, and returns the new collection; on success the caller refreshes // the directory. import { useState } from 'react' import { createCollection } from '../api' const TYPE_OPTIONS = [ { value: 'document', label: 'Document — prose RFCs' }, { value: 'specification', label: 'Specification' }, { value: 'bdd', label: 'BDD — behaviour scenarios' }, ] const VISIBILITY_OPTIONS = [ { value: '', label: 'Inherit from project' }, { value: 'public', label: 'Public' }, { value: 'unlisted', label: 'Unlisted (link-only)' }, { value: 'gated', label: 'Gated (hidden from the public)' }, ] export default function CreateCollectionModal({ projectId, onClose, onCreated }) { const [collectionId, setCollectionId] = useState('') const [type, setType] = useState('document') const [name, setName] = useState('') const [visibility, setVisibility] = useState('') const [submitting, setSubmitting] = useState(false) const [error, setError] = useState(null) async function handleCreate(e) { e.preventDefault() const cid = collectionId.trim().toLowerCase() if (!cid) return setSubmitting(true) setError(null) try { const col = await createCollection(projectId, { collectionId: cid, type, name: name.trim() || null, visibility: visibility || null, }) onCreated?.(col) } catch (err) { setError(err.message || 'Failed to create the collection.') } finally { setSubmitting(false) } } return (