2016-11-05 16:27:01 +05:30
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
2016-11-06 01:53:56 +05:30
|
|
|
import classNames from 'classnames';
|
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
|
|
|
|
|
|
|
import { skins, SKIN_DARK } from 'components/ui';
|
|
|
|
|
2016-11-05 16:27:01 +05:30
|
|
|
import styles from './accountSwitcher.scss';
|
2016-11-06 01:53:56 +05:30
|
|
|
import messages from './AccountSwitcher.intl.json';
|
2016-11-05 16:27:01 +05:30
|
|
|
|
|
|
|
const accounts = {
|
|
|
|
active: {id: 7, username: 'SleepWalker', email: 'danilenkos@auroraglobal.com'},
|
|
|
|
available: [
|
|
|
|
{id: 7, username: 'SleepWalker', email: 'danilenkos@auroraglobal.com'},
|
|
|
|
{id: 8, username: 'ErickSkrauch', email: 'erick@foo.bar'},
|
|
|
|
{id: 9, username: 'Ely-en', email: 'ely@-enfoo.bar'},
|
|
|
|
{id: 10, username: 'Ely-by', email: 'ely-by@foo.bar'},
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class AccountSwitcher extends Component {
|
2016-11-06 01:53:56 +05:30
|
|
|
static displayName = 'AccountSwitcher';
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
accounts: PropTypes.shape({ // TODO: accounts shape
|
|
|
|
active: PropTypes.shape({
|
|
|
|
id: PropTypes.number
|
|
|
|
}),
|
|
|
|
available: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
id: PropTypes.number
|
|
|
|
}))
|
|
|
|
}),
|
|
|
|
skin: PropTypes.oneOf(skins),
|
|
|
|
hightLightActiveAccount: 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,
|
|
|
|
accounts
|
|
|
|
};
|
|
|
|
|
2016-11-05 16:27:01 +05:30
|
|
|
render() {
|
2016-11-06 01:53:56 +05:30
|
|
|
const { accounts, skin, allowAdd, allowLogout, highlightActiveAccount } = this.props;
|
|
|
|
|
|
|
|
let {available} = accounts;
|
|
|
|
|
|
|
|
if (highlightActiveAccount) {
|
|
|
|
available = available.filter((account) => account.id !== accounts.active.id);
|
|
|
|
}
|
|
|
|
|
2016-11-05 16:27:01 +05:30
|
|
|
return (
|
2016-11-06 01:53:56 +05:30
|
|
|
<div className={classNames(
|
|
|
|
styles.accountSwitcher,
|
|
|
|
styles[`${skin}AccountSwitcher`],
|
|
|
|
)}>
|
|
|
|
{highlightActiveAccount ? (
|
2016-11-05 16:27:01 +05:30
|
|
|
<div>
|
2016-11-06 01:53:56 +05:30
|
|
|
<div className="account-icon"></div>
|
2016-11-05 16:27:01 +05:30
|
|
|
<div>
|
2016-11-06 01:53:56 +05:30
|
|
|
<div>
|
|
|
|
{accounts.active.username}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{accounts.active.email}
|
|
|
|
</div>
|
|
|
|
<a href="">
|
|
|
|
<Message {...messages.goToEly} />
|
|
|
|
</a>
|
|
|
|
<a href="">
|
|
|
|
<Message {...messages.logout} />
|
|
|
|
</a>
|
2016-11-05 16:27:01 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
2016-11-06 01:53:56 +05:30
|
|
|
) : null}
|
|
|
|
{available.map((account) => (
|
2016-11-05 16:27:01 +05:30
|
|
|
<div key={account.id}>
|
|
|
|
<div className="account-icon"></div>
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
{account.username}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{account.email}
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-11-06 01:53:56 +05:30
|
|
|
{allowLogout ? (
|
|
|
|
<div className={styles.logoutIcon}></div>
|
|
|
|
) : (
|
|
|
|
<div className={styles.nextIcon}></div>
|
|
|
|
)}
|
2016-11-05 16:27:01 +05:30
|
|
|
</div>
|
|
|
|
))}
|
2016-11-06 01:53:56 +05:30
|
|
|
{allowAdd ? (
|
2016-11-05 16:27:01 +05:30
|
|
|
<div>
|
2016-11-06 01:53:56 +05:30
|
|
|
<div>
|
|
|
|
<span className={styles.addAccount}>+</span>
|
|
|
|
<Message {...messages.addAccount} />
|
|
|
|
</div>
|
2016-11-05 16:27:01 +05:30
|
|
|
</div>
|
2016-11-06 01:53:56 +05:30
|
|
|
) : null}
|
2016-11-05 16:27:01 +05:30
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|