From 811a1c0622d695f6589f85c34d6e2b16cf09857d Mon Sep 17 00:00:00 2001 From: ialexanderbrito Date: Tue, 1 Nov 2022 14:27:34 -0300 Subject: [PATCH] feat: add use perfil --- src/hooks/usePerfil.tsx | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/hooks/usePerfil.tsx 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(), + }; +}