Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetpack plugin: add Jetpack partner coupon banner on My Page #22633

Merged
merged 6 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions projects/plugins/jetpack/_inc/client/my-plan/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getSiteConnectionStatus } from 'state/connection';

import MyPlanHeader from './my-plan-header';
import MyPlanBody from './my-plan-body';
import MyPlanPartnerCoupon from './my-plan-partner-coupon';

export function MyPlan( props ) {
let sitePlan = props.sitePlan.product_slug || '',
Expand All @@ -34,6 +35,7 @@ export function MyPlan( props ) {
return (
<React.Fragment>
<QuerySite />
<MyPlanPartnerCoupon siteRawUrl={ props.siteRawUrl } />
<MyPlanHeader
activeProducts={ props.activeProducts }
plan={ sitePlan }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* External dependencies
*/
import React, { useCallback, useEffect } from 'react';
import PropTypes from 'prop-types';

/**
* Internal dependencies
*/
import analytics from 'lib/analytics';
import MyPlanCard from '../my-plan-card';
import { imagePath } from 'constants/urls';

/**
* Import styles
*/
import './style.scss';

const MyPlanBanner = props => {
const { productSlug, action, title, tagLine, trackingId } = props;

useEffect( () => {
analytics.tracks.recordEvent( 'jetpack_my_plan_banner_view', {
type: trackingId,
} );
}, [ trackingId ] );

const trackActionClick = useCallback( () => {
analytics.tracks.recordJetpackClick( {
target: trackingId,
feature: 'my-plan-banner',
page: 'my-plan',
} );
kallehauge marked this conversation as resolved.
Show resolved Hide resolved
}, [ trackingId ] );

return (
<div className="jp-my-plan-banner">
<div
className="jp-my-plan-banner__card dops-card"
style={ { backgroundImage: `url(${ imagePath }jetpack-banner-gradient.png)` } }
>
<MyPlanCard
productSlug={ productSlug }
action={ React.cloneElement( action, { onClick: trackActionClick } ) }
title={ title }
tagLine={ tagLine }
/>
</div>
</div>
);
};

MyPlanBanner.propTypes = {
productSlug: PropTypes.string.isRequired,
trackingId: PropTypes.string.isRequired,
action: PropTypes.element.isRequired,
tagLine: PropTypes.oneOfType( [ PropTypes.string, PropTypes.node, PropTypes.element ] ),
title: PropTypes.oneOfType( [ PropTypes.string, PropTypes.node, PropTypes.element ] ),
};

export default MyPlanBanner;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@import '../../scss/calypso-colors';

.jp-my-plan-banner__card {
background-color: $white;
background-position: 100%;
background-size: 50% 100%;
background-repeat: no-repeat;
}

.jp-my-plan-banner .my-plan-card__icon {
margin-top: 8px;
margin-bottom: 8px;
}

.jp-my-plan-banner .my-plan-card__header {
align-self: center;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* External dependencies
*/
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { getRedirectUrl } from '@automattic/jetpack-components';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import Button from 'components/button';
import MyPlanBanner from '../my-plan-banner';
import { getPartnerCoupon } from 'state/initial-state';

const MyPlanPartnerCoupon = ( { partnerCoupon, siteRawUrl } ) => {
if ( 'object' !== typeof partnerCoupon ) {
return null;
}

const redeemButton = (
<Button
primary
href={ getRedirectUrl( 'jetpack-plugin-partner-coupon-checkout', {
path: partnerCoupon.product.slug,
site: siteRawUrl,
query: `coupon=${ partnerCoupon.coupon_code }`,
} ) }
>
{ __( 'Redeem', 'jetpack' ) }
atanas-dev marked this conversation as resolved.
Show resolved Hide resolved
</Button>
);

return (
<MyPlanBanner
productSlug={ partnerCoupon.product.slug }
action={ redeemButton }
title={ sprintf(
/* translators: %s: Jetpack product or plan name. */
__( 'Get %s free for one year!', 'jetpack' ),
partnerCoupon.product.title
) }
tagLine={ sprintf(
/* translators: %1$s: the name of a Jetpack partner, %2$s: the name of a Jetpack product or plan. */
__(
'Redeem your %1$s coupon to get started with %2$s for free the first year!',
kallehauge marked this conversation as resolved.
Show resolved Hide resolved
'jetpack'
),
partnerCoupon.partner.name,
partnerCoupon.product.title
) }
trackingId="jetpack-partner-coupon"
/>
);
};

MyPlanPartnerCoupon.propTypes = {
partnerCoupon: PropTypes.oneOfType( [ PropTypes.object, PropTypes.bool ] ).isRequired,
siteRawUrl: PropTypes.string.isRequired,
};

export default connect( state => ( {
partnerCoupon: getPartnerCoupon( state ),
} ) )( MyPlanPartnerCoupon );
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

Added Jetpack Partner Coupon banner on My Plan page
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.