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'; ...@@ -14,6 +14,7 @@ import Navigation from '../lib/Navigation';
import { getMessageTranslation } from './message/utils'; import { getMessageTranslation } from './message/utils';
import { LISTENER } from './Toast'; import { LISTENER } from './Toast';
import EventEmitter from '../utils/events'; import EventEmitter from '../utils/events';
import { showConfirmationAlert } from '../utils/info';
class MessageActions extends React.Component { class MessageActions extends React.Component {
static propTypes = { static propTypes = {
...@@ -223,29 +224,18 @@ class MessageActions extends React.Component { ...@@ -223,29 +224,18 @@ class MessageActions extends React.Component {
} }
handleDelete = () => { handleDelete = () => {
const { message } = this.props; showConfirmationAlert({
Alert.alert( message: I18n.t('You_will_not_be_able_to_recover_this_message'),
I18n.t('Are_you_sure_question_mark'), callToAction: I18n.t('Delete'),
I18n.t('You_will_not_be_able_to_recover_this_message'), onPress: async() => {
[ const { message } = this.props;
{ try {
text: I18n.t('Cancel'), await RocketChat.deleteMessage(message.id, message.subscription.id);
style: 'cancel' } catch (e) {
}, log(e);
{
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);
}
}
} }
], }
{ cancelable: false } });
);
} }
handleEdit = () => { handleEdit = () => {
......
...@@ -491,5 +491,8 @@ export default { ...@@ -491,5 +491,8 @@ export default {
Server_selection: 'Server selection', Server_selection: 'Server selection',
Server_selection_numbers: 'Server selection 1...9', Server_selection_numbers: 'Server selection 1...9',
Add_server: 'Add server', 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 { ...@@ -440,5 +440,8 @@ export default {
Server_selection: 'Seleção de servidor', Server_selection: 'Seleção de servidor',
Server_selection_numbers: 'Selecionar servidor 1...9', Server_selection_numbers: 'Selecionar servidor 1...9',
Add_server: 'Adicionar servidor', 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 { 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 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 { ...@@ -22,7 +22,7 @@ import {
} from '../../utils/deviceInfo'; } from '../../utils/deviceInfo';
import openLink from '../../utils/openLink'; import openLink from '../../utils/openLink';
import scrollPersistTaps from '../../utils/scrollPersistTaps'; import scrollPersistTaps from '../../utils/scrollPersistTaps';
import { showErrorAlert } from '../../utils/info'; import { showErrorAlert, showConfirmationAlert } from '../../utils/info';
import styles from './styles'; import styles from './styles';
import sharedStyles from '../Styles'; import sharedStyles from '../Styles';
import { loggerConfig, analytics } from '../../utils/log'; import { loggerConfig, analytics } from '../../utils/log';
...@@ -88,21 +88,33 @@ class SettingsView extends React.Component { ...@@ -88,21 +88,33 @@ class SettingsView extends React.Component {
appStart: PropTypes.func appStart: PropTypes.func
} }
logout = () => { handleLogout = () => {
const { logout, split } = this.props; showConfirmationAlert({
if (split) { message: I18n.t('You_will_be_logged_out_of_this_application'),
Navigation.navigate('RoomView'); callToAction: I18n.t('Logout'),
} onPress: () => {
logout(); const { logout, split } = this.props;
if (split) {
Navigation.navigate('RoomView');
}
logout();
}
});
} }
clearCache = async() => { handleClearCache = () => {
const { showConfirmationAlert({
server: { server }, loginRequest, token, appStart message: I18n.t('This_will_clear_all_your_offline_data'),
} = this.props; callToAction: I18n.t('Clear'),
await appStart('loading'); onPress: async() => {
await RocketChat.clearCache({ server }); const {
await loginRequest({ resume: token }, true); server: { server }, loginRequest, token, appStart
} = this.props;
await appStart('loading');
await RocketChat.clearCache({ server });
await loginRequest({ resume: token }, true);
}
});
} }
toggleMarkdown = (value) => { toggleMarkdown = (value) => {
...@@ -329,7 +341,7 @@ class SettingsView extends React.Component { ...@@ -329,7 +341,7 @@ class SettingsView extends React.Component {
<ListItem <ListItem
title={I18n.t('Clear_cache')} title={I18n.t('Clear_cache')}
testID='settings-clear-cache' testID='settings-clear-cache'
onPress={this.clearCache} onPress={this.handleClearCache}
right={this.renderDisclosure} right={this.renderDisclosure}
color={themes[theme].dangerColor} color={themes[theme].dangerColor}
theme={theme} theme={theme}
...@@ -338,7 +350,7 @@ class SettingsView extends React.Component { ...@@ -338,7 +350,7 @@ class SettingsView extends React.Component {
<ListItem <ListItem
title={I18n.t('Logout')} title={I18n.t('Logout')}
testID='settings-logout' testID='settings-logout'
onPress={this.logout} onPress={this.handleLogout}
right={this.renderDisclosure} right={this.renderDisclosure}
color={themes[theme].dangerColor} color={themes[theme].dangerColor}
theme={theme} 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