[NEW] Logout from other logged in locations (#2386)
* Logout from other logged in locations * Add UI feedback for the request result * Refactor request to use the proper REST API * Change backgroundColor * I18n Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
49ea816f5c
commit
67ecab7169
|
@ -631,5 +631,9 @@ export default {
|
|||
After_seconds_set_by_admin: 'After {{seconds}} seconds (set by admin)',
|
||||
Dont_activate: 'Don\'t activate now',
|
||||
Queued_chats: 'Queued chats',
|
||||
Queue_is_empty: 'Queue is empty'
|
||||
Queue_is_empty: 'Queue is empty',
|
||||
Logout_from_other_logged_in_locations: 'Logout from other logged in locations',
|
||||
You_will_be_logged_out_from_other_locations: 'You\'ll be logged out from other locations.',
|
||||
Logged_out_of_other_clients_successfully: 'Logged out of other clients successfully',
|
||||
Logout_failed: 'Logout failed!'
|
||||
};
|
||||
|
|
|
@ -577,5 +577,9 @@ export default {
|
|||
After_seconds_set_by_admin: 'Após {{seconds}} segundos (Configurado pelo adm)',
|
||||
Dont_activate: 'Não ativar agora',
|
||||
Queued_chats: 'Bate-papos na fila',
|
||||
Queue_is_empty: 'A fila está vazia'
|
||||
Queue_is_empty: 'A fila está vazia',
|
||||
Logout_from_other_logged_in_locations: 'Sair de outros locais logados',
|
||||
You_will_be_logged_out_from_other_locations: 'Você perderá a sessão de outros clientes',
|
||||
Logged_out_of_other_clients_successfully: 'Desconectado de outros clientes com sucesso',
|
||||
Logout_failed: 'Falha ao desconectar!'
|
||||
};
|
||||
|
|
|
@ -419,6 +419,10 @@ const RocketChat = {
|
|||
return user;
|
||||
},
|
||||
logout,
|
||||
logoutOtherLocations() {
|
||||
const { id: userId } = reduxStore.getState().login.user;
|
||||
return this.sdk.post('users.removeOtherTokens', { userId });
|
||||
},
|
||||
removeServer,
|
||||
async clearCache({ server }) {
|
||||
try {
|
||||
|
|
|
@ -119,6 +119,8 @@ export default {
|
|||
PROFILE_SAVE_AVATAR_F: 'profile_save_avatar_f',
|
||||
PROFILE_SAVE_CHANGES: 'profile_save_changes',
|
||||
PROFILE_SAVE_CHANGES_F: 'profile_save_changes_f',
|
||||
PROFILE_LOGOUT_OTHER_LOCATIONS: 'profile_logout_other_locations',
|
||||
PROFILE_LOGOUT_OTHER_LOCATIONS_F: 'profile_logout_other_locations_f',
|
||||
|
||||
// SETTINGS VIEW
|
||||
SE_CONTACT_US: 'se_contact_us',
|
||||
|
|
|
@ -13,7 +13,7 @@ import KeyboardView from '../../presentation/KeyboardView';
|
|||
import sharedStyles from '../Styles';
|
||||
import styles from './styles';
|
||||
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
||||
import { showErrorAlert } from '../../utils/info';
|
||||
import { showErrorAlert, showConfirmationAlert } from '../../utils/info';
|
||||
import { LISTENER } from '../../containers/Toast';
|
||||
import EventEmitter from '../../utils/events';
|
||||
import RocketChat from '../../lib/rocketchat';
|
||||
|
@ -426,6 +426,23 @@ class ProfileView extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
logoutOtherLocations = () => {
|
||||
logEvent(events.PROFILE_LOGOUT_OTHER_LOCATIONS);
|
||||
showConfirmationAlert({
|
||||
message: I18n.t('You_will_be_logged_out_from_other_locations'),
|
||||
callToAction: I18n.t('Logout'),
|
||||
onPress: async() => {
|
||||
try {
|
||||
await RocketChat.logoutOtherLocations();
|
||||
EventEmitter.emit(LISTENER, { message: I18n.t('Logged_out_of_other_clients_successfully') });
|
||||
} catch {
|
||||
logEvent(events.PROFILE_LOGOUT_OTHER_LOCATIONS_F);
|
||||
EventEmitter.emit(LISTENER, { message: I18n.t('Logout_failed') });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
name, username, email, newPassword, avatarUrl, customFields, avatar, saving
|
||||
|
@ -552,6 +569,14 @@ class ProfileView extends React.Component {
|
|||
loading={saving}
|
||||
theme={theme}
|
||||
/>
|
||||
<Button
|
||||
title={I18n.t('Logout_from_other_logged_in_locations')}
|
||||
type='secondary'
|
||||
backgroundColor={themes[theme].chatComponentBackground}
|
||||
onPress={this.logoutOtherLocations}
|
||||
testID='profile-view-logout-other-locations'
|
||||
theme={theme}
|
||||
/>
|
||||
</ScrollView>
|
||||
</SafeAreaView>
|
||||
</KeyboardView>
|
||||
|
|
Loading…
Reference in New Issue