Skip to content

Commit

Permalink
Don't fetch add-on transaction history in onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyip committed Sep 21, 2023
1 parent e8c6736 commit 21e2cfb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions client/my-sites/add-ons/hooks/use-add-ons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import useAddOnPrices from './use-add-on-prices';
import type { AddOnMeta } from '@automattic/data-stores';

// some memoization. executes far too many times
const useAddOns = ( siteId?: number ): ( AddOnMeta | null )[] => {
const useAddOns = ( siteId?: number, isInSignup = false ): ( AddOnMeta | null )[] => {
const translate = useTranslate();

const addOnsActive = [
Expand Down Expand Up @@ -130,22 +130,25 @@ const useAddOns = ( siteId?: number ): ( AddOnMeta | null )[] => {
// get the list of supported features
const siteFeatures = getFeaturesBySiteId( state, siteId );
const filter = getBillingTransactionFilters( state, 'past' );
const filteredTransactions =
billingTransactions && filterTransactions( billingTransactions, filter, siteId );

const spaceUpgradesPurchased: number[] = [];

if ( filteredTransactions?.length && siteId ) {
for ( const transaction of filteredTransactions ) {
transaction.items?.length &&
spaceUpgradesPurchased.push(
...transaction.items
.filter( ( item ) => item.wpcom_product_slug === PRODUCT_1GB_SPACE )
.map( ( item ) => Number( item.licensed_quantity ) )
);
// It doesn't make sense to fetch purchase history and limit space upgrade add-ons if the user is
// creating a brand new site. For the time being, skip fetching transaction history in onboarding
// flows.
if ( billingTransactions && ! isInSignup ) {
const filteredTransactions = filterTransactions( billingTransactions, filter, siteId );

if ( filteredTransactions?.length ) {
for ( const transaction of filteredTransactions ) {
transaction.items?.length &&
spaceUpgradesPurchased.push(
...transaction.items
.filter( ( item ) => item.wpcom_product_slug === PRODUCT_1GB_SPACE )
.map( ( item ) => Number( item.licensed_quantity ) )
);
}
}
}

// Determine which Stats Add-On to show based on the site's commercial classification.
const isSiteMarkedCommercial = getSiteOption( state, siteId, 'is_commercial' );

Expand Down
2 changes: 1 addition & 1 deletion client/my-sites/plans-features-main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ const PlansFeaturesMain = ( {
const [ masterbarHeight, setMasterbarHeight ] = useState( 0 );
const translate = useTranslate();
const plansComparisonGridRef = useRef< HTMLDivElement >( null );
const storageAddOns = useAddOns( siteId ?? undefined ).filter(
const storageAddOns = useAddOns( siteId ?? undefined, isInSignup ).filter(
( addOn ) => addOn?.productSlug === PRODUCT_1GB_SPACE
);
const selectedStorageOptions = useSelect( ( select ) => {
Expand Down

0 comments on commit 21e2cfb

Please sign in to comment.