From 234aeb342a8e648804247b7a9d079cba7f82d530 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 29 Sep 2017 14:19:11 +0300 Subject: [PATCH] Use tx state helpers --- .../OrderDetailsPanel/OrderDetailsPanel.js | 155 +++++++++--------- 1 file changed, 74 insertions(+), 81 deletions(-) diff --git a/src/components/OrderDetailsPanel/OrderDetailsPanel.js b/src/components/OrderDetailsPanel/OrderDetailsPanel.js index ed77c31d..3602ab2a 100644 --- a/src/components/OrderDetailsPanel/OrderDetailsPanel.js +++ b/src/components/OrderDetailsPanel/OrderDetailsPanel.js @@ -21,93 +21,89 @@ const breakdown = transaction => { : null; }; -const orderTitle = (lastTransition, listingLink, customerName) => { - switch (lastTransition) { - case propTypes.TX_TRANSITION_PREAUTHORIZE: - return ( - - - - +const orderTitle = (transaction, listingLink, customerName) => { + if (propTypes.txIsPreauthorized(transaction)) { + return ( + + - ); - case propTypes.TX_TRANSITION_ACCEPT: - return ( - - - - - + + + ); + } else if (propTypes.txIsAccepted(transaction)) { + return ( + + + - ); - case propTypes.TX_TRANSITION_REJECT: - return ( - - ); - case propTypes.TX_TRANSITION_AUTO_REJECT: - return ( - - ); - case propTypes.TX_TRANSITION_MARK_DELIVERED: - return ( - - ); - default: - return null; + + + ); + } else if (propTypes.txIsRejected(transaction)) { + return ; + } else if (propTypes.txIsAutorejected(transaction)) { + return ( + + ); + } else if (propTypes.txIsDelivered(transaction)) { + return ; + } else { + return null; } }; -const orderMessage = (lastTransition, listingTitle, providerName, lastTransitionedAt) => { +const orderMessage = (transaction, listingTitle, providerName) => { const transitionDate = ( - + ); - switch (lastTransition) { - case propTypes.TX_TRANSITION_PREAUTHORIZE: - return ( - - ); - case propTypes.TX_TRANSITION_ACCEPT: - return ( - - ); - case propTypes.TX_TRANSITION_REJECT: - return ( - - ); - case propTypes.TX_TRANSITION_AUTO_REJECT: - return ( - - ); - case propTypes.TX_TRANSITION_MARK_DELIVERED: - return ( - - ); - default: - return null; + if (propTypes.txIsPreauthorized(transaction)) { + return ( + + ); + } else if (propTypes.txIsAccepted(transaction)) { + return ( + + ); + } else if (propTypes.txIsRejected(transaction)) { + return ( + + ); + } else if (propTypes.txIsAutorejected(transaction)) { + return ( + + ); + } else if (propTypes.txIsDelivered(transaction)) { + return ( + + ); + } else { + return null; } }; @@ -141,8 +137,6 @@ export const OrderDetailsPanelComponent = props => { const authorDisplayName = userDisplayName(currentProvider, bannedUserDisplayName); const customerDisplayName = userDisplayName(currentCustomer, bannedUserDisplayName); - const lastTransitionedAt = currentTransaction.attributes.lastTransitionedAt; - const lastTransition = currentTransaction.attributes.lastTransition; let listingLink = null; @@ -163,10 +157,10 @@ export const OrderDetailsPanelComponent = props => { : currentListing.attributes.title; const bookingInfo = breakdown(currentTransaction); - const orderHeading = orderTitle(lastTransition, listingLink, customerDisplayName); + const orderHeading = orderTitle(currentTransaction, listingLink, customerDisplayName); const message = listingDeleted ? orderMessageDeletedListing - : orderMessage(lastTransition, listingLink, authorDisplayName, lastTransitionedAt); + : orderMessage(currentTransaction, listingLink, authorDisplayName); const firstImage = currentListing.images && currentListing.images.length > 0 ? currentListing.images[0] @@ -244,7 +238,6 @@ export const OrderDetailsPanelComponent = props => { OrderDetailsPanelComponent.defaultProps = { rootClassName: null, className: null, - lastTransition: null, }; const { string } = PropTypes;