Skip to content

Commit

Permalink
Update isEligibleForProPlan selector to check if siteId is Pro as well (
Browse files Browse the repository at this point in the history
#64457)

* Add plan check to the Pro plan eligibility checker

* Add server-friendly plan check

* Remove unnecessary and faulty current plan fetch
  • Loading branch information
claudiucelfilip committed Jun 16, 2022
1 parent 2ca11e5 commit e43f2b4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions client/my-sites/plans-comparison/is-eligible-for-pro-plan.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { isEnabled } from '@automattic/calypso-config';
import { isPro } from '@automattic/calypso-products';
import isAtomicSite from 'calypso/state/selectors/is-site-automated-transfer';
import isSiteWPForTeams from 'calypso/state/selectors/is-site-wpforteams';
import { isJetpackSite } from 'calypso/state/sites/selectors';
import { isJetpackSite, getSite } from 'calypso/state/sites/selectors';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import type { AppState } from 'calypso/types';

export function isEligibleForProPlan( state: AppState, siteId?: number ): boolean {
export function isEligibleForProPlan( state: AppState, siteId?: number | null ): boolean {
if (
siteId &&
( ( isJetpackSite( state, siteId ) && ! isAtomicSite( state, siteId ) ) ||
isSiteWPForTeams( state, siteId ) )
) {
return false;
}
siteId = siteId || getSelectedSiteId( state );
const selectedSite = getSite( state, siteId || '' );
const currentPlan = selectedSite?.plan;
if ( currentPlan && isPro( currentPlan ) ) {
return true;
}

return isEnabled( 'plans/pro-plan' );
}

0 comments on commit e43f2b4

Please sign in to comment.