Skip to content

Commit

Permalink
Add default jetpack icon on iconless sites in My Purchases
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeyGuyDylan committed Sep 20, 2024
1 parent 5eae987 commit 5e5a46c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
6 changes: 6 additions & 0 deletions client/assets/images/icons/jetpack-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 31 additions & 2 deletions client/me/purchases/purchase-item/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
PLAN_ANNUAL_PERIOD,
PLAN_BIENNIAL_PERIOD,
PLAN_TRIENNIAL_PERIOD,
isJetpackPlan,
isJetpackProduct,
} from '@automattic/calypso-products';
import page from '@automattic/calypso-router';
import { CompactCard, Gridicon } from '@automattic/components';
Expand All @@ -15,9 +17,12 @@ import { ExternalLink } from '@wordpress/components';
import { Icon, warning as warningIcon } from '@wordpress/icons';
import clsx from 'clsx';
import { localize, useTranslate } from 'i18n-calypso';
import { get } from 'lodash';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import akismetIcon from 'calypso/assets/images/icons/akismet-icon.svg';
import jetpackIcon from 'calypso/assets/images/icons/jetpack-icon.svg';
import payPalImage from 'calypso/assets/images/upgrades/paypal-full.svg';
import upiImage from 'calypso/assets/images/upgrades/upi.svg';
import SiteIcon from 'calypso/blocks/site-icon';
Expand All @@ -44,6 +49,8 @@ import {
hasPaymentMethod,
} from 'calypso/lib/purchases';
import { getPurchaseListUrlFor } from 'calypso/my-sites/purchases/paths';
import getSiteIconUrl from 'calypso/state/selectors/get-site-icon-url';
import { getSite } from 'calypso/state/sites/selectors';
import {
isTemporarySitePurchase,
isJetpackTemporarySitePurchase,
Expand Down Expand Up @@ -519,7 +526,7 @@ class PurchaseItem extends Component {
}

getSiteIcon = () => {
const { site, isDisconnectedSite, purchase } = this.props;
const { site, isDisconnectedSite, purchase, iconUrl } = this.props;

if ( isAkismetTemporarySitePurchase( purchase ) ) {
return (
Expand All @@ -541,6 +548,16 @@ class PurchaseItem extends Component {
);
}

const isJetpackPurchase = isJetpackProduct( purchase ) || isJetpackPlan( purchase );

if ( ! iconUrl && isJetpackPurchase ) {
return (
<div className="purchase-item__static-icon">
<img src={ jetpackIcon } alt="Jetpack icon" />;
</div>
);
}

return <SiteIcon site={ site } size={ 36 } />;
};

Expand Down Expand Up @@ -654,4 +671,16 @@ PurchaseItem.propTypes = {
isBackupMethodAvailable: PropTypes.bool,
};

export default localize( withLocalizedMoment( PurchaseItem ) );
export default connect( ( state, { site } ) => {
const stateSite = getSite( state, get( site, 'ID' ) );

if ( ! stateSite ) {
return {
iconUrl: site?.icon?.img,
};
}

return {
iconUrl: getSiteIconUrl( state, stateSite.ID ),
};
} )( localize( withLocalizedMoment( PurchaseItem ) ) );

0 comments on commit 5e5a46c

Please sign in to comment.