accounts-frontend/packages/app/services/authFlow/AcceptRulesState.ts

35 lines
1.0 KiB
TypeScript
Raw Normal View History

import logger from 'app/services/logger';
2016-08-03 00:29:29 +05:30
import AbstractState from './AbstractState';
import { AuthContext } from './AuthFlow';
2016-08-03 00:29:29 +05:30
import CompleteState from './CompleteState';
export default class AcceptRulesState extends AbstractState {
2020-05-24 04:38:24 +05:30
enter(context: AuthContext): Promise<void> | void {
const { user } = context.getState();
2016-08-03 00:29:29 +05:30
if (!user.isDeleted && user.shouldAcceptRules) {
2020-05-24 04:38:24 +05:30
context.navigate('/accept-rules');
} else {
context.setState(new CompleteState());
}
2016-08-03 00:29:29 +05:30
}
2020-05-24 04:38:24 +05:30
resolve(context: AuthContext): Promise<void> | void {
context
.run('acceptRules')
.then(() => context.setState(new CompleteState()))
.catch((err = {}) => err.errors || logger.warn('Error accepting rules', err));
}
2016-08-03 00:29:29 +05:30
reject(context: AuthContext, payload: Record<string, any>): void {
if (payload.deleteAccount) {
context.navigate('/profile/delete');
return;
}
2020-05-24 04:38:24 +05:30
context.run('logout');
}
2016-08-03 00:29:29 +05:30
}