-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
192 lines (177 loc) · 5.12 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
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';
import { useEffect, useState, useCallback } from '@wordpress/element';
import apiFetch from '@wordpress/api-fetch';
import {
Notice,
__experimentalText as Text, // eslint-disable-line @wordpress/no-unsafe-wp-apis --- _experimentalText unlikely to change/disappear and also used by WC Core
} from '@wordpress/components';
/**
* Internal dependencies
*/
import './style.scss';
import { useSettingsSelect, useCreateNotice } from '../../helpers/effects';
import { DISAPPROVAL_COPY_STATES } from '../../constants';
/**
* Render the list of the disapproval reasons.
*
* @fires wcadmin_pfw_documentation_link_click with `{ link_id: 'merchant-guidelines', context: 'merchant-disapproval-reasons' }`
*
* @param {Object} props React props
* @param {Array} props.reasons
* @return { JSX.Element } The rendered element
*/
const FormattedReasons = ( { reasons } ) => {
if ( reasons === undefined ) {
return null;
}
const formattedReasons = reasons.map(
( reason ) =>
undefined !== DISAPPROVAL_COPY_STATES[ reason ] && (
<li key={ reason }>{ DISAPPROVAL_COPY_STATES[ reason ] }</li>
)
);
if ( ! formattedReasons ) {
return null;
}
return <ul className="ul-square">{ formattedReasons }</ul>;
};
const HealthCheck = () => {
const createNotice = useCreateNotice();
const appSettings = useSettingsSelect();
const [ healthStatus, setHealthStatus ] = useState();
const checkHealth = useCallback( async () => {
try {
const results = await apiFetch( {
path:
wcSettings.pinterest_for_woocommerce.apiRoute + '/health/',
method: 'GET',
} );
setHealthStatus( results );
} catch ( error ) {
createNotice(
'error',
error.message ||
__(
'Couldn’t retrieve the health status of your account.',
'pinterest-for-woocommerce'
)
);
}
}, [ createNotice ] );
useEffect( () => {
checkHealth();
}, [ checkHealth ] );
if ( healthStatus === undefined || healthStatus.status === 'approved' ) {
return null;
}
const notices = {
pending_initial_configuration: {
status: 'warning',
message: __(
'The feed is being configured. Depending on the number of products this may take a while as the feed needs to be fully generated before it is been sent to Pinterest for registration. You can check the status of the generation process in the Catalog tab.',
'pinterest-for-woocommerce'
),
dismissible: false,
},
pending: {
status: 'warning',
message: __(
'Please hold on tight as your account is pending approval from Pinterest. This may take up to 5 business days.',
'pinterest-for-woocommerce'
),
dismissible: false,
},
declined: {
status: 'error',
message: __(
'Your merchant account is disapproved.',
'pinterest-for-woocommerce'
),
body: __(
'If you have a valid reason for appealing a merchant review decision (such as having corrected the violations that resulted in the disapproval), you can submit an appeal.',
'pinterest-for-woocommerce'
),
reasons: healthStatus.reasons,
dismissible: false,
actions: [
{
label: __(
'Submit an appeal',
'pinterest-for-woocommerce'
),
url: addQueryArgs(
wcSettings.pinterest_for_woocommerce.pinterestLinks
.appealDeclinedMerchant,
{ advertiserId: appSettings.tracking_advertiser }
),
},
],
},
appeal_pending: {
status: 'warning',
dismissible: false,
message: __(
'Your merchant account is disapproved.',
'pinterest-for-woocommerce'
),
body: __(
'Please hold on tight as there is an Appeal pending for your Pinterest account.',
'pinterest-for-woocommerce'
),
},
merchant_connected_diff_platform: {
status: 'error',
dismissible: false,
message: __(
'Unable to upload catalog.',
'pinterest-for-woocommerce'
),
body: __(
'It looks like your Pinterest business account is connected to another e-commerce platform. Only one platform can be linked to a business account. To upload your catalog, disconnect your business account from the other platform and try again.',
'pinterest-for-woocommerce'
),
},
merchant_locale_not_valid: {
status: 'error',
dismissible: false,
message: __(
'Unable to register feed.',
'pinterest-for-woocommerce'
),
body: __(
'It looks like your WordPress language settings are not supported by Pinterest.',
'pinterest-for-woocommerce'
),
},
error: {
status: 'error',
dismissible: false,
},
};
const notice = notices[ healthStatus.status ] || notices.error;
if ( notice.status === 'error' && ! notice.message ) {
notice.message =
healthStatus.message ||
__(
'Could not fetch account status.',
'pinterest-for-woocommerce'
);
}
return (
<Notice
status={ notice.status }
isDismissible={ notice.dismissible }
actions={ notice.actions || [] }
className="pinterest-for-woocommerce-healthcheck-notice"
>
<Text variant="titleSmall">{ notice.message }</Text>
<FormattedReasons reasons={ notice.reasons } />
{ notice.body }
</Notice>
);
};
export default HealthCheck;