-
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.
Plans (grid): Disable term-savings price display if another discount …
…is active (intro/coupon/etc.) (#96631)
- Loading branch information
1 parent
61e16fb
commit 90dd8f2
Showing
6 changed files
with
103 additions
and
13 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
client/my-sites/plans-features-main/hooks/use-eligibility-for-term-savings-price-display.ts
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,66 @@ | ||
import { isEnabled } from '@automattic/calypso-config'; | ||
import { | ||
getPlanSlugForTermVariant, | ||
PlanSlug, | ||
URL_FRIENDLY_TERMS_MAPPING, | ||
UrlFriendlyTermType, | ||
} from '@automattic/calypso-products'; | ||
import { AddOns, Plans } from '@automattic/data-stores'; | ||
import { GridPlan } from '@automattic/plans-grid-next'; | ||
import useLongerPlanTermDefaultExperiment from './experiments/use-longer-plan-term-default-experiment'; | ||
import useCheckPlanAvailabilityForPurchase from './use-check-plan-availability-for-purchase'; | ||
|
||
const useEligibilityForTermSavingsPriceDisplay = ( { | ||
gridPlans, | ||
displayedIntervals, | ||
coupon, | ||
siteId, | ||
storageAddOns, | ||
isInSignup, | ||
}: { | ||
gridPlans: GridPlan[]; | ||
displayedIntervals: UrlFriendlyTermType[]; | ||
storageAddOns: ( AddOns.AddOnMeta | null )[] | null; | ||
coupon?: string; | ||
siteId?: number | null; | ||
isInSignup?: boolean; | ||
} ) => { | ||
const longerPlanTermDefaultExperiment = useLongerPlanTermDefaultExperiment(); | ||
const planSlugs = gridPlans.map( ( { planSlug } ) => planSlug ); | ||
const planSlugsForAllDisplayedIntervals = planSlugs.flatMap( | ||
( planSlug ) => | ||
displayedIntervals | ||
.map( ( term ) => | ||
getPlanSlugForTermVariant( planSlug, URL_FRIENDLY_TERMS_MAPPING[ term ] ) | ||
) | ||
.filter( ( planSlug ) => planSlug !== undefined ) as PlanSlug[] | ||
); | ||
const pricingForAllDisplayedIntervals = Plans.usePricingMetaForGridPlans( { | ||
planSlugs: planSlugsForAllDisplayedIntervals, | ||
storageAddOns, | ||
coupon, | ||
siteId, | ||
useCheckPlanAvailabilityForPurchase, | ||
} ); | ||
const isAnyGridPlanDiscounted = Object.values( pricingForAllDisplayedIntervals ?? {} ).reduce( | ||
( isDiscounted, { discountedPrice, introOffer } ) => { | ||
const hasDiscount = | ||
'number' === typeof discountedPrice.monthly || | ||
( introOffer && ! introOffer.isOfferComplete ); | ||
return isDiscounted || !! hasDiscount; | ||
}, | ||
false | ||
); | ||
|
||
if ( isAnyGridPlanDiscounted ) { | ||
return false; | ||
} | ||
|
||
return ( | ||
( isEnabled( 'plans/term-savings-price-display' ) || | ||
longerPlanTermDefaultExperiment.isEligibleForTermSavings ) && | ||
isInSignup | ||
); | ||
}; | ||
|
||
export default useEligibilityForTermSavingsPriceDisplay; |
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,13 @@ | ||
import { | ||
TERM_ANNUALLY, | ||
TERM_BIENNIALLY, | ||
TERM_MONTHLY, | ||
TERM_TRIENNIALLY, | ||
} from '@automattic/calypso-products'; | ||
|
||
export const EFFECTIVE_TERMS_LIST = < const >[ | ||
TERM_MONTHLY, | ||
TERM_ANNUALLY, | ||
TERM_BIENNIALLY, | ||
TERM_TRIENNIALLY, | ||
]; |
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