-
Notifications
You must be signed in to change notification settings - Fork 69
/
index.tsx
249 lines (233 loc) · 6.37 KB
/
index.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
/** @format **/
/**
* External dependencies
*/
import React from 'react';
import { dateI18n } from '@wordpress/date';
import { __, sprintf } from '@wordpress/i18n';
import moment from 'moment';
import {
Card,
CardBody,
CardHeader,
ExternalLink,
// @ts-expect-error: Suppressing Module '"@wordpress/components"' has no exported member '__experimentalText'.
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis -- used by TableCard component which we replicate here.
__experimentalText as Text,
} from '@wordpress/components';
import {
SummaryListPlaceholder,
SummaryList,
OrderStatus,
} from '@woocommerce/components';
import interpolateComponents from '@automattic/interpolate-components';
import classNames from 'classnames';
/**
* Internal dependencies.
*/
import type { CachedDeposit } from 'types/deposits';
import { useDeposit } from 'data';
import TransactionsList from 'transactions/list';
import Page from 'components/page';
import ErrorBoundary from 'components/error-boundary';
import { TestModeNotice } from 'components/test-mode-notice';
import InlineNotice from 'components/inline-notice';
import { formatCurrency, formatExplicitCurrency } from 'utils/currency';
import { displayStatus } from '../strings';
import './style.scss';
/**
* Renders the deposit status indicator UI, re-purposing the OrderStatus component from @woocommerce/components.
*/
const Status: React.FC< { status: string } > = ( { status } ) => (
<OrderStatus order={ { status } } orderStatusMap={ displayStatus } />
);
interface SummaryItemProps {
label: string;
value: string | JSX.Element;
valueClass?: string | false;
detail?: string;
}
/**
* A custom SummaryNumber with custom value className, reusing @woocommerce/components styles.
*/
const SummaryItem: React.FC< SummaryItemProps > = ( {
label,
value,
valueClass,
detail,
} ) => (
<li className="woocommerce-summary__item-container">
<div className="woocommerce-summary__item">
<div className="woocommerce-summary__item-label">{ label }</div>
<div className="woocommerce-summary__item-data">
<div
className={ classNames(
'woocommerce-summary__item-value',
valueClass
) }
>
{ value }
</div>
</div>
{ detail && (
<div className="wcpay-summary__item-detail">{ detail }</div>
) }
</div>
</li>
);
interface DepositOverviewProps {
deposit: CachedDeposit | undefined;
}
export const DepositOverview: React.FC< DepositOverviewProps > = ( {
deposit,
} ) => {
if ( ! deposit ) {
return (
<InlineNotice icon status="error" isDismissible={ false }>
{ __(
`The deposit you are looking for cannot be found.`,
'woocommerce-payments'
) }
</InlineNotice>
);
}
const depositDateLabel = deposit.automatic
? __( 'Deposit date', 'woocommerce-payments' )
: __( 'Instant deposit date', 'woocommerce-payments' );
const depositDateItem = (
<SummaryItem
key="depositDate"
label={
`${ depositDateLabel }: ` +
dateI18n(
'M j, Y',
moment.utc( deposit.date ).toISOString(),
true // TODO Change call to gmdateI18n and remove this deprecated param once WP 5.4 support ends.
)
}
value={ <Status status={ deposit.status } /> }
detail={ deposit.bankAccount }
/>
);
return (
<div className="wcpay-deposit-overview">
{ deposit.automatic ? (
<Card className="wcpay-deposit-automatic">
<ul>
{ depositDateItem }
<li className="wcpay-deposit-amount">
{ formatExplicitCurrency(
deposit.amount,
deposit.currency
) }
</li>
</ul>
</Card>
) : (
<SummaryList
label={ __( 'Deposit overview', 'woocommerce-payments' ) }
>
{ () => [
depositDateItem,
<SummaryItem
key="depositAmount"
label={ __(
'Deposit amount',
'woocommerce-payments'
) }
value={ formatExplicitCurrency(
deposit.amount + deposit.fee,
deposit.currency
) }
/>,
<SummaryItem
key="depositFees"
label={ sprintf(
/* translators: %s - amount representing the fee percentage */
__( '%s service fee', 'woocommerce-payments' ),
`${ deposit.fee_percentage }%`
) }
value={ formatCurrency(
deposit.fee,
deposit.currency
) }
valueClass={
0 < deposit.fee && 'wcpay-deposit-fee'
}
/>,
<SummaryItem
key="netDepositAmount"
label={ __(
'Net deposit amount',
'woocommerce-payments'
) }
value={ formatExplicitCurrency(
deposit.amount,
deposit.currency
) }
valueClass="wcpay-deposit-net"
/>,
] }
</SummaryList>
) }
</div>
);
};
interface DepositDetailsProps {
query: {
id: string;
};
}
export const DepositDetails: React.FC< DepositDetailsProps > = ( {
query: { id: depositId },
} ) => {
const { deposit, isLoading } = useDeposit( depositId );
const isInstantDeposit = ! isLoading && deposit && ! deposit.automatic;
return (
<Page>
<TestModeNotice currentPage="deposits" isDetailsView={ true } />
<ErrorBoundary>
{ isLoading ? (
<SummaryListPlaceholder numberOfItems={ 2 } />
) : (
<DepositOverview deposit={ deposit } />
) }
</ErrorBoundary>
{ deposit && (
<ErrorBoundary>
{ isInstantDeposit ? (
// If instant deposit, show a message instead of the transactions list.
// Matching the components used in @woocommerce/components TableCard for consistent UI.
<Card>
<CardHeader>
<Text size={ 16 } weight={ 600 } as="h2">
{ __(
'Deposit transactions',
'woocommerce-payments'
) }
</Text>
</CardHeader>
<CardBody className="wcpay-deposit-overview--instant__transactions-list-message">
{ interpolateComponents( {
/* Translators: {{learnMoreLink}} is a link element (<a/>). */
mixedString: __(
`We're unable to show transaction history on instant deposits. {{learnMoreLink}}Learn more{{/learnMoreLink}}`,
'woocommerce-payments'
),
components: {
learnMoreLink: (
<ExternalLink href="https://woo.com/document/woopayments/deposits/instant-deposits/#transactions" />
),
},
} ) }
</CardBody>
</Card>
) : (
<TransactionsList depositId={ depositId } />
) }
</ErrorBoundary>
) }
</Page>
);
};
export default DepositDetails;