diff --git a/src/hooks/usePerfil.tsx b/src/hooks/usePerfil.tsx new file mode 100644 index 0000000..036ad0d --- /dev/null +++ b/src/hooks/usePerfil.tsx @@ -0,0 +1,42 @@ +export function usePerfil() { + const storagedUser = JSON.parse(localStorage.getItem('@barber:user') || '{}'); + + function isBarbeiro() { + if (storagedUser) { + if (storagedUser.tipoUsuario?.authority === 'GERENCIADOR') { + return true; + } + } + + return false; + } + + function isCliente() { + if (storagedUser) { + if ( + storagedUser.tipoUsuario?.authority === 'CLIENTE' || + storagedUser.tipoUsuario?.authority === 'ADMINISTRADOR' + ) { + return true; + } + } + + return false; + } + + function isAdmin() { + if (storagedUser) { + if (storagedUser.tipoUsuario?.authority === 'ADMINISTRADOR') { + return true; + } + } + + return false; + } + + return { + isBarbeiro: isBarbeiro(), + isCliente: isCliente(), + isAdmin: isAdmin(), + }; +}