From 28b5821dae9bd8158d0b3a4f8753b99f76991e11 Mon Sep 17 00:00:00 2001 From: Youssef Muhamad Date: Mon, 10 Feb 2020 11:53:42 -0300 Subject: [PATCH] [NEW] Confirm logout/clear cache (#1688) --- app/containers/MessageActions.js | 34 +++++++++--------------- app/i18n/locales/en.js | 5 +++- app/i18n/locales/pt-BR.js | 5 +++- app/utils/info.js | 20 +++++++++++++++ app/views/SettingsView/index.js | 44 ++++++++++++++++++++------------ 5 files changed, 68 insertions(+), 40 deletions(-) diff --git a/app/containers/MessageActions.js b/app/containers/MessageActions.js index 0c294533a..ab3677fce 100644 --- a/app/containers/MessageActions.js +++ b/app/containers/MessageActions.js @@ -14,6 +14,7 @@ import Navigation from '../lib/Navigation'; import { getMessageTranslation } from './message/utils'; import { LISTENER } from './Toast'; import EventEmitter from '../utils/events'; +import { showConfirmationAlert } from '../utils/info'; class MessageActions extends React.Component { static propTypes = { @@ -223,29 +224,18 @@ class MessageActions extends React.Component { } handleDelete = () => { - const { message } = this.props; - Alert.alert( - I18n.t('Are_you_sure_question_mark'), - I18n.t('You_will_not_be_able_to_recover_this_message'), - [ - { - text: I18n.t('Cancel'), - style: 'cancel' - }, - { - text: I18n.t('Yes_action_it', { action: 'delete' }), - style: 'destructive', - onPress: async() => { - try { - await RocketChat.deleteMessage(message.id, message.subscription.id); - } catch (e) { - log(e); - } - } + showConfirmationAlert({ + message: I18n.t('You_will_not_be_able_to_recover_this_message'), + callToAction: I18n.t('Delete'), + onPress: async() => { + const { message } = this.props; + try { + await RocketChat.deleteMessage(message.id, message.subscription.id); + } catch (e) { + log(e); } - ], - { cancelable: false } - ); + } + }); } handleEdit = () => { diff --git a/app/i18n/locales/en.js b/app/i18n/locales/en.js index 6d3a3d474..7f2f83007 100644 --- a/app/i18n/locales/en.js +++ b/app/i18n/locales/en.js @@ -491,5 +491,8 @@ export default { Server_selection: 'Server selection', Server_selection_numbers: 'Server selection 1...9', Add_server: 'Add server', - New_line: 'New line' + New_line: 'New line', + You_will_be_logged_out_of_this_application: 'You will be logged out of this application.', + Clear: 'Clear', + This_will_clear_all_your_offline_data: 'This will clear all your offline data.' }; diff --git a/app/i18n/locales/pt-BR.js b/app/i18n/locales/pt-BR.js index f438ca0cb..3835a602e 100644 --- a/app/i18n/locales/pt-BR.js +++ b/app/i18n/locales/pt-BR.js @@ -440,5 +440,8 @@ export default { Server_selection: 'Seleção de servidor', Server_selection_numbers: 'Selecionar servidor 1...9', Add_server: 'Adicionar servidor', - New_line: 'Nova linha' + New_line: 'Nova linha', + You_will_be_logged_out_of_this_application: 'Você sairá deste aplicativo.', + Clear: 'Limpar', + This_will_clear_all_your_offline_data: 'Isto limpará todos os seus dados offline.' }; diff --git a/app/utils/info.js b/app/utils/info.js index 62564122e..8114ef2aa 100644 --- a/app/utils/info.js +++ b/app/utils/info.js @@ -1,3 +1,23 @@ import { Alert } from 'react-native'; +import I18n from '../i18n'; export const showErrorAlert = (message, title, onPress = () => {}) => Alert.alert(title, message, [{ text: 'OK', onPress }], { cancelable: true }); + +export const showConfirmationAlert = ({ message, callToAction, onPress }) => ( + Alert.alert( + I18n.t('Are_you_sure_question_mark'), + message, + [ + { + text: I18n.t('Cancel'), + style: 'cancel' + }, + { + text: callToAction, + style: 'destructive', + onPress + } + ], + { cancelable: false } + ) +); diff --git a/app/views/SettingsView/index.js b/app/views/SettingsView/index.js index d9e24a457..17cd34ef0 100644 --- a/app/views/SettingsView/index.js +++ b/app/views/SettingsView/index.js @@ -22,7 +22,7 @@ import { } from '../../utils/deviceInfo'; import openLink from '../../utils/openLink'; import scrollPersistTaps from '../../utils/scrollPersistTaps'; -import { showErrorAlert } from '../../utils/info'; +import { showErrorAlert, showConfirmationAlert } from '../../utils/info'; import styles from './styles'; import sharedStyles from '../Styles'; import { loggerConfig, analytics } from '../../utils/log'; @@ -88,21 +88,33 @@ class SettingsView extends React.Component { appStart: PropTypes.func } - logout = () => { - const { logout, split } = this.props; - if (split) { - Navigation.navigate('RoomView'); - } - logout(); + handleLogout = () => { + showConfirmationAlert({ + message: I18n.t('You_will_be_logged_out_of_this_application'), + callToAction: I18n.t('Logout'), + onPress: () => { + const { logout, split } = this.props; + if (split) { + Navigation.navigate('RoomView'); + } + logout(); + } + }); } - clearCache = async() => { - const { - server: { server }, loginRequest, token, appStart - } = this.props; - await appStart('loading'); - await RocketChat.clearCache({ server }); - await loginRequest({ resume: token }, true); + handleClearCache = () => { + showConfirmationAlert({ + message: I18n.t('This_will_clear_all_your_offline_data'), + callToAction: I18n.t('Clear'), + onPress: async() => { + const { + server: { server }, loginRequest, token, appStart + } = this.props; + await appStart('loading'); + await RocketChat.clearCache({ server }); + await loginRequest({ resume: token }, true); + } + }); } toggleMarkdown = (value) => { @@ -329,7 +341,7 @@ class SettingsView extends React.Component {