Skip to content

Commit

Permalink
Update plans store.
Browse files Browse the repository at this point in the history
- Add resetPlan action
- Use undefined instead of PLAN_FREE as selected plan
- extract defaultPaidPlan and freePlan as constants
  • Loading branch information
Razvan Papadopol committed May 8, 2020
1 parent b43e1d5 commit 8807a5a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
6 changes: 6 additions & 0 deletions client/landing/gutenboarding/stores/plans/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ export const setPlan = ( slug: string | undefined ) => {
slug,
};
};

export const resetPlan = () => {
return {
type: 'RESET_PLAN' as const,
};
};
8 changes: 8 additions & 0 deletions client/landing/gutenboarding/stores/plans/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
/**
* External dependencies
*/
import * as plans from '../../../../lib/plans/constants';

export const STORE_KEY = 'automattic/onboard/plans';

export const freePlan = plans.PLAN_FREE;
export const defaultPaidPlan = plans.PLAN_PREMIUM;
5 changes: 4 additions & 1 deletion client/landing/gutenboarding/stores/plans/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
*/
import { controls } from '@wordpress/data-controls';
import { plugins, registerStore, use } from '@wordpress/data';
import { SelectFromMap, DispatchFromMap } from '@automattic/data-stores';

/**
* Internal dependencies
*/
import { STORE_KEY } from './constants';
import reducer from './reducer';
import * as actions from './actions';
import * as selectors from './selectors';
import persistOptions from './persist';
import { SelectFromMap, DispatchFromMap } from '@automattic/data-stores';

use( plugins.persistence, persistOptions );

Expand Down
14 changes: 12 additions & 2 deletions client/landing/gutenboarding/stores/plans/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/**
* Internal dependencies
* External dependencies
*/
import * as plans from '../../../../lib/plans/constants';

/**
* Internal dependencies
*/
import { freePlan } from './constants';

export const supportedPlanSlugs = [
plans.PLAN_FREE,
plans.PLAN_PERSONAL,
Expand All @@ -24,7 +29,12 @@ const DEFAUlT_STATE: {
const reducer = function ( state = DEFAUlT_STATE, action: PlanAction ) {
switch ( action.type ) {
case 'SET_PLAN':
return { ...state, selectedPlanSlug: action.slug };
return {
...state,
selectedPlanSlug: action.slug !== freePlan ? action.slug : DEFAUlT_STATE.selectedPlanSlug,
};
case 'RESET_PLAN':
return DEFAUlT_STATE;
default:
return state;
}
Expand Down
11 changes: 6 additions & 5 deletions client/landing/gutenboarding/stores/plans/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
* External dependencies
*/
import { getPlan, getPlanPath } from '../../../../lib/plans';

/**
* Internal dependencies
*/
import { State, supportedPlanSlugs } from './reducer';
import * as plans from 'lib/plans/constants';
import { getPlan, getPlanPath } from 'lib/plans';
import { planFeatures, planDetails } from './plans-data';

const freePlan = plans.PLAN_FREE;
const defaultPaidPlan = plans.PLAN_PREMIUM;
import { defaultPaidPlan, freePlan } from './constants';

function getFortifiedPlan( slug: string | undefined ) {
if ( ! slug ) {
Expand Down

0 comments on commit 8807a5a

Please sign in to comment.