diff --git a/app/routes/activity/components/Activity.js b/app/routes/activity/components/Activity.js
index be61ab6a..064ac5f1 100644
--- a/app/routes/activity/components/Activity.js
+++ b/app/routes/activity/components/Activity.js
@@ -33,9 +33,10 @@ class Activity extends Component {
setInvoice,
paymentModalOpen,
invoiceModalOpen,
- currentTicker
+ currentTicker,
+ sortedActivity
} = this.props
-
+ console.log('sortedActivity: ', sortedActivity)
if (invoiceLoading || paymentLoading) { return
Loading...
}
return (
diff --git a/app/routes/activity/containers/ActivityContainer.js b/app/routes/activity/containers/ActivityContainer.js
index 25f0652e..35658ed7 100644
--- a/app/routes/activity/containers/ActivityContainer.js
+++ b/app/routes/activity/containers/ActivityContainer.js
@@ -12,6 +12,7 @@ import {
paymentSelectors
} from '../../../reducers/payment'
import { fetchTransactions } from '../../../reducers/transaction'
+import { activitySelectors } from '../../../selectors'
import Activity from '../components/Activity'
const mapDispatchToProps = {
@@ -23,6 +24,7 @@ const mapDispatchToProps = {
searchInvoices
}
+console.log('activitySelectors: ', activitySelectors)
const mapStateToProps = state => ({
activity: state.activity,
@@ -36,7 +38,9 @@ const mapStateToProps = state => ({
paymentModalOpen: paymentSelectors.paymentModalOpen(state),
invoiceModalOpen: invoiceSelectors.invoiceModalOpen(state),
- currentTicker: tickerSelectors.currentTicker(state)
+ currentTicker: tickerSelectors.currentTicker(state),
+
+ sortedActivity: activitySelectors.sortedActivity(state)
})
export default connect(mapStateToProps, mapDispatchToProps)(Activity)
diff --git a/app/selectors/activity.js b/app/selectors/activity.js
new file mode 100644
index 00000000..7d89239c
--- /dev/null
+++ b/app/selectors/activity.js
@@ -0,0 +1,22 @@
+import { createSelector } from 'reselect'
+
+const activitySelectors = {}
+const paymentsSelector = state => state.payment.payments
+const invoicesSelector = state => state.invoice.invoices
+const transactionsSelector = state => state.transaction.transactions
+
+activitySelectors.sortedActivity = createSelector(
+ paymentsSelector,
+ invoicesSelector,
+ transactionsSelector,
+ (payments, invoices, transactions) => {
+ return [...payments, ...invoices, ...transactions].sort((a, b) => {
+ let aTimestamp = a.hasOwnProperty('time_stamp') ? a.time_stamp : a.creation_date
+ let bTimestamp = b.hasOwnProperty('time_stamp') ? b.time_stamp : b.creation_date
+
+ return bTimestamp - aTimestamp
+ })
+ }
+)
+
+export default activitySelectors
\ No newline at end of file
diff --git a/app/selectors/index.js b/app/selectors/index.js
new file mode 100644
index 00000000..f28a76aa
--- /dev/null
+++ b/app/selectors/index.js
@@ -0,0 +1,5 @@
+import activitySelectors from './activity'
+
+export default {
+ activitySelectors
+}
\ No newline at end of file