Handle commercial lead prices

This commit is contained in:
Almira Krdzic
2018-10-11 07:12:53 +02:00
parent 84cd11f9c9
commit b53fbe5402
21 changed files with 1278 additions and 232 deletions

View File

@@ -27,15 +27,9 @@ export const fetchShopPackages = (cl, search) => {
return dispatch => {
dispatch(requestShopPackages());
let searchParam = search ? '?search=' +search : ''
return client.fetch({
url: `${API_SERVER}/wp-json/wc/v2/products` + searchParam,
// TODO: Add comercialLead parameter after the support for it is added on backend
// method: 'post',
// data: {
// idCommercialLead: (cl && cl.value) || 0,
// search
// }
return client.fetch({
url: `${API_SERVER}/wp-json/wc/v2/products?cl_id=${cl.idCommercialLead}` + searchParam,
})
.then(response => {
if (response.data) {
@@ -68,23 +62,29 @@ const generateClOptions = (commercialLeads) => {
export const fetchShopCommercialLeads = () => {
return dispatch => {
dispatch(requestShopCommercialLeads());
// TODO: FetchcomercialLead after the support for it is added on backend
// return client.fetch({url: `${API_SERVER}/coMarket/api/getAllCommercialLeads`})
// .then(response => {
// if(response.data && response.data.commercialLeads){
const clOptions = generateClOptions([{ "idCommercialLead": 14, "commercialLeadName": "Coor Service Management", "mail": "rikard@co-ideation.com" }]);
dispatch(recieveShopCommercialLeads(clOptions));
if (clOptions.length) {
dispatch(selectCommercialLead(clOptions[0]));
dispatch(fetchShopPackages(clOptions[0]));
}
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/commercial-leads` })
.then(response => {
if(response.data){
const clOptions = generateClOptions(response.data.map(cl => ({
idCommercialLead: cl.id,
commercialLeadName: cl.name
})));
dispatch(recieveShopCommercialLeads(clOptions));
if (clOptions.length) {
dispatch(selectCommercialLead(clOptions[0]));
dispatch(fetchShopPackages(clOptions[0]));
}
}
})
.catch(error => {
client.onError(error, dispatch);
});
}
// })
// .catch(error => {
// client.onError(error, dispatch);
// });
}
// }
export const selectCommercialLead = (cl) => ({
type: SELECT_SHOP_COMMERCIAL_LEAD,