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 7e8fc4a
Showing 1 changed file with 22 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

0 comments on commit 7e8fc4a

Please sign in to comment.