File size: 832 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
import { useQuery, UseQueryOptions } from '@tanstack/react-query';
import wp from 'calypso/lib/wp';
import { GITHUB_DEPLOYMENTS_QUERY_KEY } from '../constants';
import { CodeDeploymentData } from '../deployments/use-code-deployments-query';

export const CODE_DEPLOYMENTS_QUERY_KEY = 'code-deployments';

export const useCodeDeploymentQuery = (
	siteId: number | null,
	deploymentId: number,
	options?: UseQueryOptions< CodeDeploymentData >
) => {
	return useQuery< CodeDeploymentData >( {
		enabled: !! siteId,
		queryKey: [ GITHUB_DEPLOYMENTS_QUERY_KEY, CODE_DEPLOYMENTS_QUERY_KEY, siteId, deploymentId ],
		queryFn: (): CodeDeploymentData =>
			wp.req.get( {
				path: `/sites/${ siteId }/hosting/code-deployments/${ deploymentId }`,
				apiNamespace: 'wpcom/v2',
			} ),
		meta: {
			persist: false,
		},
		...options,
	} );
};