UI Action Handler Changes, Misc Fixes

This commit is contained in:
Qstick
2017-11-26 15:09:45 -05:00
parent 7825319d89
commit cd5b658196
193 changed files with 6992 additions and 6341 deletions
@@ -1,43 +1,42 @@
import $ from 'jquery';
import { batchActions } from 'redux-batched-actions';
import getSectionState from 'Utilities/State/getSectionState';
import { set, update } from '../baseActions';
function createSaveHandler(section, url, getFromState) {
return function(payload) {
return function(dispatch, getState) {
dispatch(set({ section, isSaving: true }));
function createSaveHandler(section, url) {
return function(getState, payload, dispatch) {
dispatch(set({ section, isSaving: true }));
const state = getFromState(getState());
const saveData = Object.assign({}, state.item, state.pendingChanges);
const state = getSectionState(getState(), section, true);
const saveData = Object.assign({}, state.item, state.pendingChanges);
const promise = $.ajax({
url,
method: 'PUT',
dataType: 'json',
data: JSON.stringify(saveData)
});
const promise = $.ajax({
url,
method: 'PUT',
dataType: 'json',
data: JSON.stringify(saveData)
});
promise.done((data) => {
dispatch(batchActions([
update({ section, data }),
promise.done((data) => {
dispatch(batchActions([
update({ section, data }),
set({
section,
isSaving: false,
saveError: null,
pendingChanges: {}
})
]));
});
promise.fail((xhr) => {
dispatch(set({
set({
section,
isSaving: false,
saveError: xhr
}));
});
};
saveError: null,
pendingChanges: {}
})
]));
});
promise.fail((xhr) => {
dispatch(set({
section,
isSaving: false,
saveError: xhr
}));
});
};
}