fix: add role-based permissions to forms page

- Hide Generate Default Template and Save Changes buttons for wizard/observer
- Backend already enforces owner/researcher for mutations
- UI now provides cleaner experience for read-only roles
This commit is contained in:
2026-03-22 17:26:52 -04:00
parent 67ad904f62
commit 8529d0ef89

View File

@@ -254,6 +254,9 @@ export default function StudyFormsPage({ params }: StudyFormsPageProps) {
if (!study) return <div>Loading...</div>; if (!study) return <div>Loading...</div>;
const userRole = (study as any)?.userRole;
const canManage = userRole === "owner" || userRole === "researcher";
return ( return (
<EntityView> <EntityView>
<PageHeader <PageHeader
@@ -268,48 +271,50 @@ export default function StudyFormsPage({ params }: StudyFormsPageProps) {
icon="FileText" icon="FileText"
description="Design and manage the consent form that participants must sign before participating in your trials." description="Design and manage the consent form that participants must sign before participating in your trials."
actions={ actions={
<div className="flex gap-2"> canManage ? (
<Button <div className="flex gap-2">
variant="outline"
size="sm"
onClick={() =>
generateConsentMutation.mutate({ studyId: study.id })
}
disabled={
generateConsentMutation.isPending ||
updateConsentMutation.isPending
}
>
{generateConsentMutation.isPending ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : (
<Plus className="mr-2 h-4 w-4" />
)}
Generate Default Template
</Button>
{activeConsentForm && (
<Button <Button
variant="outline"
size="sm" size="sm"
onClick={() => onClick={() =>
updateConsentMutation.mutate({ generateConsentMutation.mutate({ studyId: study.id })
studyId: study.id,
content: editorTarget,
})
} }
disabled={ disabled={
updateConsentMutation.isPending || generateConsentMutation.isPending ||
editorTarget === activeConsentForm.content updateConsentMutation.isPending
} }
> >
{updateConsentMutation.isPending ? ( {generateConsentMutation.isPending ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" /> <Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : ( ) : (
<Save className="mr-2 h-4 w-4" /> <Plus className="mr-2 h-4 w-4" />
)} )}
Save Changes Generate Default Template
</Button> </Button>
)} {activeConsentForm && (
</div> <Button
size="sm"
onClick={() =>
updateConsentMutation.mutate({
studyId: study.id,
content: editorTarget,
})
}
disabled={
updateConsentMutation.isPending ||
editorTarget === activeConsentForm.content
}
>
{updateConsentMutation.isPending ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : (
<Save className="mr-2 h-4 w-4" />
)}
Save Changes
</Button>
)}
</div>
) : null
} }
> >
{activeConsentForm ? ( {activeConsentForm ? (