From 50f404ed1dd5cb346ba73141e4b919056bd4528a Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Wed, 9 Nov 2022 19:33:05 +0400 Subject: [PATCH 1/8] Add warning when a user attempts to logout when offline --- src/pages/settings/InitialSettingsPage.js | 36 +++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/InitialSettingsPage.js b/src/pages/settings/InitialSettingsPage.js index 994ed5e099c7..915dc0faa772 100755 --- a/src/pages/settings/InitialSettingsPage.js +++ b/src/pages/settings/InitialSettingsPage.js @@ -3,6 +3,7 @@ import {View, ScrollView, Pressable} from 'react-native'; import PropTypes from 'prop-types'; import _ from 'underscore'; import {withOnyx} from 'react-native-onyx'; +import { withNetwork } from '../../components/OnyxProvider'; import Str from 'expensify-common/lib/str'; import styles from '../../styles/styles'; import Text from '../../components/Text'; @@ -28,6 +29,7 @@ import cardPropTypes from '../../components/cardPropTypes'; import * as Wallet from '../../libs/actions/Wallet'; import walletTermsPropTypes from '../EnablePayments/walletTermsPropTypes'; import * as PolicyUtils from '../../libs/PolicyUtils'; +import ConfirmModal from '../../components/ConfirmModal'; const propTypes = { /* Onyx Props */ @@ -96,6 +98,11 @@ class InitialSettingsPage extends React.Component { this.getWalletBalance = this.getWalletBalance.bind(this); this.getDefaultMenuItems = this.getDefaultMenuItems.bind(this); this.getMenuItem = this.getMenuItem.bind(this); + this.signout = this.signout.bind(this); + + this.state = { + shouldShowSignoutConfirmModal: false, + }; } componentDidMount() { @@ -171,11 +178,25 @@ class InitialSettingsPage extends React.Component { { translationKey: 'initialSettingsPage.signOut', icon: Expensicons.Exit, - action: Session.signOutAndRedirectToSignIn, - }, + action: () => { signout(false); }, + } ]); } + signout(shouldForceSignout = false) { + if (!this.props.network.isOffline || shouldForceSignout) { + Session.signOutAndRedirectToSignIn(); + return; + } + + // When offline, warn the user that any actions they took while offline will be lost if they sign out + this.toggleSignoutConfirmModal(true); + } + + toggleSignoutConfirmModal(value) { + this.setState({ shouldShowSignoutConfirmModal: value }); + } + getMenuItem(item, index) { const keyTitle = item.translationKey ? this.props.translate(item.translationKey) : item.title; const isPaymentItem = item.translationKey === 'common.payments'; @@ -247,6 +268,16 @@ class InitialSettingsPage extends React.Component { )} {_.map(this.getDefaultMenuItems(), (item, index) => this.getMenuItem(item, index))} + + + @@ -286,4 +317,5 @@ export default compose( key: ONYXKEYS.WALLET_TERMS, }, }), + withNetwork(), )(InitialSettingsPage); From d03d52c65b6423f72ac7a4ae20e1eab2c38105f7 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Wed, 9 Nov 2022 19:38:17 +0400 Subject: [PATCH 2/8] Allow cancellation of sign out action --- src/pages/settings/InitialSettingsPage.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/settings/InitialSettingsPage.js b/src/pages/settings/InitialSettingsPage.js index 915dc0faa772..d4a911f528cc 100755 --- a/src/pages/settings/InitialSettingsPage.js +++ b/src/pages/settings/InitialSettingsPage.js @@ -178,7 +178,7 @@ class InitialSettingsPage extends React.Component { { translationKey: 'initialSettingsPage.signOut', icon: Expensicons.Exit, - action: () => { signout(false); }, + action: () => { this.signout(false); }, } ]); } @@ -276,6 +276,7 @@ class InitialSettingsPage extends React.Component { cancelText={this.props.translate('common.cancel')} isVisible={this.state.shouldShowSignoutConfirmModal} onConfirm={this.signout} + onCancel={() => this.toggleSignoutConfirmModal(false)} /> From c043743bd4d483f3c7cc8e800d57809e62340821 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Wed, 9 Nov 2022 19:41:19 +0400 Subject: [PATCH 3/8] Update confirm modal text --- src/languages/en.js | 1 + src/languages/es.js | 1 + src/pages/settings/InitialSettingsPage.js | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/languages/en.js b/src/languages/en.js index 46af537b89e0..db48b40595a2 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -108,6 +108,7 @@ export default { maxParticipantsReached: ({count}) => `You've selected the maximum number (${count}) of participants.`, youAppearToBeOffline: 'You appear to be offline.', thisFeatureRequiresInternet: 'This feature requires an active internet connection to be used.', + areYouSure: 'Are you sure?', }, attachmentPicker: { cameraPermissionRequired: 'Camera permission required', diff --git a/src/languages/es.js b/src/languages/es.js index 5b80314f5099..77808c3d7703 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -108,6 +108,7 @@ export default { maxParticipantsReached: ({count}) => `Has seleccionado el número máximo (${count}) de participantes.`, youAppearToBeOffline: 'Parece que estás desconectado.', thisFeatureRequiresInternet: 'Esta función requiere una conexión a Internet activa para ser utilizada.', + areYouSure: '¿Estás seguro?', }, attachmentPicker: { cameraPermissionRequired: 'Se necesita permiso para usar la cámara', diff --git a/src/pages/settings/InitialSettingsPage.js b/src/pages/settings/InitialSettingsPage.js index d4a911f528cc..3c02ba24d798 100755 --- a/src/pages/settings/InitialSettingsPage.js +++ b/src/pages/settings/InitialSettingsPage.js @@ -270,9 +270,9 @@ class InitialSettingsPage extends React.Component { {_.map(this.getDefaultMenuItems(), (item, index) => this.getMenuItem(item, index))} Date: Thu, 10 Nov 2022 13:11:33 +0400 Subject: [PATCH 4/8] Update sign out confirmation text --- src/languages/en.js | 1 + src/languages/es.js | 1 + src/pages/settings/InitialSettingsPage.js | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/languages/en.js b/src/languages/en.js index db48b40595a2..7ffe826f9bf7 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -340,6 +340,7 @@ export default { }, security: 'Security', signOut: 'Sign out', + signOutConfirmationText: 'You\'ll lose any offline changes if you sign-out.', versionLetter: 'v', readTheTermsAndPrivacyPolicy: { phrase1: 'Read the', diff --git a/src/languages/es.js b/src/languages/es.js index 77808c3d7703..b437a1e3468e 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -341,6 +341,7 @@ export default { }, security: 'Seguridad', signOut: 'Desconectar', + signOutConfirmationText: '', versionLetter: 'v', readTheTermsAndPrivacyPolicy: { phrase1: 'Leer los', diff --git a/src/pages/settings/InitialSettingsPage.js b/src/pages/settings/InitialSettingsPage.js index 3c02ba24d798..bca7193af476 100755 --- a/src/pages/settings/InitialSettingsPage.js +++ b/src/pages/settings/InitialSettingsPage.js @@ -270,8 +270,9 @@ class InitialSettingsPage extends React.Component { {_.map(this.getDefaultMenuItems(), (item, index) => this.getMenuItem(item, index))} Date: Thu, 10 Nov 2022 13:13:28 +0400 Subject: [PATCH 5/8] Improve function name and fix sign out --- src/pages/settings/InitialSettingsPage.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pages/settings/InitialSettingsPage.js b/src/pages/settings/InitialSettingsPage.js index bca7193af476..21205d7f50e6 100755 --- a/src/pages/settings/InitialSettingsPage.js +++ b/src/pages/settings/InitialSettingsPage.js @@ -98,7 +98,7 @@ class InitialSettingsPage extends React.Component { this.getWalletBalance = this.getWalletBalance.bind(this); this.getDefaultMenuItems = this.getDefaultMenuItems.bind(this); this.getMenuItem = this.getMenuItem.bind(this); - this.signout = this.signout.bind(this); + this.signout = this.signOut.bind(this); this.state = { shouldShowSignoutConfirmModal: false, @@ -183,7 +183,7 @@ class InitialSettingsPage extends React.Component { ]); } - signout(shouldForceSignout = false) { + signOut(shouldForceSignout = false) { if (!this.props.network.isOffline || shouldForceSignout) { Session.signOutAndRedirectToSignIn(); return; @@ -276,10 +276,9 @@ class InitialSettingsPage extends React.Component { confirmText={this.props.translate('initialSettingsPage.signOut')} cancelText={this.props.translate('common.cancel')} isVisible={this.state.shouldShowSignoutConfirmModal} - onConfirm={this.signout} + onConfirm={() => this.signOut(true)} onCancel={() => this.toggleSignoutConfirmModal(false)} /> - From b28264c3a512471fe876ec2b5cc33ac2c318bf8d Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Mon, 21 Nov 2022 18:20:11 +0000 Subject: [PATCH 6/8] Fix lint errors --- src/pages/settings/InitialSettingsPage.js | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/pages/settings/InitialSettingsPage.js b/src/pages/settings/InitialSettingsPage.js index 21205d7f50e6..d50c8d94dc07 100755 --- a/src/pages/settings/InitialSettingsPage.js +++ b/src/pages/settings/InitialSettingsPage.js @@ -3,8 +3,8 @@ import {View, ScrollView, Pressable} from 'react-native'; import PropTypes from 'prop-types'; import _ from 'underscore'; import {withOnyx} from 'react-native-onyx'; -import { withNetwork } from '../../components/OnyxProvider'; import Str from 'expensify-common/lib/str'; +import {withNetwork} from '../../components/OnyxProvider'; import styles from '../../styles/styles'; import Text from '../../components/Text'; import * as Session from '../../libs/actions/Session'; @@ -179,22 +179,12 @@ class InitialSettingsPage extends React.Component { translationKey: 'initialSettingsPage.signOut', icon: Expensicons.Exit, action: () => { this.signout(false); }, - } + }, ]); } - signOut(shouldForceSignout = false) { - if (!this.props.network.isOffline || shouldForceSignout) { - Session.signOutAndRedirectToSignIn(); - return; - } - - // When offline, warn the user that any actions they took while offline will be lost if they sign out - this.toggleSignoutConfirmModal(true); - } - toggleSignoutConfirmModal(value) { - this.setState({ shouldShowSignoutConfirmModal: value }); + this.setState({shouldShowSignoutConfirmModal: value}); } getMenuItem(item, index) { @@ -220,6 +210,16 @@ class InitialSettingsPage extends React.Component { ); } + signOut(shouldForceSignout = false) { + if (!this.props.network.isOffline || shouldForceSignout) { + Session.signOutAndRedirectToSignIn(); + return; + } + + // When offline, warn the user that any actions they took while offline will be lost if they sign out + this.toggleSignoutConfirmModal(true); + } + openProfileSettings() { Navigation.navigate(ROUTES.SETTINGS_PROFILE); } From a241d06c4916d6d0451d55d6b25c99918caeb0c4 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Mon, 21 Nov 2022 18:37:57 +0000 Subject: [PATCH 7/8] Fix more lint errors --- src/pages/settings/InitialSettingsPage.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/settings/InitialSettingsPage.js b/src/pages/settings/InitialSettingsPage.js index d50c8d94dc07..c2bf6b384b87 100755 --- a/src/pages/settings/InitialSettingsPage.js +++ b/src/pages/settings/InitialSettingsPage.js @@ -98,6 +98,7 @@ class InitialSettingsPage extends React.Component { this.getWalletBalance = this.getWalletBalance.bind(this); this.getDefaultMenuItems = this.getDefaultMenuItems.bind(this); this.getMenuItem = this.getMenuItem.bind(this); + this.toggleSignoutConfirmModal = this.toggleSignoutConfirmModal.bind(this); this.signout = this.signOut.bind(this); this.state = { @@ -183,10 +184,6 @@ class InitialSettingsPage extends React.Component { ]); } - toggleSignoutConfirmModal(value) { - this.setState({shouldShowSignoutConfirmModal: value}); - } - getMenuItem(item, index) { const keyTitle = item.translationKey ? this.props.translate(item.translationKey) : item.title; const isPaymentItem = item.translationKey === 'common.payments'; @@ -210,6 +207,10 @@ class InitialSettingsPage extends React.Component { ); } + toggleSignoutConfirmModal(value) { + this.setState({shouldShowSignoutConfirmModal: value}); + } + signOut(shouldForceSignout = false) { if (!this.props.network.isOffline || shouldForceSignout) { Session.signOutAndRedirectToSignIn(); From 5cb9403d4340309373cc3f3db30f3f7137ec5b7e Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Wed, 23 Nov 2022 15:59:26 +0000 Subject: [PATCH 8/8] Add translation --- src/languages/es.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/es.js b/src/languages/es.js index 470d7dbd4ae7..60a21ef31c48 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -363,7 +363,7 @@ export default { }, security: 'Seguridad', signOut: 'Desconectar', - signOutConfirmationText: '', + signOutConfirmationText: 'Si cierras sesión perderás los cambios hechos mientras estabas desconectado', versionLetter: 'v', readTheTermsAndPrivacyPolicy: { phrase1: 'Leer los',