Fixes
This commit is contained in:
@@ -5,9 +5,12 @@ import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {
|
||||
REQUEST_SHOP_PACKAGES,
|
||||
RECIEVE_SHOP_PACKAGES,
|
||||
SEARCH_SHOP_PACKAGES_REQUEST,
|
||||
SEARCH_SHOP_PACKAGES_RESULT,
|
||||
REQUEST_SHOPS,
|
||||
RECEIVE_SHOPS,
|
||||
SELECT_SHOP
|
||||
SELECT_SHOP,
|
||||
SHOP_PAGE_SIZE
|
||||
} from '../../constants/coMarketConstants';
|
||||
import { fromWCPackage } from '../../helpers/PackageHelper';
|
||||
|
||||
@@ -17,30 +20,60 @@ const requestShopPackages = () => ({
|
||||
type: REQUEST_SHOP_PACKAGES,
|
||||
isLoading: true
|
||||
});
|
||||
const recieveShopPackages = (json) => ({
|
||||
const recieveShopPackages = (packages, page = 1) => ({
|
||||
type: RECIEVE_SHOP_PACKAGES,
|
||||
isLoading: false,
|
||||
shopPackages: json
|
||||
shopPackages: packages,
|
||||
page: page,
|
||||
});
|
||||
|
||||
export const fetchShopPackages = (shop, search) => {
|
||||
export const fetchShopPackages = (shop, page = 1) => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopPackages());
|
||||
let searchParam = search ? '?search=' +search : ''
|
||||
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/wp-json/wc/v2/products?shop_id=${shop.id}` + searchParam,
|
||||
url: `${API_SERVER}/wp-json/wc/v2/products?shop_id=${shop.id}&page=${page}&per_page=${SHOP_PAGE_SIZE + 1}`,
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
dispatch(recieveShopPackages(response.data.map(wcPackage => fromWCPackage(wcPackage))))
|
||||
const packages = response.data.map(wcPackage => fromWCPackage(wcPackage));
|
||||
dispatch(recieveShopPackages(packages, page))
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const searchShopPackagesRequest = () => ({
|
||||
type: SEARCH_SHOP_PACKAGES_REQUEST,
|
||||
isLoading: true
|
||||
});
|
||||
const searchShopPackagesResult = (packages) => ({
|
||||
type: SEARCH_SHOP_PACKAGES_RESULT,
|
||||
isLoading: false,
|
||||
shopPackages: packages,
|
||||
});
|
||||
|
||||
export const searchShopPackages = (shop, search) => {
|
||||
return dispatch => {
|
||||
dispatch(searchShopPackagesRequest());
|
||||
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/wp-json/wc/v2/products?shop_id=${shop.id}&search=${search}`,
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
const packages = response.data.map(wcPackage => fromWCPackage(wcPackage));
|
||||
dispatch(searchShopPackagesResult(packages))
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const requestShops = () => ({
|
||||
type: REQUEST_SHOPS
|
||||
|
||||
Reference in New Issue
Block a user