File size: 1,842 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React from 'react';
import { useState } from 'react';
import { useRef } from 'react';
import { Button, Overlay } from 'react-bootstrap';
import Popover from 'react-bootstrap/Popover'
import './PopOver.css';
import toast from 'react-hot-toast';
import { handleSignOut } from '../../Login/LoginManager';
import { SET_USER, useAppContext } from '../../../context';

const PopOver = () => {
    const { state:{user: { name, email, img }}, dispatch} = useAppContext()
    const [show, setShow] = useState(false);
    const [target, setTarget] = useState(null);
    const ref = useRef(null);
    const handleClick = (event) => {
        setShow(!show);
        setTarget(event.target);
    };
    const signOut = () => {
        const loading = toast.loading('Please wait...');
        handleSignOut()
        .then(res => {
            toast.dismiss(loading);
            console.log(res);
            dispatch({type: SET_USER, payload: res})
            toast.error('Logged Out!');
        })
    }
    return (
        <div >
            <img src={img} alt="" onClick={handleClick} className="popImg"/>
             <Overlay
                show={show}
                target={target}
                placement="bottom"
                container={ref.current}
                containerPadding={50}
            >
                <Popover id="popover-contained">
                    <div className="text-center">
                        <img src={img} alt="" className="popUserImg"/>
                        <p className="userName">{`${name}`}</p>
                        <p className="userEmail">{email}</p>
                        <Button variant="outline-danger" size="sm" onClick={signOut}>Log out</Button>
                    </div>
                 </Popover> 
            </Overlay> 
        </div>
    );
};

export default PopOver;