summaryrefslogtreecommitdiffstats
path: root/front/odiparpack/app/components/Chat/ChatHeader.js
blob: b3456e91ce120fb42f3dd7b7a3b909238e0eb3be (plain)
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
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import classNames from 'classnames';
import MoreVertIcon from '@material-ui/icons/MoreVert';
import ArrowBack from '@material-ui/icons/ArrowBack';
import { Typography, AppBar, Menu, MenuItem, Avatar, IconButton, Toolbar } from '@material-ui/core';
import styles from '../Contact/contact-jss';


const optionsOpt = [
  'Delete Conversation',
  'Option 1',
  'Option 2',
  'Option 3',
];

const ITEM_HEIGHT = 48;

class ChatHeader extends React.Component {
  state = {
    anchorElOpt: null,
  };

  handleClickOpt = event => {
    this.setState({ anchorElOpt: event.currentTarget });
  };

  handleCloseOpt = () => {
    this.setState({ anchorElOpt: null });
  };

  handleRemove = (person) => {
    this.props.remove(person);
  }

  render() {
    const {
      classes,
      chatSelected,
      dataContact,
      showMobileDetail,
      hideDetail,
    } = this.props;
    const { anchorElOpt } = this.state;
    return (
      <AppBar
        position="absolute"
        className={classNames(classes.appBar, classes.appBarShift)}
      >
        <Toolbar>
          {showMobileDetail && (
            <IconButton
              color="inherit"
              aria-label="open drawer"
              onClick={() => hideDetail()}
              className={classes.navIconHide}
            >
              <ArrowBack />
            </IconButton>
          )}
          <Avatar alt="avatar" src={dataContact.getIn([chatSelected, 'avatar'])} className={classes.avatar} />
          <Typography variant="h6" className={classes.flex} color="inherit" noWrap>
            {dataContact.getIn([chatSelected, 'name'])}
            <Typography variant="caption" component="p" className={classes.status} color="inherit" noWrap>
              <span className={classes.online} />
              {' '}
Online
            </Typography>
          </Typography>
          <IconButton
            aria-label="More"
            aria-owns={anchorElOpt ? 'long-menu' : null}
            aria-haspopup="true"
            className={classes.button}
            onClick={this.handleClickOpt}
          >
            <MoreVertIcon color="inherit" />
          </IconButton>
        </Toolbar>
        <Menu
          id="long-menu"
          anchorEl={anchorElOpt}
          open={Boolean(anchorElOpt)}
          onClose={this.handleCloseOpt}
          PaperProps={{
            style: {
              maxHeight: ITEM_HEIGHT * 4.5,
              width: 200,
            },
          }}
        >
          {optionsOpt.map(option => {
            if (option === 'Delete Conversation') {
              return (
                <MenuItem key={option} onClick={this.handleRemove}>
                  {option}
                </MenuItem>
              );
            }
            return (
              <MenuItem key={option} selected={option === 'Edit Profile'} onClick={this.handleCloseOpt}>
                {option}
              </MenuItem>
            );
          })}
        </Menu>
      </AppBar>
    );
  }
}

ChatHeader.propTypes = {
  classes: PropTypes.object.isRequired,
  dataContact: PropTypes.object.isRequired,
  showMobileDetail: PropTypes.bool.isRequired,
  hideDetail: PropTypes.func.isRequired,
  remove: PropTypes.func.isRequired,
  chatSelected: PropTypes.number.isRequired,
};

export default withStyles(styles)(ChatHeader);