accounts-frontend/src/components/accounts/AccountSwitcher.jsx

139 lines
5.4 KiB
React
Raw Normal View History

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';
2016-11-08 11:37:04 +05:30
import { skins, SKIN_DARK, COLOR_WHITE } from 'components/ui';
import { Button } from 'components/ui/form';
2016-11-06 01:53:56 +05:30
import styles from './accountSwitcher.scss';
2016-11-06 01:53:56 +05:30
import messages from './AccountSwitcher.intl.json';
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: 'erickskrauch@yandex.ru'},
{id: 9, username: 'Ely-en', email: 'ely-en@ely.by'},
{id: 10, username: 'Ely-by', email: 'ely-pt@ely.by'},
]
};
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),
highlightActiveAccount: PropTypes.bool, // whether active account should be expanded and shown on the top
2016-11-06 01:53:56 +05:30
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
};
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);
}
return (
2016-11-06 01:53:56 +05:30
<div className={classNames(
styles.accountSwitcher,
styles[`${skin}AccountSwitcher`],
)}>
{highlightActiveAccount ? (
<div className={styles.item}>
<div className={classNames(
styles.accountIcon,
styles.activeAccountIcon,
styles.accountIcon1
)}></div>
<div className={styles.activeAccountInfo}>
<div className={styles.activeAccountUsername}>
2016-11-06 01:53:56 +05:30
{accounts.active.username}
</div>
<div className={classNames(styles.accountEmail, styles.activeAccountEmail)}>
2016-11-06 01:53:56 +05:30
{accounts.active.email}
</div>
<div className={styles.links}>
<div className={styles.link}>
<a href="">
<Message {...messages.goToEly} />
</a>
</div>
<div className={styles.link}>
<a href="" className={styles.link}>
<Message {...messages.logout} />
</a>
</div>
</div>
</div>
</div>
2016-11-06 01:53:56 +05:30
) : null}
{available.map((account, id) => (
<div className={classNames(styles.item, styles.accountSwitchItem)} key={account.id}>
<div className={classNames(
styles.accountIcon,
styles[`accountIcon${id % 7 + (highlightActiveAccount ? 2 : 1)}`]
)}></div>
2016-11-06 01:53:56 +05:30
{allowLogout ? (
<div className={styles.logoutIcon}></div>
) : (
<div className={styles.nextIcon}></div>
)}
<div className={styles.accountInfo}>
<div className={styles.accountUsername}>
{account.username}
</div>
<div className={styles.accountEmail}>
{account.email}
</div>
</div>
</div>
))}
2016-11-06 01:53:56 +05:30
{allowAdd ? (
<div>
<Button
2016-11-08 11:37:04 +05:30
color={COLOR_WHITE}
block
small
className={styles.addAccount}
label={
<Message {...messages.addAccount}>
{(message) =>
<span>
<div className={styles.addIcon} />
{message}
</span>
}
</Message>
}
/>
</div>
2016-11-06 01:53:56 +05:30
) : null}
</div>
);
}
}