Initial Commit Rework

This commit is contained in:
Qstick
2017-09-03 22:20:56 -04:00
parent 74a4cc048c
commit 95051cbd63
2483 changed files with 101351 additions and 111396 deletions
@@ -0,0 +1,44 @@
import $ from 'jquery';
import { batchActions } from 'redux-batched-actions';
import { set, update } from '../baseActions';
function createSaveHandler(section, url, getFromState) {
return function(payload) {
return function(dispatch, getState) {
dispatch(set({ section, isSaving: true }));
const state = getFromState(getState());
const saveData = Object.assign({}, state.item, state.pendingChanges);
const promise = $.ajax({
url,
method: 'PUT',
dataType: 'json',
data: JSON.stringify(saveData)
});
promise.done((data) => {
dispatch(batchActions([
update({ section, data }),
set({
section,
isSaving: false,
saveError: null,
pendingChanges: {}
})
]));
});
promise.fail((xhr) => {
dispatch(set({
section,
isSaving: false,
saveError: xhr
}));
});
};
};
}
export default createSaveHandler;