* 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) => {
|
||||
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());
|
||||
|
|
|
@ -50,7 +50,6 @@ const Form = (props) => {
|
|||
type="text"
|
||||
className="form-control"
|
||||
placeholder={t('form_enter_hostname')}
|
||||
validate={[required]}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue