Merge pull request #443 from sharetribe/handle-changed-listing-shape

Handle changed listing shape
This commit is contained in:
Kimmo Puputti 2017-09-29 10:48:27 +03:00 committed by GitHub
commit 02ef54c898
8 changed files with 33 additions and 31 deletions

View file

@ -73,7 +73,7 @@ export const ManageListingCardComponent = props => {
const classes = classNames(rootClassName || css.root, className);
const currentListing = ensureListing(listing);
const id = currentListing.id.uuid;
const { title = '', price, open } = currentListing.attributes;
const { title = '', price, closed } = currentListing.attributes;
const slug = createSlug(title);
const firstImage = currentListing.images && currentListing.images.length > 0
? currentListing.images[0]
@ -87,7 +87,7 @@ export const ManageListingCardComponent = props => {
const { formattedPrice, priceTitle } = priceData(price, intl);
/* eslint-disable jsx-a11y/no-static-element-interactions */
const closedOverlay = open
const closedOverlay = !closed
? null
: <div
className={css.closedOverlayWrapper}
@ -175,7 +175,7 @@ export const ManageListingCardComponent = props => {
<div className={css.menubarGradient} />
<div className={css.menubar}>
<Menu
className={classNames(css.menu, { [css.cardIsOpen]: open })}
className={classNames(css.menu, { [css.cardIsOpen]: !closed })}
contentPlacementOffset={MENU_CONTENT_OFFSET}
contentPosition="left"
useArrow={false}

View file

@ -172,12 +172,13 @@ exports[`OrderDetailsPanel matches snapshot 1`] = `
"listing": Object {
"attributes": Object {
"address": "listing1 address",
"closed": false,
"deleted": false,
"description": "listing1 description",
"geolocation": LatLng {
"lat": 40,
"lng": 60,
},
"open": true,
"price": Money {
"amount": 5500,
"currency": "USD",
@ -349,12 +350,13 @@ exports[`OrderDetailsPanel matches snapshot 1`] = `
"listing": Object {
"attributes": Object {
"address": "listing1 address",
"closed": false,
"deleted": false,
"description": "listing1 description",
"geolocation": LatLng {
"lat": 40,
"lng": 60,
},
"open": true,
"price": Money {
"amount": 5500,
"currency": "USD",

View file

@ -198,12 +198,13 @@ exports[`SaleDetailsPanel matches snapshot 1`] = `
"listing": Object {
"attributes": Object {
"address": "listing1 address",
"closed": false,
"deleted": false,
"description": "listing1 description",
"geolocation": LatLng {
"lat": 40,
"lng": 60,
},
"open": true,
"price": Money {
"amount": 5500,
"currency": "USD",
@ -332,12 +333,13 @@ exports[`SaleDetailsPanel matches snapshot 1`] = `
"listing": Object {
"attributes": Object {
"address": "listing1 address",
"closed": false,
"deleted": false,
"description": "listing1 description",
"geolocation": LatLng {
"lat": 40,
"lng": 60,
},
"open": true,
"price": Money {
"amount": 5500,
"currency": "USD",

View file

@ -278,7 +278,7 @@ export class ListingPageComponent extends Component {
</div>
: null;
const showClosedListingHelpText = currentListing.id && !currentListing.attributes.open;
const showClosedListingHelpText = currentListing.id && currentListing.attributes.closed;
const bookingHeading = (
<div className={css.bookingHeading}>
<h2 className={css.bookingTitle}>
@ -297,7 +297,7 @@ export class ListingPageComponent extends Component {
);
const handleBookingSubmit = values => {
const isClosed = !currentListing.attributes.open;
const isClosed = currentListing.attributes.closed;
if (isOwnListing || isClosed) {
window.scrollTo(0, 0);
} else {
@ -310,7 +310,7 @@ export class ListingPageComponent extends Component {
const listingClasses = classNames(css.pageRoot);
const handleBookButtonClick = () => {
const isClosed = !currentListing.attributes.open;
const isClosed = currentListing.attributes.closed;
if (isOwnListing || isClosed) {
window.scrollTo(0, 0);
} else {
@ -324,7 +324,7 @@ export class ListingPageComponent extends Component {
? <div onClick={e => e.stopPropagation()}>
<ActionBar
isOwnListing={isOwnListing}
isClosed={!currentListing.attributes.open}
isClosed={currentListing.attributes.closed}
editParams={editParams}
/>
</div>
@ -430,7 +430,7 @@ export class ListingPageComponent extends Component {
</div>
{bookingHeading}
{currentListing.attributes.open
{!currentListing.attributes.closed
? <BookingDatesForm
className={css.bookingForm}
onSubmit={handleBookingSubmit}
@ -449,7 +449,7 @@ export class ListingPageComponent extends Component {
</div>
</div>
{currentListing.attributes.open
{!currentListing.attributes.closed
? <Button rootClassName={css.bookButton} onClick={handleBookButtonClick}>
{bookBtnMessage}
</Button>

View file

@ -117,12 +117,13 @@ exports[`OrderPage matches snapshot 1`] = `
"listing": Object {
"attributes": Object {
"address": "listing1 address",
"closed": false,
"deleted": false,
"description": "listing1 description",
"geolocation": LatLng {
"lat": 40,
"lng": 60,
},
"open": true,
"price": Money {
"amount": 5500,
"currency": "USD",

View file

@ -124,12 +124,13 @@ exports[`SalePage matches snapshot 1`] = `
"listing": Object {
"attributes": Object {
"address": "listing1 address",
"closed": false,
"deleted": false,
"description": "listing1 description",
"geolocation": LatLng {
"lat": 40,
"lng": 60,
},
"open": true,
"price": Money {
"amount": 5500,
"currency": "USD",

View file

@ -22,7 +22,7 @@ import Decimal from 'decimal.js';
import { types as sdkTypes } from './sdkLoader';
const { UUID, LatLng, LatLngBounds, Money } = sdkTypes;
const { arrayOf, bool, func, instanceOf, number, oneOf, oneOfType, shape, string } = PropTypes;
const { arrayOf, bool, func, instanceOf, number, oneOf, shape, string } = PropTypes;
// Fixed value
export const value = val => oneOf([val]);
@ -108,24 +108,19 @@ export const image = shape({
}),
});
const listingAttributes = shape({
title: string.isRequired,
description: string.isRequired,
address: string.isRequired,
geolocation: latlng.isRequired,
open: bool.isRequired,
price: money,
});
const deletedListingAttributes = shape({
deleted: value(true).isRequired,
});
// Denormalised listing object
export const listing = shape({
id: uuid.isRequired,
type: value('listing').isRequired,
attributes: oneOfType([listingAttributes, deletedListingAttributes]).isRequired,
attributes: shape({
title: string.isRequired,
description: string.isRequired,
address: string.isRequired,
geolocation: latlng.isRequired,
closed: bool.isRequired,
deleted: bool.isRequired,
price: money,
}).isRequired,
author: user,
images: arrayOf(image),
});

View file

@ -78,7 +78,8 @@ export const createListing = (id, attributes = {}, includes = {}) => ({
description: `${id} description`,
address: `${id} address`,
geolocation: new LatLng(40, 60),
open: true,
closed: false,
deleted: false,
price: new Money(5500, 'USD'),
...attributes,
},