-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't display intro discount if not eligible (#95484)
* Don't display intro discount if not eligible * Fix tests * Remove testing edit in config file * Add global window object in tests * Fix test
- Loading branch information
1 parent
c3ca7c8
commit a96495f
Showing
4 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { AppState } from 'calypso/types'; | ||
|
||
/** | ||
* @param {Object} state Global state tree | ||
* @param {number} productId The productId to check for an intro offer | ||
* @param {number|'none'|undefined} siteId The ID of the site we're querying | ||
* @returns {boolean} Whether the site is eligible for an intro offer | ||
*/ | ||
|
||
export default function getIntroOfferEligibility( | ||
state: AppState, | ||
productId: number, | ||
siteId: number | 'none' | undefined | ||
): boolean { | ||
const siteIdKey = siteId && typeof siteId === 'number' && siteId > 0 ? siteId : 'none'; | ||
|
||
const introOffer = state.sites?.introOffers?.items?.[ siteIdKey ]?.[ productId ]; | ||
|
||
const ineligibleReason = introOffer?.ineligibleReason; | ||
|
||
return ! ineligibleReason || ineligibleReason?.length === 0; | ||
} |