diff --git a/src/app/(dashboard)/cards/[id]/page.tsx b/src/app/(dashboard)/cards/[id]/page.tsx index 04c4540..6b07189 100644 --- a/src/app/(dashboard)/cards/[id]/page.tsx +++ b/src/app/(dashboard)/cards/[id]/page.tsx @@ -47,6 +47,7 @@ import { import { Switch } from "@/components/ui/switch"; import { cn } from "@/lib/utils"; import { useUserProfile } from "@/lib/user-profile"; +import { can } from "@/lib/permissions"; import { DynamicField, type FormFieldDef } from "@/components/cards/dynamic-field"; const SECTION_LABELS: Record = { @@ -167,6 +168,10 @@ export default function CardDetailPage() { const isAdmin = role === "admin" || role === "owner"; const isReviewer = role === "reviewer"; const isViewer = role === "viewer"; + const canEditAnyCard = can(role, "cards.edit"); + const canReprocess = can(role, "cards.reprocess"); + const canAssign = can(role, "cards.assign"); + const canExport = can(role, "cards.edit"); const [card, setCard] = React.useState(null); const [loadError, setLoadError] = React.useState(false); @@ -186,8 +191,8 @@ export default function CardDetailPage() { const [fieldDataEdits, setFieldDataEdits] = React.useState>({}); const isAssignedToMe = card?.assignedToId && userId === card.assignedToId; - const canEdit = isAdmin || (isReviewer && isAssignedToMe); - const canMarkComplete = isAdmin || (isReviewer && isAssignedToMe); + const canEdit = canEditAnyCard || (isReviewer && !!isAssignedToMe); + const canMarkComplete = canEditAnyCard || (isReviewer && !!isAssignedToMe); const fetchCard = React.useCallback(async () => { setLoading(true); @@ -223,12 +228,12 @@ export default function CardDetailPage() { }, [fetchCard]); React.useEffect(() => { - if (!isAdmin) return; + if (!canAssign) return; fetch("/api/users") .then((r) => r.json()) .then((data) => setUsers(data.users || [])) .catch(() => {}); - }, [isAdmin]); + }, [canAssign]); React.useEffect(() => { const params = new URLSearchParams(window.location.search); @@ -589,7 +594,7 @@ export default function CardDetailPage() {
- {isAdmin && ocrStatus !== "processing" && ( + {canReprocess && ocrStatus !== "processing" && ( )} - {isAdmin && users.length > 0 && ( + {canAssign && users.length > 0 && (