[FIX] App not showing proper alert on team leave (#3161)
* [IMPROVEMENT] refactoring how to leave team * Fix the data passed to leaveTeam * Fixed the lint error in i18n, the path of i18n, merged two ifs in one * Fixed the Saga's flow when try to leave a room * Fixed params passed to leaveRoom * Fix the function name of leaveTeam Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
29ccb47456
commit
0b7461e800
|
@ -14,11 +14,12 @@ export function unsubscribeRoom(rid) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function leaveRoom(rid, t) {
|
export function leaveRoom(roomType, room, selected) {
|
||||||
return {
|
return {
|
||||||
type: types.ROOM.LEAVE,
|
type: types.ROOM.LEAVE,
|
||||||
rid,
|
room,
|
||||||
t
|
roomType,
|
||||||
|
selected
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -724,6 +724,7 @@
|
||||||
"creating_team": "creating team",
|
"creating_team": "creating team",
|
||||||
"team-name-already-exists": "A team with that name already exists",
|
"team-name-already-exists": "A team with that name already exists",
|
||||||
"Add_Channel_to_Team": "Add Channel to Team",
|
"Add_Channel_to_Team": "Add Channel to Team",
|
||||||
|
"Left_The_Team_Successfully": "Left the team successfully",
|
||||||
"Create_New": "Create New",
|
"Create_New": "Create New",
|
||||||
"Add_Existing": "Add Existing",
|
"Add_Existing": "Add Existing",
|
||||||
"Add_Existing_Channel": "Add Existing Channel",
|
"Add_Existing_Channel": "Add Existing Channel",
|
||||||
|
|
|
@ -22,7 +22,7 @@ export default function(state = initialState, action) {
|
||||||
case ROOM.LEAVE:
|
case ROOM.LEAVE:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
rid: action.rid,
|
rid: action.room.rid,
|
||||||
isDeleting: true
|
isDeleting: true
|
||||||
};
|
};
|
||||||
case ROOM.DELETE:
|
case ROOM.DELETE:
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
takeLatest, take, select, delay, race, put
|
takeLatest, take, select, delay, race, put
|
||||||
} from 'redux-saga/effects';
|
} from 'redux-saga/effects';
|
||||||
|
|
||||||
|
import EventEmitter from '../utils/events';
|
||||||
import Navigation from '../lib/Navigation';
|
import Navigation from '../lib/Navigation';
|
||||||
import * as types from '../actions/actionsTypes';
|
import * as types from '../actions/actionsTypes';
|
||||||
import { removedRoom } from '../actions/room';
|
import { removedRoom } from '../actions/room';
|
||||||
|
@ -11,6 +12,7 @@ import RocketChat from '../lib/rocketchat';
|
||||||
import log, { logEvent, events } from '../utils/log';
|
import log, { logEvent, events } from '../utils/log';
|
||||||
import I18n from '../i18n';
|
import I18n from '../i18n';
|
||||||
import { showErrorAlert } from '../utils/info';
|
import { showErrorAlert } from '../utils/info';
|
||||||
|
import { LISTENER } from '../containers/Toast';
|
||||||
|
|
||||||
const watchUserTyping = function* watchUserTyping({ rid, status }) {
|
const watchUserTyping = function* watchUserTyping({ rid, status }) {
|
||||||
const auth = yield select(state => state.login.isAuthenticated);
|
const auth = yield select(state => state.login.isAuthenticated);
|
||||||
|
@ -30,13 +32,18 @@ const watchUserTyping = function* watchUserTyping({ rid, status }) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemovedRoom = function* handleRemovedRoom() {
|
const handleRemovedRoom = function* handleRemovedRoom(roomType) {
|
||||||
const isMasterDetail = yield select(state => state.app.isMasterDetail);
|
const isMasterDetail = yield select(state => state.app.isMasterDetail);
|
||||||
if (isMasterDetail) {
|
if (isMasterDetail) {
|
||||||
yield Navigation.navigate('DrawerNavigator');
|
yield Navigation.navigate('DrawerNavigator');
|
||||||
} else {
|
} else {
|
||||||
yield Navigation.navigate('RoomsListView');
|
yield Navigation.navigate('RoomsListView');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (roomType === 'team') {
|
||||||
|
EventEmitter.emit(LISTENER, { message: I18n.t('Left_The_Team_Successfully') });
|
||||||
|
}
|
||||||
|
|
||||||
// types.ROOM.REMOVE is triggered by `subscriptions-changed` with `removed` arg
|
// types.ROOM.REMOVE is triggered by `subscriptions-changed` with `removed` arg
|
||||||
const { timeout } = yield race({
|
const { timeout } = yield race({
|
||||||
deleteFinished: take(types.ROOM.REMOVED),
|
deleteFinished: take(types.ROOM.REMOVED),
|
||||||
|
@ -47,12 +54,19 @@ const handleRemovedRoom = function* handleRemovedRoom() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLeaveRoom = function* handleLeaveRoom({ rid, t }) {
|
const handleLeaveRoom = function* handleLeaveRoom({ room, roomType, selected }) {
|
||||||
logEvent(events.RA_LEAVE);
|
logEvent(events.RA_LEAVE);
|
||||||
try {
|
try {
|
||||||
const result = yield RocketChat.leaveRoom(rid, t);
|
let result = {};
|
||||||
if (result.success) {
|
|
||||||
yield handleRemovedRoom();
|
if (roomType === 'channel') {
|
||||||
|
result = yield RocketChat.leaveRoom(room.rid, room.t);
|
||||||
|
} else if (roomType === 'team') {
|
||||||
|
result = yield RocketChat.leaveTeam({ teamName: room.name, ...(selected && { rooms: selected }) });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result?.success) {
|
||||||
|
yield handleRemovedRoom(roomType);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logEvent(events.RA_LEAVE_F);
|
logEvent(events.RA_LEAVE_F);
|
||||||
|
|
|
@ -10,7 +10,9 @@ import { Q } from '@nozbe/watermelondb';
|
||||||
import { compareServerVersion, methods } from '../../lib/utils';
|
import { compareServerVersion, methods } from '../../lib/utils';
|
||||||
import Touch from '../../utils/touch';
|
import Touch from '../../utils/touch';
|
||||||
import { setLoading as setLoadingAction } from '../../actions/selectedUsers';
|
import { setLoading as setLoadingAction } from '../../actions/selectedUsers';
|
||||||
import { leaveRoom as leaveRoomAction, closeRoom as closeRoomAction } from '../../actions/room';
|
import {
|
||||||
|
leaveRoom as leaveRoomAction, closeRoom as closeRoomAction
|
||||||
|
} from '../../actions/room';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
import sharedStyles from '../Styles';
|
import sharedStyles from '../Styles';
|
||||||
import Avatar from '../../containers/Avatar';
|
import Avatar from '../../containers/Avatar';
|
||||||
|
@ -54,7 +56,6 @@ class RoomActionsView extends React.Component {
|
||||||
theme: PropTypes.string,
|
theme: PropTypes.string,
|
||||||
fontScale: PropTypes.number,
|
fontScale: PropTypes.number,
|
||||||
serverVersion: PropTypes.string,
|
serverVersion: PropTypes.string,
|
||||||
isMasterDetail: PropTypes.bool,
|
|
||||||
addUserToJoinedRoomPermission: PropTypes.array,
|
addUserToJoinedRoomPermission: PropTypes.array,
|
||||||
addUserToAnyCRoomPermission: PropTypes.array,
|
addUserToAnyCRoomPermission: PropTypes.array,
|
||||||
addUserToAnyPRoomPermission: PropTypes.array,
|
addUserToAnyPRoomPermission: PropTypes.array,
|
||||||
|
@ -426,39 +427,13 @@ class RoomActionsView extends React.Component {
|
||||||
showConfirmationAlert({
|
showConfirmationAlert({
|
||||||
message: I18n.t('Are_you_sure_you_want_to_leave_the_room', { room: RocketChat.getRoomTitle(room) }),
|
message: I18n.t('Are_you_sure_you_want_to_leave_the_room', { room: RocketChat.getRoomTitle(room) }),
|
||||||
confirmationText: I18n.t('Yes_action_it', { action: I18n.t('leave') }),
|
confirmationText: I18n.t('Yes_action_it', { action: I18n.t('leave') }),
|
||||||
onPress: () => leaveRoom(room.rid, room.t)
|
onPress: () => leaveRoom('channel', room)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLeaveTeam = async(selected) => {
|
|
||||||
logEvent(events.RA_LEAVE_TEAM);
|
|
||||||
try {
|
|
||||||
const { room } = this.state;
|
|
||||||
const { navigation, isMasterDetail } = this.props;
|
|
||||||
const result = await RocketChat.leaveTeam({ teamName: room.name, ...(selected && { rooms: selected }) });
|
|
||||||
|
|
||||||
if (result.success) {
|
|
||||||
if (isMasterDetail) {
|
|
||||||
navigation.navigate('DrawerNavigator');
|
|
||||||
} else {
|
|
||||||
navigation.navigate('RoomsListView');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
logEvent(events.RA_LEAVE_TEAM_F);
|
|
||||||
log(e);
|
|
||||||
showErrorAlert(
|
|
||||||
e.data.error
|
|
||||||
? I18n.t(e.data.error)
|
|
||||||
: I18n.t('There_was_an_error_while_action', { action: I18n.t('leaving_team') }),
|
|
||||||
I18n.t('Cannot_leave')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
leaveTeam = async() => {
|
leaveTeam = async() => {
|
||||||
const { room } = this.state;
|
const { room } = this.state;
|
||||||
const { navigation } = this.props;
|
const { navigation, leaveRoom } = this.props;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
|
@ -479,21 +454,21 @@ class RoomActionsView extends React.Component {
|
||||||
title: 'Leave_Team',
|
title: 'Leave_Team',
|
||||||
data: teamChannels,
|
data: teamChannels,
|
||||||
infoText: 'Select_Team_Channels',
|
infoText: 'Select_Team_Channels',
|
||||||
nextAction: data => this.handleLeaveTeam(data),
|
nextAction: data => leaveRoom('team', room, data),
|
||||||
showAlert: () => showErrorAlert(I18n.t('Last_owner_team_room'), I18n.t('Cannot_leave'))
|
showAlert: () => showErrorAlert(I18n.t('Last_owner_team_room'), I18n.t('Cannot_leave'))
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
showConfirmationAlert({
|
showConfirmationAlert({
|
||||||
message: I18n.t('You_are_leaving_the_team', { team: RocketChat.getRoomTitle(room) }),
|
message: I18n.t('You_are_leaving_the_team', { team: RocketChat.getRoomTitle(room) }),
|
||||||
confirmationText: I18n.t('Yes_action_it', { action: I18n.t('leave') }),
|
confirmationText: I18n.t('Yes_action_it', { action: I18n.t('leave') }),
|
||||||
onPress: () => this.handleLeaveTeam()
|
onPress: () => leaveRoom('team', room)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showConfirmationAlert({
|
showConfirmationAlert({
|
||||||
message: I18n.t('You_are_leaving_the_team', { team: RocketChat.getRoomTitle(room) }),
|
message: I18n.t('You_are_leaving_the_team', { team: RocketChat.getRoomTitle(room) }),
|
||||||
confirmationText: I18n.t('Yes_action_it', { action: I18n.t('leave') }),
|
confirmationText: I18n.t('Yes_action_it', { action: I18n.t('leave') }),
|
||||||
onPress: () => this.handleLeaveTeam()
|
onPress: () => leaveRoom('team', room)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1122,7 +1097,7 @@ const mapStateToProps = state => ({
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
leaveRoom: (rid, t) => dispatch(leaveRoomAction(rid, t)),
|
leaveRoom: (roomType, room, selected) => dispatch(leaveRoomAction(roomType, room, selected)),
|
||||||
closeRoom: rid => dispatch(closeRoomAction(rid)),
|
closeRoom: rid => dispatch(closeRoomAction(rid)),
|
||||||
setLoadingInvite: loading => dispatch(setLoadingAction(loading))
|
setLoadingInvite: loading => dispatch(setLoadingAction(loading))
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue