File size: 930 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
25
26
27
28
29
30
31
32
import { useQuery } from '@tanstack/react-query';
import { buildQueryKey, callApi } from '../helpers';
import { useIsLoggedIn, useIsQueryEnabled } from '../hooks';
import type { SiteSubscriptionDetailsResponse } from '../types';

const useSiteSubscriptionDetailsQuery = ( blogId = '', subscriptionId = '' ) => {
	const { id, isLoggedIn } = useIsLoggedIn();
	const enabled = useIsQueryEnabled();

	return useQuery( {
		queryKey: buildQueryKey(
			[ 'read', 'site-subscription-details', blogId, subscriptionId ],
			isLoggedIn,
			id
		),
		queryFn: async () => {
			return callApi< SiteSubscriptionDetailsResponse< string > >( {
				path: blogId
					? '/read/sites/' + blogId + '/subscription-details'
					: '/read/subscriptions/' + subscriptionId,
				isLoggedIn,
				apiNamespace: 'wpcom/v2',
				apiVersion: '2',
			} );
		},
		enabled,
		refetchOnWindowFocus: false,
	} );
};

export default useSiteSubscriptionDetailsQuery;