From c50bcb4ba062cc7cab8e26ab95acf8b9cbf34b86 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Thu, 30 Jun 2022 15:26:27 +0200 Subject: [PATCH 01/23] New onyx key for multiple types of close account data --- src/ONYXKEYS.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index 1f47b414ee23..45d71ab0bd33 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -180,8 +180,8 @@ export default { // Is Keyboard shortcuts modal open? IS_SHORTCUTS_MODAL_OPEN: 'isShortcutsModalOpen', - // Is close acount modal open? - IS_CLOSE_ACCOUNT_MODAL_OPEN: 'isCloseAccountModalOpen', + // Data from when user attempts to close their account (loading status and error message) + CLOSE_ACCOUNT_DATA: 'closeAccountData', // Stores information about active wallet transfer amount, selectedAccountID, status, etc WALLET_TRANSFER: 'walletTransfer', From 9dfaa326dcb51010019702ee59e8ba76666cc65c Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Thu, 30 Jun 2022 15:26:50 +0200 Subject: [PATCH 02/23] Replace User_Delete with CloseAccount --- src/libs/actions/User.js | 38 +++++++++++++++++++++++++++----------- src/libs/deprecatedAPI.js | 10 ---------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 148d5cbfa40e..b2316e4a8ea8 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -83,17 +83,33 @@ function updatePassword(oldPassword, password) { * @param {String} message optional reason for closing account */ function closeAccount(message) { - DeprecatedAPI.User_Delete({message}).then((response) => { - console.debug('User_Delete: ', JSON.stringify(response)); - - if (response.jsonCode === 200) { - Growl.show(Localize.translateLocal('closeAccountPage.closeAccountSuccess'), CONST.GROWL.SUCCESS); - redirectToSignIn(); - return; - } - - // Inform user that they are currently unable to close their account - CloseAccountActions.showCloseAccountModal(); + API.write('CloseAccount', {message}, { + optimisticData: [ + { + onyxMethod: 'merge', + key: ONYXKEYS.CLOSE_ACCOUNT_DATA, + value: {isModalOpen: false, isLoading: true}, + }, + ], + successData: [ + { + onyxMethod: 'merge', + key: ONYXKEYS.CLOSE_ACCOUNT_DATA, + value: {isLoading: false}, + }, + { + onyxMethod: 'set', + key: ONYXKEYS.SESSION, + value: null, + }, + ], + failureData: [ + { + onyxMethod: 'merge', + key: ONYXKEYS.CLOSE_ACCOUNT_DATA, + value: {isModalOpen: true, isLoading: false}, + }, + ], }); } diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index 67333741f0a7..af3c0202e317 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -452,16 +452,6 @@ function UpdateAccount(parameters) { return Network.post(commandName, parameters); } -/** - * @param {Object} parameters - * @param {String} parameters.message - * @returns {Promise} - */ -function User_Delete(parameters) { - const commandName = 'User_Delete'; - return Network.post(commandName, parameters); -} - /** * @returns {Promise} */ From 4345f96b447befcccc558b397788445bf772f036 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Thu, 30 Jun 2022 15:27:24 +0200 Subject: [PATCH 03/23] Update close account page and action --- src/libs/actions/CloseAccount.js | 27 ++++++------------- .../settings/Security/CloseAccountPage.js | 24 ++++++++++------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/libs/actions/CloseAccount.js b/src/libs/actions/CloseAccount.js index ceb78aa68bf0..564ddffa62e8 100644 --- a/src/libs/actions/CloseAccount.js +++ b/src/libs/actions/CloseAccount.js @@ -1,33 +1,22 @@ import Onyx from 'react-native-onyx'; import ONYXKEYS from '../../ONYXKEYS'; -let isCloseAccountModalOpen; +let isCloseAccountErrorModalOpen; Onyx.connect({ - key: ONYXKEYS.IS_CLOSE_ACCOUNT_MODAL_OPEN, - callback: flag => isCloseAccountModalOpen = flag, + key: ONYXKEYS.CLOSE_ACCOUNT_DATA, + callback: data => isCloseAccountErrorModalOpen = Boolean(data.error), }); /** - * Set CloseAccount flag to show modal +* Unset CloseAccount error message to hide modal */ -function showCloseAccountModal() { - if (isCloseAccountModalOpen) { +function hideCloseAccountErrorModal() { + if (!isCloseAccountErrorModalOpen) { return; } - Onyx.set(ONYXKEYS.IS_CLOSE_ACCOUNT_MODAL_OPEN, true); -} - -/** -* Unset CloseAccount flag to hide modal - */ -function hideCloseAccountModal() { - if (!isCloseAccountModalOpen) { - return; - } - Onyx.set(ONYXKEYS.IS_CLOSE_ACCOUNT_MODAL_OPEN, false); + Onyx.merge(ONYXKEYS.CLOSE_ACCOUNT_DATA, {error: ''}); } export { - showCloseAccountModal, - hideCloseAccountModal, + hideCloseAccountErrorModal, }; diff --git a/src/pages/settings/Security/CloseAccountPage.js b/src/pages/settings/Security/CloseAccountPage.js index 2f9d7f5360e2..aa9c6b86e7e2 100644 --- a/src/pages/settings/Security/CloseAccountPage.js +++ b/src/pages/settings/Security/CloseAccountPage.js @@ -24,8 +24,14 @@ import ONYXKEYS from '../../../ONYXKEYS'; const propTypes = { /** Onyx Props */ - /** Is the Close Account information modal open? */ - isCloseAccoutModalOpen: PropTypes.bool, + /** Data from when user attempts to close their account */ + closeAccountData: PropTypes.shape({ + /** Error message if previous attempt to close account was unsuccessful */ + error: PropTypes.string.isRequired, + + /** Is account currently being closed? */ + isLoading: PropTypes.bool.isRequired, + }), /** Session of currently logged in user */ session: PropTypes.shape({ @@ -38,7 +44,7 @@ const propTypes = { }; const defaultProps = { - isCloseAccoutModalOpen: false, + closeAccountData: {error: '', isLoading: false}, }; class CloseAccountPage extends Component { @@ -105,7 +111,7 @@ class CloseAccountPage extends Component {