Skip to content

Commit

Permalink
Redirect to plugins.php after plugin activation instead of Congrats p…
Browse files Browse the repository at this point in the history
…age (#95050)

* Redirect to plugins.php after plugin activation instead of Congrats page

* See if Simple flow works with longer wait time

* Check WPCOM_FEATURES_MANAGE_PLUGINS before redirecting
  • Loading branch information
okmttdhr authored Oct 7, 2024
1 parent e80588b commit cf0aa1a
Showing 1 changed file with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { PLAN_BUSINESS, WPCOM_FEATURES_ATOMIC, getPlan } from '@automattic/calypso-products';
import {
PLAN_BUSINESS,
WPCOM_FEATURES_ATOMIC,
getPlan,
WPCOM_FEATURES_MANAGE_PLUGINS,
} from '@automattic/calypso-products';
import page from '@automattic/calypso-router';
import { Button } from '@automattic/components';
import { css, Global, ThemeProvider } from '@emotion/react';
Expand Down Expand Up @@ -43,7 +48,7 @@ import getUploadedPluginId from 'calypso/state/selectors/get-uploaded-plugin-id'
import isPluginUploadComplete from 'calypso/state/selectors/is-plugin-upload-complete';
import isSiteAutomatedTransfer from 'calypso/state/selectors/is-site-automated-transfer';
import siteHasFeature from 'calypso/state/selectors/site-has-feature';
import { isJetpackSite } from 'calypso/state/sites/selectors';
import { isJetpackSite, getSiteAdminUrl } from 'calypso/state/sites/selectors';
import {
initiateThemeTransfer as initiateTransfer,
installAndActivateTheme,
Expand Down Expand Up @@ -260,29 +265,41 @@ const MarketplaceProductInstall = ( {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ pluginUploadComplete, installedPlugin, setCurrentStep ] );

const pluginsUrl = useSelector( ( state ) =>
getSiteAdminUrl( state, siteId, 'plugins.php?activate=true' )
);
const canManagePlugins = useSelector( ( state ) => {
return siteHasFeature( state, selectedSite?.ID, WPCOM_FEATURES_MANAGE_PLUGINS );
} );
// Check completition of all flows and redirect to thank you page
useEffect( () => {
if (
// Default process
( installedPlugin && pluginActive ) ||
// Transfer to atomic using a marketplace plugin
( atomicFlow && transferStates.COMPLETE === automatedTransferStatus ) ||
( atomicFlow && transferStates.COMPLETE === automatedTransferStatus && canManagePlugins ) ||
// Transfer to atomic uploading a zip plugin
( uploadedPluginSlug &&
isPluginUploadFlow &&
! isAtomic &&
transferStates.COMPLETE === automatedTransferStatus )
transferStates.COMPLETE === automatedTransferStatus &&
canManagePlugins )
) {
waitFor( 1 ).then( () =>
page.redirect(
`/marketplace/thank-you/${ selectedSiteSlug }?hide-progress-bar&plugins=${
installedPlugin?.slug || pluginSlug || uploadedPluginSlug
}`
)
);
waitFor( 1 ).then( () => {
window.location.href = pluginsUrl as string;
} );
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ pluginActive, automatedTransferStatus, atomicFlow, isPluginUploadFlow, isAtomic ] ); // We need to trigger this hook also when `automatedTransferStatus` changes cause the plugin install is done on the background in that case.
}, [
pluginActive,
automatedTransferStatus,
atomicFlow,
isPluginUploadFlow,
isAtomic,
canManagePlugins,
installedPlugin,
uploadedPluginSlug,
pluginsUrl,
] ); // We need to trigger this hook also when `automatedTransferStatus` changes cause the plugin install is done on the background in that case.

// Validate theme is already active
useEffect( () => {
Expand Down

0 comments on commit cf0aa1a

Please sign in to comment.