Skip to content

Commit

Permalink
fix: add prop to protected component to show update action (#8307)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nil20 authored Jan 9, 2025
1 parent a533093 commit 6d3b7ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/client/src/components/ProtectedComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ import { Scope } from '@opencrvs/commons/client'
interface ScopeComponentProps {
scopes?: Scope[]
denyScopes?: Scope[]
conditional?: boolean
children: React.ReactNode
}

const ProtectedComponent: React.FC<ScopeComponentProps> = ({
scopes,
denyScopes,
children
children,
conditional
}) => {
const { hasAnyScope } = usePermissions()
const hasRequiredScope = !scopes || hasAnyScope(scopes)
const hasDeniedScope = denyScopes && hasAnyScope(denyScopes)

return hasRequiredScope && !hasDeniedScope ? <>{children}</> : null
return (hasRequiredScope && !hasDeniedScope) || conditional ? (
<>{children}</>
) : null
}

export default ProtectedComponent
5 changes: 4 additions & 1 deletion packages/client/src/views/RecordAudit/ActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ export const ActionMenu: React.FC<{
isActionable={isActionable}
/>
</ProtectedComponent>
<ProtectedComponent scopes={RECORD_ALLOWED_SCOPES.UPDATE}>
<ProtectedComponent
scopes={RECORD_ALLOWED_SCOPES.UPDATE}
conditional={isDraft}
>
<UpdateAction
declarationId={id}
declarationStatus={status}
Expand Down

0 comments on commit 6d3b7ac

Please sign in to comment.