delivery step actions
This commit is contained in:
68
frontend/src/actions/orders/customerQuestionnairesActions.js
Normal file
68
frontend/src/actions/orders/customerQuestionnairesActions.js
Normal file
@@ -0,0 +1,68 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user