@@ -14,7 +14,7 @@ import {
14
14
Title ,
15
15
} from '@reapit/elements'
16
16
import { GetActionNames , getActions , useReapitGet } from '@reapit/use-reapit-data'
17
- import React , { FC } from 'react'
17
+ import React , { FC , useEffect , useRef } from 'react'
18
18
import { reapitConnectBrowserSession } from '../../../../core/connect-session'
19
19
import { cx } from '@linaria/core'
20
20
import { DnsContainerElement , DnsContainerRow , DnsInputElement , DnsValue } from './__styles__'
@@ -36,6 +36,7 @@ export const PipelineDnsStepThree: FC<{
36
36
} > = ( { pipelineId } ) => {
37
37
const { connectSession } = useReapitConnect ( reapitConnectBrowserSession )
38
38
const { appPipelineState } = useAppState ( )
39
+ const pollingRef = useRef < NodeJS . Timeout > ( )
39
40
40
41
const [ certificate , loading , , fetchCertificate , refetching ] = useReapitGet < {
41
42
DomainValidationOptions : {
@@ -56,6 +57,24 @@ export const PipelineDnsStepThree: FC<{
56
57
fetchWhenTrue : [ connectSession ] ,
57
58
} )
58
59
60
+ const pollFetchCertificate = async ( ) => {
61
+ await fetchCertificate ( )
62
+ }
63
+
64
+ useEffect ( ( ) => {
65
+ pollingRef . current = setInterval ( pollFetchCertificate , 10000 )
66
+
67
+ return ( ) => {
68
+ clearInterval ( pollingRef . current )
69
+ }
70
+ } , [ ] )
71
+
72
+ const clearPollAndCall = async ( ) => {
73
+ clearInterval ( pollingRef . current )
74
+ await fetchCertificate ( )
75
+ pollingRef . current = setInterval ( pollFetchCertificate , 10000 )
76
+ }
77
+
59
78
if ( certificate ?. Status === 'ISSUED' ) {
60
79
appPipelineState . appPipelineRefresh ( )
61
80
}
@@ -122,7 +141,7 @@ export const PipelineDnsStepThree: FC<{
122
141
) ) }
123
142
</ DnsContainerElement >
124
143
< ButtonGroup >
125
- < Button intent = "primary" onClick = { ( ) => fetchCertificate ( ) } loading = { refetching } disabled = { refetching } >
144
+ < Button intent = "primary" onClick = { ( ) => clearPollAndCall ( ) } loading = { refetching } disabled = { refetching } >
126
145
Refresh
127
146
</ Button >
128
147
</ ButtonGroup >
0 commit comments