import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import { getActivities } from './transaction-activity-log.util' import Card from '../card' export default class TransactionActivityLog extends PureComponent { static contextTypes = { t: PropTypes.func, } static propTypes = { transaction: PropTypes.object, } state = { activities: [], } componentDidMount () { this.setActivites() } componentDidUpdate (prevProps) { const { transaction: { history: prevHistory = [] } = {} } = prevProps const { transaction: { history = [] } = {} } = this.props if (prevHistory.length !== history.length) { this.setActivites() } } setActivites () { const activities = getActivities(this.props.transaction) this.setState({ activities }) } renderActivity (activity, index) { return (
{ this.renderActivityText(activity) }
) } renderActivityText (activity) { const { eventKey, value, valueDescriptionKey } = activity return (
{ `Transaction ` } { `${eventKey}` } { valueDescriptionKey && value ? ( { ` with a ${valueDescriptionKey} of ` } { value } . ) : '.' }
) } render () { const { t } = this.context const { activities } = this.state return (
{ activities.map((activity, index) => ( this.renderActivity(activity, index) )) }
) } }