Skip to content

Commit

Permalink
Merge pull request #1131 from sharetribe/ensure-booking-transition-ex…
Browse files Browse the repository at this point in the history
…ists

Ensure booking transition exists
  • Loading branch information
OtterleyW committed Jul 8, 2019
2 parents 3791a2e + cd525d0 commit 423a920
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?".
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app",
"version": "3.1.0",
"version": "3.1.1",
"private": true,
"license": "Apache-2.0",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/BookingPanel/BookingPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 13 additions & 4 deletions src/components/TransactionPanel/TransactionPanel.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -182,6 +183,7 @@ export class TransactionPanelComponent extends Component {
onSubmitBookingRequest,
timeSlots,
fetchTimeSlotsError,
nextTransitions,
} = this.props;

const currentTransaction = ensureTransaction(transaction);
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -483,6 +491,7 @@ TransactionPanelComponent.propTypes = {
onSubmitBookingRequest: func.isRequired,
timeSlots: arrayOf(propTypes.timeSlot),
fetchTimeSlotsError: propTypes.error,
nextTransitions: array,

// Sale related props
onAcceptSale: func.isRequired,
Expand Down
41 changes: 40 additions & 1 deletion src/containers/TransactionPage/TransactionPage.duck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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) => {
Expand All @@ -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)),
]);
};
4 changes: 4 additions & 0 deletions src/containers/TransactionPage/TransactionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const TransactionPageComponent = props => {
onDeclineSale,
timeSlots,
fetchTimeSlotsError,
processTransitions,
callSetInitialValues,
onInitializeCardPaymentData,
} = props;
Expand Down Expand Up @@ -232,6 +233,7 @@ export const TransactionPageComponent = props => {
declineInProgress={declineInProgress}
acceptSaleError={acceptSaleError}
declineSaleError={declineSaleError}
nextTransitions={processTransitions}
onSubmitBookingRequest={handleSubmitBookingRequest}
timeSlots={timeSlots}
fetchTimeSlotsError={fetchTimeSlotsError}
Expand Down Expand Up @@ -334,6 +336,7 @@ const mapStateToProps = state => {
sendReviewError,
timeSlots,
fetchTimeSlotsError,
processTransitions,
} = state.TransactionPage;
const { currentUser } = state.user;

Expand Down Expand Up @@ -361,6 +364,7 @@ const mapStateToProps = state => {
sendReviewError,
timeSlots,
fetchTimeSlotsError,
processTransitions,
};
};

Expand Down

0 comments on commit 423a920

Please sign in to comment.