diff --git a/CHANGELOG.md b/CHANGELOG.md index c69c93050..3db0de033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ https://github.com/sharetribe/flex-template-web/ ## Upcoming version 2019-XX-XX +- [fix] Add allowOnlyOneListing prop to EditListingPage and redirect to existing listing if true. + [#52](https://github.com/sharetribe/ftw-time/pull/52) - [fix] Recently added Footer on EditListingWizard was on top of payout details modal. [#51](https://github.com/sharetribe/ftw-time/pull/51) - [change] Hide policy tab ("sauna rules") from `EditListingWizard`. Also, fix height of the page diff --git a/src/containers/EditListingPage/EditListingPage.js b/src/containers/EditListingPage/EditListingPage.js index 4f52ac890..b0df645db 100644 --- a/src/containers/EditListingPage/EditListingPage.js +++ b/src/containers/EditListingPage/EditListingPage.js @@ -8,6 +8,7 @@ import { types as sdkTypes } from '../../util/sdkLoader'; import { LISTING_PAGE_PARAM_TYPE_DRAFT, LISTING_PAGE_PARAM_TYPE_NEW, + LISTING_PAGE_PARAM_TYPE_EDIT, LISTING_PAGE_PARAM_TYPES, LISTING_PAGE_PENDING_APPROVAL_VARIANT, createSlug, @@ -41,6 +42,8 @@ const { UUID } = sdkTypes; export const EditListingPageComponent = props => { const { currentUser, + currentUserListing, + currentUserListingFetched, createStripeAccountError, fetchInProgress, getOwnListing, @@ -61,6 +64,7 @@ export const EditListingPageComponent = props => { page, params, scrollingDisabled, + allowOnlyOneListing, } = props; const { id, type } = params; @@ -102,6 +106,19 @@ export const EditListingPageComponent = props => { }; return ; + } else if (allowOnlyOneListing && isNewURI && currentUserListingFetched && currentUserListing) { + // If we allow only one listing per provider, we need to redirect to correct listing. + return ( + + ); } else if (showForm) { const { createListingDraftError = null, @@ -226,12 +243,16 @@ EditListingPageComponent.defaultProps = { listingDraft: null, notificationCount: 0, sendVerificationEmailError: null, + currentUserListing: null, + currentUserListingFetched: false, }; EditListingPageComponent.propTypes = { createStripeAccountError: propTypes.error, currentUser: propTypes.currentUser, getOwnListing: func.isRequired, + currentUserListing: propTypes.ownListing, + currentUserListingFetched: bool, onAddAvailabilityException: func.isRequired, onDeleteAvailabilityException: func.isRequired, onCreateListingDraft: func.isRequired, @@ -265,7 +286,7 @@ EditListingPageComponent.propTypes = { const mapStateToProps = state => { const page = state.EditListingPage; const { createStripeAccountInProgress, createStripeAccountError } = state.stripe; - const { currentUser } = state.user; + const { currentUser, currentUserListing, currentUserListingFetched } = state.user; const fetchInProgress = createStripeAccountInProgress; @@ -277,6 +298,8 @@ const mapStateToProps = state => { return { createStripeAccountError, currentUser, + currentUserListing, + currentUserListingFetched, fetchInProgress, getOwnListing, page, diff --git a/src/routeConfiguration.js b/src/routeConfiguration.js index 51ef26bba..f661fad59 100644 --- a/src/routeConfiguration.js +++ b/src/routeConfiguration.js @@ -121,7 +121,7 @@ const routeConfiguration = () => { path: '/l/:slug/:id/:type/:tab', name: 'EditListingPage', auth: true, - component: props => , + component: props => , loadData: EditListingPage.loadData, },