From 60e892d99319b22444b758ca19ca5ed93c702f7c Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sat, 1 Aug 2020 01:40:11 +0300 Subject: [PATCH] Allow account deletion from the user agreement page --- packages/app/components/accounts/actions.ts | 2 +- .../app/components/auth/acceptRules/AcceptRules.tsx | 13 ++++++++++--- .../app/services/authFlow/AcceptRulesState.test.ts | 8 +++++++- packages/app/services/authFlow/AcceptRulesState.ts | 8 +++++++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/app/components/accounts/actions.ts b/packages/app/components/accounts/actions.ts index dc02e01..f14ced6 100644 --- a/packages/app/components/accounts/actions.ts +++ b/packages/app/components/accounts/actions.ts @@ -78,7 +78,7 @@ export function authenticate( sessionStorage.setItem(`stranger${newAccount.id}`, '1'); } - if (auth && auth.oauth && auth.oauth.clientId) { + if (auth?.oauth?.clientId) { // if we authenticating during oauth, we disable account chooser // because user probably has made his choise now // this may happen, when user registers, logs in or uses account diff --git a/packages/app/components/auth/acceptRules/AcceptRules.tsx b/packages/app/components/auth/acceptRules/AcceptRules.tsx index dd98c70..060f480 100644 --- a/packages/app/components/auth/acceptRules/AcceptRules.tsx +++ b/packages/app/components/auth/acceptRules/AcceptRules.tsx @@ -7,6 +7,7 @@ import Body from './AcceptRulesBody'; const messages = defineMessages({ title: 'User Agreement', declineAndLogout: 'Decline and logout', + deleteAccount: 'Delete account', }); export default factory({ @@ -17,7 +18,13 @@ export default factory({ autoFocus: true, children: , }, - links: { - label: messages.declineAndLogout, - }, + links: [ + { + label: messages.declineAndLogout, + }, + { + label: messages.deleteAccount, + payload: { deleteAccount: true }, + }, + ], }); diff --git a/packages/app/services/authFlow/AcceptRulesState.test.ts b/packages/app/services/authFlow/AcceptRulesState.test.ts index 84c4988..75de1ca 100644 --- a/packages/app/services/authFlow/AcceptRulesState.test.ts +++ b/packages/app/services/authFlow/AcceptRulesState.test.ts @@ -83,7 +83,13 @@ describe('AcceptRulesState', () => { it('should logout', () => { expectRun(mock, 'logout'); - state.reject(context); + state.reject(context, {}); + }); + + it('should navigate to the account deletion page', () => { + expectNavigate(mock, '/profile/delete'); + + state.reject(context, { deleteAccount: true }); }); }); }); diff --git a/packages/app/services/authFlow/AcceptRulesState.ts b/packages/app/services/authFlow/AcceptRulesState.ts index 17aa0ca..7e01504 100644 --- a/packages/app/services/authFlow/AcceptRulesState.ts +++ b/packages/app/services/authFlow/AcceptRulesState.ts @@ -22,7 +22,13 @@ export default class AcceptRulesState extends AbstractState { .catch((err = {}) => err.errors || logger.warn('Error accepting rules', err)); } - reject(context: AuthContext): void { + reject(context: AuthContext, payload: Record): void { + if (payload.deleteAccount) { + context.navigate('/profile/delete'); + + return; + } + context.run('logout'); } }