22 * External dependencies
33 */
44import { Button , Spinner , Tooltip } from '@wordpress/components' ;
5+ import { useEffect , useState } from '@wordpress/element' ;
56import { __ } from '@wordpress/i18n' ;
67/**
78 * Internal dependencies
@@ -13,6 +14,7 @@ type PluginActionButtonProps = {
1314 slug : string ;
1415 pluginFile : string ;
1516 isInstalled : boolean ;
17+ isActive : boolean ;
1618 refreshStatus : ( ) => void ;
1719 trackEventName : string ;
1820} ;
@@ -21,6 +23,7 @@ const PluginActionButton = ( {
2123 slug,
2224 pluginFile,
2325 isInstalled,
26+ isActive,
2427 refreshStatus,
2528 trackEventName,
2629} : PluginActionButtonProps ) => {
@@ -31,13 +34,13 @@ const PluginActionButton = ( {
3134 trackEventName
3235 ) ;
3336
34- // Permissions from consolidated Forms config (shared across editor and dashboard)
3537 const config = useFormsConfig ( ) ;
3638 const canUserInstallPlugins = Boolean ( config ?. canInstallPlugins ) ;
3739 const canUserActivatePlugins = Boolean ( config ?. canActivatePlugins ) ;
3840
3941 const canPerformAction = isInstalled ? canUserActivatePlugins : canUserInstallPlugins ;
40- const isDisabled = isInstalling || ! canPerformAction ;
42+ const [ isReconcilingStatus , setIsReconcilingStatus ] = useState ( false ) ;
43+ const isDisabled = isInstalling || isReconcilingStatus || ! canPerformAction ;
4144
4245 const handleAction = async ( event : MouseEvent ) => {
4346 event . stopPropagation ( ) ;
@@ -47,14 +50,23 @@ const PluginActionButton = ( {
4750 const success = await installPlugin ( ) ;
4851
4952 if ( success && refreshStatus ) {
53+ setIsReconcilingStatus ( true ) ; // Keeps button in loading state until integrations refresh.
5054 refreshStatus ( ) ;
5155 }
5256 } ;
5357
58+ useEffect ( ( ) => {
59+ if ( isReconcilingStatus && isActive ) {
60+ setIsReconcilingStatus ( false ) ; // Removes button loading state when integratoin status is recevied and isActive.
61+ }
62+ } , [ isReconcilingStatus , isActive ] ) ;
63+
5464 const getButtonText = ( ) => {
5565 return (
56- ( isInstalling && isInstalled && __ ( 'Activating…' , 'jetpack-forms' ) ) ||
57- ( isInstalling && __ ( 'Installing…' , 'jetpack-forms' ) ) ||
66+ ( ( isInstalling || isReconcilingStatus ) &&
67+ isInstalled &&
68+ __ ( 'Activating…' , 'jetpack-forms' ) ) ||
69+ ( ( isInstalling || isReconcilingStatus ) && __ ( 'Installing…' , 'jetpack-forms' ) ) ||
5870 ( isInstalled && __ ( 'Activate' , 'jetpack-forms' ) ) ||
5971 __ ( 'Install' , 'jetpack-forms' )
6072 ) ;
@@ -89,7 +101,7 @@ const PluginActionButton = ( {
89101 onClick = { handleAction }
90102 disabled = { isDisabled }
91103 style = { isDisabled ? { pointerEvents : 'none' } : undefined }
92- icon = { isInstalling ? < Spinner /> : undefined }
104+ icon = { isInstalling || isReconcilingStatus ? < Spinner /> : undefined }
93105 __next40pxDefaultSize
94106 >
95107 { getButtonText ( ) }
0 commit comments