/*
Copyright (C) 2017 Cloudbase Solutions SRL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
import React from 'react';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import s from './UserDropdown.scss';
import Dropdown from 'react-dropdown';
import Location from '../../core/Location';
import UserStore from '../../stores/UserStore';
import UserActions from '../../actions/UserActions';
class UserDropdown extends Dropdown {
static defaultProps = {
options: [
{ label: "Profile", value: "profile" },
{ label: "Sign Out", value: "signout" },
],
baseClassName: "UserDropdown"
}
constructor(props) {
super(props)
this.store = UserStore
}
setValue(value) {
switch (value) {
case "profile":
Location.push("/user/profile");
break;
case "signout":
UserActions.logout()
break;
default:
break;
}
}
buildMenu() {
let buildMenuResult = super.buildMenu.call(this)
return (
{this.props.userData.name}
{this.props.userData.email}
{buildMenuResult}
)
}
handleMouseDown(event) {
super.handleMouseDown.call(this, event)
this.setState({ firstHover: false })
}
render() {
let result = super.render.call(this)
let children = Object.assign({}, result.props.children)
children = [( this.handleMouseDown(e)}
/>), children[1]]
let newResult = React.cloneElement(result, { children: children })
return newResult
}
}
export default withStyles(UserDropdown, s);