UNPKG

redux-security

Version:
128 lines (91 loc) 5.44 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; 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 _accountCircle = require('material-ui/svg-icons/action/account-circle'); var _accountCircle2 = _interopRequireDefault(_accountCircle); var _IconButton = require('material-ui/IconButton'); var _IconButton2 = _interopRequireDefault(_IconButton); var _authSnackbar = require('./auth.snackbar.login'); var _authSnackbar2 = _interopRequireDefault(_authSnackbar); var _authSnackbar3 = require('./auth.snackbar.logout'); var _authSnackbar4 = _interopRequireDefault(_authSnackbar3); var _authSnackbar5 = require('./auth.snackbar.signup'); var _authSnackbar6 = _interopRequireDefault(_authSnackbar5); var _reduxLocale = require('redux-locale'); var _i18n = require('../i18n'); var _config = require('../config'); var _select = require('../select'); var _colors = require('material-ui/styles/colors'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 AuthAvatar = function (_React$Component) { _inherits(AuthAvatar, _React$Component); function AuthAvatar(props, context) { _classCallCheck(this, AuthAvatar); var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(AuthAvatar).call(this, props, context)); _this.componentWillReceiveProps = function (nextProps) { var auth = (0, _select.select)(nextProps.auth); if (auth.docs.length()) { _this.setState({ style: styles.success }); } else if (auth.error()) { _this.setState({ style: styles.failure }); } else { _this.setState({ style: styles.normal }); } }; var _props$serviceName = props.serviceName; var serviceName = _props$serviceName === undefined ? _config.SERVICE : _props$serviceName; var t = (0, _reduxLocale.localeAPI)(); _this.state = { serviceName: serviceName, style: styles.normal, tooltip: t.cap(_i18n.i18n.LOGIN) + ' / ' + t.cap(_i18n.i18n.LOGOUT) }; return _this; } _createClass(AuthAvatar, [{ key: 'render', value: function render() { var _props = this.props; var onClick = _props.onClick; var serviceName = _props.serviceName; var auth = _props.auth; return _react2.default.createElement( 'div', null, _react2.default.createElement( _IconButton2.default, _extends({ onClick: onClick }, { iconStyle: styles.iconStyle, style: this.state.style, tooltip: this.state.tooltip, tooltipPosition: 'bottom-left' }), _react2.default.createElement(_accountCircle2.default, null) ), _react2.default.createElement(_authSnackbar2.default, { serviceName: serviceName, auth: auth }), _react2.default.createElement(_authSnackbar4.default, { serviceName: serviceName, auth: auth }), _react2.default.createElement(_authSnackbar6.default, { serviceName: serviceName, auth: auth }) ); } }]); return AuthAvatar; }(_react2.default.Component); var styles = { iconStyle: { height: '42px', width: '42px' }, success: { height: '52px', width: '52px', padding: '5px', borderRadius: '50%', backgroundColor: _colors.green200 }, failure: { height: '52px', width: '52px', padding: '5px', borderRadius: '50%', backgroundColor: _colors.red200 }, normal: { height: '52px', width: '52px', padding: '5px', borderRadius: '50%', backgroundColor: _colors.cyan400 } }; AuthAvatar.propTypes = { auth: _react.PropTypes.object.isRequired, serviceName: _react.PropTypes.string, onClick: _react.PropTypes.func }; exports.default = AuthAvatar;