From 46689930c39566d9f52d5c16fad8c72f55e88663 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Fri, 2 Jul 2021 16:13:41 -0300 Subject: [PATCH] [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 Co-authored-by: Diego Mello --- app/actions/room.js | 7 ++-- app/i18n/locales/en.json | 5 ++- app/i18n/locales/pt-BR.json | 6 +++- app/reducers/room.js | 2 +- app/sagas/room.js | 29 +++++++++++----- app/views/RoomInfoEditView/index.js | 52 +++++++++++------------------ 6 files changed, 54 insertions(+), 47 deletions(-) diff --git a/app/actions/room.js b/app/actions/room.js index 4ad7e87f6..2753d7b9a 100644 --- a/app/actions/room.js +++ b/app/actions/room.js @@ -23,11 +23,12 @@ export function leaveRoom(roomType, room, selected) { }; } -export function deleteRoom(rid, t) { +export function deleteRoom(roomType, room, selected) { return { type: types.ROOM.DELETE, - rid, - t + room, + roomType, + selected }; } diff --git a/app/i18n/locales/en.json b/app/i18n/locales/en.json index 926b0c674..723b4dd9e 100644 --- a/app/i18n/locales/en.json +++ b/app/i18n/locales/en.json @@ -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?", "Load_More": "Load More", "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" } \ No newline at end of file diff --git a/app/i18n/locales/pt-BR.json b/app/i18n/locales/pt-BR.json index 9b34d87d3..06b00f685 100644 --- a/app/i18n/locales/pt-BR.json +++ b/app/i18n/locales/pt-BR.json @@ -665,5 +665,9 @@ "Team_not_found": "Time não encontrado", "Private_Team": "Equipe Privada", "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" } \ No newline at end of file diff --git a/app/reducers/room.js b/app/reducers/room.js index de47fcede..980715051 100644 --- a/app/reducers/room.js +++ b/app/reducers/room.js @@ -28,7 +28,7 @@ export default function(state = initialState, action) { case ROOM.DELETE: return { ...state, - rid: action.rid, + rid: action.room.rid, isDeleting: true }; case ROOM.CLOSE: diff --git a/app/sagas/room.js b/app/sagas/room.js index e17a06da9..70a0bc4da 100644 --- a/app/sagas/room.js +++ b/app/sagas/room.js @@ -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); if (isMasterDetail) { yield Navigation.navigate('DrawerNavigator'); @@ -40,9 +40,13 @@ const handleRemovedRoom = function* handleRemovedRoom(roomType) { yield Navigation.navigate('RoomsListView'); } - if (roomType === 'team') { - EventEmitter.emit(LISTENER, { message: I18n.t('Left_The_Team_Successfully') }); + if (actionType === 'leave') { + 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 const { timeout } = yield race({ @@ -66,7 +70,7 @@ const handleLeaveRoom = function* handleLeaveRoom({ room, roomType, selected }) } if (result?.success) { - yield handleRemovedRoom(roomType); + yield handleRemovedRoom(roomType, 'leave'); } } catch (e) { 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); try { - const result = yield RocketChat.deleteRoom(rid, t); - if (result.success) { - yield handleRemovedRoom(); + let result = {}; + + 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) { 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') })); } }; diff --git a/app/views/RoomInfoEditView/index.js b/app/views/RoomInfoEditView/index.js index d5dd7f0c5..28666b2ca 100644 --- a/app/views/RoomInfoEditView/index.js +++ b/app/views/RoomInfoEditView/index.js @@ -292,34 +292,11 @@ class RoomInfoEditView extends React.Component { }, 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() => { const { room } = this.state; - const { navigation } = this.props; + const { + navigation, deleteCPermission, deletePPermission, deleteRoom + } = this.props; try { const db = database.active; @@ -329,16 +306,27 @@ class RoomInfoEditView extends React.Component { 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', { title: 'Delete_Team', - data: teamChannels, + data: teamChannelOwner, infoText: 'Select_channels_to_delete', nextAction: (selected) => { showConfirmationAlert({ message: I18n.t('You_are_deleting_the_team', { team: RocketChat.getRoomTitle(room) }), 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({ message: I18n.t('You_are_deleting_the_team', { team: RocketChat.getRoomTitle(room) }), confirmationText: I18n.t('Yes_action_it', { action: I18n.t('delete') }), - onPress: () => this.handleDeleteTeam() + onPress: () => deleteRoom('team', room) }); } } catch (e) { @@ -375,7 +363,7 @@ class RoomInfoEditView extends React.Component { { text: I18n.t('Yes_action_it', { action: I18n.t('delete') }), style: 'destructive', - onPress: () => deleteRoom(room.rid, room.t) + onPress: () => deleteRoom('channel', room) } ], { cancelable: false } @@ -767,7 +755,7 @@ const mapStateToProps = state => ({ }); 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));