Skip to content

Commit

Permalink
fix: other tabs break when accepting a team invitation via a link (#7200
Browse files Browse the repository at this point in the history
)
  • Loading branch information
igorlesnenko authored Oct 7, 2022
1 parent a119339 commit d51ca5a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/client/mutations/AcceptTeamInvitationMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -33,6 +34,11 @@ graphql`
}
team {
name
organization {
id
name
}
...DashNavListTeam
}
}
`
Expand Down Expand Up @@ -111,13 +117,18 @@ export const acceptTeamInvitationTeamUpdater: SharedUpdater<AcceptTeamInvitation
) => {
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<AcceptTeamInvitationMutation_team> = (
payload,
{atmosphere}
) => {
const {team, teamMember} = payload
const {viewerId} = atmosphere
if (!team || !teamMember) return
const {name: teamName} = team
const {id: teamMemberId, preferredName} = teamMember
Expand All @@ -126,11 +137,14 @@ export const acceptTeamInvitationTeamOnNext: OnNextHandler<AcceptTeamInvitationM
'removeSnackbar',
(snack) => 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d51ca5a

Please sign in to comment.