Skip to content

Commit

Permalink
[FIX] App not showing proper alert on team delete (#3219)
Browse files Browse the repository at this point in the history
* [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>
  • Loading branch information
3 people authored Jul 2, 2021
1 parent 8517b1f commit 4668993
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 47 deletions.
7 changes: 4 additions & 3 deletions app/actions/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

Expand Down
5 changes: 4 additions & 1 deletion app/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
6 changes: 5 additions & 1 deletion app/i18n/locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion app/reducers/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 20 additions & 9 deletions app/sagas/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ 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');
} else {
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({
Expand All @@ -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);
Expand All @@ -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') }));
}
};

Expand Down
52 changes: 20 additions & 32 deletions app/views/RoomInfoEditView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -329,24 +306,35 @@ 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)
});
}
});
} else {
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) {
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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));

0 comments on commit 4668993

Please sign in to comment.