From d51ca5a1836756c284530e79f3ba17615e8cbf68 Mon Sep 17 00:00:00 2001 From: Igor Lesnenko Date: Fri, 7 Oct 2022 18:27:08 +0400 Subject: [PATCH] fix: other tabs break when accepting a team invitation via a link (#7200) --- .../mutations/AcceptTeamInvitationMutation.ts | 24 +++++++++++++++---- .../public/mutations/acceptTeamInvitation.ts | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/client/mutations/AcceptTeamInvitationMutation.ts b/packages/client/mutations/AcceptTeamInvitationMutation.ts index 3419947dbbb..447828f77b3 100644 --- a/packages/client/mutations/AcceptTeamInvitationMutation.ts +++ b/packages/client/mutations/AcceptTeamInvitationMutation.ts @@ -13,6 +13,7 @@ import fromTeamMemberId from '../utils/relay/fromTeamMemberId' import getGraphQLError from '../utils/relay/getGraphQLError' import {AcceptTeamInvitationMutation as TAcceptTeamInvitationMutation} from '../__generated__/AcceptTeamInvitationMutation.graphql' import {AcceptTeamInvitationMutation_team} from '../__generated__/AcceptTeamInvitationMutation_team.graphql' +import handleAddOrganization from './handlers/handleAddOrganization' import handleAddTeamMembers from './handlers/handleAddTeamMembers' import handleAddTeams from './handlers/handleAddTeams' import handleAuthenticationRedirect from './handlers/handleAuthenticationRedirect' @@ -33,6 +34,11 @@ graphql` } team { name + organization { + id + name + } + ...DashNavListTeam } } ` @@ -111,6 +117,10 @@ export const acceptTeamInvitationTeamUpdater: SharedUpdater { const teamMember = payload.getLinkedRecord('teamMember') handleAddTeamMembers(teamMember, store) + const team = payload.getLinkedRecord('team') + const organization = team.getLinkedRecord('organization') + handleAddOrganization(organization, store) + handleAddTeams(team, store) } export const acceptTeamInvitationTeamOnNext: OnNextHandler = ( @@ -118,6 +128,7 @@ export const acceptTeamInvitationTeamOnNext: OnNextHandler { const {team, teamMember} = payload + const {viewerId} = atmosphere if (!team || !teamMember) return const {name: teamName} = team const {id: teamMemberId, preferredName} = teamMember @@ -126,11 +137,14 @@ export const acceptTeamInvitationTeamOnNext: OnNextHandler snack.key === `pushInvitation:${teamId}:${userId}` ) - atmosphere.eventEmitter.emit('addSnackbar', { - autoDismiss: 5, - key: `acceptTeamInvitation:${teamMemberId}`, - message: `${preferredName} just joined team ${teamName}` - }) + + if (userId !== viewerId) { + atmosphere.eventEmitter.emit('addSnackbar', { + autoDismiss: 5, + key: `acceptTeamInvitation:${teamMemberId}`, + message: `${preferredName} just joined team ${teamName}` + }) + } } interface LocalHandler extends HistoryMaybeLocalHandler { diff --git a/packages/server/graphql/public/mutations/acceptTeamInvitation.ts b/packages/server/graphql/public/mutations/acceptTeamInvitation.ts index 53f086c9616..5e204585d48 100644 --- a/packages/server/graphql/public/mutations/acceptTeamInvitation.ts +++ b/packages/server/graphql/public/mutations/acceptTeamInvitation.ts @@ -126,6 +126,9 @@ const acceptTeamInvitation: MutationResolvers['acceptTeamInvitation'] = async ( // Tell the rest of the team about the new team member publish(SubscriptionChannel.TEAM, teamId, 'AcceptTeamInvitationPayload', data, subOptions) + // Send individualized message to the user + publish(SubscriptionChannel.TEAM, viewerId, 'AcceptTeamInvitationPayload', data, subOptions) + // Give the team lead new suggested actions if (teamLeadUserIdWithNewActions) { // the team lead just needs data about themselves. alternatively we could make an eg AcceptTeamInvitationTeamLeadPayload, but nulls are just as good