From e9d0fab8d18749372af9d6db650501657d80ae1c Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Thu, 8 Apr 2021 20:32:23 -0400 Subject: [PATCH] MM-29317 Select default team when current team is archived (#5295) --- app/components/post/post.js | 2 +- app/screens/channel/channel_base.js | 4 ++++ app/screens/channel/channel_base.test.js | 10 ++++++++++ app/screens/channel/index.js | 9 ++++++--- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/components/post/post.js b/app/components/post/post.js index 0315ec65c..462e7ed33 100644 --- a/app/components/post/post.js +++ b/app/components/post/post.js @@ -52,7 +52,7 @@ export default class Post extends PureComponent { hasComments: PropTypes.bool, isSearchResult: PropTypes.bool, commentedOnPost: PropTypes.object, - managedConfig: PropTypes.object.isRequired, + managedConfig: PropTypes.object, onHashtagPress: PropTypes.func, onPermalinkPress: PropTypes.func, shouldRenderReplyButton: PropTypes.bool, diff --git a/app/screens/channel/channel_base.js b/app/screens/channel/channel_base.js index 39ad17665..96e71390a 100644 --- a/app/screens/channel/channel_base.js +++ b/app/screens/channel/channel_base.js @@ -132,6 +132,10 @@ export default class ChannelBase extends PureComponent { }); } + if (prevProps.currentTeamId && !this.props.currentTeamId) { + this.props.actions.selectDefaultTeam(); + } + if (this.props.currentTeamId && (!this.props.currentChannelId || this.props.currentTeamId !== prevProps.currentTeamId)) { this.loadChannels(this.props.currentTeamId); diff --git a/app/screens/channel/channel_base.test.js b/app/screens/channel/channel_base.test.js index b2a8e42ea..bcd73f719 100644 --- a/app/screens/channel/channel_base.test.js +++ b/app/screens/channel/channel_base.test.js @@ -106,4 +106,14 @@ describe('ChannelBase', () => { EventEmitter.emit(General.REMOVED_FROM_CHANNEL); expect(alert).toHaveBeenCalled(); }); + + test('should call selectDefault team when the current team is archived', () => { + const wrapper = shallow( + , + {context: {intl: {formatMessage: jest.fn()}}}, + ); + + wrapper.setProps({currentTeamId: '', currentChannelId: ''}); + expect(baseProps.actions.selectDefaultTeam).toHaveBeenCalledTimes(1); + }); }); diff --git a/app/screens/channel/index.js b/app/screens/channel/index.js index 0ca69d265..e6ba1c191 100644 --- a/app/screens/channel/index.js +++ b/app/screens/channel/index.js @@ -36,14 +36,17 @@ function mapStateToProps(state) { ); } + const currentTeamId = currentTeam?.delete_at === 0 ? currentTeam?.id : ''; + const currentChannelId = currentTeam?.delete_at === 0 ? getCurrentChannelId(state) : ''; + return { - currentTeamId: currentTeam?.id, - currentChannelId: getCurrentChannelId(state), + currentChannelId, + currentTeamId, isSupportedServer, isSystemAdmin, + showTermsOfService: shouldShowTermsOfService(state), teamName: currentTeam?.display_name, theme: getTheme(state), - showTermsOfService: shouldShowTermsOfService(state), }; }