diff --git a/webapp/channels/src/components/team_general_tab/team_general_tab.test.tsx b/webapp/channels/src/components/team_general_tab/team_general_tab.test.tsx index aed275791a..a38bb343ee 100644 --- a/webapp/channels/src/components/team_general_tab/team_general_tab.test.tsx +++ b/webapp/channels/src/components/team_general_tab/team_general_tab.test.tsx @@ -126,7 +126,10 @@ describe('components/TeamSettings', () => { wrapper.instance().handleAllowedDomainsSubmit(); expect(actions.patchTeam).toHaveBeenCalledTimes(1); - expect(actions.patchTeam).toHaveBeenCalledWith(props.team); + expect(actions.patchTeam).toHaveBeenCalledWith({ + allowed_domains: '', + id: props.team?.id, + }); }); test('should call actions.patchTeam on handleNameSubmit', () => { @@ -141,7 +144,10 @@ describe('components/TeamSettings', () => { wrapper.instance().handleNameSubmit(); expect(actions.patchTeam).toHaveBeenCalledTimes(1); - expect(actions.patchTeam).toHaveBeenCalledWith(props.team); + expect(actions.patchTeam).toHaveBeenCalledWith({ + display_name: props.team?.display_name, + id: props.team?.id, + }); }); test('should call actions.patchTeam on handleInviteIdSubmit', () => { @@ -173,7 +179,10 @@ describe('components/TeamSettings', () => { } expect(actions.patchTeam).toHaveBeenCalledTimes(1); - expect(actions.patchTeam).toHaveBeenCalledWith(props.team); + expect(actions.patchTeam).toHaveBeenCalledWith({ + description: newDescription, + id: props.team?.id, + }); }); test('should match snapshot when team is group constrained', () => { diff --git a/webapp/channels/src/components/team_general_tab/team_general_tab.tsx b/webapp/channels/src/components/team_general_tab/team_general_tab.tsx index ccabefdc0c..8b01ce0d44 100644 --- a/webapp/channels/src/components/team_general_tab/team_general_tab.tsx +++ b/webapp/channels/src/components/team_general_tab/team_general_tab.tsx @@ -106,9 +106,10 @@ export class GeneralTab extends React.PureComponent { handleAllowedDomainsSubmit = async () => { const state = {serverError: '', clientError: ''}; - const data = {...this.props.team}; - data.allowed_domains = this.state.allowed_domains; - + const data = { + id: this.props.team?.id, + allowed_domains: this.state.allowed_domains, + }; const {error} = await this.props.actions.patchTeam(data); if (error) { @@ -151,9 +152,10 @@ export class GeneralTab extends React.PureComponent { return; } - const data = {...this.props.team}; - data.display_name = this.state.name; - + const data = { + id: this.props.team?.id, + display_name: this.state.name, + }; const {error} = await this.props.actions.patchTeam(data); if (error) { @@ -198,9 +200,10 @@ export class GeneralTab extends React.PureComponent { return; } - const data = {...this.props.team}; - data.description = this.state.description; - + const data = { + id: this.props.team?.id, + description: this.state.description, + }; const {error} = await this.props.actions.patchTeam(data); if (error) { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts index 858b71a9db..692df925e3 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts @@ -737,38 +737,77 @@ describe('Actions.Teams', () => { }); it('setTeamIcon', async () => { + const team = {id: 'teamId', invite_id: ''}; + store = configureStore({ + entities: { + teams: { + teams: { + [team!.id]: {...team}, + }, + }, + }, + }); + TestHelper.mockLogin(); store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); await loadMe()(store.dispatch, store.getState); - const team = TestHelper.basicTeam; + let state = store.getState(); + expect(state.entities.teams.teams[team!.id].invite_id).toEqual(''); + const imageData = fs.createReadStream('src/packages/mattermost-redux/test/assets/images/test.png'); nock(Client4.getTeamRoute(team!.id)). post('/image'). reply(200, OK_RESPONSE); + nock(Client4.getTeamRoute(team!.id)). + get(''). + reply(200, {...team, invite_id: 'inviteId'}); + const {data} = await Actions.setTeamIcon(team!.id, imageData as any)(store.dispatch, store.getState) as ActionResult; expect(data).toEqual(OK_RESPONSE); + + state = store.getState(); + expect(state.entities.teams.teams[team!.id].invite_id).toEqual('inviteId'); }); it('removeTeamIcon', async () => { + const team = {id: 'teamId', invite_id: ''}; + store = configureStore({ + entities: { + teams: { + teams: { + [team!.id]: {...team}, + }, + }, + }, + }); + TestHelper.mockLogin(); store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); await loadMe()(store.dispatch, store.getState); - const team = TestHelper.basicTeam; + let state = store.getState(); + expect(state.entities.teams.teams[team!.id].invite_id).toEqual(''); nock(Client4.getTeamRoute(team!.id)). delete('/image'). reply(200, OK_RESPONSE); + nock(Client4.getTeamRoute(team!.id)). + get(''). + reply(200, {...team, invite_id: 'inviteId'}); + const {data} = await Actions.removeTeamIcon(team!.id)(store.dispatch, store.getState) as ActionResult; expect(data).toEqual(OK_RESPONSE); + + state = store.getState(); + expect(state.entities.teams.teams[team!.id].invite_id).toEqual('inviteId'); }); it('updateTeamScheme', async () => { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.ts index b07523c768..d57c391b43 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.ts @@ -737,22 +737,27 @@ export function joinTeam(inviteId: string, teamId: string): ActionFunc { } export function setTeamIcon(teamId: string, imageData: File): ActionFunc { - return bindClientFunc({ - clientFunc: Client4.setTeamIcon, - params: [ - teamId, - imageData, - ], - }); + return async (dispatch: DispatchFunc) => { + await Client4.setTeamIcon(teamId, imageData); + const team = await Client4.getTeam(teamId); + dispatch({ + type: TeamTypes.PATCHED_TEAM, + data: team, + }); + return {data: {status: 'OK'}}; + }; } export function removeTeamIcon(teamId: string): ActionFunc { - return bindClientFunc({ - clientFunc: Client4.removeTeamIcon, - params: [ - teamId, - ], - }); + return async (dispatch: DispatchFunc) => { + await Client4.removeTeamIcon(teamId); + const team = await Client4.getTeam(teamId); + dispatch({ + type: TeamTypes.PATCHED_TEAM, + data: team, + }); + return {data: {status: 'OK'}}; + }; } export function updateTeamScheme(teamId: string, schemeId: string): ActionFunc {