Skip to content

Commit

Permalink
fix: approved barber
Browse files Browse the repository at this point in the history
  • Loading branch information
ialexanderbrito committed May 27, 2022
1 parent f8657e2 commit 393f0ff
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/components/DropdownMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useDropdown } from 'hooks/useDropdown';
import styles from './DropdownMenu.module.scss';

export function DropdownMenu() {
const { user, isAlexander, isBarbeiro, isBarbeiroAprroved } = useAuth();
const { user, isAlexander, isBarbeiro, isBarbeiroApproved } = useAuth();
const { activeMenu, dropdownRef, calcHeight, menuHeight, photo } = useDropdown();

return (
Expand Down Expand Up @@ -40,7 +40,7 @@ export function DropdownMenu() {
</DropdownItem>

{isAlexander && <DropdownItem link="/admin">Painel Admin</DropdownItem>}
{isBarbeiro && isBarbeiroAprroved && <DropdownItem link="/horarios">Atualizar horários</DropdownItem>}
{isBarbeiro && isBarbeiroApproved && <DropdownItem link="/horarios">Atualizar horários</DropdownItem>}

<DropdownItem logout>Sair</DropdownItem>
</div>
Expand Down
16 changes: 10 additions & 6 deletions src/contexts/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export function AuthProvider({ children }: any) {
return false;
}

function isBarbeiroAprroved() {
if (approved === 'S') {
return true;
function isBarbeiroApproved() {
if (approved === '') {
return false;
}

return false;
return true;
}

async function checkUser() {
Expand Down Expand Up @@ -117,7 +117,11 @@ export function AuthProvider({ children }: any) {
}

async function verificarStatusBarbeiro() {
const { data, status, error } = await getBarbeiro(user?.id || '', true);
const storagedUser = JSON.parse(localStorage.getItem('supabase.auth.token') || '{}');

const id = storagedUser?.currentSession?.user.id;

const { data, status, error } = await getBarbeiro(id, true);

if (error) {
switch (status) {
Expand Down Expand Up @@ -239,7 +243,7 @@ export function AuthProvider({ children }: any) {
isBarbeiro: isBarbeiro(),
isCliente: isCliente(),
isAlexander: isAlexander(),
isBarbeiroAprroved: isBarbeiroAprroved(),
isBarbeiroApproved: isBarbeiroApproved(),
}}
>
{children}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Barbeiro/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import styles from './Barbeiro.module.scss';

export function Barbeiro() {
const navigate = useNavigate();
const { isBarbeiroAprroved } = useAuth();
const { isBarbeiroApproved } = useAuth();
const {
clientes,
selectDay,
Expand All @@ -38,7 +38,7 @@ export function Barbeiro() {

return (
<div className={styles.containerBarbeiro}>
{isBarbeiroAprroved === false ? (
{isBarbeiroApproved === false ? (
<div className={styles.containerAviso}>
<h2 className={styles.titleHome}>
Você ainda não foi aprovado para trabalhar como barbeiro.
Expand Down
2 changes: 1 addition & 1 deletion src/types/IContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export interface AuthContextProps {
isBarbeiro: boolean;
isCliente: boolean;
isAlexander: boolean;
isBarbeiroAprroved: boolean;
isBarbeiroApproved: boolean;
}

export interface FormikProps {
Expand Down

0 comments on commit 393f0ff

Please sign in to comment.