Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Forms: fix plugin activation state.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const IntegrationCardHeader = ( {
slug={ cardData.slug }
pluginFile={ cardData.pluginFile }
isInstalled={ isInstalled }
isActive={ isActive }
refreshStatus={ cardData.refreshStatus }
trackEventName={ cardData.trackEventName }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { Button, Spinner, Tooltip } from '@wordpress/components';
import { useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
Expand All @@ -13,6 +14,7 @@ type PluginActionButtonProps = {
slug: string;
pluginFile: string;
isInstalled: boolean;
isActive: boolean;
refreshStatus: () => void;
trackEventName: string;
};
Expand All @@ -21,6 +23,7 @@ const PluginActionButton = ( {
slug,
pluginFile,
isInstalled,
isActive,
refreshStatus,
trackEventName,
}: PluginActionButtonProps ) => {
Expand All @@ -31,13 +34,13 @@ const PluginActionButton = ( {
trackEventName
);

// Permissions from consolidated Forms config (shared across editor and dashboard)
const config = useFormsConfig();
const canUserInstallPlugins = Boolean( config?.canInstallPlugins );
const canUserActivatePlugins = Boolean( config?.canActivatePlugins );

const canPerformAction = isInstalled ? canUserActivatePlugins : canUserInstallPlugins;
const isDisabled = isInstalling || ! canPerformAction;
const [ isReconcilingStatus, setIsReconcilingStatus ] = useState( false );
const isDisabled = isInstalling || isReconcilingStatus || ! canPerformAction;

const handleAction = async ( event: MouseEvent ) => {
event.stopPropagation();
Expand All @@ -47,14 +50,23 @@ const PluginActionButton = ( {
const success = await installPlugin();

if ( success && refreshStatus ) {
setIsReconcilingStatus( true ); // Keeps button in loading state until integrations refresh.
refreshStatus();
}
};

useEffect( () => {
if ( isReconcilingStatus && isActive ) {
setIsReconcilingStatus( false ); // Removes button loading state when integratoin status is recevied and isActive.
}
}, [ isReconcilingStatus, isActive ] );

const getButtonText = () => {
return (
( isInstalling && isInstalled && __( 'Activating…', 'jetpack-forms' ) ) ||
( isInstalling && __( 'Installing…', 'jetpack-forms' ) ) ||
( ( isInstalling || isReconcilingStatus ) &&
isInstalled &&
__( 'Activating…', 'jetpack-forms' ) ) ||
( ( isInstalling || isReconcilingStatus ) && __( 'Installing…', 'jetpack-forms' ) ) ||
( isInstalled && __( 'Activate', 'jetpack-forms' ) ) ||
__( 'Install', 'jetpack-forms' )
);
Expand Down Expand Up @@ -89,7 +101,7 @@ const PluginActionButton = ( {
onClick={ handleAction }
disabled={ isDisabled }
style={ isDisabled ? { pointerEvents: 'none' } : undefined }
icon={ isInstalling ? <Spinner /> : undefined }
icon={ isInstalling || isReconcilingStatus ? <Spinner /> : undefined }
__next40pxDefaultSize
>
{ getButtonText() }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Forms: fix plugin activation state.
Loading