Unverified Commit 28b5821d authored by Youssef Muhamad's avatar Youssef Muhamad Committed by GitHub
Browse files

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

parent b90cf9e4
......@@ -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',
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 = () => {
......
......@@ -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.'
};
......@@ -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.'
};
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 }
)
);
......@@ -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,15 +88,25 @@ class SettingsView extends React.Component {
appStart: PropTypes.func
}
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() => {
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;
......@@ -104,6 +114,8 @@ class SettingsView extends React.Component {
await RocketChat.clearCache({ server });
await loginRequest({ resume: token }, true);
}
});
}
toggleMarkdown = (value) => {
AsyncStorage.setItem(MARKDOWN_KEY, JSON.stringify(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}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment