Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function resourceQuotasAdminFormReducer(
state = initialState,
action: resourceQuotasActions.Actions,
): ResourceQuotasAdminFormState {
switch (action.type) {
case resourceQuotasActions.ResourceQuotasActionTypes.UPDATE_ADMIN_FORM_FIELD: {
const resourceType = action.payload.resourceType;
return update(state, {
form: {
[resourceType]: {
$merge: omit(action.payload, 'resourceType'),
},
},
});
}
case resourceQuotasActions.ResourceQuotasActionTypes.UPDATE_ADMIN_FORM: {
return {
...state,
form: action.payload,
};
}
case resourceQuotasActions.ResourceQuotasActionTypes.UPDATE_RESOURCE_QUOTAS_REQUEST: {
optionsOverride.handleOnClick();
}
return this._handle_toast_on_click(e);
},
handleRemove: this._handle_toast_remove,
},
});
const toastOperation = {
[`${this.props.newestOnTop ? `$unshift` : `$push`}`]: [newToast],
};
const messageOperation = {
[`${this.props.newestOnTop ? `$unshift` : `$push`}`]: [message],
};
const nextState = update(this.state, {
toasts: toastOperation,
messageList: messageOperation,
});
this.setState(nextState);
}
_notify(type, message, title, optionsOverride = {}) {
if (this.props.preventDuplicates) {
if (_.includes(this.state.messageList, message)) {
return;
}
}
const key = this.state.toastId++;
const toastId = key;
const newToast = update(optionsOverride, {
$merge: {
type,
title,
message,
toastId,
key,
ref: `toasts__${key}`,
handleOnClick: (e) => {
if (`function` === typeof optionsOverride.handleOnClick) {
optionsOverride.handleOnClick();
}
return this._handle_toast_on_click(e);
},
handleRemove: this._handle_toast_remove,
},
});
...state.limits,
[resourceType]: action.payload.limit,
},
};
}
case resourceQuotasActions.ResourceQuotasActionTypes.UPDATE_USER_FORM_QUOTAS: {
return update(state, {
$merge: {
quotas: action.payload,
},
});
}
case resourceQuotasActions.ResourceQuotasActionTypes.UPDATE_USER_FORM_LIMITS: {
return update(state, {
$merge: {
limits: mapValues(action.payload, 'max'),
},
});
}
default:
return state;
}
}
this.state.toasts[operationName]((found, toast, index) => {
if (found || toast.toastId !== toastId) {
return false;
}
this.setState(update(this.state, {
toasts: { $splice: [[index, 1]] },
messageList: { $splice: [[index, 1]] },
}));
return true;
}, false);
}