import { useState, type FormEvent } from 'react'; import { useCollection } from '@feltdb/core/react'; import { invitations } from '../feltdb'; import { useAuth } from '../context/AuthContext'; import { runAcceptInvitationWorkflow, runInviteMemberWorkflow } from '../../workflows/invitation'; export function Invitations() { const { user, organization } = useAuth(); const state = useCollection(invitations); const [message, setMessage] = useState(''); async function invite(event: FormEvent) { event.preventDefault(); if (!user || !organization) return; const form = event.currentTarget; setMessage(''); try { await runInviteMemberWorkflow({ organization: organization.id, actor: user.id, email: String(new FormData(form).get('email')), role: 'member' }); form.reset(); } catch (error) { setMessage(error instanceof Error ? error.message : 'Invitation failed.'); } } return
Invitation workflow

Invitations

Invitation visibility combines self(user) | member.

{state.data.filter(item => item.status === 'pending').length}
{message &&

{message}

}
{state.data.length ? state.data.slice().reverse().map(invitation =>
{invitation.email}{invitation.role} ยท {invitation.status}
{invitation.user === user?.id && invitation.status === 'pending' && }
) :
No invitations yetFor this starter, invite another user who has already signed up.
}
; }