Skip to content

Commit

Permalink
Redirect customers back to the payment task after enabling an offline…
Browse files Browse the repository at this point in the history
… gateway (woocommerce#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
  • Loading branch information
moon0326 authored Mar 2, 2022
1 parent ab7be49 commit 72e885e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: Tweak

Redirect customers back to the payment task after enabling an offline payment gateway #8389
19 changes: 17 additions & 2 deletions client/tasks/fills/PaymentGatewaySuggestions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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' },
{},
'/'
),
}
: {}
);
} );
};

Expand Down
17 changes: 12 additions & 5 deletions client/tasks/task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand Down

0 comments on commit 72e885e

Please sign in to comment.