diff --git a/client/src/__locales/en.json b/client/src/__locales/en.json index effca193..a515f532 100644 --- a/client/src/__locales/en.json +++ b/client/src/__locales/en.json @@ -68,6 +68,9 @@ "dhcp_new_static_lease": "New static lease", "dhcp_static_leases_not_found": "No DHCP static leases found", "dhcp_add_static_lease": "Add static lease", + "dhcp_reset_leases": "Reset all leases", + "dhcp_reset_leases_confirm": "Are you sure you want to reset all leases?", + "dhcp_reset_leases_success": "DHCP leases successfully reset", "dhcp_reset": "Are you sure you want to reset the DHCP configuration?", "country": "Country", "city": "City", diff --git a/client/src/actions/index.js b/client/src/actions/index.js index 8b2ccf9e..4f4b6b20 100644 --- a/client/src/actions/index.js +++ b/client/src/actions/index.js @@ -547,6 +547,22 @@ export const resetDhcp = () => async (dispatch) => { } }; +export const resetDhcpLeasesRequest = createAction('RESET_DHCP_LEASES_REQUEST'); +export const resetDhcpLeasesSuccess = createAction('RESET_DHCP_LEASES_SUCCESS'); +export const resetDhcpLeasesFailure = createAction('RESET_DHCP_LEASES_FAILURE'); + +export const resetDhcpLeases = () => async (dispatch) => { + dispatch(resetDhcpLeasesRequest()); + try { + const status = await apiClient.resetDhcpLeases(); + dispatch(resetDhcpLeasesSuccess(status)); + dispatch(addSuccessToast('dhcp_reset_leases_success')); + } catch (error) { + dispatch(addErrorToast({ error })); + dispatch(resetDhcpLeasesFailure()); + } +}; + export const toggleLeaseModal = createAction('TOGGLE_LEASE_MODAL'); export const addStaticLeaseRequest = createAction('ADD_STATIC_LEASE_REQUEST'); diff --git a/client/src/api/Api.js b/client/src/api/Api.js index fc42eeb4..1f6b2832 100644 --- a/client/src/api/Api.js +++ b/client/src/api/Api.js @@ -264,6 +264,8 @@ class Api { DHCP_RESET = { path: 'dhcp/reset', method: 'POST' }; + DHCP_LEASES_RESET = { path: 'dhcp/reset_leases', method: 'POST' }; + getDhcpStatus() { const { path, method } = this.DHCP_STATUS; return this.makeRequest(path, method); @@ -315,6 +317,11 @@ class Api { return this.makeRequest(path, method); } + resetDhcpLeases() { + const { path, method } = this.DHCP_LEASES_RESET; + return this.makeRequest(path, method); + } + // Installation INSTALL_GET_ADDRESSES = { path: 'install/get_addresses', method: 'GET' }; diff --git a/client/src/components/Settings/Dhcp/index.js b/client/src/components/Settings/Dhcp/index.js index 8af73188..844e662e 100644 --- a/client/src/components/Settings/Dhcp/index.js +++ b/client/src/components/Settings/Dhcp/index.js @@ -21,6 +21,7 @@ import { getDhcpStatus, resetDhcp, setDhcpConfig, + resetDhcpLeases, toggleDhcp, toggleLeaseModal, } from '../../../actions'; @@ -111,6 +112,12 @@ const Dhcp = () => { })); }; + const handleReset = () => { + if (window.confirm(t('dhcp_reset_leases_confirm'))) { + dispatch(resetDhcpLeases()); + } + }; + const enteredSomeV4Value = Object.values(v4) .some(Boolean); const enteredSomeV6Value = Object.values(v6) @@ -188,18 +195,18 @@ const Dhcp = () => { {toggleDhcpButton} @@ -269,16 +276,23 @@ const Dhcp = () => { processingDeleting={processingDeleting} cidr={cidr} /> - -
- +
+ + +
diff --git a/client/src/reducers/dhcp.js b/client/src/reducers/dhcp.js index d6e2868a..4c2fe991 100644 --- a/client/src/reducers/dhcp.js +++ b/client/src/reducers/dhcp.js @@ -118,6 +118,11 @@ const dhcp = handleActions( v6: {}, interface_name: '', }), + [actions.resetDhcpLeasesSuccess]: (state) => ({ + ...state, + leases: [], + staticLeases: [], + }), [actions.toggleLeaseModal]: (state) => { const newState = {