2016-11-06 01:53:56 +05:30
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
import { connect } from 'app/functions';
|
2019-12-08 00:32:00 +05:30
|
|
|
import BaseAuthBody from 'app/components/auth/BaseAuthBody';
|
2020-10-23 03:53:59 +05:30
|
|
|
import type { Account } from 'app/components/accounts';
|
2016-11-06 01:53:56 +05:30
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
import AccountSwitcher from './AccountSwitcher';
|
2016-11-06 01:53:56 +05:30
|
|
|
import styles from './chooseAccount.scss';
|
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
// I can't connect the ChooseAccountBody component with redux's "connect" function
|
|
|
|
// to get accounts list because it will break the TransitionMotion animation implementation.
|
|
|
|
//
|
|
|
|
// So to provide accounts list to the component, I'll create connected version of
|
|
|
|
// the composes with already provided accounts list
|
|
|
|
const ConnectedAccountSwitcher = connect((state) => ({
|
|
|
|
accounts: state.accounts.available,
|
|
|
|
}))(AccountSwitcher);
|
|
|
|
|
2016-11-06 01:53:56 +05:30
|
|
|
export default class ChooseAccountBody extends BaseAuthBody {
|
2020-05-24 04:38:24 +05:30
|
|
|
static displayName = 'ChooseAccountBody';
|
|
|
|
static panelId = 'chooseAccount';
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { client } = this.context.auth;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{this.renderErrors()}
|
|
|
|
|
|
|
|
<div className={styles.description}>
|
|
|
|
{client ? (
|
|
|
|
<Message
|
2020-06-04 22:11:27 +05:30
|
|
|
key="pleaseChooseAccountForApp"
|
|
|
|
defaultMessage="Please select an account that you want to use to authorize {appName}"
|
2020-05-24 04:38:24 +05:30
|
|
|
values={{
|
|
|
|
appName: <span className={styles.appName}>{client.name}</span>,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : (
|
2020-10-23 03:53:59 +05:30
|
|
|
<Message
|
|
|
|
key="pleaseChooseAccount"
|
|
|
|
defaultMessage="Please select an account you're willing to use"
|
|
|
|
/>
|
2020-05-24 04:38:24 +05:30
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={styles.accountSwitcherContainer}>
|
2020-10-23 03:53:59 +05:30
|
|
|
<ConnectedAccountSwitcher onAccountClick={this.onSwitch} />
|
2020-05-24 04:38:24 +05:30
|
|
|
</div>
|
2016-11-06 01:53:56 +05:30
|
|
|
</div>
|
2020-05-24 04:38:24 +05:30
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
onSwitch = (account: Account): Promise<void> => {
|
|
|
|
return Promise.resolve(this.context.resolve(account));
|
2020-05-24 04:38:24 +05:30
|
|
|
};
|
2016-11-06 01:53:56 +05:30
|
|
|
}
|