Don't set currenUserHasListings if fetched listing is in draft state

This commit is contained in:
Jenni Nurmi 2018-11-16 16:04:26 +02:00
parent 5b8a7145be
commit bcd36e9619

View file

@ -1,9 +1,13 @@
import omitBy from 'lodash/omitBy';
import isUndefined from 'lodash/isUndefined';
import config from '../config';
import { denormalisedResponseEntities } from '../util/data';
import { denormalisedResponseEntities, ensureOwnListing } from '../util/data';
import { storableError } from '../util/errors';
import { TRANSITION_REQUEST, TRANSITION_REQUEST_AFTER_ENQUIRY } from '../util/types';
import {
LISTING_STATE_DRAFT,
TRANSITION_REQUEST,
TRANSITION_REQUEST_AFTER_ENQUIRY,
} from '../util/types';
import * as log from '../util/log';
import { authInfo } from './Auth.duck';
@ -275,7 +279,11 @@ export const fetchCurrentUserHasListings = () => (dispatch, getState, sdk) => {
.query(params)
.then(response => {
const hasListings = response.data.data && response.data.data.length > 0;
dispatch(fetchCurrentUserHasListingsSuccess(!!hasListings));
const hasPublishedListings =
hasListings &&
ensureOwnListing(response.data.data[0]).attributes.state !== LISTING_STATE_DRAFT;
dispatch(fetchCurrentUserHasListingsSuccess(!!hasPublishedListings));
})
.catch(e => dispatch(fetchCurrentUserHasListingsError(storableError(e))));
};