generated from nimblehq/git-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#19] Display user information in header and add sidebar for logging …
…the user out
- Loading branch information
1 parent
856692f
commit 997ef75
Showing
5 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.sidebar { | ||
border: 5px bla solid; | ||
|
||
background: rgba(30, 30, 30, 0.9); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import AuthAdapter from 'adapters/authAdapter'; | ||
import { getItem, clearItem } from 'helpers/localStorage'; | ||
import { User } from 'types/User'; | ||
|
||
import styles from './Sidebar.module.scss'; | ||
import { LOGIN_URL } from '../../constants'; | ||
|
||
type SidebarProps = { | ||
user: User; | ||
}; | ||
|
||
function Sidebar({ user }: SidebarProps) { | ||
const navigate = useNavigate(); | ||
|
||
const performLogout = async (e: React.SyntheticEvent) => { | ||
e.stopPropagation(); | ||
|
||
const accessToken = getItem('UserProfile')?.auth.access_token; | ||
await AuthAdapter.logout(accessToken); | ||
clearItem('UserProfile'); | ||
navigate(LOGIN_URL); | ||
}; | ||
|
||
return ( | ||
<aside className={`${styles.sidebar} fixed top-0 right-0 flex h-screen w-1/6 min-w-fit flex-col gap-10 p-0`}> | ||
<div className="flex h-16 flex-col items-center justify-between px-5 md:flex-row md:border-b md:border-b-white"> | ||
<span className="pt-2 font-bold text-white">{user.name}</span> | ||
<img className="cursor-pointer rounded-full" height={36} width={36} src={user.avatarUrl} alt="profile"></img> | ||
</div> | ||
<button onClick={performLogout} className="left-5 text-xl text-white opacity-50"> | ||
Logout | ||
</button> | ||
</aside> | ||
); | ||
} | ||
|
||
export default Sidebar; |