TransactionPanel: has correct next transition for enquiry

This commit is contained in:
Vesa Luusua 2019-07-05 17:51:58 +03:00
parent a3898f6341
commit f9dae4bac4
2 changed files with 17 additions and 4 deletions

View file

@ -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,

View file

@ -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,
};
};