Unverified Commit 46689930 authored by Reinaldo Neto's avatar Reinaldo Neto Committed by GitHub
Browse files

[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: default avatarGerzon Z <gerzonc@icloud.com>
Co-authored-by: default avatarDiego Mello <diegolmello@gmail.com>
parent 8517b1fd
......@@ -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
};
}
......
......@@ -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
......@@ -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
......@@ -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:
......
......@@ -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') }));
}
};
......
......@@ -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));
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment