[FIX] App not showing proper alert on team delete (#3219)

* [FIX] Rule to delete team's channel

* Fixed Saga and flow to delete team and team's channel

* Adjusted the warning alert as the Figma

Co-authored-by: Gerzon Z <gerzonc@icloud.com>
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Reinaldo Neto 2021-07-02 16:13:41 -03:00 committed by GitHub
parent 8517b1fd13
commit 46689930c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 47 deletions

View File

@ -23,11 +23,12 @@ export function leaveRoom(roomType, room, selected) {
}; };
} }
export function deleteRoom(rid, t) { export function deleteRoom(roomType, room, selected) {
return { return {
type: types.ROOM.DELETE, type: types.ROOM.DELETE,
rid, room,
t roomType,
selected
}; };
} }

View File

@ -762,5 +762,8 @@
"Move_to_Team_Warning": "After reading the previous intructions about this behavior, do you still want to move this channel to the selected team?", "Move_to_Team_Warning": "After reading the previous intructions about this behavior, do you still want to move this channel to the selected team?",
"Load_More": "Load More", "Load_More": "Load More",
"Load_Newer": "Load Newer", "Load_Newer": "Load Newer",
"Load_Older": "Load Older" "Load_Older": "Load Older",
"Left_The_Room_Successfully": "Left the room successfully",
"Deleted_The_Team_Successfully": "Team deleted successfully",
"Deleted_The_Room_Successfully": "Room deleted successfully"
} }

View File

@ -665,5 +665,9 @@
"Team_not_found": "Time não encontrado", "Team_not_found": "Time não encontrado",
"Private_Team": "Equipe Privada", "Private_Team": "Equipe Privada",
"Add_Existing_Channel": "Adicionar Canal Existente", "Add_Existing_Channel": "Adicionar Canal Existente",
"invalid-room": "Sala inválida" "invalid-room": "Sala inválida",
"Left_The_Team_Successfully": "Saiu do time com sucesso",
"Left_The_Room_Successfully": "Saiu da sala com sucesso",
"Deleted_The_Team_Successfully": "Time deletado com sucesso",
"Deleted_The_Room_Successfully": "Sala deletada com sucesso"
} }

View File

@ -28,7 +28,7 @@ export default function(state = initialState, action) {
case ROOM.DELETE: case ROOM.DELETE:
return { return {
...state, ...state,
rid: action.rid, rid: action.room.rid,
isDeleting: true isDeleting: true
}; };
case ROOM.CLOSE: case ROOM.CLOSE:

View File

@ -32,7 +32,7 @@ const watchUserTyping = function* watchUserTyping({ rid, status }) {
} }
}; };
const handleRemovedRoom = function* handleRemovedRoom(roomType) { const handleRemovedRoom = function* handleRemovedRoom(roomType, actionType) {
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');
@ -40,9 +40,13 @@ const handleRemovedRoom = function* handleRemovedRoom(roomType) {
yield Navigation.navigate('RoomsListView'); yield Navigation.navigate('RoomsListView');
} }
if (roomType === 'team') { if (actionType === 'leave') {
EventEmitter.emit(LISTENER, { message: I18n.t('Left_The_Team_Successfully') }); EventEmitter.emit(LISTENER, { message: roomType === 'team' ? I18n.t('Left_The_Team_Successfully') : I18n.t('Left_The_Room_Successfully') });
} }
if (actionType === 'delete') {
EventEmitter.emit(LISTENER, { message: roomType === 'team' ? I18n.t('Deleted_The_Team_Successfully') : I18n.t('Deleted_The_Room_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({
@ -66,7 +70,7 @@ const handleLeaveRoom = function* handleLeaveRoom({ room, roomType, selected })
} }
if (result?.success) { if (result?.success) {
yield handleRemovedRoom(roomType); yield handleRemovedRoom(roomType, 'leave');
} }
} catch (e) { } catch (e) {
logEvent(events.RA_LEAVE_F); logEvent(events.RA_LEAVE_F);
@ -80,16 +84,23 @@ const handleLeaveRoom = function* handleLeaveRoom({ room, roomType, selected })
} }
}; };
const handleDeleteRoom = function* handleDeleteRoom({ rid, t }) { const handleDeleteRoom = function* handleDeleteRoom({ room, roomType, selected }) {
logEvent(events.RI_EDIT_DELETE); logEvent(events.RI_EDIT_DELETE);
try { try {
const result = yield RocketChat.deleteRoom(rid, t); let result = {};
if (result.success) {
yield handleRemovedRoom(); if (roomType === 'channel') {
result = yield RocketChat.deleteRoom(room.rid, room.t);
} else if (roomType === 'team') {
result = yield RocketChat.deleteTeam({ teamId: room.teamId, ...(selected && { roomsToRemove: selected }) });
}
if (result?.success) {
yield handleRemovedRoom(roomType, 'delete');
} }
} catch (e) { } catch (e) {
logEvent(events.RI_EDIT_DELETE_F); logEvent(events.RI_EDIT_DELETE_F);
Alert.alert(I18n.t('Oops'), I18n.t('There_was_an_error_while_action', { action: I18n.t('deleting_room') })); Alert.alert(I18n.t('Oops'), I18n.t('There_was_an_error_while_action', { action: roomType === 'team' ? I18n.t('deleting_team') : I18n.t('deleting_room') }));
} }
}; };

