-
-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable Transactions page SSR #4753
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { graphql } from '@apollo/react-hoc'; | ||
import { get } from 'lodash'; | ||
import styled from 'styled-components'; | ||
|
||
import { CollectiveType } from '../lib/constants/collectives'; | ||
import { API_V2_CONTEXT, gqlV2 } from '../lib/graphql/helpers'; | ||
import { addCollectiveCoverData } from '../lib/graphql/queries'; | ||
|
||
import Body from '../components/Body'; | ||
|
@@ -15,9 +17,112 @@ import Footer from '../components/Footer'; | |
import Header from '../components/Header'; | ||
import Loading from '../components/Loading'; | ||
import Page from '../components/Page'; | ||
import Transactions from '../components/transactions/Transactions'; | ||
import Transactions, { getVariablesFromQuery } from '../components/transactions/Transactions'; | ||
import { withUser } from '../components/UserProvider'; | ||
|
||
const transactionsQuery = gqlV2/* GraphQL */ ` | ||
query Transactions( | ||
$slug: String! | ||
$limit: Int! | ||
$offset: Int! | ||
$type: TransactionType | ||
$minAmount: Int | ||
$maxAmount: Int | ||
$dateFrom: ISODateTime | ||
$searchTerm: String | ||
) { | ||
transactions( | ||
account: { slug: $slug } | ||
limit: $limit | ||
offset: $offset | ||
type: $type | ||
minAmount: $minAmount | ||
maxAmount: $maxAmount | ||
dateFrom: $dateFrom | ||
searchTerm: $searchTerm | ||
) { | ||
totalCount | ||
offset | ||
limit | ||
nodes { | ||
id | ||
uuid | ||
amount { | ||
currency | ||
valueInCents | ||
} | ||
netAmount { | ||
currency | ||
valueInCents | ||
} | ||
platformFee { | ||
currency | ||
valueInCents | ||
} | ||
paymentProcessorFee { | ||
currency | ||
valueInCents | ||
} | ||
hostFee { | ||
currency | ||
valueInCents | ||
} | ||
type | ||
description | ||
createdAt | ||
isRefunded | ||
toAccount { | ||
id | ||
name | ||
slug | ||
type | ||
imageUrl | ||
... on Collective { | ||
host { | ||
name | ||
slug | ||
type | ||
} | ||
} | ||
} | ||
fromAccount { | ||
id | ||
name | ||
slug | ||
type | ||
imageUrl | ||
} | ||
paymentMethod { | ||
type | ||
} | ||
order { | ||
id | ||
status | ||
} | ||
expense { | ||
id | ||
status | ||
tags | ||
type | ||
legacyId | ||
comments { | ||
totalCount | ||
} | ||
payoutMethod { | ||
type | ||
} | ||
account { | ||
slug | ||
} | ||
createdByAccount { | ||
slug | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const TransactionPageWrapper = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
|
@@ -28,13 +133,14 @@ const TransactionPageWrapper = styled.div` | |
`; | ||
|
||
class TransactionsPage extends React.Component { | ||
static getInitialProps({ query: { collectiveSlug } }) { | ||
return { slug: collectiveSlug }; | ||
static async getInitialProps({ query: { collectiveSlug, ...query } }) { | ||
return { slug: collectiveSlug, query }; | ||
} | ||
|
||
static propTypes = { | ||
slug: PropTypes.string, // from getInitialProps, for addCollectiveCoverData | ||
data: PropTypes.object.isRequired, // from withData | ||
transactionsQuery: PropTypes.object, | ||
LoggedInUser: PropTypes.object, | ||
}; | ||
|
||
|
@@ -92,6 +198,7 @@ class TransactionsPage extends React.Component { | |
</Container> | ||
|
||
<Transactions | ||
transactionsQuery={this.props.transactionsQuery} | ||
collective={collective} | ||
showCSVlink={true} | ||
filters={true} | ||
|
@@ -106,4 +213,15 @@ class TransactionsPage extends React.Component { | |
} | ||
} | ||
|
||
export default withUser(addCollectiveCoverData(TransactionsPage)); | ||
const addTransactionsData = graphql(transactionsQuery, { | ||
skip: props => !props.slug, | ||
name: 'transactionsQuery', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a good name, it's confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that it creates confusion with the query itself, something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I renamed it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks better! |
||
options: props => { | ||
return { | ||
variables: { slug: props.slug, ...getVariablesFromQuery(props.query) }, | ||
context: API_V2_CONTEXT, | ||
}; | ||
}, | ||
}); | ||
|
||
export default withUser(addTransactionsData(addCollectiveCoverData(TransactionsPage))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
collectiveSlug
is required inopencollective-frontend/server/pages.js
Line 41 in a34c29a