11import * as C from '@/constants'
22import * as T from '@/constants/types'
33import * as Kb from '@/common-adapters'
4- import { useTeamsState } from '@/stores/teams'
54import { RPCError } from '@/util/errors'
65import * as React from 'react'
76import { useSafeNavigation } from '@/util/safe-navigation'
@@ -31,27 +30,19 @@ const getInviteError = (error: unknown, missingKey: boolean) => {
3130const JoinFromInvite = ( { inviteDetails : initialInviteDetails , inviteID = '' , inviteKey = '' } : Props ) => {
3231 const [ details , setDetails ] = React . useState ( initialInviteDetails )
3332 const [ error , setError ] = React . useState ( '' )
34- const [ localRespondToInviteLink , setLocalRespondToInviteLink ] = React . useState <
35- ( ( accept : boolean ) => void ) | undefined
36- > ( )
37- const storedRespondToInviteLink = useTeamsState ( s => s . dispatch . dynamic . respondToInviteLink )
38- const respondToInviteLink = localRespondToInviteLink ?? storedRespondToInviteLink
3933 const loaded = details !== undefined || ! ! error
4034 const joinTeam = C . useRPC ( T . RPCGen . teamsTeamAcceptInviteOrRequestAccessRpcListener )
4135 const requestInviteLinkDetails = C . useRPC ( T . RPCGen . teamsGetInviteLinkDetailsRpcPromise )
4236 const [ clickedJoin , setClickedJoin ] = React . useState ( false )
4337 const [ showSuccess , setShowSuccess ] = React . useState ( false )
4438 const rpcWaiting = C . Waiting . useAnyWaiting ( C . waitingKeyTeamsJoinTeam )
4539 const waiting = rpcWaiting && clickedJoin
46- const wasWaitingRef = React . useRef ( waiting )
4740
4841 React . useEffect ( ( ) => {
4942 setDetails ( initialInviteDetails )
5043 setError ( '' )
51- setLocalRespondToInviteLink ( undefined )
5244 setClickedJoin ( false )
5345 setShowSuccess ( false )
54- wasWaitingRef . current = false
5546 } , [ initialInviteDetails , inviteID , inviteKey ] )
5647
5748 React . useEffect ( ( ) => {
@@ -69,52 +60,43 @@ const JoinFromInvite = ({inviteDetails: initialInviteDetails, inviteID = '', inv
6960 setError ( getInviteError ( rpcError , true ) )
7061 }
7162 )
72- return
7363 }
64+ } , [ inviteID , inviteKey , loaded , requestInviteLinkDetails ] )
65+
66+ const nav = useSafeNavigation ( )
7467
68+ const onNavUp = ( ) => nav . safeNavigateUp ( )
69+ const onJoinTeam = ( ) => {
70+ if ( ! inviteKey ) {
71+ return
72+ }
73+ setClickedJoin ( true )
74+ setError ( '' )
7575 joinTeam (
7676 [
7777 {
7878 customResponseIncomingCallMap : {
7979 'keybase.1.teamsUi.confirmInviteLinkAccept' : ( params , response ) => {
8080 setDetails ( params . details )
81- setLocalRespondToInviteLink ( ( ) => accept => {
82- setLocalRespondToInviteLink ( undefined )
83- response . result ( accept )
84- } )
81+ response . result ( true )
8582 } ,
8683 } ,
8784 incomingCallMap : { } ,
8885 params : { tokenOrName : inviteKey } ,
8986 waitingKey : C . waitingKeyTeamsJoinTeam ,
9087 } ,
9188 ] ,
92- ( ) => { } ,
89+ ( ) => {
90+ setClickedJoin ( false )
91+ setShowSuccess ( true )
92+ } ,
9393 rpcError => {
94- setLocalRespondToInviteLink ( undefined )
94+ setClickedJoin ( false )
9595 setError ( getInviteError ( rpcError , false ) )
9696 }
9797 )
98- } , [ inviteID , inviteKey , joinTeam , loaded , requestInviteLinkDetails ] )
99-
100- const nav = useSafeNavigation ( )
101-
102- const onNavUp = ( ) => nav . safeNavigateUp ( )
103- const onJoinTeam = ( ) => {
104- setClickedJoin ( true )
105- respondToInviteLink ?.( true )
106- }
107- const onClose = ( ) => {
108- respondToInviteLink ?.( true )
109- onNavUp ( )
11098 }
111- React . useEffect ( ( ) => {
112- wasWaitingRef . current = waiting
113- } , [ waiting ] )
114-
115- React . useEffect ( ( ) => {
116- setShowSuccess ( wasWaitingRef . current && ! waiting && ! error )
117- } , [ waiting , error ] )
99+ const onClose = ( ) => onNavUp ( )
118100
119101 const teamname = ( details ?. teamName . parts || [ ] ) . join ( '.' )
120102
0 commit comments