Handle missing attributes for listing or its author

This commit is contained in:
Kimmo Puputti 2017-02-23 13:51:38 +02:00
parent 1278f24b1a
commit 1cfbd46913
2 changed files with 5 additions and 3 deletions

View file

@ -6,9 +6,11 @@ import css from './ListingCard.css';
const ListingCard = props => {
const { listing } = props;
const id = listing.id.uuid;
const { title, description, address } = listing.attributes;
const { title = '', description = '', address = '' } = listing.attributes || {};
const slug = encodeURIComponent(title.split(' ').join('-'));
const authorName = `${listing.author.attributes.profile.firstName} ${listing.author.attributes.profile.lastName}`;
const authorName = listing.author && listing.author.attributes
? `${listing.author.attributes.profile.firstName} ${listing.author.attributes.profile.lastName}`
: '';
// TODO: these are not yet present in the API data, figure out what
// to do with them

View file

@ -5,7 +5,7 @@ import css from './ListingCardSmall.css';
const ListingCardSmall = props => {
const { listing } = props;
const title = listing.attributes.title;
const { title = '' } = listing.attributes || {};
const id = listing.id.uuid;
const slug = encodeURIComponent(title.split(' ').join('-'));