Files
old-new-wiaas/frontend/src/actions/orders/customerQuestionnairesActions.js
2018-10-30 17:20:56 +01:00

68 lines
2.1 KiB
JavaScript

import {
API_SERVER
} from '../../config';
import {
UPLOAD_CUSTOMER_QUESTIONNAIRE,
REQUEST_CUSTOMER_QUESTIONNAIRES,
RECEIVE_CUSTOMER_QUESTIONNAIRES,
orderMessages, REQUEST_CUSTOMER_ACCEPTANCE, RECEIVE_CUSTOMER_ACCEPTANCE, UPLOAD_CUSTOMER_ACCEPTANCE
} from '../../constants/ordersConstants';
import {
updateMessages
} from '../notification/notificationActions';
import HtmlClient from '../../helpers/HtmlClient';
import {fetchCustomerAcceptance} from "./customerAcceptanceActions";
const htmlClient = new HtmlClient();
const requestCustomerQuestionnaires = () => ({
type: REQUEST_CUSTOMER_QUESTIONNAIRES
});
const receiveCustomerQuestionnaires = (json) => ({
type: RECEIVE_CUSTOMER_QUESTIONNAIRES,
customerQuestionnaires: json
});
const uploadCustomerQuestionnaireAction = () => ({
type: UPLOAD_CUSTOMER_QUESTIONNAIRE
});
export const fetchCustomerQuestionnaires = (idOrder) => {
return dispatch => {
dispatch(requestCustomerQuestionnaires());
return htmlClient.fetch({
url: `${API_SERVER}/wp-json/wiaas/customer-questionnaires/${idOrder}`,
method: 'get'
})
.then(response => {
if (typeof response.data !== 'undefined') {
dispatch(receiveCustomerQuestionnaires(response.data));
}
})
.catch(error => {
htmlClient.onError(error, dispatch);
});
}
}
export const uploadCustomerQuestionnaire = (orderId, actionId, file) => {
return dispatch => {
dispatch(uploadCustomerQuestionnaireAction());
return htmlClient.uploadFile(file, {
url: `${API_SERVER}/wp-json/wiaas/customer-questionnaires/${orderId}/upload/${actionId}`,
}).then(response => {
if (typeof response.data !== 'undefined') {
dispatch(updateMessages(response.data.messages, orderMessages));
dispatch(fetchCustomerQuestionnaires(orderId));
}
}).catch(error => {
htmlClient.onError(error, dispatch);
});
}
}