-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partner Coupon: Add a new Partner Coupon Redeem CTA (#22413)
Add a new partner coupon redeem CTA for connected users on the "At a Glance" page when a partner coupon is detected on the site. The CTA has a "Remind me later" option which will store the current timestamp in localStorage and hide the CTA until 3 days have passed. PT: pdpAdu-1U-p2
- Loading branch information
1 parent
d793b09
commit 2fe11ce
Showing
23 changed files
with
675 additions
and
107 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
vendor/ | ||
node_modules/ | ||
.nyc_output/ | ||
coverage/ |
4 changes: 4 additions & 0 deletions
4
projects/js-packages/partner-coupon/changelog/add-partner-coupon-redeem-post-connection-cta
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,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Add a new CTA to redeem a partner coupon after a connection is established and a partner coupon is detected |
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
173 changes: 173 additions & 0 deletions
173
...cts/js-packages/partner-coupon/components/redeem-partner-coupon-post-connection/index.jsx
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,173 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React, { useCallback, useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { ActionButton, JetpackLogo } from '@automattic/jetpack-components'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { usePartnerCouponRedemption } from '../../hooks'; | ||
|
||
/** | ||
* Import styles | ||
*/ | ||
import './style.scss'; | ||
|
||
export const DISMISS_LS_ITEM_NAME = 'jetpackRedeemPartnerCouponDismissedAt'; | ||
export const DISMISS_LS_ITEM_MAX_AGE = 3 * 24 * 60 * 60; // 3 days | ||
|
||
/** | ||
* Is partner coupon redeem CTA dismissed? | ||
* | ||
* @returns {boolean} Is the redeem CTA dismissed? | ||
*/ | ||
function isDismissed() { | ||
const dismissedAt = localStorage.getItem( DISMISS_LS_ITEM_NAME ); | ||
|
||
if ( | ||
! dismissedAt || | ||
new Date().getTime() > parseInt( dismissedAt ) + DISMISS_LS_ITEM_MAX_AGE * 1000 | ||
) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Dismiss partner coupon redeem CTA. | ||
* | ||
* @returns {void} | ||
*/ | ||
function dismiss() { | ||
localStorage.setItem( DISMISS_LS_ITEM_NAME, new Date().getTime() ); | ||
} | ||
|
||
const RedeemPartnerCouponPostConnection = props => { | ||
const { | ||
connectionStatus, | ||
partnerCoupon, | ||
assetBaseUrl, | ||
siteRawUrl, | ||
tracksUserData, | ||
analytics, | ||
} = props; | ||
const [ dismissed, setDismissed ] = useState( isDismissed() ); | ||
|
||
const onClick = usePartnerCouponRedemption( | ||
partnerCoupon, | ||
siteRawUrl, | ||
connectionStatus, | ||
tracksUserData, | ||
analytics | ||
); | ||
|
||
const onRemindMeLater = useCallback( () => { | ||
dismiss(); | ||
setDismissed( isDismissed() ); | ||
}, [ setDismissed ] ); | ||
|
||
if ( dismissed ) { | ||
return null; | ||
} | ||
|
||
let logoComponent = null; | ||
|
||
if ( partnerCoupon.partner.logo ) { | ||
logoComponent = ( | ||
<> | ||
<JetpackLogo /> | ||
<span>+</span> | ||
<img | ||
src={ `${ assetBaseUrl }${ partnerCoupon.partner.logo.src }` } | ||
alt={ sprintf( | ||
/* translators: %s: Name of Jetpack partner. */ | ||
__( 'Logo of %s who are offering a coupon in partnership with Jetpack', 'jetpack' ), | ||
partnerCoupon.partner.name | ||
) } | ||
width={ partnerCoupon.partner.logo.width } | ||
height={ partnerCoupon.partner.logo.height } | ||
/> | ||
</> | ||
); | ||
} else { | ||
logoComponent = <JetpackLogo />; | ||
} | ||
|
||
return ( | ||
<div className="jetpack-redeem-partner-coupon-post-connection"> | ||
<div className="jetpack-redeem-partner-coupon-post-connection__layout"> | ||
<div className="jetpack-redeem-partner-coupon-post-connection__content"> | ||
<div className="jetpack-redeem-partner-coupon-post-connection__logo"> | ||
{ logoComponent } | ||
</div> | ||
|
||
<h2 className="jetpack-redeem-partner-coupon-post-connection__heading"> | ||
{ __( 'One free year of Jetpack Backup', 'jetpack' ) } | ||
</h2> | ||
</div> | ||
<div | ||
className="jetpack-redeem-partner-coupon-post-connection__aside" | ||
style={ { | ||
backgroundImage: `url(${ assetBaseUrl }/images/jetpack-aside-background.jpg)`, | ||
} } | ||
> | ||
<img src={ assetBaseUrl + '/images/cloud-checkmark.svg' } alt="" /> | ||
</div> | ||
<div className="jetpack-redeem-partner-coupon-post-connection__subcontent"> | ||
<p> | ||
{ sprintf( | ||
/* translators: %s: Name of a Jetpack product. */ | ||
__( | ||
'Redeem your coupon and get started with %s for free the first year! Never worry about losing your data, ever.', | ||
'jetpack' | ||
), | ||
partnerCoupon.product.title | ||
) } | ||
</p> | ||
|
||
<ul> | ||
{ partnerCoupon.product.features.map( ( feature, key ) => ( | ||
<li key={ key }>{ feature }</li> | ||
) ) } | ||
</ul> | ||
|
||
<div className="jetpack-redeem-partner-coupon-post-connection__actions"> | ||
<div> | ||
<ActionButton | ||
label={ sprintf( | ||
/* translators: %s: Name of a Jetpack product. */ | ||
__( 'Redeem %s', 'jetpack' ), | ||
partnerCoupon.product.title | ||
) } | ||
onClick={ onClick } | ||
/> | ||
</div> | ||
<div> | ||
<button | ||
className="jetpack-redeem-partner-coupon-post-connection__remind-me-later" | ||
onClick={ onRemindMeLater } | ||
> | ||
{ __( 'Remind me later', 'jetpack' ) } | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
RedeemPartnerCouponPostConnection.propTypes = { | ||
assetBaseUrl: PropTypes.string.isRequired, | ||
connectionStatus: PropTypes.object.isRequired, | ||
partnerCoupon: PropTypes.object.isRequired, | ||
siteRawUrl: PropTypes.string.isRequired, | ||
tracksUserData: PropTypes.bool.isRequired, | ||
analytics: PropTypes.object, | ||
}; | ||
|
||
export default RedeemPartnerCouponPostConnection; |
Oops, something went wrong.