Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactRedux = require('react-redux');

var _reactIntl = require('react-intl');

var _components = require('@doodle/components');

var _ic_keyboard_arrow_down = require('@doodle/components/visuals/Icon/svg/ic_keyboard_arrow_down.svg');

var _ic_keyboard_arrow_down2 = _interopRequireDefault(_ic_keyboard_arrow_down);

var _actions = require('../../state/actions');

var _messages = require('./messages');

var _messages2 = _interopRequireDefault(_messages);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var UserMenu = function (_Component) {
  _inherits(UserMenu, _Component);

  function UserMenu() {
    _classCallCheck(this, UserMenu);

    return _possibleConstructorReturn(this, (UserMenu.__proto__ || Object.getPrototypeOf(UserMenu)).apply(this, arguments));
  }

  _createClass(UserMenu, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          name = _props.name,
          avatar = _props.avatar,
          onClickLogout = _props.onClickLogout,
          intl = _props.intl,
          customItems = _props.customItems;

      var formattedItems = customItems.map(function (item) {
        return {
          label: intl.formatMessage(item.label),
          to: item.to,
          action: item.action
        };
      });

      return _react2.default.createElement(
        _components.Menu,
        {
          className: 'UserMenu',
          variant: 'linkWhite',
          horizontalAlign: 'right',
          items: [{
            label: intl.formatMessage(_messages2.default.dashboard),
            to: '/dashboard'
          }, {
            label: intl.formatMessage(_messages2.default.account),
            to: '/account'
          }].concat(_toConsumableArray(formattedItems), [{
            label: intl.formatMessage(_messages2.default.logout),
            action: onClickLogout
          }])
        },
        _react2.default.createElement(_components.UserAvatar, { name: name, avatar: avatar }),
        _react2.default.createElement(_components.Icon, { icon: _ic_keyboard_arrow_down2.default })
      );
    }
  }]);

  return UserMenu;
}(_react.Component);

UserMenu.propTypes = {
  name: _propTypes2.default.string.isRequired,
  avatar: _propTypes2.default.string,
  onClickLogout: _propTypes2.default.func.isRequired,
  intl: _reactIntl.intlShape.isRequired,
  customItems: _propTypes2.default.arrayOf(_propTypes2.default.shape({
    label: _propTypes2.default.shape({ id: _propTypes2.default.string, defaultMessage: _propTypes2.default.string }).isRequired,
    to: _propTypes2.default.string,
    action: _propTypes2.default.func
  }))
};
UserMenu.defaultProps = {
  avatar: null,
  customItems: []
};


var mapStateToProps = function mapStateToProps(state) {
  return {
    name: state.user.data.name,
    avatar: state.user.data.avatarLargeUrl
  };
};

var mapDispatchToProps = function mapDispatchToProps(dispatch) {
  return {
    onClickLogout: function onClickLogout() {
      return dispatch((0, _actions.logout)());
    }
  };
};

exports.default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)((0, _reactIntl.injectIntl)(UserMenu));