Skip to content

Commit

Permalink
#916 Redirect user when leaving or deleting channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane VIEIRA committed Feb 15, 2021
1 parent 685328b commit b872c78
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,26 @@ export default (props: Props): JSX.Element => {

const leaveChannel = async () => {
if (props.channel.data.user_member) {
//Fixme, this is not pretty, we should find a way to do this in one line
const channelMember = new ChannelMemberResource({
...props.channel.data.user_member,
});
channelMember.setPersisted();
await channelMembersCollection.upsert(channelMember, { withoutBackend: true });
return await channelMembersCollection.remove(channelMember);

try {
//Fixme, this is not pretty, we should find a way to do this in one line
channelMember.setPersisted();
await channelMembersCollection.upsert(channelMember, { withoutBackend: true });
await channelMembersCollection.remove(channelMember).then(redirectToWorkspace);
} catch (err) {
console.log('Error in ChannelMenu.tsx', err);
}
}
};

const redirectToWorkspace = () => {
const url = RouterServices.generateRouteFromState({ workspaceId: workspaceId, channelId: '' });
return RouterServices.history.push(url);
};

const editChannel = () => {
ModalManager.open(
<ChannelWorkspaceEditor
Expand All @@ -98,9 +108,8 @@ export default (props: Props): JSX.Element => {
);
};

const removeChannel = () => {
return channelsCollection.remove({ id: props.channel.data.id });
};
const removeChannel = async () =>
await channelsCollection.remove({ id: props.channel.data.id }).then(redirectToWorkspace);

let menu: object[] = [
{
Expand Down Expand Up @@ -141,18 +150,12 @@ export default (props: Props): JSX.Element => {
),
className: 'danger',
onClick: () => {
AlertManager.confirm(() => leaveChannel(), undefined, {
title: Languages.t(
isDirectChannel
? 'scenes.app.channelsbar.hide_discussion_leaving.title'
: 'components.alert.confirm',
),
text: Languages.t(
isDirectChannel
? 'scenes.app.channelsbar.hide_discussion_leaving.content'
: 'components.alert.confirm_click',
),
});
if (props.channel.data.visibility === 'private') {
return AlertManager.confirm(() => leaveChannel(), undefined, {
title: Languages.t('components.alert.leave_private_channel.title'),
text: Languages.t('components.alert.leave_private_channel.description'),
});
} else return leaveChannel();
},
},
];
Expand Down
3 changes: 3 additions & 0 deletions twake/frontend/src/app/services/languages/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1897,4 +1897,7 @@ export default {
'scenes.apps.messages.message.activity_message.a_deleted_channel_connector':
'$1 removed a connector $2',
'scenes.client.channelbar.channelmemberslist.tag': "It's you",
'components.alert.leave_private_channel.title': 'Are you sure you want to leave the channel ?',
'components.alert.leave_private_channel.description':
'You will not be able to join this private channel again unless someone invite you.',
};
3 changes: 3 additions & 0 deletions twake/frontend/src/app/services/languages/locale/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -1968,4 +1968,7 @@ export default {
'scenes.apps.messages.message.activity_message.a_deleted_channel_connector':
'$1 a supprimé le connecteur $2',
'scenes.client.channelbar.channelmemberslist.tag': "C'est vous",
'components.alert.leave_private_channel.title': 'Voulez-vous vraiment quitter la chaîne?',
'components.alert.leave_private_channel.description':
"Vous ne pourrez plus rejoindre cette chaîne privée à moins que quelqu'un ne vous invite.",
};

0 comments on commit b872c78

Please sign in to comment.