11import React , { FC , useContext } from 'react'
22import { CTAButton , ComponentColor } from '@influxdata/clockface'
33import { CheckoutContext } from 'src/checkout/context/checkout'
4+ import { GoogleOptimizeExperiment } from 'src/cloud/components/experiments/GoogleOptimizeExperiment'
5+ import { getDataLayerIdentity } from 'src/cloud/utils/experiments'
6+ import { CREDIT_250_EXPERIMENT_ID } from 'src/shared/constants'
7+ import { event } from 'src/cloud/utils/reporting'
8+ import { isFlagEnabled } from 'src/shared/utils/featureFlag'
49
510const CancelButton : FC = ( ) => {
611 const { handleCancelClick} = useContext ( CheckoutContext )
712
8- return (
13+ const original = (
914 < CTAButton
1015 color = { ComponentColor . Default }
1116 onClick = { handleCancelClick }
@@ -14,6 +19,37 @@ const CancelButton: FC = () => {
1419 testID = "checkout-cancel--button"
1520 />
1621 )
22+
23+ const handleCancelCredit250Click = ( ) => {
24+ const identity = getDataLayerIdentity ( )
25+ event ( 'checkout.cancel.credit-250.upgrade' , {
26+ location : 'checkout' ,
27+ ...identity ,
28+ experimentId : CREDIT_250_EXPERIMENT_ID ,
29+ experimentVariantId : '1' ,
30+ } )
31+ handleCancelClick ( )
32+ }
33+
34+ if ( isFlagEnabled ( 'credit250Experiment' ) ) {
35+ return (
36+ < GoogleOptimizeExperiment
37+ experimentID = { CREDIT_250_EXPERIMENT_ID }
38+ original = { original }
39+ variants = { [
40+ < CTAButton
41+ key = "1"
42+ color = { ComponentColor . Default }
43+ onClick = { handleCancelCredit250Click }
44+ text = "Cancel"
45+ id = "button-cancel" // for google-analytics
46+ testID = "checkout-cancel--button"
47+ /> ,
48+ ] }
49+ />
50+ )
51+ }
52+ return original
1753}
1854
1955export default CancelButton
0 commit comments