Redirect customers back to the payment task after enabling an offline gateway (https://github.com/woocommerce/woocommerce-admin/pull/8389)

* Redirect customers back to the payment task page after enabling an offline payment

* Add changelog

* Make hasPlugins property boolean

* Remove unnecessary type checking

* Fix the comparison logic
This commit is contained in:
Moon 2022-03-01 17:45:44 -08:00 committed by GitHub
parent d2205a6faf
commit 5d55b9b625
3 changed files with 33 additions and 7 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: Tweak
Redirect customers back to the payment task after enabling an offline payment gateway #8389

View File

@ -12,6 +12,7 @@ import { recordEvent } from '@woocommerce/tracks';
import { useMemo, useCallback, useEffect } from '@wordpress/element';
import { registerPlugin } from '@wordpress/plugins';
import { WooOnboardingTask } from '@woocommerce/onboarding';
import { getNewPath } from '@woocommerce/navigation';
/**
* Internal dependencies
@ -69,7 +70,9 @@ export const PaymentGatewaySuggestions = ( { onComplete, query } ) => {
const enrichedSuggestion = {
installed: !! mappedPaymentGateways[ id ],
postInstallScripts: installedGateway.post_install_scripts,
hasPlugins: suggestion.plugins && suggestion.plugins.length,
hasPlugins: !! (
suggestion.plugins && suggestion.plugins.length
),
enabled: installedGateway.enabled || false,
needsSetup: installedGateway.needs_setup,
settingsUrl: installedGateway.settings_url,
@ -121,7 +124,19 @@ export const PaymentGatewaySuggestions = ( { onComplete, query } ) => {
updatePaymentGateway( id, {
enabled: true,
} ).then( () => {
onComplete();
onComplete(
// use the paymentGateways variable.
// gateway variable doesn't have hasPlugins property.
! paymentGateways.get( id )?.hasPlugins
? {
redirectPath: getNewPath(
{ task: 'payments' },
{},
'/'
),
}
: {}
);
} );
};

View File

@ -26,11 +26,18 @@ export const Task: React.FC< TaskProps > = ( { query, task } ) => {
optimisticallyCompleteTask,
} = useDispatch( ONBOARDING_STORE_NAME );
const onComplete = useCallback( () => {
optimisticallyCompleteTask( id );
getHistory().push( getNewPath( {}, '/', {} ) );
invalidateResolutionForStoreSelector( 'getTaskLists' );
}, [ id ] );
const onComplete = useCallback(
( options ) => {
optimisticallyCompleteTask( id );
getHistory().push(
options && options.redirectPath
? options.redirectPath
: getNewPath( {}, '/', {} )
);
invalidateResolutionForStoreSelector( 'getTaskLists' );
},
[ id ]
);
return (
<>