index.js 4.02 KB
Newer Older
syadziy's avatar
syadziy committed
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
import React, { useState, useEffect } from 'react';
import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
import { makeStyles } from '@material-ui/core/styles';
import Fade from '@material-ui/core/Fade';
import Grid from '@material-ui/core/Grid';
import { Typography, Avatar } from '@material-ui/core';
import Images from '../assets/Images';
import { Link, useRouteMatch } from 'react-router-dom';
import Constant from '../library/Constant';

const useStyles = makeStyles({
    avatar: {
        margin: 10,
    },
    orangeAvatar: {
        margin: 10,
        color: '#fff',
        backgroundColor: 'black',
    },
})

function FadeMenu() {
    const [anchorEl, setAnchorEl] = React.useState(null);
    const open = Boolean(anchorEl);

    const handleClick = event => {
        setAnchorEl(event.currentTarget);
    };

    const handleClose = () => {
        setAnchorEl(null);
    };

    const handleLogout = () => {
        localStorage.removeItem(Constant.TOKEN)
        window.location.reload();
        setAnchorEl(null);
    }

    const classes = useStyles();

    let { path, url } = useRouteMatch();

    return (
        <div>
            <Grid container justify="center" alignItems="center" >
                <div onClick={handleClick}>
                    <img src={Images.dropdownWhite} alt="React Logo" style={{ marginLeft: 15 }} />
                </div>
            </Grid>
            <Menu
                id="fade-menu"
                anchorEl={anchorEl}
                keepMounted
                open={open}
                onClose={handleClose}
                TransitionComponent={Fade}
            >
                <MenuItem disabled={true} style={{ opacity: 1 }}>
                    <div style={{ display: 'flex', alignItems: 'center' }}>
                        <Avatar className={classes.orangeAvatar}>T</Avatar>
                        <div>
                            <Typography>Tommy</Typography>
                            <Typography>tom_my@gmail.com</Typography>
                        </div>
                    </div>
                </MenuItem>
                <MenuItem onClick={handleClose}>
                    <Link to={'/home/profile'}>
                        <div style={{ display: 'flex', padding: 10 }}>
                            <img src={Images.setting} style={{ height: 20, width: 20, marginRight: 20 }} />
                            <Typography style={{ color: 'black', textDecoration: 'none'}}>Settings</Typography>
                        </div>
                    </Link>
                </MenuItem>
                <MenuItem onClick={handleLogout}>
                    <div style={{ display: 'flex', padding: 10 }}>
                        <img src={Images.logout} style={{ height: 20, width: 20, marginRight: 20 }} />
                        <Typography>Logout</Typography>
                    </div>
                </MenuItem>
            </Menu>
        </div>
    );
}

const footerStyle = {
    backgroundColor: "#0d2846",
    fontSize: "20px",
    color: "white",
    // borderTop: "1px solid #E7E7E7",
    textAlign: "center",
    padding: "20px",
    left: 0,
    bottom: 0,
    right: 0,
    height: "80px",
    width: "100%"
};

const phantomStyle = {
    display: "block",
};

function Footer({ children }) {
    return (
        <div>
            {/* <div style={phantomStyle} /> */}
            <div style={footerStyle}>{children}</div>
        </div>
    );
}

function getWindowDimensions() {
    const { innerWidth: width, innerHeight: height } = window;
    return {
        width,
        height
    };
}

function UseWindowDimensions() {
    const [windowDimensions, setWindowDimensions] = useState(
        getWindowDimensions()
    );

    useEffect(() => {
        function handleResize() {
            setWindowDimensions(getWindowDimensions());
        }

        window.addEventListener("resize", handleResize);
        return () => window.removeEventListener("resize", handleResize);
    }, []);

    return windowDimensions;
}

export { FadeMenu, Footer, UseWindowDimensions };