mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
Update to use current API endpoints for own listings
This commit is contained in:
parent
de47b54462
commit
e2813fb346
8 changed files with 68 additions and 21 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 { getOwnListingsById } 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,7 @@ const mapStateToProps = state => {
|
|||
const fetchInProgress = createStripeAccountInProgress;
|
||||
|
||||
const getListing = id => {
|
||||
const listings = getListingsById(state, [id]);
|
||||
const listings = getOwnListingsById(state, [id]);
|
||||
return listings.length === 1 ? listings[0] : null;
|
||||
};
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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 }),
|
||||
|
|
|
|||
|
|
@ -46,6 +46,21 @@ export const getListingsById = (state, listingIds) => {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the denormalised ownListing entities with the given IDs
|
||||
*
|
||||
* @param {Object} state the full Redux store
|
||||
* @param {Array<UUID>} listingIds listing IDs to select from the store
|
||||
*/
|
||||
export const getOwnListingsById = (state, listingIds) => {
|
||||
const { entities } = state.marketplaceData;
|
||||
try {
|
||||
return denormalisedEntities(entities, 'ownListing', listingIds);
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the denormalised entities from the given entity references.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue