-
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.
Free Trials: Add
CartTrialAd
to PopoverCart
Fixes #1119.
- Loading branch information
1 parent
1332b94
commit 3ed6d9f
Showing
6 changed files
with
88 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import page from 'page'; | ||
import React from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { cartItems } from 'lib/cart-values'; | ||
import { getCurrentPlan, getDaysSinceTrialStarted } from 'lib/plans'; | ||
import i18n from 'lib/mixins/i18n'; | ||
import { addItem } from 'lib/upgrades/actions'; | ||
|
||
const CartTrialAd = ( { cart, sitePlans, selectedSite } ) => { | ||
function addToCartAndRedirect( event ) { | ||
event.preventDefault(); | ||
|
||
addItem( cartItems.planItem( getCurrentPlan( sitePlans.data ).productSlug ) ); | ||
|
||
page( `/checkout/${ selectedSite.slug }` ); | ||
} | ||
|
||
const isDataLoading = ! sitePlans.hasLoadedFromServer || ! cart.hasLoadedFromServer, | ||
currentPlan = getCurrentPlan( sitePlans.data ); | ||
|
||
if ( isDataLoading || | ||
! currentPlan.freeTrial || | ||
cartItems.getDomainRegistrations( cart ).length !== 1 ) { | ||
// we return `<noscript />` here because we can't return null in a stateless component | ||
// see https://github.com/facebook/react/issues/5355#issuecomment-152949327 | ||
return <noscript />; | ||
} | ||
|
||
return ( | ||
<div className="popover-cart__cart-trial-ad"> | ||
{ | ||
i18n.translate( 'You are currently on day %(days)d of your {{strong}}%(planName)s trial{{/strong}}.', { | ||
components: { strong: <strong /> }, | ||
args: { | ||
days: getDaysSinceTrialStarted( currentPlan ), | ||
planName: currentPlan.productName | ||
} | ||
} ) | ||
} | ||
{ ' ' } | ||
{ | ||
i18n.translate( 'Get this domain for free when you upgrade.' ) | ||
} | ||
{ ' ' } | ||
<a href="#" onClick={ addToCartAndRedirect }>{ i18n.translate( 'Upgrade Now' ) }</a> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CartTrialAd; |
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