File size: 769 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import { useQuery, UseQueryResult } from '@tanstack/react-query';
import wpcom from 'calypso/lib/wp';
import { mapSingleLicenseApiToLicense } from './utils';
import type { UserLicenseApi, UserLicense } from './types';
const useUserLicenseBySubscriptionQuery = (
subscriptionId: number
): UseQueryResult< UserLicense > => {
const queryKey = [ 'user-license', subscriptionId ];
return useQuery< UserLicenseApi, Error, UserLicense >( {
queryKey,
queryFn: async () =>
wpcom.req.get( {
path: `/jetpack-licensing/user/subscription/${ subscriptionId }`,
apiNamespace: 'wpcom/v2',
} ),
select: mapSingleLicenseApiToLicense,
refetchIntervalInBackground: false,
refetchOnWindowFocus: false,
} );
};
export default useUserLicenseBySubscriptionQuery;
|