mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-09 17:14:21 +02:00
add HOC for role restriction
This commit is contained in:
parent
b67cb0afb1
commit
089af3880a
@ -3,6 +3,7 @@ import { useSelector } from "react-redux"
|
||||
import { selectTeamList } from "../../store/teamList"
|
||||
import TeamWithCandidates from "./TeamWithCandidates"
|
||||
import styles from "./styles.module.scss"
|
||||
import withUserRole from "../../utils/withUserRole"
|
||||
|
||||
const TeamsWithCandidates: FC = (): JSX.Element => {
|
||||
const teams = useSelector(selectTeamList)
|
||||
@ -25,4 +26,4 @@ const TeamsWithCandidates: FC = (): JSX.Element => {
|
||||
)
|
||||
}
|
||||
|
||||
export default memo(TeamsWithCandidates)
|
||||
export default withUserRole("répartiteur", memo(TeamsWithCandidates))
|
||||
|
@ -86,7 +86,7 @@ export default [
|
||||
loadData: loadAnnouncementsData,
|
||||
},
|
||||
{
|
||||
path: "/team-assign-e26as",
|
||||
path: "/team-assign",
|
||||
component: AsyncTeamAssignment,
|
||||
loadData: loadTeamAssignmentData,
|
||||
},
|
||||
|
12
src/utils/withUserRole.tsx
Normal file
12
src/utils/withUserRole.tsx
Normal file
@ -0,0 +1,12 @@
|
||||
import React from "react"
|
||||
import { useSelector } from "react-redux"
|
||||
import { selectUserRoles } from "../store/auth"
|
||||
|
||||
function withUserRole<T>(requiredRole: string, Component: React.ComponentType<T>) {
|
||||
return (props: T): JSX.Element | null => {
|
||||
const roles = useSelector(selectUserRoles)
|
||||
return roles.includes(requiredRole) ? <Component {...props} /> : null
|
||||
}
|
||||
}
|
||||
|
||||
export default withUserRole
|
Loading…
x
Reference in New Issue
Block a user