Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: other tabs break when accepting a team invitation via a link #7200

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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