MSP-3074 add roles

This commit is contained in:
Anastasiia committed 2024-04-01 18:16:00 +03:00
1 parent 5a29bfc7f6
commit 9c1b859971
36 files changed
+1063 -100

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
import {TypedUseSelectorHook, useDispatch, useSelector} from 'react-redux';
import {AppDispatch, RootState} from '../store';
export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
+17
View File
@@ -0,0 +1,17 @@
import {useMemo} from 'react';
import {useAppSelector} from "./redux.ts";
import {PermissionKeys} from "../types/roles.type.ts";
export const useRole = () => {
const {profile} = useAppSelector((state: any) => state.profileReducer);
const role: string = useMemo(() => profile && profile.role, [profile]);
const hasPermission = (permission: PermissionKeys) => {
const userPermission = profile.permissions || [];
return userPermission.includes(permission);
};
return {role, hasPermission};
};
export default useRole;