@@ -8,15 +8,18 @@ import { AlertModal, ArrowUpRightRegularIcon } from "@hashintel/design-system";
88import { useUpdateAuthenticatedUser } from "../components/hooks/use-update-authenticated-user" ;
99import {
1010 acceptOrgInvitationMutation ,
11+ getMyPendingInvitationsQuery ,
1112 getPendingInvitationByEntityIdQuery ,
1213} from "../graphql/queries/knowledge/org.queries" ;
1314import { hasAccessToHashQuery } from "../graphql/queries/user.queries" ;
15+ import { useInvites } from "../shared/invites-context" ;
1416import { getPlainLayout } from "../shared/layout" ;
1517import { Button } from "../shared/ui" ;
1618import { useAuthInfo } from "./shared/auth-info-context" ;
1719import { AuthLayout } from "./shared/auth-layout" ;
1820import { parseGraphQLError } from "./shared/auth-utils" ;
1921import { VerifyEmailStep } from "./shared/verify-email-step" ;
22+ import { useActiveWorkspace } from "./shared/workspace-context" ;
2023import { AcceptOrgInvitation } from "./signup.page/accept-org-invitation" ;
2124import { AccountSetupForm } from "./signup.page/account-setup-form" ;
2225import { SignupRegistrationForm } from "./signup.page/signup-registration-form" ;
@@ -26,6 +29,8 @@ import { SignupSteps } from "./signup.page/signup-steps";
2629import type {
2730 AcceptOrgInvitationMutation ,
2831 AcceptOrgInvitationMutationVariables ,
32+ GetMyPendingInvitationsQuery ,
33+ GetMyPendingInvitationsQueryVariables ,
2934 GetPendingInvitationByEntityIdQuery ,
3035 GetPendingInvitationByEntityIdQueryVariables ,
3136 HasAccessToHashQuery ,
@@ -95,6 +100,8 @@ const SignupPage: NextPageWithLayout = () => {
95100
96101 const { authenticatedUser, refetch : refetchAuthenticatedUser } =
97102 useAuthInfo ( ) ;
103+ const { refetch : refetchInvites } = useInvites ( ) ;
104+ const { updateActiveWorkspaceWebId } = useActiveWorkspace ( ) ;
98105
99106 const userHasVerifiedEmail =
100107 authenticatedUser ?. emails . find ( ( { verified } ) => verified ) !== undefined ;
@@ -139,12 +146,24 @@ const SignupPage: NextPageWithLayout = () => {
139146 skip : ! invitationId ,
140147 } ) ;
141148
149+ const { data : pendingInvitationsData , loading : pendingInvitationsLoading } =
150+ useQuery <
151+ GetMyPendingInvitationsQuery ,
152+ GetMyPendingInvitationsQueryVariables
153+ > ( getMyPendingInvitationsQuery , {
154+ skip : ! ! invitationId || ! authenticatedUser || ! userHasVerifiedEmail ,
155+ } ) ;
156+
142157 const [ acceptInvitation ] = useMutation <
143158 AcceptOrgInvitationMutation ,
144159 AcceptOrgInvitationMutationVariables
145160 > ( acceptOrgInvitationMutation ) ;
146161
147- const invitation = invitationData ?. getPendingInvitationByEntityId ;
162+ const invitation =
163+ invitationData ?. getPendingInvitationByEntityId ??
164+ pendingInvitationsData ?. getMyPendingInvitations [ 0 ] ;
165+
166+ const loadingInvitation = invitationLoading || pendingInvitationsLoading ;
148167
149168 const [ acceptingInvitation , setAcceptingInvitation ] = useState ( false ) ;
150169 const acceptingInvitationEntityIdRef = useRef < EntityId | undefined > (
@@ -220,7 +239,9 @@ const SignupPage: NextPageWithLayout = () => {
220239 } )
221240 . then ( async ( result ) => {
222241 if ( result ?. accepted || result ?. alreadyAMember ) {
242+ refetchInvites ( ) ;
223243 await refetchAuthenticatedUser ( ) ;
244+ updateActiveWorkspaceWebId ( invitation . org . webId ) ;
224245 void router . replace ( "/" ) ;
225246 return ;
226247 }
@@ -245,15 +266,17 @@ const SignupPage: NextPageWithLayout = () => {
245266 clearInvitationAcceptanceReservation ,
246267 invitation ,
247268 refetchAuthenticatedUser ,
269+ refetchInvites ,
248270 router ,
271+ updateActiveWorkspaceWebId ,
249272 ] ) ;
250273
251274 useEffect ( ( ) => {
252275 if (
253276 router . isReady &&
254277 authenticatedUser ?. accountSignupComplete &&
255278 invitationId &&
256- ! invitationLoading &&
279+ ! loadingInvitation &&
257280 ! invitation &&
258281 ! acceptingInvitation
259282 ) {
@@ -264,7 +287,7 @@ const SignupPage: NextPageWithLayout = () => {
264287 authenticatedUser ?. accountSignupComplete ,
265288 invitation ,
266289 invitationId ,
267- invitationLoading ,
290+ loadingInvitation ,
268291 router ,
269292 ] ) ;
270293
@@ -340,15 +363,21 @@ const SignupPage: NextPageWithLayout = () => {
340363 }
341364
342365 await refetchAuthenticatedUser ( ) ;
366+ refetchInvites ( ) ;
367+ if ( invitation ) {
368+ updateActiveWorkspaceWebId ( invitation . org . webId ) ;
369+ }
343370
344371 void router . push ( "/" ) ;
345372 } ,
346373 [
347374 acceptInvitationOnce ,
348375 clearInvitationAcceptanceReservation ,
349376 invitation ,
377+ refetchInvites ,
350378 refetchAuthenticatedUser ,
351379 updateAuthenticatedUser ,
380+ updateActiveWorkspaceWebId ,
352381 router ,
353382 ] ,
354383 ) ;
@@ -395,7 +424,9 @@ const SignupPage: NextPageWithLayout = () => {
395424 >
396425 < Grid container columnSpacing = { 16 } >
397426 < Grid item xs = { 12 } md = { 7 } >
398- { invitationLoading ? null : invitation && showInvitationStep ? (
427+ { loadingInvitation ? null : invitation &&
428+ showInvitationStep &&
429+ ! authenticatedUser ? (
399430 < AcceptOrgInvitation
400431 invitation = { invitation }
401432 onAccept = { ( ) => setShowInvitationStep ( false ) }
0 commit comments