import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; import classNames from 'classnames'; import { Link } from 'react-router-dom'; import { FormattedMessage as Message } from 'react-intl'; import loader from 'services/loader'; import { skins, SKIN_DARK, COLOR_WHITE } from 'components/ui'; import { Button } from 'components/ui/form'; import { authenticate, revoke } from 'components/accounts/actions'; import { getActiveAccount } from 'components/accounts/reducer'; import styles from './accountSwitcher.scss'; import messages from './AccountSwitcher.intl.json'; export class AccountSwitcher extends Component { static displayName = 'AccountSwitcher'; static propTypes = { switchAccount: PropTypes.func.isRequired, removeAccount: PropTypes.func.isRequired, onAfterAction: PropTypes.func, // called after each action performed onSwitch: PropTypes.func, // called after switching an account. The active account will be passed as arg accounts: PropTypes.object, // eslint-disable-line skin: PropTypes.oneOf(skins), highlightActiveAccount: PropTypes.bool, // whether active account should be expanded and shown on the top allowLogout: PropTypes.bool, // whether to show logout icon near each account allowAdd: PropTypes.bool // whether to show add account button }; static defaultProps = { skin: SKIN_DARK, highlightActiveAccount: true, allowLogout: true, allowAdd: true, onAfterAction() {}, onSwitch() {} }; render() { const { accounts, skin, allowAdd, allowLogout, highlightActiveAccount } = this.props; const activeAccount = getActiveAccount({ accounts }); let {available} = accounts; if (highlightActiveAccount) { available = available.filter((account) => account.id !== activeAccount.id); } return (
{highlightActiveAccount ? (
{activeAccount.username}
{activeAccount.email}
) : null} {available.map((account, index) => (
{allowLogout ? (
) : (
)}
{account.username}
{account.email}
))} {allowAdd ? (