🧑‍💻 Debug tool “reset” respects onboarding state

This commit is contained in:
Philipp Stracker 2025-01-13 14:42:59 +01:00
parent 5173954776
commit 99d93888e1
No known key found for this signature in database
2 changed files with 23 additions and 1 deletions

View file

@ -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();
} );