View File

@ -292,34 +292,11 @@ class RoomInfoEditView extends React.Component {
}, 100); }, 100);
} }
handleDeleteTeam = async(selected) => {
logEvent(events.RI_EDIT_DELETE_TEAM);
const { navigation, isMasterDetail } = this.props;
const { room } = this.state;
try {
const result = await RocketChat.deleteTeam({ teamId: room.teamId, ...(selected && { roomsToRemove: selected }) });
if (result.success) {
if (isMasterDetail) {
navigation.navigate('DrawerNavigator');
} else {
navigation.navigate('RoomsListView');
}
}
} catch (e) {
logEvent(events.RI_EDIT_DELETE_TEAM_F);
log(e);
showErrorAlert(
e.data.error
? I18n.t(e.data.error)
: I18n.t('There_was_an_error_while_action', { action: I18n.t('deleting_team') }),
I18n.t('Cannot_delete')
);
}
}
deleteTeam = async() => { deleteTeam = async() => {
const { room } = this.state; const { room } = this.state;
const { navigation } = this.props; const {
navigation, deleteCPermission, deletePPermission, deleteRoom
} = this.props;
try { try {
const db = database.active; const db = database.active;
@ -329,16 +306,27 @@ class RoomInfoEditView extends React.Component {
Q.where('team_main', Q.notEq(true)) Q.where('team_main', Q.notEq(true))
); );
if (teamChannels.length) { const teamChannelOwner = [];
for (let i = 0; i < teamChannels.length; i += 1) {
const permissionType = teamChannels[i].t === 'c' ? deleteCPermission : deletePPermission;
// eslint-disable-next-line no-await-in-loop
const permissions = await RocketChat.hasPermission([
permissionType
], teamChannels[i].rid);
if (permissions[0]) { teamChannelOwner.push(teamChannels[i]); }
}
if (teamChannelOwner.length) {
navigation.navigate('SelectListView', { navigation.navigate('SelectListView', {
title: 'Delete_Team', title: 'Delete_Team',
data: teamChannels, data: teamChannelOwner,
infoText: 'Select_channels_to_delete', infoText: 'Select_channels_to_delete',
nextAction: (selected) => { nextAction: (selected) => {
showConfirmationAlert({ showConfirmationAlert({
message: I18n.t('You_are_deleting_the_team', { team: RocketChat.getRoomTitle(room) }), message: I18n.t('You_are_deleting_the_team', { team: RocketChat.getRoomTitle(room) }),
confirmationText: I18n.t('Yes_action_it', { action: I18n.t('delete') }), confirmationText: I18n.t('Yes_action_it', { action: I18n.t('delete') }),
onPress: () => this.handleDeleteTeam(selected) onPress: () => deleteRoom('team', room, selected)
}); });
} }
}); });
@ -346,7 +334,7 @@ class RoomInfoEditView extends React.Component {
showConfirmationAlert({ showConfirmationAlert({
message: I18n.t('You_are_deleting_the_team', { team: RocketChat.getRoomTitle(room) }), message: I18n.t('You_are_deleting_the_team', { team: RocketChat.getRoomTitle(room) }),
confirmationText: I18n.t('Yes_action_it', { action: I18n.t('delete') }), confirmationText: I18n.t('Yes_action_it', { action: I18n.t('delete') }),
onPress: () => this.handleDeleteTeam() onPress: () => deleteRoom('team', room)
}); });
} }
} catch (e) { } catch (e) {
@ -375,7 +363,7 @@ class RoomInfoEditView extends React.Component {
{ {
text: I18n.t('Yes_action_it', { action: I18n.t('delete') }), text: I18n.t('Yes_action_it', { action: I18n.t('delete') }),
style: 'destructive', style: 'destructive',
onPress: () => deleteRoom(room.rid, room.t) onPress: () => deleteRoom('channel', room)
} }
], ],
{ cancelable: false } { cancelable: false }
@ -767,7 +755,7 @@ const mapStateToProps = state => ({
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
deleteRoom: (rid, t) => dispatch(deleteRoomAction(rid, t)) deleteRoom: (roomType, room, selected) => dispatch(deleteRoomAction(roomType, room, selected))
}); });
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(RoomInfoEditView)); export default connect(mapStateToProps, mapDispatchToProps)(withTheme(RoomInfoEditView));