File size: 593 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { type BillingTerm, getTermFromDuration } from '@automattic/calypso-products';
import usePlans from '../queries/use-plans';
import useCurrentPlan from './use-current-plan';

interface Props {
	siteId?: string | number | null;
}

const useCurrentPlanTerm = ( { siteId }: Props ): BillingTerm[ 'term' ] | undefined => {
	const plans = usePlans( { coupon: undefined } ).data;
	const currentPlan = useCurrentPlan( { siteId } );

	return plans && currentPlan
		? getTermFromDuration( plans[ currentPlan.planSlug ]?.pricing?.billPeriod )
		: undefined;
};

export default useCurrentPlanTerm;