From 3eb5f165442eebd569ca9842fd53d1685057e963 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Fri, 5 Jul 2019 17:49:25 +0300 Subject: [PATCH 1/4] Fix proptype validation for BookingPanel --- src/components/BookingPanel/BookingPanel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/BookingPanel/BookingPanel.js b/src/components/BookingPanel/BookingPanel.js index f8198953..14fc5f06 100644 --- a/src/components/BookingPanel/BookingPanel.js +++ b/src/components/BookingPanel/BookingPanel.js @@ -176,7 +176,7 @@ BookingPanel.propTypes = { onSubmit: func.isRequired, title: oneOfType([node, string]).isRequired, subTitle: oneOfType([node, string]), - authorDisplayName: string.isRequired, + authorDisplayName: oneOfType([node, string]).isRequired, onManageDisableScrolling: func.isRequired, timeSlots: arrayOf(propTypes.timeSlot), fetchTimeSlotsError: propTypes.error, From a3898f634134c9a7fa0339e18dca2887dafb21aa Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Fri, 5 Jul 2019 17:50:24 +0300 Subject: [PATCH 2/4] TransactionPage.duck: Fetch process transitions on loadData --- .../TransactionPage/TransactionPage.duck.js | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/containers/TransactionPage/TransactionPage.duck.js b/src/containers/TransactionPage/TransactionPage.duck.js index 903777bf..7bbfa4e4 100644 --- a/src/containers/TransactionPage/TransactionPage.duck.js +++ b/src/containers/TransactionPage/TransactionPage.duck.js @@ -35,6 +35,10 @@ export const FETCH_TRANSACTION_REQUEST = 'app/TransactionPage/FETCH_TRANSACTION_ export const FETCH_TRANSACTION_SUCCESS = 'app/TransactionPage/FETCH_TRANSACTION_SUCCESS'; export const FETCH_TRANSACTION_ERROR = 'app/TransactionPage/FETCH_TRANSACTION_ERROR'; +export const FETCH_TRANSITIONS_REQUEST = 'app/TransactionPage/FETCH_TRANSITIONS_REQUEST'; +export const FETCH_TRANSITIONS_SUCCESS = 'app/TransactionPage/FETCH_TRANSITIONS_SUCCESS'; +export const FETCH_TRANSITIONS_ERROR = 'app/TransactionPage/FETCH_TRANSITIONS_ERROR'; + export const ACCEPT_SALE_REQUEST = 'app/TransactionPage/ACCEPT_SALE_REQUEST'; export const ACCEPT_SALE_SUCCESS = 'app/TransactionPage/ACCEPT_SALE_SUCCESS'; export const ACCEPT_SALE_ERROR = 'app/TransactionPage/ACCEPT_SALE_ERROR'; @@ -82,6 +86,9 @@ const initialState = { sendReviewError: null, timeSlots: null, fetchTimeSlotsError: null, + fetchTransitionsInProgress: false, + fetchTransitionsError: null, + processTransitions: null, }; // Merge entity arrays using ids, so that conflicting items in newer array (b) overwrite old values (a). @@ -109,6 +116,14 @@ export default function checkoutPageReducer(state = initialState, action = {}) { console.error(payload); // eslint-disable-line return { ...state, fetchTransactionInProgress: false, fetchTransactionError: payload }; + case FETCH_TRANSITIONS_REQUEST: + return { ...state, fetchTransitionsInProgress: true, fetchTransitionsError: null }; + case FETCH_TRANSITIONS_SUCCESS: + return { ...state, fetchTransitionsInProgress: false, processTransitions: payload }; + case FETCH_TRANSITIONS_ERROR: + console.error(payload); // eslint-disable-line + return { ...state, fetchTransitionsInProgress: false, fetchTransitionsError: payload }; + case ACCEPT_SALE_REQUEST: return { ...state, acceptInProgress: true, acceptSaleError: null, declineSaleError: null }; case ACCEPT_SALE_SUCCESS: @@ -192,6 +207,13 @@ const fetchTransactionSuccess = response => ({ }); const fetchTransactionError = e => ({ type: FETCH_TRANSACTION_ERROR, error: true, payload: e }); +const fetchTransitionsRequest = () => ({ type: FETCH_TRANSITIONS_REQUEST }); +const fetchTransitionsSuccess = response => ({ + type: FETCH_TRANSITIONS_SUCCESS, + payload: response, +}); +const fetchTransitionsError = e => ({ type: FETCH_TRANSITIONS_ERROR, error: true, payload: e }); + const acceptSaleRequest = () => ({ type: ACCEPT_SALE_REQUEST }); const acceptSaleSuccess = () => ({ type: ACCEPT_SALE_SUCCESS }); const acceptSaleError = e => ({ type: ACCEPT_SALE_ERROR, error: true, payload: e }); @@ -564,6 +586,19 @@ const fetchTimeSlots = listingId => (dispatch, getState, sdk) => { }); }; +export const fetchNextTransitions = id => (dispatch, getState, sdk) => { + dispatch(fetchTransitionsRequest()); + + return sdk.processTransitions + .query({ transactionId: id }) + .then(res => { + dispatch(fetchTransitionsSuccess(res.data.data)); + }) + .catch(e => { + dispatch(fetchTransitionsError(storableError(e))); + }); +}; + // loadData is a collection of async calls that need to be made // before page has all the info it needs to render itself export const loadData = params => (dispatch, getState) => { @@ -579,5 +614,9 @@ export const loadData = params => (dispatch, getState) => { dispatch(setInitialValues(initialValues)); // Sale / order (i.e. transaction entity in API) - return Promise.all([dispatch(fetchTransaction(txId, txRole)), dispatch(fetchMessages(txId, 1))]); + return Promise.all([ + dispatch(fetchTransaction(txId, txRole)), + dispatch(fetchMessages(txId, 1)), + dispatch(fetchNextTransitions(txId)), + ]); }; From f9dae4bac4300dde77783b29ed02f2e8de1c7022 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Fri, 5 Jul 2019 17:51:58 +0300 Subject: [PATCH 3/4] TransactionPanel: has correct next transition for enquiry --- .../TransactionPanel/TransactionPanel.js | 17 +++++++++++++---- .../TransactionPage/TransactionPage.js | 4 ++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/components/TransactionPanel/TransactionPanel.js b/src/components/TransactionPanel/TransactionPanel.js index d300d617..7274219d 100644 --- a/src/components/TransactionPanel/TransactionPanel.js +++ b/src/components/TransactionPanel/TransactionPanel.js @@ -1,8 +1,9 @@ import React, { Component } from 'react'; -import PropTypes from 'prop-types'; +import { array, arrayOf, bool, func, number, string } from 'prop-types'; import { injectIntl, intlShape } from 'react-intl'; import classNames from 'classnames'; import { + TRANSITION_REQUEST_PAYMENT_AFTER_ENQUIRY, txIsAccepted, txIsCanceled, txIsDeclined, @@ -182,6 +183,7 @@ export class TransactionPanelComponent extends Component { onSubmitBookingRequest, timeSlots, fetchTimeSlotsError, + nextTransitions, } = this.props; const currentTransaction = ensureTransaction(transaction); @@ -202,9 +204,16 @@ export class TransactionPanelComponent extends Component { const stateDataFn = tx => { if (txIsEnquired(tx)) { + const transitions = Array.isArray(nextTransitions) + ? nextTransitions.map(transition => { + return transition.attributes.name; + }) + : []; + const hasCorrectNextTransition = + transitions.length > 0 && transitions.includes(TRANSITION_REQUEST_PAYMENT_AFTER_ENQUIRY); return { headingState: HEADING_ENQUIRED, - showBookingPanel: isCustomer && !isProviderBanned, + showBookingPanel: isCustomer && !isProviderBanned && hasCorrectNextTransition, }; } else if (txIsPaymentPending(tx)) { return { @@ -456,10 +465,9 @@ TransactionPanelComponent.defaultProps = { sendReviewError: null, timeSlots: null, fetchTimeSlotsError: null, + nextTransitions: null, }; -const { arrayOf, bool, func, number, string } = PropTypes; - TransactionPanelComponent.propTypes = { rootClassName: string, className: string, @@ -483,6 +491,7 @@ TransactionPanelComponent.propTypes = { onSubmitBookingRequest: func.isRequired, timeSlots: arrayOf(propTypes.timeSlot), fetchTimeSlotsError: propTypes.error, + nextTransitions: array, // Sale related props onAcceptSale: func.isRequired, diff --git a/src/containers/TransactionPage/TransactionPage.js b/src/containers/TransactionPage/TransactionPage.js index 15df684c..e5b3bed9 100644 --- a/src/containers/TransactionPage/TransactionPage.js +++ b/src/containers/TransactionPage/TransactionPage.js @@ -74,6 +74,7 @@ export const TransactionPageComponent = props => { onDeclineSale, timeSlots, fetchTimeSlotsError, + processTransitions, callSetInitialValues, onInitializeCardPaymentData, } = props; @@ -232,6 +233,7 @@ export const TransactionPageComponent = props => { declineInProgress={declineInProgress} acceptSaleError={acceptSaleError} declineSaleError={declineSaleError} + nextTransitions={processTransitions} onSubmitBookingRequest={handleSubmitBookingRequest} timeSlots={timeSlots} fetchTimeSlotsError={fetchTimeSlotsError} @@ -334,6 +336,7 @@ const mapStateToProps = state => { sendReviewError, timeSlots, fetchTimeSlotsError, + processTransitions, } = state.TransactionPage; const { currentUser } = state.user; @@ -361,6 +364,7 @@ const mapStateToProps = state => { sendReviewError, timeSlots, fetchTimeSlotsError, + processTransitions, }; }; From cd525d07089bb4b868c35121be56dd5029a0be28 Mon Sep 17 00:00:00 2001 From: Jenni Nurmi Date: Mon, 8 Jul 2019 13:46:00 +0300 Subject: [PATCH 4/4] Update changelog and package.json --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8f465c0..ca68ff69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,13 @@ way to update this template, but currently, we follow a pattern: ## Upcoming version 2019-XX-XX +## [v3.1.1] 2019-07-08 + +- [fix] Ensure on `TransactionPanel` that enquiry has a correct transition when a customer tries to + book the listing. This might happen with transaction process changes (e.g. when changing from + previous default to SCA process). + [#1131](https://github.com/sharetribe/flex-template-web/pull/1131) + ## [v3.1.0] 2019-07-05 - [fix] SectionHero: fix type in search params. There was an extra "/s?". diff --git a/package.json b/package.json index a5c4f087..5d59d316 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "app", - "version": "3.1.0", + "version": "3.1.1", "private": true, "license": "Apache-2.0", "dependencies": {