File size: 872 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import { SECTION_SET } from 'calypso/state/action-types';
import { combineReducers, withSchemaValidation } from 'calypso/state/utils';
export const upgradeIntent = withSchemaValidation( { type: 'string' }, ( state = '', action ) => {
if ( action.type !== SECTION_SET ) {
return state;
}
if ( action.isLoading || ! action.section?.name ) {
// Leave the intent alone until the new section is fully loaded
return state;
}
if (
[ 'checkout', 'checkout-pending', 'checkout-thank-you', 'plans' ].includes(
action.section.name
)
) {
// Leave the intent alone for sections that should not clear it
return state;
}
if ( [ 'plugins', 'themes', 'hosting' ].includes( action.section.name ) ) {
return action.section.name;
}
// Clear the intent when any other section is loaded
return '';
} );
export default combineReducers( {
upgradeIntent,
} );
|