Created
December 3, 2021 04:32
-
-
Save hieptl/ff3300ad344cb4bd47c574d85d23207f to your computer and use it in GitHub Desktop.
header.js - client - Zoom Clone
This file contains hidden or 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
| import { useContext } from 'react'; | |
| import Context from '../../context'; | |
| import { useHistory } from 'react-router-dom'; | |
| function Header(props) { | |
| const { toggleCreate, toggleJoin } = props; | |
| const { user, setUser, cometChat } = useContext(Context); | |
| const history = useHistory(); | |
| const showCreate = () => { | |
| toggleCreate(true); | |
| }; | |
| const showJoin = () => { | |
| toggleJoin(true); | |
| }; | |
| const logout = async () => { | |
| const isLogout = window.confirm('Do you want to log out ?'); | |
| if (isLogout) { | |
| await cometChat.logout(); | |
| setUser(null); | |
| localStorage.removeItem('auth'); | |
| history.push('/login'); | |
| } | |
| } | |
| return ( | |
| <div className="header"> | |
| <div className="header__left"> | |
| <span className="header__app-name">Zoom Clone</span> | |
| { | |
| user && ( | |
| <div className="header__right"> | |
| <img src={user.user_avatar} alt={user.user_email}/> | |
| <span>Hello, {user.user_full_name}</span> | |
| </div> | |
| ) | |
| } | |
| <span className="header__option" onClick={showCreate}>Create Meeting</span> | |
| <span className="header__option" onClick={showJoin}>Join Meeting</span> | |
| </div> | |
| <span className="header__logout" onClick={logout}><span>Logout</span></span> | |
| </div> | |
| ); | |
| } | |
| export default Header; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment