accounts-frontend/packages/app/components/auth/chooseAccount/ChooseAccountBody.tsx

61 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2016-11-06 01:53:56 +05:30
import React from 'react';
import { FormattedMessage as Message } from 'react-intl';
import { connect } from 'app/functions';
import BaseAuthBody from 'app/components/auth/BaseAuthBody';
import { getSortedAccounts } from 'app/components/accounts/reducer';
import type { Account } from 'app/components/accounts';
2016-11-06 01:53:56 +05:30
import AccountSwitcher from './AccountSwitcher';
2016-11-06 01:53:56 +05:30
import styles from './chooseAccount.scss';
// 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: getSortedAccounts(state),
}))(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
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>,
}}
/>
) : (
<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}>
<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
);
}
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
}