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

30 lines
872 B
TypeScript
Raw Normal View History

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 {
return context.run('acceptRules').then(() => context.setState(new CompleteState()));
2020-05-24 04:38:24 +05:30
}
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
}