Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Use CloseAccount to replace User_Delete and refactor related pages #9635

Merged
merged 31 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c50bcb4
New onyx key for multiple types of close account data
Beamanator Jun 30, 2022
9dfaa32
Replace User_Delete with CloseAccount
Beamanator Jun 30, 2022
4345f96
Update close account page and action
Beamanator Jun 30, 2022
77c6728
Remove old command
Beamanator Jun 30, 2022
4970ab6
Clean up some props and proptypes
Beamanator Jun 30, 2022
3eca6e3
Clean up imports & close account data
Beamanator Jun 30, 2022
7a2a794
Account for empty close account data
Beamanator Jun 30, 2022
bb9e58b
Lint: Prefer default export
Beamanator Jun 30, 2022
2c2c07e
Merge branch 'main' of github.com:Expensify/App into beaman-refactorU…
Beamanator Jul 1, 2022
5466d2a
Make one-function action work better
Beamanator Jul 1, 2022
587b68c
Paging dr Spacey...
Beamanator Jul 1, 2022
8f9d9f6
Merge branch 'main' of github.com:Expensify/App into beaman-refactorU…
Beamanator Jul 4, 2022
fed23a9
Remove redundant 'data' in onyx key suffix
Beamanator Jul 4, 2022
46cc5b1
Remove unused translation
Beamanator Jul 4, 2022
3d39f40
Merge branch 'main' of github.com:Expensify/App into beaman-refactorU…
Beamanator Jul 8, 2022
8a32a15
Clear onyx data on closeAccount success
Beamanator Jul 8, 2022
85ec2b3
Merge branch 'main' of github.com:Expensify/App into beaman-refactorU…
Beamanator Jul 11, 2022
64de3cf
Update react native onyx version
Beamanator Jul 11, 2022
53dc8b5
Merge branch 'main' of github.com:Expensify/App into beaman-refactorU…
Beamanator Jul 14, 2022
f7360b5
Add onyx method 'clear'
Beamanator Jul 14, 2022
3ab21d1
Use onyx method consts
Beamanator Jul 14, 2022
318f5f1
Merge branch 'main' of github.com:Expensify/App into beaman-refactorU…
Beamanator Jul 15, 2022
510c2ef
Make prop name same as onyx key
Beamanator Jul 15, 2022
35d73f1
Remove successData and explain why
Beamanator Jul 15, 2022
149ec7a
Remove unused const
Beamanator Jul 15, 2022
2859a34
Merge branch 'main' of github.com:Expensify/App into beaman-refactorU…
Beamanator Jul 18, 2022
a393005
Don't worry about closing already closed modal
Beamanator Jul 18, 2022
300f7ce
Remove unused onyx subscription
Beamanator Jul 18, 2022
2e8f6a9
Rename function to describe what it does
Beamanator Jul 18, 2022
200e5a8
Revert unnecessary package-lock changes
Beamanator Jul 19, 2022
5c6cb1c
Merge branch 'main' of github.com:Expensify/App into beaman-refactorU…
Beamanator Jul 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,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 related to user closing their account (loading status and error message)
CLOSE_ACCOUNT: 'closeAccount',

