intervention-pages
Version:
40 lines (39 loc) • 1.41 kB
JavaScript
import { _sendRequest } from '../utils/request-helper';
import { getEndpoint } from '../utils/endpoint-helper';
import { interventionEndpoints } from '../utils/intervention-endpoints';
import { SHOW_TOAST } from './actionsConstants';
export const setIntervention = (intervention) => {
return {
type: 'UPDATE_CURRENT_INTERVENTION',
current: intervention
};
};
export const getIntervention = (interventionId) => (dispatch) => {
return _sendRequest({
endpoint: getEndpoint(interventionEndpoints.intervention, { interventionId: interventionId })
}).then((intervention) => {
dispatch(setIntervention(intervention));
});
};
export const showToast = (message, showCloseBtn = true) => {
return {
type: SHOW_TOAST,
message,
showCloseBtn
};
};
export const patchIntervention = (interventionChunck, interventionId) => (dispatch, getState) => {
if (!interventionId) {
interventionId = getState().app.routeDetails.params.interventionId;
}
return _sendRequest({
endpoint: getEndpoint(interventionEndpoints.intervention, { interventionId: interventionId }),
body: interventionChunck,
method: 'PATCH'
}).then((intervention) => {
dispatch({
type: 'UPDATE_CURRENT_INTERVENTION',
current: intervention
});
});
};