2020-10-23 03:53:59 +05:30
|
|
|
import React, { ComponentType, useCallback, useState } from 'react';
|
2019-12-08 01:13:08 +05:30
|
|
|
import clsx from 'clsx';
|
2020-10-23 03:53:59 +05:30
|
|
|
import ClickAwayListener from 'react-click-away-listener';
|
2016-11-05 16:27:01 +05:30
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
import { Account } from 'app/components/accounts';
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
import AccountSwitcher from './AccountSwitcher';
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
import styles from './loggedInPanel.scss';
|
2016-11-11 13:09:01 +05:30
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
interface Props {
|
|
|
|
activeAccount: Account;
|
|
|
|
accounts: ReadonlyArray<Account>;
|
|
|
|
onSwitchAccount?: (account: Account) => Promise<any>;
|
|
|
|
onRemoveAccount?: (account: Account) => Promise<any>;
|
|
|
|
}
|
2017-07-13 00:00:05 +05:30
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
const LoggedInPanel: ComponentType<Props> = ({ activeAccount, accounts, onSwitchAccount, onRemoveAccount }) => {
|
|
|
|
const [isAccountSwitcherActive, setAccountSwitcherState] = useState(false);
|
|
|
|
const hideAccountSwitcher = useCallback(() => setAccountSwitcherState(false), []);
|
|
|
|
const onAccountClick = useCallback(
|
|
|
|
async (account: Account) => {
|
|
|
|
if (onSwitchAccount) {
|
|
|
|
await onSwitchAccount(account);
|
|
|
|
}
|
2016-11-11 13:09:01 +05:30
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
setAccountSwitcherState(false);
|
|
|
|
},
|
|
|
|
[onSwitchAccount],
|
|
|
|
);
|
2020-05-24 04:38:24 +05:30
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
return (
|
|
|
|
<div className={styles.loggedInPanel}>
|
|
|
|
<div
|
|
|
|
className={clsx(styles.activeAccount, {
|
|
|
|
[styles.activeAccountExpanded]: isAccountSwitcherActive,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<ClickAwayListener onClickAway={hideAccountSwitcher}>
|
|
|
|
<button
|
|
|
|
className={styles.activeAccountButton}
|
|
|
|
onClick={setAccountSwitcherState.bind(null, !isAccountSwitcherActive)}
|
|
|
|
>
|
2020-05-24 04:38:24 +05:30
|
|
|
<span className={styles.userIcon} />
|
2020-10-23 03:53:59 +05:30
|
|
|
<span className={styles.userName}>{activeAccount.username}</span>
|
2020-05-24 04:38:24 +05:30
|
|
|
<span className={styles.expandIcon} />
|
|
|
|
</button>
|
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
<div className={styles.accountSwitcherContainer}>
|
|
|
|
<AccountSwitcher
|
|
|
|
activeAccount={activeAccount}
|
|
|
|
accounts={accounts}
|
|
|
|
onAccountClick={onAccountClick}
|
|
|
|
onRemoveClick={onRemoveAccount}
|
|
|
|
onLoginClick={hideAccountSwitcher}
|
|
|
|
/>
|
2020-05-24 04:38:24 +05:30
|
|
|
</div>
|
2020-10-23 03:53:59 +05:30
|
|
|
</ClickAwayListener>
|
2020-05-24 04:38:24 +05:30
|
|
|
</div>
|
2020-10-23 03:53:59 +05:30
|
|
|
</div>
|
2020-05-24 04:38:24 +05:30
|
|
|
);
|
2020-10-23 03:53:59 +05:30
|
|
|
};
|
2016-11-11 13:09:01 +05:30
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
export default LoggedInPanel;
|