From 2a31ccc4583faf0832d6803676080ae020f2befc Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Wed, 7 Nov 2018 12:15:35 +0200 Subject: [PATCH] EditListingWizard panels: pass all errors as fetchErrors to Final Form --- .../EditListingDescriptionPanel.js | 11 ++++++----- .../EditListingFeaturesPanel.js | 6 ++++-- .../EditListingLocationPanel.js | 7 +++++-- .../EditListingPhotosPanel.js | 16 ++++++---------- .../EditListingPoliciesPanel.js | 6 ++++-- .../EditListingPricingPanel.js | 6 ++++-- 6 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js b/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js index 17761fbc..3b1dc8cf 100644 --- a/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js +++ b/src/components/EditListingDescriptionPanel/EditListingDescriptionPanel.js @@ -1,9 +1,10 @@ import React from 'react'; -import PropTypes from 'prop-types'; +import { bool, func, object, string } from 'prop-types'; import classNames from 'classnames'; import { FormattedMessage } from 'react-intl'; import { ensureOwnListing } from '../../util/data'; import { ListingLink } from '../../components'; +import { LISTING_STATE_DRAFT } from '../../util/types'; import { EditListingDescriptionForm } from '../../forms'; import config from '../../config'; @@ -26,7 +27,8 @@ const EditListingDescriptionPanel = props => { const currentListing = ensureOwnListing(listing); const { description, title, publicData } = currentListing.attributes; - const panelTitle = currentListing.id ? ( + const isPublished = currentListing.id && currentListing.attributes.state !== LISTING_STATE_DRAFT; + const panelTitle = isPublished ? ( }} @@ -54,19 +56,18 @@ const EditListingDescriptionPanel = props => { }} onChange={onChange} updated={panelUpdated} - updateError={errors.updateListingError} updateInProgress={updateInProgress} + fetchErrors={errors} categories={config.custom.categories} /> ); }; -const { func, object, string, bool } = PropTypes; - EditListingDescriptionPanel.defaultProps = { className: null, rootClassName: null, + errors: null, listing: null, }; diff --git a/src/components/EditListingFeaturesPanel/EditListingFeaturesPanel.js b/src/components/EditListingFeaturesPanel/EditListingFeaturesPanel.js index 0f306083..f64e8b94 100644 --- a/src/components/EditListingFeaturesPanel/EditListingFeaturesPanel.js +++ b/src/components/EditListingFeaturesPanel/EditListingFeaturesPanel.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import classNames from 'classnames'; import { FormattedMessage } from 'react-intl'; +import { LISTING_STATE_DRAFT } from '../../util/types'; import { ensureListing } from '../../util/data'; import { EditListingFeaturesForm } from '../../forms'; import { ListingLink } from '../../components'; @@ -28,7 +29,8 @@ const EditListingFeaturesPanel = props => { const currentListing = ensureListing(listing); const { publicData } = currentListing.attributes; - const panelTitle = currentListing.id ? ( + const isPublished = currentListing.id && currentListing.attributes.state !== LISTING_STATE_DRAFT; + const panelTitle = isPublished ? ( }} @@ -58,8 +60,8 @@ const EditListingFeaturesPanel = props => { onChange={onChange} saveActionMsg={submitButtonText} updated={panelUpdated} - updateError={errors.updateListingError} updateInProgress={updateInProgress} + fetchErrors={errors} /> ); diff --git a/src/components/EditListingLocationPanel/EditListingLocationPanel.js b/src/components/EditListingLocationPanel/EditListingLocationPanel.js index 0075ab0e..67a1d48f 100644 --- a/src/components/EditListingLocationPanel/EditListingLocationPanel.js +++ b/src/components/EditListingLocationPanel/EditListingLocationPanel.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { FormattedMessage } from 'react-intl'; +import { LISTING_STATE_DRAFT } from '../../util/types'; import { ensureOwnListing } from '../../util/data'; import { ListingLink } from '../../components'; import { EditListingLocationForm } from '../../forms'; @@ -58,7 +59,9 @@ class EditListingLocationPanel extends Component { const classes = classNames(rootClassName || css.root, className); const currentListing = ensureOwnListing(listing); - const panelTitle = currentListing.id ? ( + const isPublished = + currentListing.id && currentListing.attributes.state !== LISTING_STATE_DRAFT; + const panelTitle = isPublished ? ( }} @@ -95,8 +98,8 @@ class EditListingLocationPanel extends Component { onChange={onChange} saveActionMsg={submitButtonText} updated={panelUpdated} - updateError={errors.updateListingError} updateInProgress={updateInProgress} + fetchErrors={errors} /> ); diff --git a/src/components/EditListingPhotosPanel/EditListingPhotosPanel.js b/src/components/EditListingPhotosPanel/EditListingPhotosPanel.js index ae77eaf6..28b8dfa7 100644 --- a/src/components/EditListingPhotosPanel/EditListingPhotosPanel.js +++ b/src/components/EditListingPhotosPanel/EditListingPhotosPanel.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import classNames from 'classnames'; +import { LISTING_STATE_DRAFT } from '../../util/types'; import { EditListingPhotosForm } from '../../forms'; import { ensureOwnListing } from '../../util/data'; import { ListingLink } from '../../components'; @@ -32,7 +33,9 @@ class EditListingPhotosPanel extends Component { const classes = classNames(rootClass, className); const currentListing = ensureOwnListing(listing); - const panelTitle = currentListing.id ? ( + const isPublished = + currentListing.id && currentListing.attributes.state !== LISTING_STATE_DRAFT; + const panelTitle = isPublished ? ( }} @@ -48,7 +51,7 @@ class EditListingPhotosPanel extends Component { className={css.form} disabled={fetchInProgress} ready={newListingCreated} - errors={errors} + fetchErrors={errors} initialValues={{ images }} images={images} onImageUpload={onImageUpload} @@ -61,7 +64,6 @@ class EditListingPhotosPanel extends Component { onRemoveImage={onRemoveImage} saveActionMsg={submitButtonText} updated={panelUpdated} - updateError={errors.updateListingError} updateInProgress={updateInProgress} /> @@ -82,13 +84,7 @@ EditListingPhotosPanel.defaultProps = { EditListingPhotosPanel.propTypes = { className: string, rootClassName: string, - errors: shape({ - createListingsError: object, - updateListingError: object, - showListingsError: object, - uploadImageError: object, - createStripeAccountError: object, - }), + errors: object, fetchInProgress: bool.isRequired, newListingCreated: bool.isRequired, images: array, diff --git a/src/components/EditListingPoliciesPanel/EditListingPoliciesPanel.js b/src/components/EditListingPoliciesPanel/EditListingPoliciesPanel.js index d3b549b1..44ac7b7c 100644 --- a/src/components/EditListingPoliciesPanel/EditListingPoliciesPanel.js +++ b/src/components/EditListingPoliciesPanel/EditListingPoliciesPanel.js @@ -2,6 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { FormattedMessage } from 'react-intl'; +import { LISTING_STATE_DRAFT } from '../../util/types'; import { ensureOwnListing } from '../../util/data'; import { ListingLink } from '../../components'; import { EditListingPoliciesForm } from '../../forms'; @@ -25,7 +26,8 @@ const EditListingPoliciesPanel = props => { const currentListing = ensureOwnListing(listing); const { publicData } = currentListing.attributes; - const panelTitle = currentListing.id ? ( + const isPublished = currentListing.id && currentListing.attributes.state !== LISTING_STATE_DRAFT; + const panelTitle = isPublished ? ( }} @@ -53,8 +55,8 @@ const EditListingPoliciesPanel = props => { onChange={onChange} saveActionMsg={submitButtonText} updated={panelUpdated} - updateError={errors.updateListingError} updateInProgress={updateInProgress} + fetchErrors={errors} /> ); diff --git a/src/components/EditListingPricingPanel/EditListingPricingPanel.js b/src/components/EditListingPricingPanel/EditListingPricingPanel.js index 78a667ed..de457593 100644 --- a/src/components/EditListingPricingPanel/EditListingPricingPanel.js +++ b/src/components/EditListingPricingPanel/EditListingPricingPanel.js @@ -2,6 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { FormattedMessage } from 'react-intl'; +import { LISTING_STATE_DRAFT } from '../../util/types'; import { ListingLink } from '../../components'; import { EditListingPricingForm } from '../../forms'; import { ensureOwnListing } from '../../util/data'; @@ -29,7 +30,8 @@ const EditListingPricingPanel = props => { const currentListing = ensureOwnListing(listing); const { price } = currentListing.attributes; - const panelTitle = currentListing.id ? ( + const isPublished = currentListing.id && currentListing.attributes.state !== LISTING_STATE_DRAFT; + const panelTitle = isPublished ? ( }} @@ -47,8 +49,8 @@ const EditListingPricingPanel = props => { onChange={onChange} saveActionMsg={submitButtonText} updated={panelUpdated} - updateError={errors.updateListingError} updateInProgress={updateInProgress} + fetchErrors={errors} /> ) : (