11import type { ReactElement } from 'react' ;
22import React from 'react' ;
33import { useRouter } from 'next/router' ;
4- import { useMutation , useQueryClient } from '@tanstack/react-query' ;
4+ import { useMutation , useQuery , useQueryClient } from '@tanstack/react-query' ;
55import { ConnectHeader } from '@dailydotdev/shared/src/components/recruiter/ConnectHeader' ;
66import { ConnectProgress } from '@dailydotdev/shared/src/components/recruiter/ConnectProgress' ;
77import { Loader } from '@dailydotdev/shared/src/components/Loader' ;
@@ -25,13 +25,53 @@ import {
2525import { GenericLoaderSpinner } from '@dailydotdev/shared/src/components/utilities/loaders' ;
2626import { IconSize } from '@dailydotdev/shared/src/components/Icon' ;
2727
28+ import { opportunityByIdOptions } from '@dailydotdev/shared/src/features/opportunity/queries' ;
29+ import { oneMinute } from '@dailydotdev/shared/src/lib/dateFormat' ;
30+ import { transactionRefetchIntervalMs } from '@dailydotdev/shared/src/graphql/njord' ;
31+ import { OpportunityState } from '@dailydotdev/shared/src/features/opportunity/protobuf/opportunity' ;
2832import { getLayout } from '../../../../components/layouts/RecruiterSelfServeLayout' ;
2933
3034function RecruiterMatchesPage ( ) : ReactElement {
3135 const router = useRouter ( ) ;
3236 const { opportunityId } = router . query ;
3337 const queryClient = useQueryClient ( ) ;
3438
39+ const { data : opportunity } = useQuery ( {
40+ ...opportunityByIdOptions ( {
41+ id : opportunityId as string ,
42+ } ) ,
43+ refetchInterval : ( query ) => {
44+ const retries = Math . max (
45+ query . state . dataUpdateCount ,
46+ query . state . fetchFailureCount ,
47+ ) ;
48+
49+ // transactions are mostly processed withing few seconds
50+ // so for now we stop retrying after 1 minute
51+ const maxRetries = ( oneMinute * 1000 ) / transactionRefetchIntervalMs ;
52+
53+ if ( retries > maxRetries ) {
54+ return false ;
55+ }
56+
57+ const queryError = query . state . error ;
58+
59+ // in case of query error keep refetching until maxRetries is reached
60+ if ( queryError ) {
61+ return transactionRefetchIntervalMs ;
62+ }
63+
64+ const isReadyForMatches =
65+ query . state . data ?. state !== OpportunityState . DRAFT ;
66+
67+ if ( isReadyForMatches ) {
68+ return false ;
69+ }
70+
71+ return transactionRefetchIntervalMs ;
72+ } ,
73+ } ) ;
74+
3575 const { allMatches, isLoading, data } = useOpportunityMatches ( {
3676 opportunityId : opportunityId as string ,
3777 status : 'candidate_accepted' ,
@@ -95,6 +135,8 @@ function RecruiterMatchesPage(): ReactElement {
95135 ) ;
96136 }
97137
138+ const isReadyForMatches = opportunity ?. state !== OpportunityState . DRAFT ;
139+
98140 return (
99141 < OpportunityProvider opportunityId = { opportunityId as string } >
100142 < div className = "flex flex-1 flex-col" >
@@ -142,8 +184,10 @@ function RecruiterMatchesPage(): ReactElement {
142184 color = { TypographyColor . Tertiary }
143185 center
144186 >
145- We’re already talking to the right developers for you — all
146- opt-in, all high-intent.
187+ { isReadyForMatches &&
188+ "We're already talking to the right developers for you — all opt-in, all high-intent." }
189+ { ! isReadyForMatches &&
190+ 'We are gonna start reaching to developers soon, we are still processing your data and payment...' }
147191 </ Typography >
148192 </ div >
149193 </ >
0 commit comments