File size: 1,245 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 35 36 37 38 39 40 41 |
import { combineReducers } from '@wordpress/data';
import type { WpcomPlansUIAction } from './actions';
import type { SelectedStorageOptionForPlan } from './types';
import type { Reducer } from 'redux';
const showDomainUpsellDialog: Reducer< boolean | undefined, WpcomPlansUIAction > = (
state,
action
) => {
if ( action.type === 'WPCOM_PLANS_UI_RESET_STORE' ) {
return undefined;
} else if ( action.type === 'WPCOM_PLANS_UI_DOMAIN_UPSELL_DIALOG_SET_SHOW' ) {
return action.show;
}
return state;
};
const selectedStorageOptionForPlan: Reducer<
SelectedStorageOptionForPlan | undefined,
WpcomPlansUIAction
> = ( state, action ) => {
if ( action.type === 'WPCOM_PLANS_UI_SET_SELECTED_STORAGE_OPTION_FOR_PLAN' ) {
return {
...state,
// @ts-expect-error TS is unhappy if we index an object by a null or an undefined value. We, however,
// expect siteId to be null or undefined here before site creation ( Ex. during onboarding ).
[ action.siteId ]: { ...state?.[ action.siteId ], [ action.planSlug ]: action.addOnSlug },
};
}
return state;
};
const reducer = combineReducers( {
showDomainUpsellDialog,
selectedStorageOptionForPlan,
} );
export type State = ReturnType< typeof reducer >;
export default reducer;
|