-
-
Notifications
You must be signed in to change notification settings - Fork 413
/
Copy pathtransactions.tsx
285 lines (272 loc) · 7.5 KB
/
transactions.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import React, { useEffect } from 'react';
import { omit } from 'lodash';
import { useRouter } from 'next/router';
import styled from 'styled-components';
import { getSSRQueryHelpers } from '../lib/apollo-client';
import { loggedInUserCanAccessFinancialData } from '../lib/collective';
import { CollectiveType } from '../lib/constants/collectives';
import { API_V2_CONTEXT, gql } from '../lib/graphql/helpers';
import useLoggedInUser from '../lib/hooks/useLoggedInUser';
import { addParentToURLIfMissing, getCollectivePageCanonicalURL } from '../lib/url-helpers';
import Body from '../components/Body';
import CollectiveNavbar from '../components/collective-navbar';
import { NAVBAR_CATEGORIES } from '../components/collective-navbar/constants';
import { accountNavbarFieldsFragment } from '../components/collective-navbar/fragments';
import { Sections } from '../components/collective-page/_constants';
import ErrorPage from '../components/ErrorPage';
import { Box } from '../components/Grid';
import Header from '../components/Header';
import Footer from '../components/navigation/Footer';
import PageFeatureNotSupported from '../components/PageFeatureNotSupported';
import { transactionsQueryCollectionFragment } from '../components/transactions/graphql/fragments';
import Transactions, { getVariablesFromQuery } from '../components/transactions/TransactionsPageContent';
const processingOrderFragment = gql`
fragment ProcessingOrderFields on Order {
id
legacyId
nextChargeDate
paymentMethod {
id
service
name
type
expiryDate
data
balance {
value
valueInCents
currency
}
}
amount {
value
valueInCents
currency
}
totalAmount {
value
valueInCents
currency
}
status
description
createdAt
frequency
tier {
id
name
}
totalDonations {
value
valueInCents
currency
}
fromAccount {
id
name
slug
isIncognito
type
... on Individual {
isGuest
}
}
toAccount {
id
slug
name
type
description
tags
imageUrl
settings
... on AccountWithHost {
host {
id
slug
paypalClientId
supportedPaymentMethods
}
}
... on Organization {
host {
id
slug
paypalClientId
supportedPaymentMethods
}
}
}
platformTipAmount {
value
valueInCents
}
}
`;
const transactionsPageQuery = gql`
query TransactionsPage(
$slug: String!
$limit: Int!
$offset: Int!
$type: TransactionType
$paymentMethodType: [PaymentMethodType]
$minAmount: Int
$maxAmount: Int
$dateFrom: DateTime
$dateTo: DateTime
$searchTerm: String
$kind: [TransactionKind]
$includeIncognitoTransactions: Boolean
$includeGiftCardTransactions: Boolean
$includeChildrenTransactions: Boolean
$virtualCard: [VirtualCardReferenceInput]
$orderBy: ChronologicalOrderInput
) {
account(slug: $slug) {
id
legacyId
slug
name
type
createdAt
imageUrl(height: 256)
currency
settings
features {
id
...NavbarFields
}
... on AccountWithParent {
parent {
id
slug
name
}
}
... on AccountWithHost {
host {
id
slug
}
}
processingOrders: orders(filter: OUTGOING, includeIncognito: true, status: [PENDING, PROCESSING]) {
totalCount
nodes {
id
...ProcessingOrderFields
}
}
}
transactions(
account: { slug: $slug }
limit: $limit
offset: $offset
type: $type
paymentMethodType: $paymentMethodType
minAmount: $minAmount
maxAmount: $maxAmount
dateFrom: $dateFrom
dateTo: $dateTo
searchTerm: $searchTerm
kind: $kind
includeIncognitoTransactions: $includeIncognitoTransactions
includeGiftCardTransactions: $includeGiftCardTransactions
includeChildrenTransactions: $includeChildrenTransactions
includeDebts: true
virtualCard: $virtualCard
orderBy: $orderBy
) {
...TransactionsQueryCollectionFragment
kinds
paymentMethodTypes
totalCount
}
}
${transactionsQueryCollectionFragment}
${accountNavbarFieldsFragment}
${processingOrderFragment}
`;
const TransactionPageWrapper = styled.div`
display: flex;
flex-direction: column;
min-height: 100vh;
#footer {
margin-top: auto;
}
`;
type TransactionsPageProps = {
query: {
collectiveSlug: string;
searchTerm?: string;
offset?: string;
ignoreIncognitoTransactions?: string;
ignoreGiftCardsTransactions?: string;
ignoreChildrenTransactions?: string;
displayPendingContributions?: string;
};
};
const transactionsPageQueryHelper = getSSRQueryHelpers<ReturnType<typeof getVariablesFromQuery>, TransactionsPageProps>(
{
query: transactionsPageQuery,
getPropsFromContext: ctx => ({ query: ctx.query as TransactionsPageProps['query'] }),
getVariablesFromContext: ctx => ({ ...getVariablesFromQuery(ctx.query), slug: ctx.query.collectiveSlug }),
context: API_V2_CONTEXT,
skipClientIfSSRThrows404: true,
},
);
// next.js export
// ts-unused-exports:disable-next-line
export const getServerSideProps = transactionsPageQueryHelper.getServerSideProps;
// next.js export
// ts-unused-exports:disable-next-line
export default function TransactionsPage(props) {
const { LoggedInUser } = useLoggedInUser();
const { data, error, variables, refetch, loading } = transactionsPageQueryHelper.useQuery(props);
const router = useRouter();
useEffect(() => {
const queryParameters = omit(props.query, ['offset', 'collectiveSlug', 'parentCollectiveSlug']);
addParentToURLIfMissing(router, account, `/transactions`, queryParameters);
});
const account = data?.account;
const accountType = account?.type;
const transactions = data?.transactions;
if (!loading) {
if (!account) {
return <ErrorPage data={data} error={error || transactionsPageQueryHelper.getSSRErrorFromPageProps(props)} />;
} else if (!loggedInUserCanAccessFinancialData(LoggedInUser, account)) {
// Hack for funds that want to keep their budget "private"
return <PageFeatureNotSupported showContactSupportLink={false} />;
}
}
return (
<TransactionPageWrapper>
<Header
collective={account}
LoggedInUser={LoggedInUser}
canonicalURL={`${getCollectivePageCanonicalURL(account)}/transactions`}
noRobots={['USER', 'INDIVIDUAL'].includes(accountType) && !account.isHost}
/>
<Body>
<CollectiveNavbar
collective={account}
isAdmin={LoggedInUser && LoggedInUser.isAdminOfCollective(account)}
selectedCategory={NAVBAR_CATEGORIES.BUDGET}
selectedSection={accountType === CollectiveType.COLLECTIVE ? Sections.BUDGET : Sections.TRANSACTIONS}
/>
<Box maxWidth={1260} m="0 auto" px={[2, 3, 4]} my={[4, 5]} data-cy="transactions-page-content">
<Transactions
transactions={transactions}
account={account}
LoggedInUser={LoggedInUser}
variables={variables}
error={error}
loading={loading}
refetch={refetch}
router={router}
/>
</Box>
</Body>
<Footer />
</TransactionPageWrapper>
);
}