diff --git a/src/components/molecules/NavBar.tsx b/src/components/molecules/NavBar.tsx index 15508942..e42a615a 100644 --- a/src/components/molecules/NavBar.tsx +++ b/src/components/molecules/NavBar.tsx @@ -1,4 +1,5 @@ -import React from 'react'; +import React, { useState, useContext } from 'react'; +import axios from 'axios'; import styled from "styled-components"; import { stopRecording } from "../../api/recording"; import { useGlobalInfoStore } from "../../context/globalInfo"; @@ -7,7 +8,8 @@ import { RecordingIcon } from "../atoms/RecorderIcon"; import { SaveRecording } from "./SaveRecording"; import { Circle } from "@mui/icons-material"; import MeetingRoomIcon from '@mui/icons-material/MeetingRoom'; -import { useNavigate } from "react-router-dom"; +import { Link, useLocation, useNavigate } from 'react-router-dom'; +import { AuthContext } from '../../context/auth'; interface NavBarProps { newRecording: () => void; @@ -18,8 +20,18 @@ interface NavBarProps { export const NavBar = ({ newRecording, recordingName, isRecording }: NavBarProps) => { const { notify, browserId, setBrowserId, recordingLength } = useGlobalInfoStore(); + const { state, dispatch } = useContext(AuthContext); + const { user } = state; const navigate = useNavigate(); + const logout = async () => { + dispatch({ type: 'LOGOUT' }); + window.localStorage.removeItem('user'); + const { data } = await axios.get('http://localhost:8080/auth/logout'); + notify('success', data.message); + navigate('/login'); + }; + // If recording is in progress, the resources and change page view by setting browserId to null // else it won't affect the page const goToMainMenu = async () => { @@ -94,6 +106,23 @@ export const NavBar = ({ newRecording, recordingName, isRecording }: NavBarProps exit : null} + { + user !== null ? ( + + ) : "" + }