From d43985d2c5ff791b8ddd2baafa04c715d172441a Mon Sep 17 00:00:00 2001 From: Sadaqat Ali Date: Sun, 28 Aug 2022 23:44:42 +0500 Subject: [PATCH] logout user when delete account is pressed and show toast --- src/config/locales/en-US.json | 5 ++ .../settings/container/settingsContainer.tsx | 54 +++++++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index aa64b9d45..7176c48da 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -549,6 +549,11 @@ "confirm_report_title":"Confirm Report!", "confirm_report_body":"Are you sure you want report?" }, + "delete": { + "confirm_delete_title": "Confirm Delete", + "confirm_delete_body": "Are you sure you want to delete account? It will erase all of your data", + "request_sent": "Your request for deletion is sent" + }, "favorites": { "title": "Favorites", "load_error": "Could not load favorites", diff --git a/src/screens/settings/container/settingsContainer.tsx b/src/screens/settings/container/settingsContainer.tsx index c76a46e63..4e8b5db3f 100644 --- a/src/screens/settings/container/settingsContainer.tsx +++ b/src/screens/settings/container/settingsContainer.tsx @@ -41,9 +41,10 @@ import { setIsBiometricEnabled, setEncryptedUnlockPin, setHidePostsThumbnails, + logout, } from '../../../redux/actions/applicationActions'; -import { toastNotification } from '../../../redux/actions/uiAction'; -import { setPushToken, getNodes } from '../../../providers/ecency/ecency'; +import { showActionModal, toastNotification } from '../../../redux/actions/uiAction'; +import { setPushToken, getNodes, deleteAccount } from '../../../providers/ecency/ecency'; import { checkClient } from '../../../providers/hive/dhive'; import { removeOtherAccount, updateCurrentAccount } from '../../../redux/actions/accountAction'; // Middleware @@ -314,9 +315,9 @@ class SettingsContainer extends Component { break; case settingsTypes.DELETE_ACCOUNT: - console.log('delete account'); - + this._handleDeleteAccount(); break; + default: break; } @@ -394,6 +395,51 @@ class SettingsContainer extends Component { } }; + _handleDeleteAccount = () => { + const { dispatch, intl, currentAccount } = this.props as any; + + const _onConfirm = () => { + deleteAccount(currentAccount.username) + .then(() => { + dispatch( + toastNotification( + intl.formatMessage({ + id: 'delete.request_sent', + }), + ), + ); + dispatch(logout()); + }) + .catch(() => { + dispatch( + toastNotification( + intl.formatMessage({ + id: 'delete.request_sent', + }), + ), + ); + dispatch(logout()); + }); + }; + + dispatch( + showActionModal({ + title: intl.formatMessage({ id: 'delete.confirm_delete_title' }), + body: intl.formatMessage({ id: 'delete.confirm_delete_body' }), + buttons: [ + { + text: intl.formatMessage({ id: 'alert.cancel' }), + onPress: () => {}, + }, + { + text: intl.formatMessage({ id: 'alert.delete' }), + onPress: _onConfirm, + }, + ], + }), + ); + + } _clearUserData = async () => { const { otherAccounts, dispatch } = this.props;