Skip to content

Commit 584a8cb

Browse files
authored
feat: added polling functions for status updates (#11534)
1 parent 8966568 commit 584a8cb

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

packages/developer-portal/src/components/apps/pipeline/dns/dns-step-three.tsx

+21-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
Title,
1515
} from '@reapit/elements'
1616
import { GetActionNames, getActions, useReapitGet } from '@reapit/use-reapit-data'
17-
import React, { FC } from 'react'
17+
import React, { FC, useEffect, useRef } from 'react'
1818
import { reapitConnectBrowserSession } from '../../../../core/connect-session'
1919
import { cx } from '@linaria/core'
2020
import { DnsContainerElement, DnsContainerRow, DnsInputElement, DnsValue } from './__styles__'
@@ -36,6 +36,7 @@ export const PipelineDnsStepThree: FC<{
3636
}> = ({ pipelineId }) => {
3737
const { connectSession } = useReapitConnect(reapitConnectBrowserSession)
3838
const { appPipelineState } = useAppState()
39+
const pollingRef = useRef<NodeJS.Timeout>()
3940

4041
const [certificate, loading, , fetchCertificate, refetching] = useReapitGet<{
4142
DomainValidationOptions: {
@@ -56,6 +57,24 @@ export const PipelineDnsStepThree: FC<{
5657
fetchWhenTrue: [connectSession],
5758
})
5859

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+
5978
if (certificate?.Status === 'ISSUED') {
6079
appPipelineState.appPipelineRefresh()
6180
}
@@ -122,7 +141,7 @@ export const PipelineDnsStepThree: FC<{
122141
))}
123142
</DnsContainerElement>
124143
<ButtonGroup>
125-
<Button intent="primary" onClick={() => fetchCertificate()} loading={refetching} disabled={refetching}>
144+
<Button intent="primary" onClick={() => clearPollAndCall()} loading={refetching} disabled={refetching}>
126145
Refresh
127146
</Button>
128147
</ButtonGroup>

packages/developer-portal/src/components/apps/pipeline/dns/dns-step-two.tsx

+21-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
useSnack,
1313
} from '@reapit/elements'
1414
import { UpdateActionNames, updateActions, UpdateReturnTypeEnum, useReapitUpdate } from '@reapit/use-reapit-data'
15-
import React, { FC } from 'react'
15+
import React, { FC, useEffect, useRef } from 'react'
1616
import { reapitConnectBrowserSession } from '../../../../core/connect-session'
1717
import { PipelineDnsStepModal } from './setup-model'
1818
import { useAppState } from '../../state/use-app-state'
@@ -41,6 +41,7 @@ export const PipelineDnsStepTwo: FC<{
4141
})
4242
const { error, success } = useSnack()
4343
const { appPipelineState } = useAppState()
44+
const pollingRef = useRef<NodeJS.Timeout>()
4445

4546
const verifyTxtRecord = async () => {
4647
const result = await sendVerifyRequest(undefined)
@@ -60,6 +61,24 @@ export const PipelineDnsStepTwo: FC<{
6061
}
6162
}
6263

64+
const pollVerifyTxtRecord = async () => {
65+
await verifyTxtRecord()
66+
}
67+
68+
useEffect(() => {
69+
pollingRef.current = setInterval(pollVerifyTxtRecord, 10000)
70+
71+
return () => {
72+
clearInterval(pollingRef.current)
73+
}
74+
}, [])
75+
76+
const clearPollAndCall = async () => {
77+
clearInterval(pollingRef.current)
78+
await verifyTxtRecord()
79+
pollingRef.current = setInterval(pollVerifyTxtRecord, 10000)
80+
}
81+
6382
return (
6483
<>
6584
<FlexContainer>
@@ -96,7 +115,7 @@ export const PipelineDnsStepTwo: FC<{
96115
loading={sendingVerify}
97116
disabled={sendingVerify}
98117
onClick={() => {
99-
verifyTxtRecord()
118+
clearPollAndCall()
100119
}}
101120
intent="primary"
102121
>

0 commit comments

Comments
 (0)