Fetch related listing for the sale page transaction

This commit is contained in:
Kimmo Puputti 2017-08-03 15:53:12 +03:00
parent b1003a62b0
commit 215c2b0b5e

View file

@ -81,15 +81,26 @@ const rejectSaleError = e => ({ type: REJECT_SALE_ERROR, error: true, payload: e
// ================ Thunks ================ //
const listingRelationship = txResponse => {
return txResponse.data.data.relationships.listing.data;
};
export const fetchSale = id =>
(dispatch, getState, sdk) => {
dispatch(fetchSaleRequest());
let txResponse = null;
return sdk.transactions
.show({ id, include: ['customer', 'provider', 'listing', 'booking'] }, { expand: true })
.then(response => {
txResponse = response;
const listingId = listingRelationship(response).id;
return sdk.listings.show({ id: listingId, include: ['author', 'images'] });
})
.then(response => {
dispatch(addMarketplaceEntities(txResponse));
dispatch(addMarketplaceEntities(response));
dispatch(fetchSaleSuccess(response));
dispatch(fetchSaleSuccess(txResponse));
return response;
})
.catch(e => {