import { useState, type FormEvent } from 'react'; import { useCollection } from '@feltdb/core/react'; import { projects } from '../feltdb'; import { useAuth } from '../context/AuthContext'; import { runProjectCreatedWorkflow } from '../../workflows/project-created'; export function Projects() { const { user, organization } = useAuth(); const state = useCollection(projects); const [busy, setBusy] = useState(false); async function submit(event: FormEvent) { event.preventDefault(); if (!user || !organization) return; const form = event.currentTarget; setBusy(true); await runProjectCreatedWorkflow({ organization: organization.id, owner: user.id, name: String(new FormData(form).get('name')) }); form.reset(); setBusy(false); } return
Project workflow

Projects

Creating a project atomically persists both Project and AuditEvent state.

{state.data.length}
{state.data.length ? state.data.slice().reverse().map(project =>
{project.name.charAt(0).toUpperCase()}
{project.name}ProjectCreated workflow · {new Date(project.created_at).toLocaleDateString()}
) :
No projects yetCreate one to produce your first workflow state.
}
; }