96 lines
2.8 KiB
JavaScript
96 lines
2.8 KiB
JavaScript
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) => {
|
|
return dispatch => {
|
|
dispatch(requestCustomerAcceptance());
|
|
return htmlClient.fetch({
|
|
url: `${API_SERVER}/wp-json/wiaas/customer-acceptance/${idEntry}`,
|
|
method: 'get'
|
|
})
|
|
.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) => {
|
|
return dispatch => {
|
|
dispatch(uploadAcceptanceAction());
|
|
return htmlClient.uploadFile(file, {
|
|
url: `${API_SERVER}/wp-json/wiaas/customer-acceptance/${idEntry}/upload-file`
|
|
}).then(response => {
|
|
if (typeof response.data !== 'undefined') {
|
|
dispatch(updateMessages(response.data.messages, orderMessages));
|
|
dispatch(fetchCustomerAcceptance(idEntry));
|
|
}
|
|
}).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) => {
|
|
return dispatch => {
|
|
dispatch(sendCustomerAcceptance());
|
|
return htmlClient.fetch({
|
|
url: `${API_SERVER}/wp-json/wiaas/customer-acceptance/${idEntry}`,
|
|
method: 'post',
|
|
data: {
|
|
actionType,
|
|
declineReason
|
|
}
|
|
})
|
|
.then(response => {
|
|
if (response.data) {
|
|
dispatch(updateMessages(response.data.messages, orderMessages));
|
|
dispatch(fetchCustomerAcceptance(idEntry));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
htmlClient.onError(error, dispatch);
|
|
});
|
|
}
|
|
}
|