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

Purchases: Highlight Upgrades Owned by Other Administrators #97198

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
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
51 changes: 51 additions & 0 deletions client/me/purchases/purchases-list/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import NoSitesMessage from 'calypso/components/empty-content/no-sites-message';
import InlineSupportLink from 'calypso/components/inline-support-link';
import Main from 'calypso/components/main';
import NavigationHeader from 'calypso/components/navigation-header';
import Notice from 'calypso/components/notice';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import TrackComponentView from 'calypso/lib/analytics/track-component-view';
import { getPurchasesBySite, getSubscriptionsBySite } from 'calypso/lib/purchases';
Expand Down Expand Up @@ -44,6 +45,55 @@ class PurchasesList extends Component {
return ! this.props.sites.length && ! this.props.subscriptions.length;
}

renderPurchasesByOtherAdminsNotice() {
const { sites, translate } = this.props;

/*
* Because this is only rendered when the user has no purchases,
* we don't need to check each site to ensure the purchases aren't
* linked with the user (they can't be, since they don't have any).
*/
const affectedSites = sites
.filter(
( site ) =>
( ! site.plan.is_free || site.products.length > 0 ) && site.capabilities.manage_options
)
.map( ( site ) => site.slug );

if ( ! affectedSites ) {
return;
}

let affectedSitesString = '';

if ( affectedSites.length === 1 ) {
affectedSitesString = affectedSites[ 0 ];
} else {
const allButLast = affectedSites.slice( 0, -1 ).join( ', ' );
const translatedAnd = translate( 'and', {
comment: 'last conjunction in a list of blognames: (blog1, blog2,) blog3 _and_ blog4',
} );
const last = affectedSites[ affectedSites.length - 1 ];

affectedSitesString = allButLast + ' ' + translatedAnd + ' ' + last;
Comment on lines +72 to +78
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do feel this is a bit clunky and fully open to recommendations - but looks like it's the approach used here (which is where I've also taken the string from to avoid the need for re-translation):

return uniqBy( xPostedToList, 'siteName' ).map( ( xPostedTo, index, array ) => {
return (
<span className="reader__x-post-site" key={ xPostedTo.siteURL + '-' + index }>
{ xPostedTo.siteName }
{ index + 2 < array.length && <span>, </span> }
{ index + 2 === array.length && (
<span>
{ ' ' }
{ translate( 'and', {
comment:
'last conjunction in a list of blognames: (blog1, blog2,) blog3 _and_ blog4',
} ) }{ ' ' }
</span>
) }
</span>
);
} );

}

return (
<Notice status="is-info" showDismiss={ false }>
{ translate(
'The upgrades for {{strong}}%(affectedSitesString)s{{/strong}} are owned by another site administrator. ' +
'These can only be managed by the purchase owner.',
{
components: { strong: <strong /> },
args: {
affectedSitesString,
},
}
) }
</Notice>
);
}

renderConciergeBanner() {
const { nextAppointment, availableSessions, isUserBlocked } = this.props;
return (
Expand Down Expand Up @@ -118,6 +168,7 @@ class PurchasesList extends Component {
eventName="calypso_no_purchases_upgrade_nudge_impression"
eventProperties={ commonEventProps }
/>
{ this.renderPurchasesByOtherAdminsNotice() }
<EmptyContent
title={ translate( 'Looking to upgrade?' ) }
line={ translate(
Expand Down
Loading