diff --git a/client/src/actions/index.js b/client/src/actions/index.js index a67aa987..d683a3f5 100644 --- a/client/src/actions/index.js +++ b/client/src/actions/index.js @@ -711,11 +711,11 @@ export const addStaticLeaseSuccess = createAction('ADD_STATIC_LEASE_SUCCESS'); export const addStaticLease = config => async (dispatch) => { dispatch(addStaticLeaseRequest()); try { + const name = config.hostname || config.ip; await apiClient.addStaticLease(config); - dispatch(addStaticLeaseSuccess()); - dispatch(addSuccessToast(t('dhcp_lease_added', { key: config.hostname }))); + dispatch(addStaticLeaseSuccess(config)); + dispatch(addSuccessToast(t('dhcp_lease_added', { key: name }))); dispatch(toggleLeaseModal()); - dispatch(getDhcpStatus()); } catch (error) { dispatch(addErrorToast({ error })); dispatch(addStaticLeaseFailure()); @@ -729,10 +729,10 @@ export const removeStaticLeaseSuccess = createAction('REMOVE_STATIC_LEASE_SUCCES export const removeStaticLease = config => async (dispatch) => { dispatch(removeStaticLeaseRequest()); try { + const name = config.hostname || config.ip; await apiClient.removeStaticLease(config); - dispatch(removeStaticLeaseSuccess()); - dispatch(addSuccessToast(t('dhcp_lease_deleted', { key: config.hostname }))); - dispatch(getDhcpStatus()); + dispatch(removeStaticLeaseSuccess(config)); + dispatch(addSuccessToast(t('dhcp_lease_deleted', { key: name }))); } catch (error) { dispatch(addErrorToast({ error })); dispatch(removeStaticLeaseFailure()); diff --git a/client/src/components/Settings/Dhcp/StaticLeases/Form.js b/client/src/components/Settings/Dhcp/StaticLeases/Form.js index 28f843ed..6695a6b3 100644 --- a/client/src/components/Settings/Dhcp/StaticLeases/Form.js +++ b/client/src/components/Settings/Dhcp/StaticLeases/Form.js @@ -50,7 +50,6 @@ const Form = (props) => { type="text" className="form-control" placeholder={t('form_enter_hostname')} - validate={[required]} /> diff --git a/client/src/components/Settings/Dhcp/StaticLeases/index.js b/client/src/components/Settings/Dhcp/StaticLeases/index.js index 1e5b9208..e96e806e 100644 --- a/client/src/components/Settings/Dhcp/StaticLeases/index.js +++ b/client/src/components/Settings/Dhcp/StaticLeases/index.js @@ -18,9 +18,10 @@ class StaticLeases extends Component { this.props.addStaticLease(data); } - handleDelete = (ip, mac, hostname) => { + handleDelete = (ip, mac, hostname = '') => { + const name = hostname || ip; // eslint-disable-next-line no-alert - if (window.confirm(this.props.t('delete_confirm', { key: hostname }))) { + if (window.confirm(this.props.t('delete_confirm', { key: name }))) { this.props.removeStaticLease({ ip, mac, hostname }); } } diff --git a/client/src/reducers/index.js b/client/src/reducers/index.js index 67d9b737..e9a012f8 100644 --- a/client/src/reducers/index.js +++ b/client/src/reducers/index.js @@ -362,9 +362,19 @@ const dhcp = handleActions({ [actions.addStaticLeaseRequest]: state => ({ ...state, processingAdding: true }), [actions.addStaticLeaseFailure]: state => ({ ...state, processingAdding: false }), - [actions.addStaticLeaseSuccess]: (state) => { + [actions.addStaticLeaseSuccess]: (state, { payload }) => { + const { + ip, mac, hostname, + } = payload; + const newLease = { + ip, + mac, + hostname: hostname || '', + }; + const leases = [...state.staticLeases, newLease]; const newState = { ...state, + staticLeases: leases, processingAdding: false, }; return newState; @@ -372,9 +382,12 @@ const dhcp = handleActions({ [actions.removeStaticLeaseRequest]: state => ({ ...state, processingDeleting: true }), [actions.removeStaticLeaseFailure]: state => ({ ...state, processingDeleting: false }), - [actions.removeStaticLeaseSuccess]: (state) => { + [actions.removeStaticLeaseSuccess]: (state, { payload }) => { + const leaseToRemove = payload.ip; + const leases = state.staticLeases.filter(item => item.ip !== leaseToRemove); const newState = { ...state, + staticLeases: leases, processingDeleting: false, }; return newState;