fix default lease duration value
This commit is contained in:
@@ -179,6 +179,7 @@ const FormDHCPv4 = ({ processingConfig, ipv4placeholders, interfaces, onSubmit }
|
|||||||
disabled={!isInterfaceIncludesIpv4}
|
disabled={!isInterfaceIncludesIpv4}
|
||||||
min={1}
|
min={1}
|
||||||
max={UINT32_RANGE.MAX}
|
max={UINT32_RANGE.MAX}
|
||||||
|
value={field.value ?? ''}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const { value } = e.target;
|
const { value } = e.target;
|
||||||
field.onChange(toNumber(value));
|
field.onChange(toNumber(value));
|
||||||
|
|||||||
@@ -40,19 +40,38 @@ import {
|
|||||||
import './index.css';
|
import './index.css';
|
||||||
import { RootState } from '../../../initialState';
|
import { RootState } from '../../../initialState';
|
||||||
|
|
||||||
|
type IPv4FormValues = {
|
||||||
|
gateway_ip?: string;
|
||||||
|
subnet_mask?: string;
|
||||||
|
range_start?: string;
|
||||||
|
range_end?: string;
|
||||||
|
lease_duration?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
type IPv6FormValues = {
|
||||||
|
range_start?: string;
|
||||||
|
range_end?: string;
|
||||||
|
lease_duration?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getDefaultV4Values = (v4: IPv4FormValues) => {
|
||||||
|
const emptyForm = Object.entries(v4).every(
|
||||||
|
([key, value]) => key === 'lease_duration' || value === ''
|
||||||
|
);
|
||||||
|
|
||||||
|
if (emptyForm) {
|
||||||
|
return {
|
||||||
|
...v4,
|
||||||
|
lease_duration: undefined,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return v4;
|
||||||
|
}
|
||||||
|
|
||||||
export type DhcpFormValues = {
|
export type DhcpFormValues = {
|
||||||
v4?: {
|
v4?: IPv4FormValues;
|
||||||
gateway_ip?: string;
|
v6?: IPv6FormValues;
|
||||||
subnet_mask?: string;
|
|
||||||
range_start?: string;
|
|
||||||
range_end?: string;
|
|
||||||
lease_duration?: number;
|
|
||||||
};
|
|
||||||
v6?: {
|
|
||||||
range_start?: string;
|
|
||||||
range_end?: string;
|
|
||||||
lease_duration?: number;
|
|
||||||
};
|
|
||||||
interface_name?: string;
|
interface_name?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,13 +80,13 @@ const DEFAULT_V4_VALUES = {
|
|||||||
subnet_mask: '',
|
subnet_mask: '',
|
||||||
range_start: '',
|
range_start: '',
|
||||||
range_end: '',
|
range_end: '',
|
||||||
lease_duration: 0,
|
lease_duration: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_V6_VALUES = {
|
const DEFAULT_V6_VALUES = {
|
||||||
range_start: '',
|
range_start: '',
|
||||||
range_end: '',
|
range_end: '',
|
||||||
lease_duration: 0,
|
lease_duration: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
const Dhcp = () => {
|
const Dhcp = () => {
|
||||||
@@ -98,7 +117,7 @@ const Dhcp = () => {
|
|||||||
const methods = useForm<DhcpFormValues>({
|
const methods = useForm<DhcpFormValues>({
|
||||||
mode: 'onBlur',
|
mode: 'onBlur',
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
v4,
|
v4: getDefaultV4Values(v4),
|
||||||
v6,
|
v6,
|
||||||
interface_name: interfaceName || '',
|
interface_name: interfaceName || '',
|
||||||
},
|
},
|
||||||
@@ -129,7 +148,7 @@ const Dhcp = () => {
|
|||||||
reset({
|
reset({
|
||||||
v4: {
|
v4: {
|
||||||
...DEFAULT_V4_VALUES,
|
...DEFAULT_V4_VALUES,
|
||||||
...v4,
|
...getDefaultV4Values(v4),
|
||||||
},
|
},
|
||||||
v6: {
|
v6: {
|
||||||
...DEFAULT_V6_VALUES,
|
...DEFAULT_V6_VALUES,
|
||||||
|
|||||||
Reference in New Issue
Block a user