Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 23 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 36.36% |
Changes | 0 |
1 | import { useDispatch } from 'react-redux'; |
||
2 | import { setLoggedInOut, setCurrentUser, setToken, setRole } from '../redux/slices/authLogin'; |
||
3 | import { useNavigate } from "react-router-dom"; |
||
4 | import { Button, ButtonProps } from 'flowbite-react'; |
||
5 | |||
6 | export default function Logout(props: ButtonProps) { |
||
7 | |||
8 | 2 | const dispatch = useDispatch(); |
|
9 | 2 | const navigate = useNavigate(); |
|
10 | |||
11 | 2 | const logOutUser = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { |
|
12 | e.preventDefault(); |
||
13 | dispatch(setLoggedInOut(false)); |
||
14 | dispatch(setCurrentUser(null)); |
||
15 | dispatch(setToken('')); |
||
16 | dispatch(setRole('guest')); |
||
17 | navigate('/'); |
||
18 | } |
||
19 | 2 | return ( |
|
20 | <Button {...props} data-testid="logoutbutton" color="failure" onClick={(e) => logOutUser(e)}>Logga ut</Button> |
||
21 | ) |
||
22 | } |
||
23 |