File size: 977 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 33 34 35 | import { useMutation, useQueryClient } from '@tanstack/react-query';
import { sslDetailsQueryKey } from 'calypso/data/domains/ssl/ssl-details-query-key';
import wp from 'calypso/lib/wp';
import type { DomainsApiError } from 'calypso/lib/domains/types';
export default function useProvisionCertificateMutation(
domainName: string,
queryOptions: {
onSuccess?: () => void;
onError?: ( error: DomainsApiError ) => void;
}
) {
const queryClient = useQueryClient();
const mutation = useMutation( {
mutationFn: () =>
wp.req
.post( {
path: `/domains/ssl/${ domainName }`,
apiNamespace: 'wpcom/v2',
} )
.then( () => {} ),
...queryOptions,
onSuccess() {
const key = sslDetailsQueryKey( domainName );
queryClient.invalidateQueries( { queryKey: key } );
queryOptions.onSuccess?.();
},
onError( error: DomainsApiError ) {
queryOptions.onError?.( error );
},
} );
return { provisionCertificate: mutation.mutate, ...mutation };
}
|