Skip to content

Commit

Permalink
🧑‍💻 Debug tool “reset” respects onboarding state
Browse files Browse the repository at this point in the history
  • Loading branch information
stracker-phil committed Jan 13, 2025
1 parent 5173954 commit 99d9388
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions modules/ppcp-settings/resources/js/data/common/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const commonReducer = createReducer( defaultTransient, defaultPersistent, {

// Keep "read-only" details and initialization flags.
cleanState.wooSettings = { ...state.wooSettings };
cleanState.merchant = { ...state.merchant };
cleanState.features = { ...state.features };
cleanState.isReady = true;

return cleanState;
Expand Down
22 changes: 21 additions & 1 deletion modules/ppcp-settings/resources/js/data/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,32 @@ export const addDebugTools = ( context, modules ) => {
/* eslint-enable no-console */
};

// Reset all Redux stores to their initial state.
context.resetStore = () => {
const stores = [ OnboardingStoreName, CommonStoreName ];
const stores = [];
const { isConnected } = wp.data.select( CommonStoreName ).merchant();

if ( isConnected ) {
// Make sure the Onboarding wizard is "completed".
const onboarding = wp.data.dispatch( OnboardingStoreName );
onboarding.setCompleted( true );
onboarding.persist();

// Reset all stores, except for the onboarding store.
stores.push( CommonStoreName );
// TODO: Add other stores here once they are available.
} else {
// Only reset the common & onboarding stores to restart the onboarding wizard.
stores.push( CommonStoreName );
stores.push( OnboardingStoreName );
}

stores.forEach( ( storeName ) => {
const store = wp.data.dispatch( storeName );

// eslint-disable-next-line no-console
console.log( `Reset store: ${ storeName }...` );

store.reset();
store.persist();
} );
Expand Down

0 comments on commit 99d9388

Please sign in to comment.