feat(forms): per-member 'Forms submitted' view on the members page

listMemberSubmissions (forms.manage, RLS-honoring, metadata only) + a
FORMS column/button -> MemberFormsDialog listing the member's
submissions (title, kind, version, date) with a link to the audited
forms results surface. Gated by forms.manage (matches existing
submission-read RLS; no new exposure).
This commit is contained in:
Moheeb Zara
2026-05-16 23:50:52 -07:00
parent 832a0aeba2
commit ed8d629472
5 changed files with 162 additions and 2 deletions
+27 -2
View File
@@ -12,6 +12,7 @@ import { PageTitle } from '@/components/ui/page-title'
import { useConfirm } from '@/components/ui/confirm'
import { MemberCertificationsDialog } from '@/components/certifications/member-certifications-dialog'
import { MemberCardsDialog } from '@/components/door/member-cards-dialog'
import { MemberFormsDialog } from '@/components/forms/member-forms-dialog'
type Member = Tables<'space_members'>
type AreaLeadRole = { id: string; area_name: string; lead_id: string | null }
@@ -31,6 +32,9 @@ interface Props {
// True when the viewer holds door.manage. Adds a per-member access-cards
// panel (card UID is a credential; managers only).
canManageCards?: boolean
// True when the viewer holds forms.manage. Adds a per-member panel
// listing the forms that member has submitted.
canViewForms?: boolean
}
const TIER_COLORS: Record<string, string> = {
@@ -42,10 +46,11 @@ const TIER_COLORS: Record<string, string> = {
const isAdmin = (role: string) => role === 'admin' || role === 'board'
export function MembersClient({ members: initialMembers, currentRole, areaLeadRoles = [], inviteSlot, canGrantCerts = false, canManageCards = false }: Props) {
export function MembersClient({ members: initialMembers, currentRole, areaLeadRoles = [], inviteSlot, canGrantCerts = false, canManageCards = false, canViewForms = false }: Props) {
const router = useRouter()
const [certMember, setCertMember] = useState<Member | null>(null)
const [cardMember, setCardMember] = useState<Member | null>(null)
const [formsMember, setFormsMember] = useState<Member | null>(null)
const confirm = useConfirm()
const [members, setMembers] = useState<Member[]>(initialMembers)
@@ -288,6 +293,9 @@ export function MembersClient({ members: initialMembers, currentRole, areaLeadRo
{canManageCards && (
<th className="px-4 py-3 text-left font-mono text-[10px] tracking-widest text-muted-foreground">CARDS</th>
)}
{canViewForms && (
<th className="px-4 py-3 text-left font-mono text-[10px] tracking-widest text-muted-foreground">FORMS</th>
)}
{isAdmin(currentRole) && (
<th className="px-4 py-3 text-left font-mono text-[10px] tracking-widest text-muted-foreground">ACTIONS</th>
)}
@@ -362,6 +370,16 @@ export function MembersClient({ members: initialMembers, currentRole, areaLeadRo
</button>
</td>
)}
{canViewForms && (
<td className="px-4 py-3">
<button
onClick={() => setFormsMember(m)}
className="font-mono text-[10px] border border-border px-3 py-2 min-h-[44px] rounded hover:border-primary hover:text-primary transition"
>
FORMS
</button>
</td>
)}
{isAdmin(currentRole) && (
<td className="px-4 py-3">
<div className="flex items-center gap-2">
@@ -407,7 +425,7 @@ export function MembersClient({ members: initialMembers, currentRole, areaLeadRo
)
}) : (
<tr>
<td colSpan={5 + (canGrantCerts ? 1 : 0) + (canManageCards ? 1 : 0) + (isAdmin(currentRole) ? 1 : 0)} className="p-0">
<td colSpan={5 + (canGrantCerts ? 1 : 0) + (canManageCards ? 1 : 0) + (canViewForms ? 1 : 0) + (isAdmin(currentRole) ? 1 : 0)} className="p-0">
<Empty className="border-0">
<EmptyHeader>
<EmptyMedia variant="icon"><Users /></EmptyMedia>
@@ -475,6 +493,13 @@ export function MembersClient({ members: initialMembers, currentRole, areaLeadRo
onClose={() => setCardMember(null)}
/>
)}
{canViewForms && (
<MemberFormsDialog
member={formsMember ? { id: formsMember.id, display_name: formsMember.display_name } : null}
onClose={() => setFormsMember(null)}
/>
)}
</div>
)
}
+6
View File
@@ -100,6 +100,11 @@ export default async function MembersPage() {
sid: self.space_id,
perm: 'door.manage',
})
const { data: canViewForms } = await supabase.rpc('user_has_permission', {
uid: user.id,
sid: self.space_id,
perm: 'forms.manage',
})
return (
<MembersClient
@@ -107,6 +112,7 @@ export default async function MembersPage() {
currentRole={self.role}
canGrantCerts={!!canGrantCerts}
canManageCards={!!canManageCards}
canViewForms={!!canViewForms}
areaLeadRoles={(areaLeadRoles ?? []) as Array<{ id: string; area_name: string; lead_id: string | null }>}
inviteSlot={
canInvite ? (