From cd39edc3ff8ed97c0042fd5d090f1673e8523cfc Mon Sep 17 00:00:00 2001 From: Ben Cooke Date: Tue, 24 Oct 2023 15:52:04 -0400 Subject: [PATCH] adding error for when invite request fails (#24436) Co-authored-by: Ben Schumacher Co-authored-by: Mattermost Build --- webapp/channels/src/actions/invite_actions.ts | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/webapp/channels/src/actions/invite_actions.ts b/webapp/channels/src/actions/invite_actions.ts index e31e802040..44ba62c57c 100644 --- a/webapp/channels/src/actions/invite_actions.ts +++ b/webapp/channels/src/actions/invite_actions.ts @@ -42,12 +42,18 @@ export function sendMembersInvites(teamId: string, users: UserProfile[], emails: if (usersToAdd.length > 0) { const response = await dispatch(addUsersToTeam(teamId, usersToAdd.map((u) => u.id))); const members = response.data || []; - for (const userToAdd of usersToAdd) { - const memberWithError = members.find((m: TeamMemberWithError) => m.user_id === userToAdd.id && m.error); - if (memberWithError) { - notSent.push({user: userToAdd, reason: memberWithError.error.message}); - } else { - sent.push({user: userToAdd, reason: localizeMessage('invite.members.added-to-team', 'This member has been added to the team.')}); + if (response.error) { + for (const userToAdd of usersToAdd) { + notSent.push({user: userToAdd, reason: response.error.message}); + } + } else { + for (const userToAdd of usersToAdd) { + const memberWithError = members.find((m: TeamMemberWithError) => m.user_id === userToAdd.id && m.error); + if (memberWithError) { + notSent.push({user: userToAdd, reason: memberWithError.error.message}); + } else { + sent.push({user: userToAdd, reason: localizeMessage('invite.members.added-to-team', 'This member has been added to the team.')}); + } } } } @@ -232,12 +238,18 @@ export function sendMembersInvitesToChannels( if (usersToAdd.length > 0) { const response = await dispatch(addUsersToTeam(teamId, usersToAdd.map((u) => u.id))); const members = response.data || []; - for (const userToAdd of usersToAdd) { - const memberWithError = members.find((m: TeamMemberWithError) => m.user_id === userToAdd.id && m.error); - if (memberWithError) { - notSent.push({user: userToAdd, reason: memberWithError.error.message}); - } else { - sent.push({user: userToAdd, reason: localizeMessage('invite.members.added-to-team', 'This member has been added to the team.')}); + if (response.error) { + for (const userToAdd of usersToAdd) { + notSent.push({user: userToAdd, reason: response.error.message}); + } + } else { + for (const userToAdd of usersToAdd) { + const memberWithError = members.find((m: TeamMemberWithError) => m.user_id === userToAdd.id && m.error); + if (memberWithError) { + notSent.push({user: userToAdd, reason: memberWithError.error.message}); + } else { + sent.push({user: userToAdd, reason: localizeMessage('invite.members.added-to-team', 'This member has been added to the team.')}); + } } } }