diff --git a/src/components/BookingBreakdown/BookingBreakdown.example.js b/src/components/BookingBreakdown/BookingBreakdown.example.js index b8dcda75..92769f50 100644 --- a/src/components/BookingBreakdown/BookingBreakdown.example.js +++ b/src/components/BookingBreakdown/BookingBreakdown.example.js @@ -22,6 +22,13 @@ const exampleTransaction = params => { createdAt: created, lastTransitionedAt: created, lastTransition: propTypes.TX_TRANSITION_PREAUTHORIZE, + transitions: [ + { + at: created, + by: propTypes.TX_TRANSITION_ACTOR_CUSTOMER, + transition: propTypes.TX_TRANSITION_PREAUTHORIZE, + }, + ], // payinTotal, payoutTotal, and lineItems required in params ...params, diff --git a/src/components/BookingBreakdown/BookingBreakdown.test.js b/src/components/BookingBreakdown/BookingBreakdown.test.js index 29c90818..b4addd56 100644 --- a/src/components/BookingBreakdown/BookingBreakdown.test.js +++ b/src/components/BookingBreakdown/BookingBreakdown.test.js @@ -17,6 +17,13 @@ const exampleTransaction = params => { createdAt: created, lastTransitionedAt: created, lastTransition: propTypes.TX_TRANSITION_PREAUTHORIZE, + transitions: [ + { + at: created, + by: propTypes.TX_TRANSITION_ACTOR_CUSTOMER, + transition: propTypes.TX_TRANSITION_PREAUTHORIZE, + }, + ], // payinTotal, payoutTotal, and lineItems required in params ...params, diff --git a/src/components/Messages/Messages.css b/src/components/Messages/Messages.css index 51fc8ca2..c7958c17 100644 --- a/src/components/Messages/Messages.css +++ b/src/components/Messages/Messages.css @@ -8,13 +8,13 @@ } .messageItem { - margin-bottom: 35px; + margin-bottom: 38px; /* Clearfix */ @apply --clearfix; @media (--viewportMedium) { - margin-bottom: 40px; + margin-bottom: 41px; } &:last-of-type { @@ -41,7 +41,11 @@ .avatar { flex-shrink: 0; - margin: 9px 12px 0 0; + margin: 6px 12px 0 0; + + @media (--viewportMedium) { + margin: 9px 12px 0 0; + } } .messageContent, @@ -49,11 +53,12 @@ @apply --marketplaceMessageFontStyles; margin: 0; - padding: 15px 14px 11px 14px; + padding: 12px 14px 11px 14px; border-radius: 8px; box-shadow: var(--boxShadow); @media (--viewportMedium) { + padding: 14px 14px 11px 14px; margin: 0; } } @@ -81,3 +86,47 @@ .ownMessageDate { text-align: right; } + +.transitionItem { + margin-bottom: 36px; + + /* Clearfix */ + @apply --clearfix; + + @media (--viewportMedium) { + margin-bottom: 40px; + } + + &:last-of-type { + margin-bottom: 0; + } +} + +.transition { + display: flex; + flex-direction: row; + padding: 3px 0 2px 0; + + @media (--viewportMedium) { + padding: 0; + } +} + +.transitionContent { + @apply --marketplaceTxTransitionFontStyles; + margin: 0; +} + +.transitionDate { + @apply --marketplaceMessageDateFontStyles; + color: var(--matterColorAnti); + margin: 7px 0 0 0; + + @media (--viewportMedium) { + margin: -1px 0 1px 0; + } +} + +.bullet { + margin-right: 6px; +} diff --git a/src/components/Messages/Messages.example.js b/src/components/Messages/Messages.example.js index f110c876..f16ad482 100644 --- a/src/components/Messages/Messages.example.js +++ b/src/components/Messages/Messages.example.js @@ -1,4 +1,12 @@ -import { createUser, createCurrentUser, createMessage } from '../../util/test-data'; +import { + createUser, + createCurrentUser, + createMessage, + createTransaction, + createListing, + createTxTransition, +} from '../../util/test-data'; +import * as propTypes from '../../util/propTypes'; import Messages from './Messages'; export const Empty = { @@ -6,6 +14,9 @@ export const Empty = { props: { messages: [], currentUser: null, + transaction: null, + customer: null, + provider: null, }, group: 'messages', }; @@ -34,3 +45,86 @@ export const WithCurrentUser = { }, group: 'messages', }; + +export const WithTransitions = { + component: Messages, + props: { + messages: [], + transaction: createTransaction({ + customer: createUser('user1'), + provider: createUser('user2'), + listing: createListing('Listing'), + transitions: [ + createTxTransition({ + at: new Date(Date.UTC(2017, 10, 9, 8, 10)), + by: propTypes.TX_TRANSITION_ACTOR_CUSTOMER, + transition: propTypes.TX_TRANSITION_PREAUTHORIZE, + }), + createTxTransition({ + at: new Date(Date.UTC(2017, 10, 9, 8, 12)), + by: propTypes.TX_TRANSITION_ACTOR_PROVIDER, + transition: propTypes.TX_TRANSITION_ACCEPT, + }), + ], + }), + currentUser: createCurrentUser('user2'), + }, + group: 'messages', +}; + +export const WithMessagesAndTransitions = { + component: Messages, + props: { + messages: [ + createMessage( + 'msg1', + { at: new Date(Date.UTC(2017, 10, 9, 8, 11)) }, + { sender: createUser('user1') } + ), + createMessage( + 'msg2', + { at: new Date(Date.UTC(2017, 10, 9, 8, 14)) }, + { sender: createUser('user1') } + ), + createMessage( + 'msg3', + { at: new Date(Date.UTC(2017, 10, 9, 8, 17)) }, + { sender: createUser('user2') } + ), + createMessage( + 'msg4', + { at: new Date(Date.UTC(2017, 10, 12, 13, 20)) }, + { sender: createUser('user2') } + ), + ], + transaction: createTransaction({ + customer: createUser('user1'), + provider: createUser('user2'), + listing: createListing('Listing'), + transitions: [ + createTxTransition({ + at: new Date(Date.UTC(2017, 10, 9, 8, 10)), + by: propTypes.TX_TRANSITION_ACTOR_CUSTOMER, + transition: propTypes.TX_TRANSITION_PREAUTHORIZE, + }), + createTxTransition({ + at: new Date(Date.UTC(2017, 10, 9, 8, 12)), + by: propTypes.TX_TRANSITION_ACTOR_PROVIDER, + transition: propTypes.TX_TRANSITION_ACCEPT, + }), + createTxTransition({ + at: new Date(Date.UTC(2017, 10, 9, 10, 33)), + by: propTypes.TX_TRANSITION_ACTOR_PROVIDER, + transition: propTypes.TX_TRANSITION_DECLINE, + }), + createTxTransition({ + at: new Date(Date.UTC(2017, 10, 9, 10, 34)), + by: propTypes.TX_TRANSITION_ACTOR_PROVIDER, + transition: propTypes.TX_TRANSITION_MARK_DELIVERED, + }), + ], + }), + currentUser: createCurrentUser('user2'), + }, + group: 'messages', +}; diff --git a/src/components/Messages/Messages.js b/src/components/Messages/Messages.js index bb490380..a5f19d2b 100644 --- a/src/components/Messages/Messages.js +++ b/src/components/Messages/Messages.js @@ -4,6 +4,7 @@ import { injectIntl, intlShape } from 'react-intl'; import classNames from 'classnames'; import { Avatar } from '../../components'; import { formatDate } from '../../util/dates'; +import { ensureTransaction, ensureUser } from '../../util/data'; import * as propTypes from '../../util/propTypes'; import css from './Messages.css'; @@ -43,11 +44,133 @@ OwnMessage.propTypes = { intl: intlShape.isRequired, }; +const Transition = props => { + const { transition, currentUser, customer, provider, listingTitle, intl } = props; + + const resolveTransitionMessage = (transition, ownRole, otherUsersName, intl) => { + const isOwnTransition = transition.by === ownRole; + const transitionType = transition.transition; + const displayName = otherUsersName; + + switch (transitionType) { + case propTypes.TX_TRANSITION_PREAUTHORIZE: + return isOwnTransition + ? intl.formatMessage({ id: 'Messages.ownTransitionRequest' }, { listingTitle }) + : intl.formatMessage({ id: 'Messages.transitionRequest' }, { displayName, listingTitle }); + case propTypes.TX_TRANSITION_ACCEPT: + return isOwnTransition + ? intl.formatMessage({ id: 'Messages.ownTransitionAccept' }) + : intl.formatMessage({ id: 'Messages.transitionAccept' }, { displayName }); + case propTypes.TX_TRANSITION_DECLINE: + return isOwnTransition + ? intl.formatMessage({ id: 'Messages.ownTransitionDecline' }) + : intl.formatMessage({ id: 'Messages.transitionDecline' }, { displayName }); + case propTypes.TX_TRANSITION_AUTO_DECLINE: + return ownRole === propTypes.TX_TRANSITION_ACTOR_PROVIDER + ? intl.formatMessage({ id: 'Messages.ownTransitionAutoDecline' }) + : intl.formatMessage({ id: 'Messages.transitionAutoDecline' }, { displayName }); + case propTypes.TX_TRANSITION_MARK_DELIVERED: + return intl.formatMessage({ id: 'Messages.transitionComplete' }); + case propTypes.TX_TRANSITION_CANCEL: + return intl.formatMessage({ id: 'Messages.transitionCancel' }); + + default: + return ''; + } + }; + + const ownRole = + currentUser.id.uuid === customer.id.uuid + ? propTypes.TX_TRANSITION_ACTOR_CUSTOMER + : propTypes.TX_TRANSITION_ACTOR_PROVIDER; + + const otherUsersName = + ownRole === propTypes.TX_TRANSITION_ACTOR_CUSTOMER + ? provider.attributes.profile.displayName + : customer.attributes.profile.displayName; + + const transitionMessage = resolveTransitionMessage(transition, ownRole, otherUsersName, intl); + const todayString = intl.formatMessage({ id: 'Messages.today' }); + + return ( +
•
+{transitionMessage}
+{formatDate(intl, todayString, transition.at)}
+•
+
-
-