[NEW] Confirm logout/clear cache (#1688)

This commit is contained in:
Youssef Muhamad 2020-02-10 11:53:42 -03:00 committed by GitHub
parent b90cf9e486
commit 28b5821dae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 40 deletions

View File

@ -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 = () => {

View File

@ -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.'
};

View File

@ -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.'
};

View File

@ -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 }
)
);

View File

@ -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 {
<ListItem
title={I18n.t('Clear_cache')}
testID='settings-clear-cache'
onPress={this.clearCache}
onPress={this.handleClearCache}
right={this.renderDisclosure}
color={themes[theme].dangerColor}
theme={theme}
@ -338,7 +350,7 @@ class SettingsView extends React.Component {
<ListItem
title={I18n.t('Logout')}
testID='settings-logout'
onPress={this.logout}
onPress={this.handleLogout}
right={this.renderDisclosure}
color={themes[theme].dangerColor}
theme={theme}