diff --git a/client/hosting/hosting-features/components/hosting-features.tsx b/client/hosting/hosting-features/components/hosting-features.tsx index 5cba8cdf5cad45..482693bc80506b 100644 --- a/client/hosting/hosting-features/components/hosting-features.tsx +++ b/client/hosting/hosting-features/components/hosting-features.tsx @@ -6,14 +6,12 @@ import { Button, Spinner } from '@wordpress/components'; import { addQueryArgs } from '@wordpress/url'; import { translate } from 'i18n-calypso'; import { useRef, useState, useEffect } from 'react'; -import { AnyAction } from 'redux'; import EligibilityWarnings from 'calypso/blocks/eligibility-warnings'; import { HostingCard } from 'calypso/components/hosting-card'; import InlineSupportLink from 'calypso/components/inline-support-link'; import { useSiteTransferStatusQuery } from 'calypso/landing/stepper/hooks/use-site-transfer/query'; import { useSelector, useDispatch } from 'calypso/state'; import { recordTracksEvent } from 'calypso/state/analytics/actions'; -import { fetchAtomicTransfer } from 'calypso/state/atomic-transfer/actions'; import { transferStates } from 'calypso/state/atomic-transfer/constants'; import isSiteWpcomAtomic from 'calypso/state/selectors/is-site-wpcom-atomic'; import siteHasFeature from 'calypso/state/selectors/site-has-feature'; @@ -61,32 +59,14 @@ const HostingFeatures = () => { const hasEnTranslation = useHasEnTranslation(); - const { data: siteTransferData, refetch: refetchSiteTransferData } = useSiteTransferStatusQuery( - siteId || undefined - ); - // `siteTransferData?.isTransferring` is not a fully reliable indicator by itself, which is why - // we also look at `siteTransferData.status` - const isTransferInProgress = + const { data: siteTransferData } = useSiteTransferStatusQuery( siteId || undefined, { + refetchIntervalInBackground: true, + } ); + + const shouldRenderActivatingCopy = ( siteTransferData?.isTransferring || siteTransferData?.status === transferStates.COMPLETED ) && ! isPlanExpired; - useEffect( () => { - if ( ! siteId ) { - return; - } - - const interval = setInterval( () => { - if ( siteTransferData?.status !== transferStates.COMPLETED ) { - refetchSiteTransferData(); - } else { - clearInterval( interval ); - dispatch( fetchAtomicTransfer( siteId ) as unknown as AnyAction ); - } - }, 3000 ); - - return () => clearInterval( interval ); - }, [ siteId, siteTransferData?.status, refetchSiteTransferData, dispatch ] ); - useEffect( () => { if ( isSiteAtomic && ! isPlanExpired ) { page.replace( redirectUrl ); @@ -191,7 +171,7 @@ const HostingFeatures = () => { let title; let description; let buttons; - if ( isTransferInProgress ) { + if ( shouldRenderActivatingCopy ) { title = translate( 'Activating hosting features' ); description = translate( "The hosting features will appear here automatically when they're ready!", @@ -255,7 +235,7 @@ const HostingFeatures = () => { return (
- { isTransferInProgress && } + { shouldRenderActivatingCopy && }

{ title }

{ description }

{ buttons } diff --git a/client/landing/stepper/hooks/use-site-transfer/query.ts b/client/landing/stepper/hooks/use-site-transfer/query.ts index 46d0e93030ff99..1875cf96bc13f2 100644 --- a/client/landing/stepper/hooks/use-site-transfer/query.ts +++ b/client/landing/stepper/hooks/use-site-transfer/query.ts @@ -52,14 +52,22 @@ export function getSiteTransferStatusQueryKey( siteId: number ) { } const shouldRefetch = ( status: TransferStates | undefined ) => { - if ( ! status || status === transferStates.NONE ) { + if ( ! status ) { return false; } + // This condition ensures that when the status is NONE, + // we expect it might change in another tab. This allows the UI to reflect any updates dynamically. + if ( transferStates.NONE === status ) { + return true; + } + return isTransferring( status ); }; -type Options = Pick< UseQueryOptions, 'retry' >; +type Options = Pick< UseQueryOptions, 'retry' > & { + refetchIntervalInBackground?: boolean; +}; /** * Query hook to get the site transfer status, pooling the endpoint. @@ -83,6 +91,7 @@ export const useSiteTransferStatusQuery = ( siteId: number | undefined, options? }; }, refetchOnWindowFocus: false, + refetchIntervalInBackground: !! options?.refetchIntervalInBackground, refetchInterval: ( { state } ) => shouldRefetch( state.data?.status ) ? REFETCH_TIME : false, enabled: !! siteId,