Skip to content

Commit

Permalink
Current plan with variation
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskmnds committed Nov 9, 2024
1 parent 17ee411 commit a0abfcc
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions client/my-sites/plans/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
PLAN_WOOEXPRESS_MEDIUM_MONTHLY,
PLAN_WOOEXPRESS_SMALL,
PLAN_WOOEXPRESS_SMALL_MONTHLY,
getBillingMonthsForTerm,
URL_FRIENDLY_TERMS_MAPPING,
} from '@automattic/calypso-products';
import page from '@automattic/calypso-router';
import { WpcomPlansUI, Plans } from '@automattic/data-stores';
Expand Down Expand Up @@ -551,19 +553,29 @@ export default function PlansWrapper( props ) {
const selectedSiteId = useSelector( getSelectedSiteId );
const currentPlan = Plans.useCurrentPlan( { siteId: selectedSiteId } );
const longerPlanTermDefaultExperiment = useLongerPlanTermDefaultExperiment();
// For WP.com plans page, if intervalType is not explicitly specified in the URL,
// we want to show plans of the same term as plan that is currently active
const intervalType = useSelector( ( state ) => getCurrentPlanTerm( state, selectedSiteId ) );
/**
* For WP.com plans page, if intervalType is not explicitly specified in the URL,
* we want to show plans of the same term as plan that is currently active
* We want to show the highest term between the current plan and the longer plan term default experiment
*/
const currentPlanTerm = useSelector( ( state ) =>
getIntervalTypeForTerm( getCurrentPlanTerm( state, selectedSiteId ) )
);
const intervalType =
longerPlanTermDefaultExperiment.term &&
currentPlanTerm &&
getBillingMonthsForTerm( URL_FRIENDLY_TERMS_MAPPING[ currentPlanTerm ] ) >
getBillingMonthsForTerm( URL_FRIENDLY_TERMS_MAPPING[ longerPlanTermDefaultExperiment.term ] )
? currentPlanTerm
: longerPlanTermDefaultExperiment.term;

return (
<CalypsoShoppingCartProvider>
<ConnectedPlans
{ ...props }
currentPlan={ currentPlan }
selectedSiteId={ selectedSiteId }
intervalType={
intervalTypeFromProps ?? longerPlanTermDefaultExperiment.term ?? intervalType
}
intervalType={ intervalTypeFromProps ?? intervalType ?? currentPlanTerm }
/>
</CalypsoShoppingCartProvider>
);
Expand Down

0 comments on commit a0abfcc

Please sign in to comment.