File size: 1,005 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import { useMutation } from '@tanstack/react-query';
import { DomainsApiError } from 'calypso/lib/domains/types';
import wp from 'calypso/lib/wp';
type Dnskey = {
algorithm: number;
flags: number;
protocol: number;
public_key: string;
rdata: string;
};
type DsData = {
algorithm: number;
digest: string;
digest_type: number;
key_tag: number;
rdata: string;
};
type EnableDnssecSuccessResponse = {
data: {
cryptokeys: Array< {
dnskey?: Dnskey;
ds_data?: Array< DsData >;
} >;
dnssec_data_set_at_registry: boolean;
};
};
export default function useEnableDnssecMutation(
domainName: string,
queryOptions: {
onSuccess?: ( success: EnableDnssecSuccessResponse ) => void;
onError?: ( error: DomainsApiError ) => void;
}
) {
const mutation = useMutation( {
mutationFn: () => {
return wp.req.post( {
path: `/domains/dnssec/${ domainName }`,
apiNamespace: 'wpcom/v2',
} );
},
...queryOptions,
} );
return { enableDnssec: mutation.mutate, ...mutation };
}
|