mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-07-01 04:33:23 +05:30
#305: fix linting errors after installing flow plugin for eslint.
Improve Authflow#run() typing
This commit is contained in:
parent
d1b19a2285
commit
82744f9300
|
@ -1,3 +1,4 @@
|
|||
// @flow
|
||||
import { combineReducers } from 'redux';
|
||||
|
||||
import {
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
// @flow
|
||||
export { default } from './MultiFactorAuth';
|
||||
export type { MfaStep } from './MfaEnable';
|
||||
|
|
|
@ -18,7 +18,7 @@ export default class LoggedInPanel extends Component<{
|
|||
isAccountSwitcherActive: false
|
||||
};
|
||||
|
||||
_isMounted: boolean = false;
|
||||
_isMounted: bool = false;
|
||||
el: ?HTMLElement;
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -95,7 +95,7 @@ export default class LoggedInPanel extends Component<{
|
|||
*/
|
||||
function createOnOutsideComponentClickHandler(
|
||||
getEl: () => ?HTMLElement,
|
||||
isActive: () => boolean,
|
||||
isActive: () => bool,
|
||||
callback: Function
|
||||
) {
|
||||
// TODO: we have the same logic in LangMenu
|
||||
|
|
|
@ -42,20 +42,32 @@ class MultiFactorAuthPage extends Component<{
|
|||
}
|
||||
|
||||
render() {
|
||||
const step = (parseInt(this.props.match.params.step, 10) || 1) - 1;
|
||||
const {user} = this.props;
|
||||
|
||||
return (
|
||||
<MultiFactorAuth
|
||||
isMfaEnabled={user.isOtpEnabled}
|
||||
onSubmit={this.onSubmit}
|
||||
step={step}
|
||||
step={this.getStep()}
|
||||
onChangeStep={this.onChangeStep}
|
||||
onComplete={this.onComplete}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
getStep(): MfaStep {
|
||||
const step = (parseInt(this.props.match.params.step, 10) || 1) - 1;
|
||||
|
||||
if (step !== 0
|
||||
&& step !== 1
|
||||
&& step !== 2
|
||||
) { // NOTE: flow does not understand Array.includes()
|
||||
return 1;
|
||||
}
|
||||
|
||||
return step;
|
||||
}
|
||||
|
||||
onChangeStep = (step: MfaStep) => {
|
||||
this.props.history.push(`/profile/mfa/step${step + 1}`);
|
||||
};
|
||||
|
|
|
@ -32,7 +32,7 @@ if (process.env.NODE_ENV === 'production') {
|
|||
|
||||
class RootPage extends Component<{
|
||||
user: User,
|
||||
isPopupActive: boolean,
|
||||
isPopupActive: bool,
|
||||
onLogoClick: Function,
|
||||
location: {
|
||||
pathname: string
|
||||
|
|
|
@ -19,8 +19,39 @@ type Request = {
|
|||
query: URLSearchParams,
|
||||
params: Object
|
||||
};
|
||||
|
||||
// TODO: temporary added to improve typing without major refactoring
|
||||
type ActionId =
|
||||
| 'updateUser'
|
||||
| 'authenticate'
|
||||
| 'logout'
|
||||
| 'goBack'
|
||||
| 'redirect'
|
||||
| 'login'
|
||||
| 'acceptRules'
|
||||
| 'forgotPassword'
|
||||
| 'recoverPassword'
|
||||
| 'register'
|
||||
| 'activate'
|
||||
| 'resendActivation'
|
||||
| 'contactUs'
|
||||
| 'setLogin'
|
||||
| 'setAccountSwitcher'
|
||||
| 'setErrors'
|
||||
| 'clearErrors'
|
||||
| 'oAuthValidate'
|
||||
| 'oAuthComplete'
|
||||
| 'setClient'
|
||||
| 'resetOAuth'
|
||||
| 'resetAuth'
|
||||
| 'setOAuthRequest'
|
||||
| 'setOAuthCode'
|
||||
| 'requirePermissionsAccept'
|
||||
| 'setScopes'
|
||||
| 'setLoadingState';
|
||||
|
||||
export interface AuthContext {
|
||||
run(actionId: string, payload: *): *;
|
||||
run(actionId: ActionId, payload?: ?Object): *;
|
||||
setState(newState: AbstractState): Promise<*> | void;
|
||||
getState(): Object;
|
||||
navigate(route: string): void;
|
||||
|
@ -94,7 +125,7 @@ export default class AuthFlow implements AuthContext {
|
|||
this.state.goBack(this);
|
||||
}
|
||||
|
||||
run(actionId: string, payload: Object): Promise<*> {
|
||||
run(actionId: ActionId, payload?: ?Object): Promise<*> {
|
||||
if (!this.actions[actionId]) {
|
||||
throw new Error(`Action ${actionId} does not exists`);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,37 @@
|
|||
// @flow
|
||||
import AuthFlow from './AuthFlow';
|
||||
export type {AuthContext} from './AuthFlow';
|
||||
|
||||
import * as actions from 'components/auth/actions';
|
||||
|
||||
const availableActions = {
|
||||
...actions
|
||||
updateUser: actions.updateUser,
|
||||
authenticate: actions.authenticate,
|
||||
logout: actions.logout,
|
||||
goBack: actions.goBack,
|
||||
redirect: actions.redirect,
|
||||
login: actions.login,
|
||||
acceptRules: actions.acceptRules,
|
||||
forgotPassword: actions.forgotPassword,
|
||||
recoverPassword: actions.recoverPassword,
|
||||
register: actions.register,
|
||||
activate: actions.activate,
|
||||
resendActivation: actions.resendActivation,
|
||||
contactUs: actions.contactUs,
|
||||
setLogin: actions.setLogin,
|
||||
setAccountSwitcher: actions.setAccountSwitcher,
|
||||
setErrors: actions.setErrors,
|
||||
clearErrors: actions.clearErrors,
|
||||
oAuthValidate: actions.oAuthValidate,
|
||||
oAuthComplete: actions.oAuthComplete,
|
||||
setClient: actions.setClient,
|
||||
resetOAuth: actions.resetOAuth,
|
||||
resetAuth: actions.resetAuth,
|
||||
setOAuthRequest: actions.setOAuthRequest,
|
||||
setOAuthCode: actions.setOAuthCode,
|
||||
requirePermissionsAccept: actions.requirePermissionsAccept,
|
||||
setScopes: actions.setScopes,
|
||||
setLoadingState: actions.setLoadingState
|
||||
};
|
||||
|
||||
export default new AuthFlow(availableActions);
|
||||
|
|
Loading…
Reference in New Issue
Block a user