diff --git a/package.json b/package.json index 14bbacbe..3dbf651d 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "redux-thunk": "^2.2.0", "sanitize.css": "^5.0.0", "sharetribe-scripts": "1.0.14", - "sharetribe-sdk": "git+ssh://git@github.com/sharetribe/sharetribe-sdk-js#267efc4ca52dd1ad54db6bf3c37ab8ebcd8a86ab", + "sharetribe-sdk": "git+ssh://git@github.com/sharetribe/sharetribe-sdk-js#7c913f2fe9ba2ff60ac29cd4fcec799d446d4722", "smoothscroll-polyfill": "^0.4.0", "source-map-support": "^0.5.0", "url": "^0.11.0" diff --git a/src/components/ManageListingCard/ManageListingCard.js b/src/components/ManageListingCard/ManageListingCard.js index 034f9e8a..ac5ef2b0 100644 --- a/src/components/ManageListingCard/ManageListingCard.js +++ b/src/components/ManageListingCard/ManageListingCard.js @@ -7,7 +7,7 @@ import classNames from 'classnames'; import routeConfiguration from '../../routeConfiguration'; import { propTypes } from '../../util/types'; import { formatMoney } from '../../util/currency'; -import { ensureListing } from '../../util/data'; +import { ensureOwnListing } from '../../util/data'; import { createSlug } from '../../util/urlHelpers'; import { createResourceLocatorString } from '../../util/routes'; import { @@ -71,7 +71,7 @@ export const ManageListingCardComponent = props => { onToggleMenu, } = props; const classes = classNames(rootClassName || css.root, className); - const currentListing = ensureListing(listing); + const currentListing = ensureOwnListing(listing); const id = currentListing.id.uuid; const { title = '', price, closed } = currentListing.attributes; const slug = createSlug(title); @@ -255,7 +255,7 @@ ManageListingCardComponent.propTypes = { hasClosingError: bool.isRequired, hasOpeningError: bool.isRequired, intl: intlShape.isRequired, - listing: propTypes.listing.isRequired, + listing: propTypes.ownListing.isRequired, isMenuOpen: bool.isRequired, actionsInProgressListingId: shape({ uuid: string.isRequired }), onCloseListing: func.isRequired, diff --git a/src/containers/EditListingPage/EditListingPage.duck.js b/src/containers/EditListingPage/EditListingPage.duck.js index 1ac65bb0..373a179e 100644 --- a/src/containers/EditListingPage/EditListingPage.duck.js +++ b/src/containers/EditListingPage/EditListingPage.duck.js @@ -216,22 +216,22 @@ export const removeListingImage = imageId => ({ // take the params object that the corresponding SDK endpoint method // expects. -// SDK method: listings.create +// SDK method: ownListings.create export const createListing = requestAction(CREATE_LISTING_REQUEST); export const createListingSuccess = successAction(CREATE_LISTING_SUCCESS); export const createListingError = errorAction(CREATE_LISTING_ERROR); -// SDK method: listings.update +// SDK method: ownListings.update export const updateListing = requestAction(UPDATE_LISTING_REQUEST); export const updateListingSuccess = successAction(UPDATE_LISTING_SUCCESS); export const updateListingError = errorAction(UPDATE_LISTING_ERROR); -// SDK method: listings.show +// SDK method: ownListings.show export const showListings = requestAction(SHOW_LISTINGS_REQUEST); export const showListingsSuccess = successAction(SHOW_LISTINGS_SUCCESS); export const showListingsError = errorAction(SHOW_LISTINGS_ERROR); -// SDK method: listings.uploadImage +// SDK method: images.uploadListingImage export const uploadImage = requestAction(UPLOAD_IMAGE_REQUEST); export const uploadImageSuccess = successAction(UPLOAD_IMAGE_SUCCESS); export const uploadImageError = errorAction(UPLOAD_IMAGE_ERROR); @@ -241,7 +241,7 @@ export const uploadImageError = errorAction(UPLOAD_IMAGE_ERROR); export function requestShowListing(actionPayload) { return (dispatch, getState, sdk) => { dispatch(showListings(actionPayload)); - return sdk.listings + return sdk.ownListings .show(actionPayload) .then(response => { // EditListingPage fetches new listing data, which also needs to be added to global data @@ -267,7 +267,7 @@ export function requestCreateListing(data) { dispatch(createListing(cleanedData)); - return sdk.listings + return sdk.ownListings .create(cleanedData) .then(response => { const id = response.data.data.id.uuid; @@ -312,7 +312,7 @@ export function requestUpdateListing(tab, data) { dispatch(updateListing(cleanedData)); const { id } = cleanedData; let updateResponse; - return sdk.listings + return sdk.ownListings .update(cleanedData) .then(response => { updateResponse = response; diff --git a/src/containers/EditListingPage/EditListingPage.js b/src/containers/EditListingPage/EditListingPage.js index f521a9bb..9518b800 100644 --- a/src/containers/EditListingPage/EditListingPage.js +++ b/src/containers/EditListingPage/EditListingPage.js @@ -7,7 +7,7 @@ import { connect } from 'react-redux'; import { types as sdkTypes } from '../../util/sdkLoader'; import { createSlug } from '../../util/urlHelpers'; import { propTypes } from '../../util/types'; -import { getListingsById } from '../../ducks/marketplaceData.duck'; +import { getMarketplaceEntities } from '../../ducks/marketplaceData.duck'; import { manageDisableScrolling, isScrollingDisabled } from '../../ducks/UI.duck'; import { stripeAccountClearError, createStripeAccount } from '../../ducks/user.duck'; import { EditListingWizard, NamedRedirect, Page } from '../../components'; @@ -216,7 +216,8 @@ const mapStateToProps = state => { const fetchInProgress = createStripeAccountInProgress; const getListing = id => { - const listings = getListingsById(state, [id]); + const listings = getMarketplaceEntities(state, [{ id, type: 'ownListing' }]); + return listings.length === 1 ? listings[0] : null; }; return { diff --git a/src/containers/ManageListingsPage/ManageListingsPage.duck.js b/src/containers/ManageListingsPage/ManageListingsPage.duck.js index d3a59955..582a72aa 100644 --- a/src/containers/ManageListingsPage/ManageListingsPage.duck.js +++ b/src/containers/ManageListingsPage/ManageListingsPage.duck.js @@ -42,15 +42,15 @@ const merge = (state, apiResponse) => { }; const updateListingAttributes = (state, listingEntity) => { - const oldListing = state.ownEntities.listing[listingEntity.id.uuid]; + const oldListing = state.ownEntities.ownListing[listingEntity.id.uuid]; const updatedListing = { ...oldListing, attributes: listingEntity.attributes }; const ownListingEntities = { - ...state.ownEntities.listing, + ...state.ownEntities.ownListing, [listingEntity.id.uuid]: updatedListing, }; return { ...state, - ownEntities: { ...state.ownEntities, listing: ownListingEntities }, + ownEntities: { ...state.ownEntities, ownListing: ownListingEntities }, }; }; @@ -146,7 +146,7 @@ export default manageListingsPageReducer; export const getListingsById = (state, listingIds) => { const { ownEntities } = state.ManageListingsPage; try { - return denormalisedEntities(ownEntities, 'listing', listingIds); + return denormalisedEntities(ownEntities, 'ownListing', listingIds); } catch (e) { return []; } @@ -238,8 +238,8 @@ export const queryOwnListings = queryParams => (dispatch, getState, sdk) => { const { include = [], page, perPage } = queryParams; - return sdk.listings - .queryOwn({ include, page, per_page: perPage }) + return sdk.ownListings + .query({ include, page, per_page: perPage }) .then(response => { dispatch(addOwnEntities(response)); dispatch(queryListingsSuccess(response)); @@ -254,7 +254,7 @@ export const queryOwnListings = queryParams => (dispatch, getState, sdk) => { export const closeListing = listingId => (dispatch, getState, sdk) => { dispatch(closeListingRequest(listingId)); - return sdk.listings + return sdk.ownListings .close({ id: listingId }, { expand: true }) .then(response => { dispatch(closeListingSuccess(response)); @@ -268,7 +268,7 @@ export const closeListing = listingId => (dispatch, getState, sdk) => { export const openListing = listingId => (dispatch, getState, sdk) => { dispatch(openListingRequest(listingId)); - return sdk.listings + return sdk.ownListings .open({ id: listingId }, { expand: true }) .then(response => { dispatch(openListingSuccess(response)); diff --git a/src/containers/ManageListingsPage/ManageListingsPage.js b/src/containers/ManageListingsPage/ManageListingsPage.js index e7e843db..42d59d13 100644 --- a/src/containers/ManageListingsPage/ManageListingsPage.js +++ b/src/containers/ManageListingsPage/ManageListingsPage.js @@ -171,7 +171,7 @@ ManageListingsPageComponent.propTypes = { listingId: propTypes.uuid.isRequired, error: propTypes.error.isRequired, }), - listings: arrayOf(propTypes.listing), + listings: arrayOf(propTypes.ownListing), onCloseListing: func.isRequired, onOpenListing: func.isRequired, openingListing: shape({ uuid: string.isRequired }), diff --git a/src/ducks/user.duck.js b/src/ducks/user.duck.js index 75fd1977..4e867608 100644 --- a/src/ducks/user.duck.js +++ b/src/ducks/user.duck.js @@ -261,17 +261,14 @@ export const fetchCurrentUserHasListings = () => (dispatch, getState, sdk) => { return Promise.resolve(null); } - const currentUserId = currentUser.id; const params = { - author_id: currentUserId, - // Since we are only interested in if the user has // listings, we only need at most one result. page: 1, per_page: 1, }; - return sdk.listings + return sdk.ownListings .query(params) .then(response => { const hasListings = response.data.data && response.data.data.length > 0; diff --git a/src/util/data.js b/src/util/data.js index aeeb07be..70c5b13c 100644 --- a/src/util/data.js +++ b/src/util/data.js @@ -141,6 +141,16 @@ export const ensureListing = listing => { return { ...empty, ...listing }; }; +/** + * Create shell objects to ensure that attributes etc. exists. + * + * @param {Object} listing entity object, which is to be ensured agains null values + */ +export const ensureOwnListing = listing => { + const empty = { id: null, type: 'ownListing', attributes: { customAttributes: {} }, images: [] }; + return { ...empty, ...listing }; +}; + /** * Create shell objects to ensure that attributes etc. exists. * diff --git a/src/util/types.js b/src/util/types.js index 727f08e6..25d6ec99 100644 --- a/src/util/types.js +++ b/src/util/types.js @@ -134,6 +134,19 @@ const listingAttributes = shape({ deleted: propTypes.value(false).isRequired, price: propTypes.money, customAttributes: object, + publicData: object, +}); + +const ownListingAttributes = shape({ + title: string.isRequired, + description: string.isRequired, + address: string.isRequired, + geolocation: propTypes.latlng.isRequired, + closed: bool.isRequired, + deleted: propTypes.value(false).isRequired, + price: propTypes.money, + customAttributes: object, + publicData: object, }); const deletedListingAttributes = shape({ @@ -150,6 +163,15 @@ propTypes.listing = shape({ images: arrayOf(propTypes.image), }); +// Denormalised ownListing object +propTypes.ownListing = shape({ + id: propTypes.uuid.isRequired, + type: propTypes.value('ownListing').isRequired, + attributes: oneOfType([ownListingAttributes, deletedListingAttributes]).isRequired, + author: propTypes.user, + images: arrayOf(propTypes.image), +}); + // Denormalised booking object propTypes.booking = shape({ id: propTypes.uuid.isRequired, diff --git a/yarn.lock b/yarn.lock index 2a69f674..6c9a8059 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7701,9 +7701,9 @@ sharetribe-scripts@1.0.14: optionalDependencies: fsevents "1.1.2" -"sharetribe-sdk@git+ssh://git@github.com/sharetribe/sharetribe-sdk-js#267efc4ca52dd1ad54db6bf3c37ab8ebcd8a86ab": +"sharetribe-sdk@git+ssh://git@github.com/sharetribe/sharetribe-sdk-js#7c913f2fe9ba2ff60ac29cd4fcec799d446d4722": version "0.0.1" - resolved "git+ssh://git@github.com/sharetribe/sharetribe-sdk-js#267efc4ca52dd1ad54db6bf3c37ab8ebcd8a86ab" + resolved "git+ssh://git@github.com/sharetribe/sharetribe-sdk-js#7c913f2fe9ba2ff60ac29cd4fcec799d446d4722" dependencies: axios "^0.15.3" js-cookie "^2.1.3"