diff --git a/src/components/modals/HostModals/AddHost.tsx b/src/components/modals/HostModals/AddHost.tsx index 7c6679ec..4f472b01 100644 --- a/src/components/modals/HostModals/AddHost.tsx +++ b/src/components/modals/HostModals/AddHost.tsx @@ -137,12 +137,6 @@ const AddHost = (props: PropsToAddHost) => { pfError: ValidatedOptions.default, }); - useEffect(() => { - if (hostIpAddress === "") { - setForceCheckbox(false); - } - }, [hostIpAddress]); - const hostNameValidationHandler = (hostname: string) => { if (hostname === "") { const hostNameVal = { @@ -218,8 +212,6 @@ const AddHost = (props: PropsToAddHost) => { pfError: ValidatedOptions.error, }; setHostIpAddressValidation(ipVal); - // Can not force DNS bypass without a valid IP address - setForceCheckbox(false); } }, [hostName, dnsZoneSelected, hostIpAddress]); @@ -394,11 +386,12 @@ const AddHost = (props: PropsToAddHost) => { name="forceCheckbox" value="force" onChange={handleForceCheckbox} - isDisabled={hostIpAddressValidation.isError || hostIpAddress === ""} + isDisabled={hostIpAddressValidation.isError} /> - Requires valid IP address + Allow adding host objects that does not have DNS entries + associated with them @@ -492,13 +485,25 @@ const AddHost = (props: PropsToAddHost) => { } const newHostPayload = { fqdn: hostName + "." + dnsZone, - userclass: hostClass, - ip_address: hostIpAddress, - force: forceCheckbox, - description: description, - random: generateOtpCheckbox, } as HostAddPayload; + // Add the rest of parameters if they are not empty + if (hostClass !== "") { + newHostPayload.userclass = hostClass; + } + if (hostIpAddress !== "") { + newHostPayload.ip_address = hostIpAddress; + } + if (forceCheckbox) { + newHostPayload.force = forceCheckbox; + } + if (description !== "") { + newHostPayload.description = description; + } + if (generateOtpCheckbox) { + newHostPayload.random = generateOtpCheckbox; + } + // Add host via API call await executeHostAddCommand(newHostPayload).then((host) => { if ("data" in host) { diff --git a/src/services/rpcHosts.ts b/src/services/rpcHosts.ts index 2e56e5a2..41b4dce0 100644 --- a/src/services/rpcHosts.ts +++ b/src/services/rpcHosts.ts @@ -38,8 +38,8 @@ export interface HostAddPayload { fqdn: string; userclass?: string; ip_address?: string; - force: boolean; // skip DNS check - random: boolean; // otp generation + force?: boolean; // skip DNS check + random?: boolean; // otp generation description?: string; } @@ -109,13 +109,16 @@ const extendedApi = api.injectEndpoints({ [payloadData["fqdn"]], { version: API_VERSION_BACKUP, - userclass: payloadData["userclass"], - ip_address: payloadData["ip_address"], - force: payloadData["force"], - description: payloadData["description"], - random: payloadData["random"], }, ]; + // Add the rest of parameters if they are not undefined + Object.keys(payloadData).forEach((key) => { + if (payloadData[key] !== undefined && key !== "fqdn") { + params[1][key] = payloadData[key]; + } + }); + console.log("params", params); + return getCommand({ method: "host_add", params: params,