// Stores information about active wallet transfer amount, selectedAccountID, status, etc
WALLET_TRANSFER: 'walletTransfer',
Expand Down
1 change: 0 additions & 1 deletion src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ export default {
enterMessageHere: 'Enter message here',
closeAccountWarning: 'Closing your account cannot be undone.',
closeAccountPermanentlyDeleteData: 'This will permanently delete all of your unsubmitted expense data. Type your phone number or email address to confirm.',
closeAccountSuccess: 'Account closed successfully',
closeAccountActionRequired: 'Looks like you need to complete some actions before closing your account. Check out the guide',
closeAccountTryAgainAfter: 'and try again after.',
enterDefaultContact: 'Enter your default contact method',
Expand Down
1 change: 0 additions & 1 deletion src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ export default {
enterMessageHere: 'Ingresa el mensaje aquí',
closeAccountWarning: 'Una vez cerrada tu cuenta no se puede revertir.',
closeAccountPermanentlyDeleteData: 'Esta acción eliminará permanentemente toda la información de tus gastos no enviados. Escribe tu número de teléfono o correo electrónico para confirmar',
closeAccountSuccess: 'Cuenta cerrada exitosamente',
closeAccountActionRequired: 'Parece que necesitas completar algunas acciones antes de cerrar tu cuenta. Mira la guía',
closeAccountTryAgainAfter: 'e intenta nuevamente',
enterDefaultContact: 'Tu método de contacto predeterminado',
Expand Down
29 changes: 5 additions & 24 deletions src/libs/actions/CloseAccount.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
import Onyx from 'react-native-onyx';
import ONYXKEYS from '../../ONYXKEYS';

let isCloseAccountModalOpen;
Onyx.connect({
key: ONYXKEYS.IS_CLOSE_ACCOUNT_MODAL_OPEN,
callback: flag => isCloseAccountModalOpen = flag,
});

/**
* Set CloseAccount flag to show modal
*/
function showCloseAccountModal() {
if (isCloseAccountModalOpen) {
return;
}
Onyx.set(ONYXKEYS.IS_CLOSE_ACCOUNT_MODAL_OPEN, true);
}

/**
* Unset CloseAccount flag to hide modal
* Clear CloseAccount error message to hide modal
*/
function hideCloseAccountModal() {
if (!isCloseAccountModalOpen) {
return;
}
Onyx.set(ONYXKEYS.IS_CLOSE_ACCOUNT_MODAL_OPEN, false);
function clearError() {
Onyx.merge(ONYXKEYS.CLOSE_ACCOUNT, {error: ''});
}

export {
showCloseAccountModal,
hideCloseAccountModal,
// eslint-disable-next-line import/prefer-default-export
clearError,
};
Julesssss marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 17 additions & 13 deletions src/libs/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import ROUTES from '../../ROUTES';
import * as Pusher from '../Pusher/pusher';
import Log from '../Log';
import NetworkConnection from '../NetworkConnection';
import redirectToSignIn from './SignInRedirect';
import Growl from '../Growl';
import * as Localize from '../Localize';
import * as CloseAccountActions from './CloseAccount';
import * as Link from './Link';
import getSkinToneEmojiFromIndex from '../../components/EmojiPicker/getSkinToneEmojiFromIndex';
import * as SequentialQueue from '../Network/SequentialQueue';
Expand Down Expand Up @@ -78,17 +76,23 @@ 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);
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
redirectToSignIn();
return;
}

// Inform user that they are currently unable to close their account
CloseAccountActions.showCloseAccountModal();
// Note: successData does not need to set isLoading to false because if the CloseAccount
// command succeeds, a Pusher response will clear all Onyx data.
Julesssss marked this conversation as resolved.
Show resolved Hide resolved
API.write('CloseAccount', {message}, {
optimisticData: [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.CLOSE_ACCOUNT,
value: {isLoading: true},
},
],
failureData: [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.CLOSE_ACCOUNT,
value: {isLoading: false},
},
],
});
}

Expand Down
11 changes: 0 additions & 11 deletions src/libs/deprecatedAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,6 @@ function SetPassword(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);
}

/**
* @param {Object} parameters
* @param {String} parameters.email
Expand Down Expand Up @@ -749,7 +739,6 @@ export {
SetPassword,
UpdatePolicy,
User_SignUp,
User_Delete,
User_IsUsingExpensifyCard,
User_ReopenAccount,
User_SecondaryLogin_Send,
Expand Down
26 changes: 16 additions & 10 deletions src/pages/settings/Security/CloseAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ import ConfirmModal from '../../../components/ConfirmModal';
import KeyboardAvoidingView from '../../../components/KeyboardAvoidingView';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import * as CloseAccountActions from '../../../libs/actions/CloseAccount';
import * as CloseAccount from '../../../libs/actions/CloseAccount';
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 */
closeAccount: PropTypes.shape({
/** Error message if previous attempt to close account was unsuccessful */
error: PropTypes.string,

/** Is account currently being closed? */
isLoading: PropTypes.bool.isRequired,
}),

/** Session of currently logged in user */
session: PropTypes.shape({
Expand All @@ -38,7 +44,7 @@ const propTypes = {
};

const defaultProps = {
isCloseAccoutModalOpen: false,
closeAccount: {error: '', isLoading: false},
};

class CloseAccountPage extends Component {
Expand Down Expand Up @@ -105,7 +111,7 @@ class CloseAccountPage extends Component {
<Button
danger
text={this.props.translate('closeAccountPage.closeAccount')}
isLoading={this.state.loading}
isLoading={this.props.closeAccount.isLoading}
onPress={() => User.closeAccount(this.state.reasonForLeaving)}
isDisabled={Str.removeSMSDomain(userEmailOrPhone).toLowerCase() !== this.state.phoneOrEmail.toLowerCase()}
/>
Expand All @@ -128,8 +134,8 @@ class CloseAccountPage extends Component {
{this.props.translate('closeAccountPage.closeAccountTryAgainAfter')}
</Text>
)}
onConfirm={CloseAccountActions.hideCloseAccountModal}
isVisible={this.props.isCloseAccoutModalOpen}
onConfirm={CloseAccount.clearError}
isVisible={Boolean(this.props.closeAccount.error)}
shouldShowCancelButton={false}
/>
</KeyboardAvoidingView>
Expand All @@ -146,9 +152,9 @@ export default compose(
withLocalize,
withWindowDimensions,
withOnyx({
isCloseAccoutModalOpen: {
key: ONYXKEYS.IS_CLOSE_ACCOUNT_MODAL_OPEN,
initWithStoredValues: false,
closeAccount: {
key: ONYXKEYS.CLOSE_ACCOUNT,
initWithStoredValues: {error: '', isLoading: false},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhhhh interesting, good catch. It looks like in that repo we default initWithStoredValues to true so I think I can pretty much just delete this line - we do actually want to load the page with the error / loading state stored

},
session: {
key: ONYXKEYS.SESSION,
Expand Down