logout fixes with role redirect

This commit is contained in:
kurpfish
2021-08-20 17:33:29 +03:00
parent 8cce68ce06
commit 7891dccb59
14 changed files with 89 additions and 29 deletions

View File

@ -1,16 +1,28 @@
import React, { useState } from 'react';
import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import { Loader } from '../Loader/Loader';
import { auth } from '../../redux/outstaffingSlice';
import { getRole } from '../../redux/roleSlice';
import './logoutButton.css'
export const LogoutButton = () => {
const [isLoggingOut, setIsLoggingOut] = useState(false);
const dispatch = useDispatch();
const userRole = useSelector(getRole);
const history = useHistory();
return (
<div className='logout-button'>
<button onClick={()=>{setIsLoggingOut(true); localStorage.clear(); dispatch(auth(false)); setIsLoggingOut(false); }}>
<button onClick={()=>{
setIsLoggingOut(true);
localStorage.clear();
dispatch(auth(false));
setIsLoggingOut(false);
history.push(userRole === 'ROLE_DEV' ? '/authdev' : '/auth')
}}>
{
isLoggingOut ? <Loader /> : 'Выйти'
} </button>