Pull request: client: add reset leases btn
Updates #1691.
Squashed commit of the following:
commit 2c48fb956aba28eae47071c9f7f4d579dde12955
Merge: 38f5191b 7547d3a4
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Thu Jun 17 14:28:23 2021 +0300
Merge branch 'master' into 1691-dhcp-reset-form
commit 38f5191bcd62eb53e4663fccdfc2a60247881931
Author: Ildar Kamalov <ik@adguard.com>
Date: Thu Jun 17 13:14:59 2021 +0300
client: handle dhcp leases reset
commit a97df17028ca640fd32b4d9762aa54fb381df7e5
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Wed Jun 16 17:12:10 2021 +0300
client: add reset leases btn
This commit is contained in:
parent
7547d3a422
commit
5104b79cf6
|
@ -68,6 +68,9 @@
|
||||||
"dhcp_new_static_lease": "New static lease",
|
"dhcp_new_static_lease": "New static lease",
|
||||||
"dhcp_static_leases_not_found": "No DHCP static leases found",
|
"dhcp_static_leases_not_found": "No DHCP static leases found",
|
||||||
"dhcp_add_static_lease": "Add static lease",
|
"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?",
|
"dhcp_reset": "Are you sure you want to reset the DHCP configuration?",
|
||||||
"country": "Country",
|
"country": "Country",
|
||||||
"city": "City",
|
"city": "City",
|
||||||
|
|
|
@ -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 toggleLeaseModal = createAction('TOGGLE_LEASE_MODAL');
|
||||||
|
|
||||||
export const addStaticLeaseRequest = createAction('ADD_STATIC_LEASE_REQUEST');
|
export const addStaticLeaseRequest = createAction('ADD_STATIC_LEASE_REQUEST');
|
||||||
|
|
|
@ -264,6 +264,8 @@ class Api {
|
||||||
|
|
||||||
DHCP_RESET = { path: 'dhcp/reset', method: 'POST' };
|
DHCP_RESET = { path: 'dhcp/reset', method: 'POST' };
|
||||||
|
|
||||||
|
DHCP_LEASES_RESET = { path: 'dhcp/reset_leases', method: 'POST' };
|
||||||
|
|
||||||
getDhcpStatus() {
|
getDhcpStatus() {
|
||||||
const { path, method } = this.DHCP_STATUS;
|
const { path, method } = this.DHCP_STATUS;
|
||||||
return this.makeRequest(path, method);
|
return this.makeRequest(path, method);
|
||||||
|
@ -315,6 +317,11 @@ class Api {
|
||||||
return this.makeRequest(path, method);
|
return this.makeRequest(path, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetDhcpLeases() {
|
||||||
|
const { path, method } = this.DHCP_LEASES_RESET;
|
||||||
|
return this.makeRequest(path, method);
|
||||||
|
}
|
||||||
|
|
||||||
// Installation
|
// Installation
|
||||||
INSTALL_GET_ADDRESSES = { path: 'install/get_addresses', method: 'GET' };
|
INSTALL_GET_ADDRESSES = { path: 'install/get_addresses', method: 'GET' };
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
getDhcpStatus,
|
getDhcpStatus,
|
||||||
resetDhcp,
|
resetDhcp,
|
||||||
setDhcpConfig,
|
setDhcpConfig,
|
||||||
|
resetDhcpLeases,
|
||||||
toggleDhcp,
|
toggleDhcp,
|
||||||
toggleLeaseModal,
|
toggleLeaseModal,
|
||||||
} from '../../../actions';
|
} 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)
|
const enteredSomeV4Value = Object.values(v4)
|
||||||
.some(Boolean);
|
.some(Boolean);
|
||||||
const enteredSomeV6Value = Object.values(v6)
|
const enteredSomeV6Value = Object.values(v6)
|
||||||
|
@ -188,18 +195,18 @@ const Dhcp = () => {
|
||||||
<PageTitle title={t('dhcp_settings')} subtitle={t('dhcp_description')} containerClass="page-title--dhcp">
|
<PageTitle title={t('dhcp_settings')} subtitle={t('dhcp_description')} containerClass="page-title--dhcp">
|
||||||
{toggleDhcpButton}
|
{toggleDhcpButton}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={statusButtonClass}
|
className={statusButtonClass}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
disabled={enabled || !interface_name || processingConfig}
|
disabled={enabled || !interface_name || processingConfig}
|
||||||
>
|
>
|
||||||
<Trans>check_dhcp_servers</Trans>
|
<Trans>check_dhcp_servers</Trans>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className='btn btn-sm btn-outline-secondary'
|
className='btn btn-sm btn-outline-secondary'
|
||||||
disabled={!enteredSomeValue || processingConfig}
|
disabled={!enteredSomeValue || processingConfig}
|
||||||
onClick={clear}
|
onClick={clear}
|
||||||
>
|
>
|
||||||
<Trans>reset_settings</Trans>
|
<Trans>reset_settings</Trans>
|
||||||
</button>
|
</button>
|
||||||
|
@ -269,16 +276,23 @@ const Dhcp = () => {
|
||||||
processingDeleting={processingDeleting}
|
processingDeleting={processingDeleting}
|
||||||
cidr={cidr}
|
cidr={cidr}
|
||||||
/>
|
/>
|
||||||
</div>
|
<div className="btn-list mt-2">
|
||||||
<div className="col-12">
|
<button
|
||||||
<button
|
type="button"
|
||||||
type="button"
|
className="btn btn-success btn-standard mt-3"
|
||||||
className="btn btn-success btn-standard mt-3"
|
onClick={toggleModal}
|
||||||
onClick={toggleModal}
|
disabled={disabledLeasesButton}
|
||||||
disabled={disabledLeasesButton}
|
>
|
||||||
>
|
<Trans>dhcp_add_static_lease</Trans>
|
||||||
<Trans>dhcp_add_static_lease</Trans>
|
</button>
|
||||||
</button>
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-secondary btn-standard mt-3"
|
||||||
|
onClick={handleReset}
|
||||||
|
>
|
||||||
|
<Trans>dhcp_reset_leases</Trans>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
|
@ -118,6 +118,11 @@ const dhcp = handleActions(
|
||||||
v6: {},
|
v6: {},
|
||||||
interface_name: '',
|
interface_name: '',
|
||||||
}),
|
}),
|
||||||
|
[actions.resetDhcpLeasesSuccess]: (state) => ({
|
||||||
|
...state,
|
||||||
|
leases: [],
|
||||||
|
staticLeases: [],
|
||||||
|
}),
|
||||||
|
|
||||||
[actions.toggleLeaseModal]: (state) => {
|
[actions.toggleLeaseModal]: (state) => {
|
||||||
const newState = {
|
const newState = {
|
||||||
|
|
Loading…
Reference in New Issue