Skip to content

Commit

Permalink
Move AddOns.useStorageAddOns into usePricingMetaForGridPlans hook
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyip committed Nov 27, 2024
1 parent 5d964b7 commit 8b6d87e
Show file tree
Hide file tree
Showing 27 changed files with 26 additions and 48 deletions.
2 changes: 1 addition & 1 deletion client/blocks/importer/wordpress/upgrade-plan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const UnwrappedUpgradePlan: React.FunctionComponent< UpgradePlanProps > =
coupon: undefined,
planSlugs: [ visiblePlan ],
siteId: site.ID,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
useCheckPlanAvailabilityForPurchase,
} );

Expand Down
2 changes: 1 addition & 1 deletion client/blocks/post-share/nudges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const UpgradeToPremiumNudge = ( { siteId }: Props ) => {
const pricing = Plans.usePricingMetaForGridPlans( {
siteId,
planSlugs: [ proposedPlanSlug as PlanSlug ],
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
coupon: undefined,
useCheckPlanAvailabilityForPurchase,
withProratedDiscounts: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ const WrappedCancelPurchaseForm = ( props ) => {
planSlugs: [ personalDowngradePlan?.getStoreSlug(), monthlyDowngradePlan?.getStoreSlug() ],
coupon: undefined,
siteId: null,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
useCheckPlanAvailabilityForPurchase,
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function PremiumGlobalStylesUpgradeModal( {
coupon: undefined,
planSlugs: [ upgradeToPlan ],
siteId: selectedSiteId,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
useCheckPlanAvailabilityForPurchase,
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const ScreenUpsell = ( { numOfSelectedGlobalStyles = 1, onCheckout, onTryStyle }
siteId: selectedSiteId,
coupon: undefined,
useCheckPlanAvailabilityForPurchase,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
} );
const pricing = pricingMeta?.[ PLAN_PREMIUM ];
const isPricingLoaded =
Expand Down
2 changes: 1 addition & 1 deletion client/me/purchases/manage-purchase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ const WrappedManagePurchase = (
planSlugs: [ relatedMonthlyPlanSlug as PlanSlug ],
siteId,
coupon: undefined,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
useCheckPlanAvailabilityForPurchase,
} );

Expand Down
2 changes: 1 addition & 1 deletion client/my-sites/checkout/upsell-nudge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ const WrappedUpsellNudge = (
siteId: selectedSiteId,
useCheckPlanAvailabilityForPurchase,
coupon: undefined,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
withProratedDiscounts: true,
} );

Expand Down
2 changes: 1 addition & 1 deletion client/my-sites/migrate/step-upgrade.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const WrappedStepUpgrade = ( props ) => {
planSlugs: [ planSlug ],
coupon: undefined,
siteId: targetSite.ID,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
useCheckPlanAvailabilityForPurchase,
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const usePlanUpsellInfo = ( { planSlug }: { planSlug: PlanSlug } ): PlanU
siteId,
coupon: undefined,
useCheckPlanAvailabilityForPurchase,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
} );
const currencyCode = pricingMeta?.[ planSlug ].currencyCode ?? 'USD';
const priceMonthly =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function useMaxPlanUpgradeCredits( { siteId, plans }: Props ): number {
const pricing = Plans.usePricingMetaForGridPlans( {
siteId,
planSlugs: plans,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
coupon: undefined,
useCheckPlanAvailabilityForPurchase,
withProratedDiscounts: true,
Expand Down
3 changes: 0 additions & 3 deletions client/my-sites/plans-features-main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ const PlansFeaturesMain = ( {
const [ lastClickedPlan, setLastClickedPlan ] = useState< string | null >( null );
const [ showPlansComparisonGrid, setShowPlansComparisonGrid ] = useState( false );
const translate = useTranslate();
const storageAddOns = AddOns.useStorageAddOns( { siteId } );
const currentPlan = Plans.useCurrentPlan( { siteId } );

const eligibleForWpcomMonthlyPlans = useSelector( ( state: IAppState ) =>
Expand Down Expand Up @@ -407,7 +406,6 @@ const PlansFeaturesMain = ( {
selectedPlan,
showLegacyStorageFeature,
siteId,
storageAddOns,
term,
useCheckPlanAvailabilityForPurchase,
useFreeTrialPlanSlugs,
Expand All @@ -430,7 +428,6 @@ const PlansFeaturesMain = ( {
selectedPlan,
showLegacyStorageFeature,
siteId,
storageAddOns,
term,
useCheckPlanAvailabilityForPurchase,
useFreeTrialPlanSlugs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const useEntrepreneurPlanPrices = () => {
],
coupon: undefined,
siteId: null,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
useCheckPlanAvailabilityForPurchase,
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function WooExpressPlans( props: WooExpressPlansProps ) {
siteId,
coupon: undefined,
useCheckPlanAvailabilityForPurchase,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
} );

const annualPlanMonthlyPrice =
Expand Down
2 changes: 1 addition & 1 deletion client/my-sites/plans/woo-express-plans-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const WooExpressPlansPage = ( {
siteId: null,
coupon: undefined,
useCheckPlanAvailabilityForPurchase,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
} );

// Using `discountedPrice` below will give us the price with any currency/conversion discounts applied.
Expand Down
2 changes: 1 addition & 1 deletion client/my-sites/stats/stats-upsell-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function StatsUpsellModal( { siteId }: { siteId: number } ) {
siteId: selectedSiteId,
coupon: undefined,
useCheckPlanAvailabilityForPurchase,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
} )?.[ PLAN_PREMIUM ];
const isLoading = plans.isLoading || ! pricing;
const isOdysseyStats = isEnabled( 'is_running_in_jetpack_site' );
Expand Down
4 changes: 2 additions & 2 deletions client/sites/overview/components/plan-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const PricingSection = () => {
coupon: undefined,
planSlugs: [ planSlug ],
siteId: site?.ID,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
useCheckPlanAvailabilityForPurchase,
} )?.[ planSlug ];
const planPurchaseLoading = ! isFreePlan && planPurchase === null;
Expand All @@ -94,7 +94,7 @@ const PricingSection = () => {
planSlug,
pricing: pricing ?? null,
isMonthlyPlan: pricing?.billingPeriod === PLAN_MONTHLY_PERIOD,
storageAddOnsForPlan: null,
reflectStorageSelectionInPlanPrices: false,
useCheckPlanAvailabilityForPurchase,
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
getTermFromDuration,
calculateMonthlyPrice,
} from '@automattic/calypso-products';
import { AddOns } from '@automattic/data-stores';
import { useSelect } from '@wordpress/data';
import * as Plans from '../';
import * as Purchases from '../../purchases';
import * as WpcomPlansUI from '../../wpcom-plans-ui';
import { COST_OVERRIDE_REASONS } from '../constants';
import type { AddOnMeta } from '../../add-ons/types';

export type UseCheckPlanAvailabilityForPurchase = ( {
planSlugs,
Expand Down Expand Up @@ -45,11 +45,6 @@ interface Props {
*/
useCheckPlanAvailabilityForPurchase: UseCheckPlanAvailabilityForPurchase;

/**
* `storageAddOmns` TODO: should become a required prop.
*/
storageAddOns: ( AddOnMeta | null )[] | null;

/**
* Whether to include discounts from plan proration.
* This is applicable only if a siteId is passed to this hook.
Expand Down Expand Up @@ -84,14 +79,14 @@ const usePricingMetaForGridPlans = ( {
siteId,
coupon,
useCheckPlanAvailabilityForPurchase,
storageAddOns,
withProratedDiscounts,
reflectStorageSelectionInPlanPrices = true,
}: Props ): { [ planSlug: string ]: Plans.PricingMetaForGridPlan } | null => {
// plans - should have a definition for all plans, being the main source of API data
const plans = Plans.usePlans( { coupon } );
// sitePlans - unclear if all plans are included
const sitePlans = Plans.useSitePlans( { coupon, siteId } );
const storageAddOns = AddOns.useStorageAddOns( { siteId } );
const currentPlan = Plans.useCurrentPlan( { siteId } );
const introOffers = Plans.useIntroOffers( { siteId, coupon } );
const purchasedPlan = Purchases.useSitePurchaseById( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const IntervalTypeToggle: React.FunctionComponent< IntervalTypeProps > =
coupon,
siteId,
useCheckPlanAvailabilityForPurchase,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
} );
const currentPlanBillingPeriod = currentSitePlanSlug
? pricingMeta?.[ currentSitePlanSlug ]?.billingPeriod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export default function useMaxDiscount(
siteId,
coupon: undefined,
useCheckPlanAvailabilityForPurchase,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
} );
const yearlyPlansPricing = Plans.usePricingMetaForGridPlans( {
planSlugs: yearlyVariantPlanSlugs,
siteId,
coupon: undefined,
useCheckPlanAvailabilityForPurchase,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
} );

const discounts = wpcomMonthlyPlans.map( ( planSlug ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function useMaxDiscountsForPlanTerms(
siteId,
coupon: undefined,
useCheckPlanAvailabilityForPurchase,
storageAddOns: null,
reflectStorageSelectionInPlanPrices: false,
} );

const termWiseMaxDiscount: Record< UrlFriendlyTermType, number > = {} as Record<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
isWooExpressPlan,
isFreePlan,
} from '@automattic/calypso-products';
import { AddOns } from '@automattic/data-stores';
import { formatCurrency } from '@automattic/format-currency';
import styled from '@emotion/styled';
import { useTranslate } from 'i18n-calypso';
Expand Down Expand Up @@ -55,15 +54,13 @@ const BillingTimeframe = ( { showRefundPeriod, planSlug }: Props ) => {
const { helpers, gridPlansIndex, coupon, siteId, enableTermSavingsPriceDisplay } =
usePlansGridContext();
const { isMonthlyPlan, billingTimeframe, pricing } = gridPlansIndex[ planSlug ];
const storageAddOns = AddOns.useStorageAddOns( { siteId } );

const { introOffer, billingPeriod } = pricing;
const planBillingDescription = usePlanBillingDescription( {
siteId,
planSlug,
pricing,
isMonthlyPlan,
storageAddOnsForPlan: storageAddOns,
coupon,
useCheckPlanAvailabilityForPurchase: helpers?.useCheckPlanAvailabilityForPurchase,
reflectStorageSelectionInPlanPrices: ! enableTermSavingsPriceDisplay,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
type PlanSlug,
} from '@automattic/calypso-products';
import { PlanPrice } from '@automattic/components';
import { AddOns, Plans } from '@automattic/data-stores';
import { Plans } from '@automattic/data-stores';
import { useEffect } from '@wordpress/element';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
Expand Down Expand Up @@ -68,11 +68,10 @@ const HeaderPrice = ( { planSlug, visibleGridPlans }: HeaderPriceProps ) => {
ignoreWhitespace: true,
} );

const storageAddOns = AddOns.useStorageAddOns( { siteId } );
const termVariantPlanSlug = useTermVariantPlanSlugForSavings( { planSlug, billingPeriod } );
const termVariantPricing = Plans.usePricingMetaForGridPlans( {
planSlugs: termVariantPlanSlug ? [ termVariantPlanSlug ] : [],
storageAddOns,
reflectStorageSelectionInPlanPrices: ! enableTermSavingsPriceDisplay,
coupon,
siteId,
useCheckPlanAvailabilityForPurchase: helpers?.useCheckPlanAvailabilityForPurchase,
Expand Down
3 changes: 1 addition & 2 deletions packages/plans-grid-next/src/hooks/data-store/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FeatureList, PlanSlug, TERMS_LIST } from '@automattic/calypso-products';
import { AddOnMeta, Plans } from '@automattic/data-stores';
import { Plans } from '@automattic/data-stores';
import { TranslateResult } from 'i18n-calypso';
import { GridPlan, HiddenPlans, PlansIntent } from '../../types';
import { UseFreeTrialPlanSlugs } from './use-grid-plans';
Expand All @@ -18,7 +18,6 @@ export interface UseGridPlansParams {
selectedPlan?: PlanSlug;
showLegacyStorageFeature?: boolean;
siteId?: number | null;
storageAddOns: ( AddOnMeta | null )[];
term?: ( typeof TERMS_LIST )[ number ]; // defaults to monthly
useCheckPlanAvailabilityForPurchase: Plans.UseCheckPlanAvailabilityForPurchase;
useFreeTrialPlanSlugs?: UseFreeTrialPlanSlugs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const useGridPlansForComparisonGrid = ( {
selectedPlan,
showLegacyStorageFeature,
siteId,
storageAddOns,
term,
useCheckPlanAvailabilityForPurchase,
useFreeTrialPlanSlugs,
Expand All @@ -42,7 +41,6 @@ const useGridPlansForComparisonGrid = ( {
selectedPlan,
siteId,
showLegacyStorageFeature,
storageAddOns,
term,
useCheckPlanAvailabilityForPurchase,
useFreeTrialPlanSlugs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const useGridPlansForFeaturesGrid = ( {
selectedPlan,
showLegacyStorageFeature,
siteId,
storageAddOns,
term,
useCheckPlanAvailabilityForPurchase,
useFreeTrialPlanSlugs,
Expand All @@ -39,7 +38,6 @@ const useGridPlansForFeaturesGrid = ( {
selectedPlan,
showLegacyStorageFeature,
siteId,
storageAddOns,
term,
useCheckPlanAvailabilityForPurchase,
useFreeTrialPlanSlugs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ const useGridPlans: UseGridPlansType = ( {
isInSignup,
eligibleForFreeHostingTrial,
isSubdomainNotGenerated,
storageAddOns,
coupon,
siteId,
isDisplayingPlansNeededForFeature,
Expand Down Expand Up @@ -287,7 +286,6 @@ const useGridPlans: UseGridPlansType = ( {
const pricedAPIPlans = Plans.usePlans( { coupon } );
const pricingMeta = Plans.usePricingMetaForGridPlans( {
planSlugs: availablePlanSlugs,
storageAddOns,
coupon,
siteId,
useCheckPlanAvailabilityForPurchase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TERM_ANNUALLY,
PLAN_HOSTING_TRIAL_MONTHLY,
} from '@automattic/calypso-products';
import { AddOns, Plans } from '@automattic/data-stores';
import { Plans } from '@automattic/data-stores';
import { formatCurrency } from '@automattic/format-currency';
import { useTranslate } from 'i18n-calypso';
import type { GridPlan } from '../../types';
Expand All @@ -19,7 +19,6 @@ interface UsePlanBillingDescriptionProps {
planSlug: PlanSlug;
pricing: GridPlan[ 'pricing' ] | null;
isMonthlyPlan?: boolean;
storageAddOnsForPlan: ( AddOns.AddOnMeta | null )[] | null;
coupon?: string;
useCheckPlanAvailabilityForPurchase: Plans.UseCheckPlanAvailabilityForPurchase;
reflectStorageSelectionInPlanPrices?: boolean;
Expand All @@ -29,7 +28,6 @@ export default function usePlanBillingDescription( {
siteId,
planSlug,
pricing,
storageAddOnsForPlan,
isMonthlyPlan,
coupon,
useCheckPlanAvailabilityForPurchase,
Expand All @@ -42,7 +40,6 @@ export default function usePlanBillingDescription( {

const yearlyVariantPricing = Plans.usePricingMetaForGridPlans( {
planSlugs: yearlyVariantPlanSlug ? [ yearlyVariantPlanSlug ] : [],
storageAddOns: storageAddOnsForPlan,
coupon,
siteId,
useCheckPlanAvailabilityForPurchase,
Expand Down

0 comments on commit 8b6d87e

Please sign in to comment.