Skip to content

Commit

Permalink
A4A: add support for new Pressable plans (#94210)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-lysenko authored Sep 4, 2024
1 parent 2eabf34 commit 86647cc
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function getHostingLogo( slug: string, showText = true ) {
*/
export function isPressableHostingProduct( keyOrSlug: string ) {
return (
keyOrSlug.startsWith( 'pressable-wp' ) ||
keyOrSlug.startsWith( 'pressable-' ) ||
keyOrSlug.startsWith( 'pressable-hosting' ) ||
keyOrSlug.startsWith( 'jetpack-pressable' )
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo } from 'react';
import useFetchLicenseCounts from 'calypso/a8c-for-agencies/data/purchases/use-fetch-license-counts';
import { APIProductFamilyProduct } from 'calypso/state/partner-portal/types';
import getPressablePlan from '../lib/get-pressable-plan';

type Props = {
plans: APIProductFamilyProduct[];
Expand All @@ -11,7 +12,7 @@ export default function useExistingPressablePlan( { plans }: Props ) {

return useMemo( () => {
const pressablePlans = Object.keys( data?.products ?? {} ).filter( ( slug ) =>
slug.startsWith( 'pressable-wp' )
slug.startsWith( 'pressable-' )
);

const existingPlan = pressablePlans.find( ( slug ) => {
Expand All @@ -20,6 +21,7 @@ export default function useExistingPressablePlan( { plans }: Props ) {

return {
existingPlan: plans.find( ( plan ) => plan.slug === existingPlan ) ?? null,
pressablePlan: existingPlan ? getPressablePlan( existingPlan ) : null,
isReady,
};
}, [ data?.products, isReady, plans ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,68 @@ const PLAN_DATA: Record< string, PressablePlan > = {
visits: 2000000,
storage: 500,
},

// New pressable plans
'pressable-build': {
slug: 'pressable-build',
install: 1,
visits: 30000,
storage: 20,
},
'pressable-growth': {
slug: 'pressable-growth',
install: 3,
visits: 50000,
storage: 30,
},
'pressable-advanced': {
slug: 'pressable-advanced',
install: 5,
visits: 75000,
storage: 35,
},
'pressable-pro': {
slug: 'pressable-pro',
install: 10,
visits: 150000,
storage: 50,
},
'pressable-premium': {
slug: 'pressable-premium',
install: 20,
visits: 400000,
storage: 80,
},
'pressable-business': {
slug: 'pressable-business',
install: 50,
visits: 1000000,
storage: 200,
},
'pressable-business-80': {
slug: 'pressable-business-80',
install: 80,
visits: 1600000,
storage: 275,
},
'pressable-business-100': {
slug: 'pressable-business-100',
install: 100,
visits: 2000000,
storage: 325,
},
'pressable-business-120': {
slug: 'pressable-business-120',
install: 120,
visits: 2400000,
storage: 375,
},
'pressable-business-150': {
slug: 'pressable-business-150',
install: 150,
visits: 3000000,
storage: 450,
},
};

export default function getPressablePlan( slug: string ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { useDispatch } from 'calypso/state';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
import { APIProductFamilyProduct } from 'calypso/state/partner-portal/types';
import { FILTER_TYPE_INSTALL, FILTER_TYPE_VISITS } from '../constants';
import getPressablePlan from '../lib/get-pressable-plan';
import getPressablePlan, { PressablePlan } from '../lib/get-pressable-plan';
import getSliderOptions from '../lib/get-slider-options';
import { FilterType } from '../types';

type Props = {
selectedPlan: APIProductFamilyProduct | null;
plans: APIProductFamilyProduct[];
existingPlan?: APIProductFamilyProduct | null;
pressablePlan?: PressablePlan | null;
onSelectPlan: ( plan: APIProductFamilyProduct | null ) => void;
isLoading?: boolean;
};
Expand All @@ -25,6 +26,7 @@ export default function PlanSelectionFilter( {
plans,
onSelectPlan,
existingPlan,
pressablePlan,
isLoading,
}: Props ) {
const translate = useTranslate();
Expand Down Expand Up @@ -83,9 +85,22 @@ export default function PlanSelectionFilter( {
: 'a4a-pressable-filter-wrapper-visits';
const wrapperClass = clsx( additionalWrapperClass, 'pressable-overview-plan-selection__filter' );

const minimum = existingPlan
? options.findIndex( ( { value } ) => value === existingPlan.slug ) + 1
: 0;
const minimum = useMemo( () => {
if ( ! pressablePlan ) {
return 0;
}

const allAvailablePlans = plans
.map( ( plan ) => getPressablePlan( plan.slug ) )
.sort( ( a, b ) => a.install - b.install );

for ( let i = 0; i < allAvailablePlans.length; i++ ) {
if ( pressablePlan.install < allAvailablePlans[ i ].install ) {
return i;
}
}
return allAvailablePlans.length;
}, [ plans, pressablePlan ] );

if ( isLoading ) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export default function PressableOverviewPlanSelection( { onAddToCart }: Props )
productSearchQuery: '',
} );

const { existingPlan, isReady: isExistingPlanFetched } = useExistingPressablePlan( {
const {
existingPlan,
pressablePlan,
isReady: isExistingPlanFetched,
} = useExistingPressablePlan( {
plans: pressablePlans,
} );

Expand Down Expand Up @@ -82,6 +86,7 @@ export default function PressableOverviewPlanSelection( { onAddToCart }: Props )
plans={ pressablePlans }
onSelectPlan={ onSelectPlan }
existingPlan={ existingPlan }
pressablePlan={ pressablePlan }
isLoading={ ! isExistingPlanFetched }
/>
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const useGetLicenseIssuedMessage = () => {
const productName =
products?.data?.find?.( ( p ) => p.slug === licenses[ 0 ].slug )?.name ?? '';

if ( licenses[ 0 ].slug.startsWith( 'pressable-wp' ) ) {
if ( licenses[ 0 ].slug.startsWith( 'pressable-' ) ) {
return translate(
'Thanks for your purchase! Below you can view and manage your new {{strong}}%(productName)s{{/strong}}',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function RevokeLicenseDialog( {

const revoke = useCallback(
( force?: boolean ) => {
if ( ! force && licenseKey.startsWith( 'pressable-wp' ) ) {
if ( ! force && licenseKey.startsWith( 'pressable-' ) ) {
setShowPressableConfirmationDialog( true );
return;
}
Expand Down

0 comments on commit 86647cc

Please sign in to comment.