Connected and enabled co-maket

This commit is contained in:
Nedim Uka
2018-08-08 14:40:00 +02:00
parent 5d84f53ea7
commit 0b899c09af
7 changed files with 202 additions and 126 deletions

View File

@@ -24,17 +24,20 @@ const recieveShopPackages = (json) => ({
export const fetchShopPackages = (cl, search) => {
return dispatch => {
dispatch(requestShopPackages());
let searchParam = search ? '?search=' +search : ''
return client.fetch({
url: `${API_SERVER}/coMarket/api/getShopPackages`,
method: 'post',
data: {
idCommercialLead: (cl && cl.value) || 0,
search
}
})
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
// }
})
.then(response => {
if(response.data && response.data.packages){
dispatch(recieveShopPackages(response.data.packages))
if (response.data) {
dispatch(recieveShopPackages(response.data))
}
})
.catch(error => {
@@ -63,22 +66,23 @@ const generateClOptions = (commercialLeads) => {
export const fetchShopCommercialLeads = () => {
return dispatch => {
dispatch(requestShopCommercialLeads());
return client.fetch({url: `${API_SERVER}/coMarket/api/getAllCommercialLeads`})
.then(response => {
if(response.data && response.data.commercialLeads){
const clOptions = generateClOptions(response.data.commercialLeads);
dispatch(recieveShopCommercialLeads(clOptions));
if (clOptions.length) {
dispatch(selectCommercialLead(clOptions[0]));
dispatch(fetchShopPackages(clOptions[0]));
}
}
})
.catch(error => {
client.onError(error, dispatch);
});
// 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]));
}
}
// })
// .catch(error => {
// client.onError(error, dispatch);
// });
}
// }
export const selectCommercialLead = (cl) => ({
type: SELECT_SHOP_COMMERCIAL_LEAD,