-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathindex.js
246 lines (228 loc) · 7.07 KB
/
index.js
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
/** @format **/
/**
* External dependencies
*/
import React, { useState } from 'react';
import { Card, Notice } from '@wordpress/components';
import { getQuery } from '@woocommerce/navigation';
import { __ } from '@wordpress/i18n';
import { dispatch } from '@wordpress/data';
/**
* Internal dependencies.
*/
import AccountBalances from 'components/account-balances';
import AccountStatus from 'components/account-status';
import ActiveLoanSummary from 'components/active-loan-summary';
import ConnectionSuccessNotice from './connection-sucess-notice';
import DepositsOverview from 'components/deposits-overview';
import ErrorBoundary from 'components/error-boundary';
import FRTDiscoverabilityBanner from 'components/fraud-risk-tools-banner';
import JetpackIdcNotice from 'components/jetpack-idc-notice';
import Page from 'components/page';
import PaymentActivity from 'wcpay/components/payment-activity';
import Welcome from 'components/welcome';
import { TestModeNotice } from 'components/test-mode-notice';
import InboxNotifications from './inbox-notifications';
import ProgressiveOnboardingEligibilityModal from './modal/progressive-onboarding-eligibility';
import TaskList from './task-list';
import { getTasks, taskSort } from './task-list/tasks';
import { useDisputes, useGetSettings, useSettings } from 'data';
import SandboxModeSwitchToLiveNotice from 'wcpay/components/sandbox-mode-switch-to-live-notice';
import './style.scss';
import BannerNotice from 'wcpay/components/banner-notice';
const OverviewPageError = () => {
const queryParams = getQuery();
const showLoginError = queryParams[ 'wcpay-login-error' ] === '1';
if ( ! wcpaySettings.errorMessage && ! showLoginError ) {
return null;
}
return (
<BannerNotice
className={ showLoginError ? 'wcpay-login-error' : '' }
status="error"
icon={ true }
isDismissible={ false }
>
{ wcpaySettings.errorMessage ||
__(
'There was a problem redirecting you to the account dashboard. Please try again.',
'woocommerce-payments'
) }
</BannerNotice>
);
};
const OverviewPage = () => {
const {
accountStatus,
accountStatus: { progressiveOnboarding },
accountLoans: { has_active_loan: hasActiveLoan },
enabledPaymentMethods,
overviewTasksVisibility,
showUpdateDetailsTask,
wpcomReconnectUrl,
} = wcpaySettings;
const isOnboardingTestMode = wcpaySettings.onboardingTestMode;
const { isLoading: settingsIsLoading } = useSettings();
const [
isTestDriveSuccessDisplayed,
setTestDriveSuccessDisplayed,
] = useState( false );
const settings = useGetSettings();
const { disputes: activeDisputes } = useDisputes( {
filter: 'awaiting_response',
per_page: 50,
} );
const tasksUnsorted = getTasks( {
showUpdateDetailsTask,
wpcomReconnectUrl,
activeDisputes,
enabledPaymentMethods,
} );
const tasks =
Array.isArray( tasksUnsorted ) && tasksUnsorted.sort( taskSort );
const queryParams = getQuery();
const accountRejected =
accountStatus.status && accountStatus.status.startsWith( 'rejected' );
const accountUnderReview = accountStatus.status === 'under_review';
const showConnectionSuccess =
queryParams[ 'wcpay-connection-success' ] === '1';
// We want to show the sandbox success notice only if the account is enabled or complete.
const isSandboxOnboardedSuccessful =
queryParams[ 'wcpay-sandbox-success' ] === 'true' &&
( ( accountStatus.status && accountStatus.status === 'complete' ) ||
accountStatus.status === 'enabled' );
const showLoanOfferError = queryParams[ 'wcpay-loan-offer-error' ] === '1';
const showServerLinkError =
queryParams[ 'wcpay-server-link-error' ] === '1';
const showResetAccountError =
queryParams[ 'wcpay-reset-account-error' ] === '1';
const showProgressiveOnboardingEligibilityModal =
showConnectionSuccess &&
progressiveOnboarding.isEnabled &&
! progressiveOnboarding.isComplete;
const showTaskList =
! accountRejected && ! accountUnderReview && tasks.length > 0;
const activeAccountFees = Object.entries( wcpaySettings.accountFees )
.map( ( [ key, value ] ) => {
const isPaymentMethodEnabled =
! settingsIsLoading &&
settings.enabled_payment_method_ids.filter(
( enabledMethod ) => {
return enabledMethod === key;
}
).length > 0;
if (
settingsIsLoading ||
! isPaymentMethodEnabled ||
value.discount.length === 0
) {
return null;
}
return { payment_method: key, fee: value };
} )
.filter( ( e ) => e && e.fee !== undefined );
if ( ! isTestDriveSuccessDisplayed && isSandboxOnboardedSuccessful ) {
dispatch( 'core/notices' ).createSuccessNotice(
__(
'Success! You can start using WooPayments in sandbox mode.',
'woocommerce-payments'
)
);
// Ensure the success message is displayed only once.
setTestDriveSuccessDisplayed( true );
}
return (
<Page isNarrow className="wcpay-overview">
<OverviewPageError />
<JetpackIdcNotice />
{ showLoanOfferError && (
<Notice status="error" isDismissible={ false }>
{ __(
'There was a problem redirecting you to the loan offer. Please check that it is not expired and try again.',
'woocommerce-payments'
) }
</Notice>
) }
{ showServerLinkError && (
<Notice status="error" isDismissible={ false }>
{ __(
'There was a problem redirecting you to the requested link. Please check that it is valid and try again.',
'woocommerce-payments'
) }
</Notice>
) }
{ showResetAccountError && (
<Notice status="error" isDismissible={ false }>
{ __(
'There was a problem resetting your account. Please wait a few seconds and try again.',
'woocommerce-payments'
) }
</Notice>
) }
{ isOnboardingTestMode ? (
<SandboxModeSwitchToLiveNotice
from="WCPAY_OVERVIEW"
source="wcpay-overview-page"
/>
) : (
<TestModeNotice
currentPage="overview"
isOnboardingTestMode={ isOnboardingTestMode }
actions={ [] }
/>
) }
<ErrorBoundary>
<FRTDiscoverabilityBanner />
</ErrorBoundary>
{ showConnectionSuccess && <ConnectionSuccessNotice /> }
{ ! accountRejected && ! accountUnderReview && (
<ErrorBoundary>
<Welcome />
{ showTaskList && (
<Card>
<ErrorBoundary>
<TaskList
tasks={ tasks }
overviewTasksVisibility={
overviewTasksVisibility
}
/>
</ErrorBoundary>
</Card>
) }
<Card>
<ErrorBoundary>
<AccountBalances />
</ErrorBoundary>
</Card>
<ErrorBoundary>
<PaymentActivity />
</ErrorBoundary>
<DepositsOverview />
</ErrorBoundary>
) }
<ErrorBoundary>
<AccountStatus
accountStatus={ accountStatus }
accountFees={ activeAccountFees }
/>
</ErrorBoundary>
{ hasActiveLoan && (
<ErrorBoundary>
<ActiveLoanSummary />
</ErrorBoundary>
) }
{ ! accountRejected && ! accountUnderReview && (
<ErrorBoundary>
<InboxNotifications />
</ErrorBoundary>
) }
{ showProgressiveOnboardingEligibilityModal && (
<ErrorBoundary>
<ProgressiveOnboardingEligibilityModal />
</ErrorBoundary>
) }
</Page>
);
};
export default OverviewPage;