|
1 |
| -import { |
2 |
| - isMonthly, |
3 |
| - isWpComPlan, |
4 |
| - getMonthlyPlanByYearly, |
5 |
| - type PlanSlug, |
6 |
| -} from '@automattic/calypso-products'; |
7 |
| -import { Plans } from '@automattic/data-stores'; |
8 | 1 | import { doesStringResembleDomain } from '@automattic/onboarding';
|
9 |
| -import { ResponseCartProduct } from '@automattic/shopping-cart'; |
10 | 2 | import { translate } from 'i18n-calypso';
|
11 |
| -import { useMemo } from 'react'; |
12 | 3 | import { untrailingslashit } from 'calypso/lib/route';
|
13 |
| -import useCheckPlanAvailabilityForPurchase from 'calypso/my-sites/plans-features-main/hooks/use-check-plan-availability-for-purchase'; |
14 | 4 | import { isUserLoggedIn } from 'calypso/state/current-user/selectors';
|
15 | 5 | import { getSelectedSite } from 'calypso/state/ui/selectors';
|
16 | 6 | import type { Context } from '@automattic/calypso-router';
|
@@ -145,52 +135,3 @@ export function getAffiliateCouponLabel(): string {
|
145 | 135 | // translators: The label of the coupon line item in checkout
|
146 | 136 | return translate( 'Exclusive Offer Applied' );
|
147 | 137 | }
|
148 |
| - |
149 |
| -/** |
150 |
| - * Calculate the equivalent monthly total prices for non-monthly WordPress.com plans from the passed |
151 |
| - * cart. For each eligible product it'd determine the equivalent monthly plan and return the monthly |
152 |
| - * plan price multiplied by the number of months in the yearly (or longer) plan. |
153 |
| - * Used for demonstrating the benefits of purchasing longer-term plans. |
154 |
| - * |
155 |
| - * @param products - Array of `ResponseCartProduct` items. |
156 |
| - * |
157 |
| - * @returns An object where each key is an eligible plan slug from the cart and the value is the |
158 |
| - * calculated total cost as if it was billed monthly. |
159 |
| - */ |
160 |
| -export function useEquivalentMonthlyTotals( |
161 |
| - products: Array< ResponseCartProduct > |
162 |
| -): Record< PlanSlug, number > { |
163 |
| - const isEligibleProduct = ( product: ResponseCartProduct ) => |
164 |
| - isWpComPlan( product?.product_slug ) && ! isMonthly( product?.product_slug ); |
165 |
| - |
166 |
| - const monthlyProductSlugs = useMemo( () => { |
167 |
| - return products |
168 |
| - .filter( isEligibleProduct ) |
169 |
| - .reduce( ( slugs: PlanSlug[], product: ResponseCartProduct ) => { |
170 |
| - if ( ! slugs.includes( product.product_slug as PlanSlug ) ) { |
171 |
| - slugs.push( getMonthlyPlanByYearly( product.product_slug ) as PlanSlug ); |
172 |
| - } |
173 |
| - return slugs; |
174 |
| - }, [] ); |
175 |
| - }, [ products ] ); |
176 |
| - const pricing = |
177 |
| - Plans.usePricingMetaForGridPlans( { |
178 |
| - planSlugs: monthlyProductSlugs, |
179 |
| - siteId: undefined, |
180 |
| - coupon: undefined, |
181 |
| - useCheckPlanAvailabilityForPurchase, |
182 |
| - } ) || {}; |
183 |
| - const monthlyEquivalentTotals = useMemo( () => { |
184 |
| - return products.filter( isEligibleProduct ).reduce( |
185 |
| - ( prices, product ) => { |
186 |
| - const monthlyPlan = getMonthlyPlanByYearly( product.product_slug ); |
187 |
| - prices[ product.product_slug as PlanSlug ] = |
188 |
| - ( product.months_per_bill_period ?? 0 ) * |
189 |
| - ( pricing[ monthlyPlan ]?.originalPrice?.monthly ?? 0 ); |
190 |
| - return prices; |
191 |
| - }, |
192 |
| - {} as Record< PlanSlug, number > |
193 |
| - ); |
194 |
| - }, [ products, pricing ] ); |
195 |
| - return monthlyEquivalentTotals; |
196 |
| -} |
0 commit comments