Files
old-new-wiaas/frontend/src/actions/orders/customerAcceptanceActions.js

96 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-06-14 16:49:28 +02:00
import {
API_SERVER
} from '../../config';
import {
REQUEST_CUSTOMER_ACCEPTANCE,
RECEIVE_CUSTOMER_ACCEPTANCE,
UPLOAD_CUSTOMER_ACCEPTANCE,
SEND_CUSTOMER_ACCEPTANCE,
orderMessages
} from '../../constants/ordersConstants';
import {
updateMessages
} from '../notification/notificationActions';
import HtmlClient from '../../helpers/HtmlClient';
const htmlClient = new HtmlClient();
const requestCustomerAcceptance = () => ({
type: REQUEST_CUSTOMER_ACCEPTANCE
});
const recieveCustomerAcceptance = (json) => ({
type: RECEIVE_CUSTOMER_ACCEPTANCE,
customerAcceptance: json
});
export const fetchCustomerAcceptance = (idEntry) => {
2018-06-14 16:49:28 +02:00
return dispatch => {
dispatch(requestCustomerAcceptance());
return htmlClient.fetch({
url: `${API_SERVER}/wp-json/wiaas/customer-acceptance/${idEntry}`,
method: 'get'
2018-06-14 16:49:28 +02:00
})
.then(response => {
if (response.data) {
dispatch(recieveCustomerAcceptance(response.data));
}
})
.catch(error => {
htmlClient.onError(error, dispatch);
});
}
}
const uploadAcceptanceAction = () => ({
type: UPLOAD_CUSTOMER_ACCEPTANCE
});
export const uploadAcceptance = (idEntry, file) => {
2018-06-14 16:49:28 +02:00
return dispatch => {
dispatch(uploadAcceptanceAction());
return htmlClient.uploadFile(file, {
url: `${API_SERVER}/wp-json/wiaas/customer-acceptance/${idEntry}/upload-file`
2018-06-14 16:49:28 +02:00
}).then(response => {
if (typeof response.data !== 'undefined') {
2018-08-18 22:05:31 +02:00
dispatch(updateMessages(response.data.messages, orderMessages));
dispatch(fetchCustomerAcceptance(idEntry));
2018-06-14 16:49:28 +02:00
}
}).catch(error => {
htmlClient.onError(error, dispatch);
});
}
}
export const badFile = () =>{
return dispatch => {
dispatch(updateMessages([{code: 'warning', message: 'INVALID_FILE_ACCEPTANCE'}], orderMessages));
}
}
const sendCustomerAcceptance = () => ({
type: SEND_CUSTOMER_ACCEPTANCE
});
export const acceptDeclineInstallation = (idEntry, actionType, declineReason) => {
2018-06-14 16:49:28 +02:00
return dispatch => {
dispatch(sendCustomerAcceptance());
return htmlClient.fetch({
url: `${API_SERVER}/wp-json/wiaas/customer-acceptance/${idEntry}`,
2018-06-14 16:49:28 +02:00
method: 'post',
data: {
actionType,
declineReason
}
})
.then(response => {
if (response.data) {
dispatch(updateMessages(response.data.messages, orderMessages));
dispatch(fetchCustomerAcceptance(idEntry));
2018-06-14 16:49:28 +02:00
}
})
.catch(error => {
htmlClient.onError(error, dispatch);
});
}
}