* client: fix page scrolling on adding/deleting leases
This commit is contained in:
parent
6f2503a09f
commit
2976726f99
|
@ -711,11 +711,11 @@ export const addStaticLeaseSuccess = createAction('ADD_STATIC_LEASE_SUCCESS');
|
||||||
export const addStaticLease = config => async (dispatch) => {
|
export const addStaticLease = config => async (dispatch) => {
|
||||||
dispatch(addStaticLeaseRequest());
|
dispatch(addStaticLeaseRequest());
|
||||||
try {
|
try {
|
||||||
|
const name = config.hostname || config.ip;
|
||||||
await apiClient.addStaticLease(config);
|
await apiClient.addStaticLease(config);
|
||||||
dispatch(addStaticLeaseSuccess());
|
dispatch(addStaticLeaseSuccess(config));
|
||||||
dispatch(addSuccessToast(t('dhcp_lease_added', { key: config.hostname })));
|
dispatch(addSuccessToast(t('dhcp_lease_added', { key: name })));
|
||||||
dispatch(toggleLeaseModal());
|
dispatch(toggleLeaseModal());
|
||||||
dispatch(getDhcpStatus());
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(addErrorToast({ error }));
|
dispatch(addErrorToast({ error }));
|
||||||
dispatch(addStaticLeaseFailure());
|
dispatch(addStaticLeaseFailure());
|
||||||
|
@ -729,10 +729,10 @@ export const removeStaticLeaseSuccess = createAction('REMOVE_STATIC_LEASE_SUCCES
|
||||||
export const removeStaticLease = config => async (dispatch) => {
|
export const removeStaticLease = config => async (dispatch) => {
|
||||||
dispatch(removeStaticLeaseRequest());
|
dispatch(removeStaticLeaseRequest());
|
||||||
try {
|
try {
|
||||||
|
const name = config.hostname || config.ip;
|
||||||
await apiClient.removeStaticLease(config);
|
await apiClient.removeStaticLease(config);
|
||||||
dispatch(removeStaticLeaseSuccess());
|
dispatch(removeStaticLeaseSuccess(config));
|
||||||
dispatch(addSuccessToast(t('dhcp_lease_deleted', { key: config.hostname })));
|
dispatch(addSuccessToast(t('dhcp_lease_deleted', { key: name })));
|
||||||
dispatch(getDhcpStatus());
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(addErrorToast({ error }));
|
dispatch(addErrorToast({ error }));
|
||||||
dispatch(removeStaticLeaseFailure());
|
dispatch(removeStaticLeaseFailure());
|
||||||
|
|
|
@ -50,7 +50,6 @@ const Form = (props) => {
|
||||||
type="text"
|
type="text"
|
||||||
className="form-control"
|
className="form-control"
|
||||||
placeholder={t('form_enter_hostname')}
|
placeholder={t('form_enter_hostname')}
|
||||||
validate={[required]}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -18,9 +18,10 @@ class StaticLeases extends Component {
|
||||||
this.props.addStaticLease(data);
|
this.props.addStaticLease(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDelete = (ip, mac, hostname) => {
|
handleDelete = (ip, mac, hostname = '') => {
|
||||||
|
const name = hostname || ip;
|
||||||
// eslint-disable-next-line no-alert
|
// 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 });
|
this.props.removeStaticLease({ ip, mac, hostname });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -362,9 +362,19 @@ const dhcp = handleActions({
|
||||||
|
|
||||||
[actions.addStaticLeaseRequest]: state => ({ ...state, processingAdding: true }),
|
[actions.addStaticLeaseRequest]: state => ({ ...state, processingAdding: true }),
|
||||||
[actions.addStaticLeaseFailure]: state => ({ ...state, processingAdding: false }),
|
[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 = {
|
const newState = {
|
||||||
...state,
|
...state,
|
||||||
|
staticLeases: leases,
|
||||||
processingAdding: false,
|
processingAdding: false,
|
||||||
};
|
};
|
||||||
return newState;
|
return newState;
|
||||||
|
@ -372,9 +382,12 @@ const dhcp = handleActions({
|
||||||
|
|
||||||
[actions.removeStaticLeaseRequest]: state => ({ ...state, processingDeleting: true }),
|
[actions.removeStaticLeaseRequest]: state => ({ ...state, processingDeleting: true }),
|
||||||
[actions.removeStaticLeaseFailure]: state => ({ ...state, processingDeleting: false }),
|
[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 = {
|
const newState = {
|
||||||
...state,
|
...state,
|
||||||
|
staticLeases: leases,
|
||||||
processingDeleting: false,
|
processingDeleting: false,
|
||||||
};
|
};
|
||||||
return newState;
|
return newState;
|
||||||
|
|
Loading…
Reference in New Issue