Skip to content

Commit ffa5839

Browse files
authored
Forms: Fix plugin button activating state (#45471)
1 parent 87c7723 commit ffa5839

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Forms: fix plugin activation state.

projects/packages/forms/src/blocks/contact-form/components/jetpack-integrations-modal/integration-card/integration-card-header.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ const IntegrationCardHeader = ( {
140140
slug={ cardData.slug }
141141
pluginFile={ cardData.pluginFile }
142142
isInstalled={ isInstalled }
143+
isActive={ isActive }
143144
refreshStatus={ cardData.refreshStatus }
144145
trackEventName={ cardData.trackEventName }
145146
/>

projects/packages/forms/src/blocks/contact-form/components/jetpack-integrations-modal/integration-card/plugin-action-button.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* External dependencies
33
*/
44
import { Button, Spinner, Tooltip } from '@wordpress/components';
5+
import { useEffect, useState } from '@wordpress/element';
56
import { __ } 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() }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: bugfix
3+
4+
Forms: fix plugin activation state.

0 commit comments

Comments
 (0)