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

Prevent users from purchasing additional mailboxes when the associated subscription expires/is expiring #53189

Merged
merged 6 commits into from
Jun 1, 2021
Merged
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
55 changes: 41 additions & 14 deletions client/my-sites/email/email-management/home/email-plan.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react';
import { connect } from 'react-redux';
import { isEnabled } from '@automattic/calypso-config';
import { localize } from 'i18n-calypso';
import { handleRenewNowClick, isExpired } from 'calypso/lib/purchases';
import page from 'page';
import PropTypes from 'prop-types';

Expand Down Expand Up @@ -118,6 +119,16 @@ class EmailPlan extends React.Component {
page( emailManagement( selectedSite.slug ) );
};

handleRenew = ( event ) => {
event.preventDefault();

const { purchase, selectedSite } = this.props;

handleRenewNowClick( purchase, selectedSite.slug, {
olaseni marked this conversation as resolved.
Show resolved Hide resolved
tracksProps: { source: 'email-plan-view' },
} );
};

getAddMailboxProps() {
const { currentRoute, domain, selectedSite } = this.props;

Expand Down Expand Up @@ -192,7 +203,7 @@ class EmailPlan extends React.Component {
return null;
}

if ( ! selectedSite || ! purchase ) {
if ( ! purchase ) {
return <VerticalNavItem isPlaceholder />;
}

Expand Down Expand Up @@ -254,17 +265,35 @@ class EmailPlan extends React.Component {
);
}

renderAddNewMailboxOrRenewalNavItem() {
const { domain, hasSubscription, purchase, selectedSite, translate } = this.props;

if ( ! domain.currentUserCanManage || ! hasSubscription ) {
return null;
}

if ( ! selectedSite || ! purchase ) {
olaseni marked this conversation as resolved.
Show resolved Hide resolved
return <VerticalNavItem isPlaceholder />;
}

if ( isExpired( purchase ) ) {
return (
<VerticalNavItem onClick={ this.handleRenew } path="#">
{ translate( 'Renew to add new mailboxes' ) }
</VerticalNavItem>
);
}

return (
<VerticalNavItem { ...this.getAddMailboxProps() }>
{ translate( 'Add new mailboxes' ) }
</VerticalNavItem>
);
}

render() {
const {
domain,
selectedSite,
hasSubscription,
purchase,
isLoadingPurchase,
translate,
} = this.props;

const addMailboxProps = this.getAddMailboxProps();
const { domain, selectedSite, hasSubscription, purchase, isLoadingPurchase } = this.props;

const { isLoadingEmailAccounts } = this.state;

return (
Expand Down Expand Up @@ -293,9 +322,7 @@ class EmailPlan extends React.Component {

<div className="email-plan__actions">
<VerticalNav>
<VerticalNavItem { ...addMailboxProps }>
{ translate( 'Add new mailbox' ) }
</VerticalNavItem>
{ this.renderAddNewMailboxOrRenewalNavItem() }
{ this.renderManageAllNavItem() }
{ this.renderBillingNavItem() }
</VerticalNav>
Expand Down