-
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: Use 2year and 3year default interval type (#96174)
Co-authored-by: Jeremy Yip <jeremy.yip@automattic.com>
- Loading branch information
1 parent
a2013c3
commit 1f562c3
Showing
8 changed files
with
126 additions
and
39 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...my-sites/plans-features-main/hooks/experiments/use-longer-plan-term-default-experiment.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,49 @@ | ||
import { useExperiment } from 'calypso/lib/explat'; | ||
|
||
const useTermFromExperimentVariant = ( | ||
experimentVariant: string | null | undefined | ||
): string | null => { | ||
switch ( experimentVariant ) { | ||
case 'default_to_three_year_plans': | ||
return '3yearly'; | ||
case 'default_to_two_year_plans': | ||
return '2yearly'; | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
/** | ||
* Returns: | ||
* - the term as yearly, 2yearly, 3yearly (etc.) to be used as default in the plans | ||
* page based on the experiment variant | ||
* - OR null/undefined if control variant or if the experiment is still loading (Subject to change) | ||
* | ||
* This hook although used for the experiment, it can be refactored in the end to | ||
* define the default term in the grid/plans page. | ||
* | ||
*/ | ||
const useLongerPlanTermDefaultExperiment = (): { | ||
isLoadingExperiment: boolean; | ||
term?: string | null; | ||
// TODO: Consider removing this and always return concrete term values (where undefined/null would mean no term savings) | ||
isEligibleForTermSavings: boolean; | ||
} => { | ||
// TODO: Figure out how to define explicit types for the experiment assignment | ||
// variation names 'default_to_three_year_plans', 'default_to_two_year_plans' | ||
// and 'emphasize_savings_only'. | ||
const [ isLoadingExperimentAssignment, experimentAssignment ] = useExperiment( | ||
'calypso_plans_page_emphasize_longer_plan_savings' | ||
); | ||
const term = useTermFromExperimentVariant( experimentAssignment?.variationName ); | ||
|
||
return { | ||
isLoadingExperiment: isLoadingExperimentAssignment, | ||
term: isLoadingExperimentAssignment ? undefined : term, | ||
isEligibleForTermSavings: !! ( | ||
experimentAssignment?.variationName && experimentAssignment.variationName !== 'control' | ||
), | ||
}; | ||
}; | ||
|
||
export default useLongerPlanTermDefaultExperiment; |
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
This file was deleted.
Oops, something went wrong.
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