-
Notifications
You must be signed in to change notification settings - Fork 2k
/
registered-domain-type.jsx
468 lines (420 loc) · 13.6 KB
/
registered-domain-type.jsx
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
/**
* External dependencies
*/
import React from 'react';
import { connect } from 'react-redux';
import { localize } from 'i18n-calypso';
/**
* Internal dependencies
*/
import config from 'config';
import { Card } from '@automattic/components';
import formatCurrency from '@automattic/format-currency';
import { withLocalizedMoment } from 'components/localized-moment';
import DomainStatus from '../card/domain-status';
import DomainWarnings from 'my-sites/domains/components/domain-warnings';
import IcannVerificationCard from 'my-sites/domains/domain-management/components/icann-verification';
import { isRecentlyRegistered, isExpiringSoon } from 'lib/domains/utils';
import {
DOMAIN_EXPIRATION,
DOMAIN_EXPIRATION_REDEMPTION,
DOMAIN_RECENTLY_REGISTERED,
} from 'lib/url/support';
import SubscriptionSettings from '../card/subscription-settings';
import { recordPaymentSettingsClick } from '../payment-settings-analytics';
import { getProductBySlug } from 'state/products-list/selectors';
import { getCurrentUserId } from 'state/current-user/selectors';
import {
getByPurchaseId,
isFetchingSitePurchases,
hasLoadedSitePurchasesFromServer,
} from 'state/purchases/selectors';
import NonPrimaryDomainPlanUpsell from '../../components/domain/non-primary-domain-plan-upsell';
import RenewButton from 'my-sites/domains/domain-management/edit/card/renew-button';
import AutoRenewToggle from 'me/purchases/manage-purchase/auto-renew-toggle';
import QuerySitePurchases from 'components/data/query-site-purchases';
import { shouldRenderExpiringCreditCard } from 'lib/purchases';
import ExpiringCreditCard from '../card/notices/expiring-credit-card';
import ExpiringSoon from '../card/notices/expiring-soon';
import DomainManagementNavigation from '../navigation';
import DomainManagementNavigationEnhanced from '../navigation/enhanced';
import { DomainExpiryOrRenewal, WrapDomainStatusButtons } from './helpers';
import OutboundTransferConfirmation from '../../components/outbound-transfer-confirmation';
import { hasPendingGSuiteUsers } from 'lib/gsuite';
import PendingGSuiteTosNotice from 'my-sites/domains/components/domain-warnings/pending-gsuite-tos-notice';
class RegisteredDomainType extends React.Component {
resolveStatus() {
const { domain, translate, purchase, moment } = this.props;
const { registrationDate, expiry } = domain;
if ( domain.pendingTransfer ) {
return {
statusText: translate( 'Outbound transfer initiated' ),
statusClass: 'status-error',
icon: 'cached',
};
}
if ( purchase && shouldRenderExpiringCreditCard( purchase ) ) {
return {
statusText: translate( 'Action required' ),
statusClass: 'status-error',
icon: 'info',
};
}
if ( domain.isPendingIcannVerification && domain.currentUserCanManage ) {
return {
statusText: translate( 'Action required' ),
statusClass: 'status-error',
icon: 'info',
};
}
if ( isExpiringSoon( domain, 30 ) ) {
const expiresMessage = translate( 'Expires in %(days)s', {
args: { days: moment.utc( expiry ).fromNow( true ) },
} );
if ( isExpiringSoon( domain, 5 ) ) {
return {
statusText: expiresMessage,
statusClass: 'status-error',
icon: 'info',
};
}
return {
statusText: expiresMessage,
statusClass: 'status-warning',
icon: 'info',
};
}
if ( domain.expired ) {
return {
statusText: translate( 'Action required' ),
statusClass: 'status-error',
icon: 'info',
};
}
const recentlyRegistered = isRecentlyRegistered( registrationDate );
if ( recentlyRegistered ) {
return {
statusText: translate( 'Activating' ),
statusClass: 'status-pending',
icon: 'cloud_upload',
};
}
if ( hasPendingGSuiteUsers( domain ) ) {
return {
statusText: translate( 'Action required' ),
statusClass: 'status-warning',
icon: 'info',
};
}
return {
statusText: translate( 'Active' ),
statusClass: 'status-success',
icon: 'check_circle',
};
}
renderExpired() {
const { domain, purchase, isLoadingPurchase, translate, moment } = this.props;
const domainsLink = ( link ) => <a href={ link } target="_blank" rel="noopener noreferrer" />;
if ( ! domain.expired || domain.pendingTransfer ) {
return null;
}
let message;
const redemptionCost = this.props.redemptionProduct
? formatCurrency(
this.props.redemptionProduct.cost,
this.props.redemptionProduct.currency_code,
{ stripZeros: true }
)
: null;
if ( ! domain.currentUserCanManage ) {
message = translate(
'{{strong}}The domain has expired{{/strong}} and is no longer active. Please contact the domain owner %(owner)s to restore it. {{domainsLink}}Learn more{{/domainsLink}}',
{
components: {
strong: <strong />,
domainsLink: domainsLink( DOMAIN_EXPIRATION ),
},
args: {
owner: domain.owner,
},
}
);
} else if ( domain.isRenewable ) {
message = translate(
'{{strong}}Your domain has expired{{/strong}} and is no longer active. You have {{strong}}%(days)s{{/strong}} to renew it at the standard rate before an additional %(redemptionCost)s redemption fee is applied. {{domainsLink}}Learn more{{/domainsLink}}',
{
components: {
domainsLink: domainsLink( DOMAIN_EXPIRATION ),
strong: <strong />,
},
args: {
days: moment.utc( domain.renewableUntil ).fromNow( true ),
redemptionCost: redemptionCost,
},
}
);
} else if ( domain.isRedeemable ) {
message = translate(
'{{strong}}Your domain has expired{{/strong}} and is no longer active. You have {{strong}}%(days)s{{/strong}} to reactivate it during this redemption period before someone else can register it. An additional redemption fee of {{strong}}%(redemptionCost)s{{/strong}} will be added to the price of the domain to reactivate it. {{domainsLink}}Learn more{{/domainsLink}}',
{
components: {
domainsLink: domainsLink( DOMAIN_EXPIRATION_REDEMPTION ),
strong: <strong />,
},
args: {
days: moment.utc( domain.redeemableUntil ).fromNow( true ),
redemptionCost: redemptionCost,
},
}
);
} else {
message = translate(
'{{strong}}Your domain has expired{{/strong}} and is no longer active. {{domainsLink}}Learn more{{/domainsLink}}',
{
components: {
domainsLink: domainsLink( DOMAIN_EXPIRATION ),
},
}
);
}
return (
<div>
<p>{ message }</p>
{ domain.currentUserCanManage &&
( isLoadingPurchase || purchase ) &&
( domain.isRenewable || domain.isRedeemable ) && (
<RenewButton
primary={ true }
purchase={ purchase }
selectedSite={ this.props.selectedSite }
subscriptionId={ parseInt( domain.subscriptionId, 10 ) }
redemptionProduct={ domain.isRedeemable ? this.props.redemptionProduct : null }
reactivate={ ! domain.isRenewable && domain.isRedeemable }
tracksProps={ { source: 'registered-domain-status', domain_status: 'expired' } }
/>
) }
</div>
);
}
renderRecentlyRegistered() {
const { domain, translate } = this.props;
const { registrationDate, name: domain_name } = domain;
const domainsLink = (
<a href={ DOMAIN_RECENTLY_REGISTERED } target="_blank" rel="noopener noreferrer" />
);
const recentlyRegistered = isRecentlyRegistered( registrationDate );
if ( ! recentlyRegistered || domain.pendingTransfer || domain.isPendingIcannVerification ) {
return null;
}
return (
<div>
{ translate(
'We are setting up {{strong}}%(domain)s{{/strong}} for you. It should start working immediately but may be unreliable in the first 30 minutes. {{domainsLink}}Learn more{{/domainsLink}}',
{
args: {
domain: domain_name,
},
components: {
domainsLink,
strong: <strong />,
},
}
) }
</div>
);
}
renderPendingGSuiteTosNotice() {
const { domain, purchase, selectedSite } = this.props;
if (
! hasPendingGSuiteUsers( domain ) ||
domain.pendingTransfer ||
domain.expired ||
domain.isPendingIcannVerification ||
isExpiringSoon( domain, 30 ) ||
isRecentlyRegistered( domain ) ||
( purchase && shouldRenderExpiringCreditCard( purchase ) )
) {
return null;
}
return (
<PendingGSuiteTosNotice
siteSlug={ selectedSite.slug }
domains={ [ domain ] }
section="domain-management"
showDomainStatusNotice
/>
);
}
renderOutboundTransferInProgress() {
const { domain, selectedSite } = this.props;
return <OutboundTransferConfirmation domain={ domain } siteId={ selectedSite.ID } />;
}
renderDefaultRenewButton() {
const { domain, purchase, isLoadingPurchase } = this.props;
if ( ! domain.currentUserCanManage ) {
return null;
}
if ( domain.expired || isExpiringSoon( domain, 30 ) ) {
return null;
}
return (
<div>
{ ( isLoadingPurchase || purchase ) && (
<RenewButton
compact={ true }
purchase={ purchase }
selectedSite={ this.props.selectedSite }
subscriptionId={ parseInt( domain.subscriptionId, 10 ) }
tracksProps={ { source: 'registered-domain-status', domain_status: 'active' } }
/>
) }
</div>
);
}
renderAutoRenewToggle() {
const { selectedSite, purchase } = this.props;
if ( ! purchase ) {
return null;
}
const content = (
<AutoRenewToggle
planName={ selectedSite.plan.product_name_short }
siteDomain={ selectedSite.domain }
purchase={ purchase }
compact={ true }
withTextStatus={ true }
toggleSource="registered-domain-status"
/>
);
return content && <WrapDomainStatusButtons>{ content }</WrapDomainStatusButtons>;
}
renderAutoRenew() {
const { isLoadingPurchase } = this.props;
if ( isLoadingPurchase ) {
return (
<WrapDomainStatusButtons className="domain-types__auto-renew-placeholder">
<p />
</WrapDomainStatusButtons>
);
}
return this.renderAutoRenewToggle();
}
planUpsellForNonPrimaryDomain() {
const { domain } = this.props;
return (
<NonPrimaryDomainPlanUpsell
tracksImpressionName="calypso_non_primary_domain_settings_plan_upsell_impression"
tracksClickName="calypso_non_primary_domain_settings_plan_upsell_click"
domain={ domain }
/>
);
}
domainWarnings() {
return (
<DomainWarnings
domain={ this.props.domain }
position="registered-domain"
selectedSite={ this.props.selectedSite }
allowedRules={ [ 'newTransfersWrongNS', 'pendingConsent' ] }
/>
);
}
handlePaymentSettingsClick = () => {
this.props.recordPaymentSettingsClick( this.props.domain );
};
render() {
const { domain, selectedSite, purchase, isLoadingPurchase } = this.props;
const { name: domain_name } = domain;
const { statusText, statusClass, icon } = this.resolveStatus();
const newStatusDesignAutoRenew = config.isEnabled( 'domains/new-status-design/auto-renew' );
const newDomainManagementNavigation = config.isEnabled(
'domains/new-status-design/new-options'
);
return (
<div className="domain-types__container">
{ selectedSite.ID && ! purchase && <QuerySitePurchases siteId={ selectedSite.ID } /> }
{ this.planUpsellForNonPrimaryDomain() }
{ this.domainWarnings() }
<DomainStatus
header={ domain_name }
statusText={ statusText }
statusClass={ statusClass }
icon={ icon }
>
{ domain.isPendingIcannVerification && domain.currentUserCanManage && (
<IcannVerificationCard
selectedDomainName={ domain.name }
selectedSiteSlug={ this.props.selectedSite.slug }
explanationContext="new-status"
compact={ true }
/>
) }
<ExpiringCreditCard
selectedSite={ selectedSite }
purchase={ purchase }
domain={ domain }
/>
<ExpiringSoon
selectedSite={ selectedSite }
purchase={ purchase }
isLoadingPurchase={ isLoadingPurchase }
domain={ domain }
/>
{ this.renderExpired() }
{ this.renderRecentlyRegistered() }
{ this.renderOutboundTransferInProgress() }
{ this.renderPendingGSuiteTosNotice() }
</DomainStatus>
<Card compact={ true } className="domain-types__expiration-row">
<DomainExpiryOrRenewal { ...this.props } />
{ this.renderDefaultRenewButton() }
{ ! newStatusDesignAutoRenew && domain.currentUserCanManage && (
<WrapDomainStatusButtons>
<SubscriptionSettings
type={ domain.type }
compact={ true }
subscriptionId={ domain.subscriptionId }
siteSlug={ this.props.selectedSite.slug }
onClick={ this.handlePaymentSettingsClick }
/>
</WrapDomainStatusButtons>
) }
{ newStatusDesignAutoRenew && domain.currentUserCanManage && this.renderAutoRenew() }
</Card>
{ newDomainManagementNavigation ? (
<DomainManagementNavigationEnhanced
domain={ domain }
selectedSite={ this.props.selectedSite }
purchase={ purchase }
isLoadingPurchase={ isLoadingPurchase }
/>
) : (
<DomainManagementNavigation
domain={ domain }
selectedSite={ this.props.selectedSite }
purchase={ purchase }
isLoadingPurchase={ isLoadingPurchase }
/>
) }
</div>
);
}
}
export default connect(
( state, ownProps ) => {
const { subscriptionId } = ownProps.domain;
const currentUserId = getCurrentUserId( state );
const purchase = subscriptionId
? getByPurchaseId( state, parseInt( subscriptionId, 10 ) )
: null;
return {
purchase: purchase && purchase.userId === currentUserId ? purchase : null,
isLoadingPurchase:
isFetchingSitePurchases( state ) || ! hasLoadedSitePurchasesFromServer( state ),
redemptionProduct: getProductBySlug( state, 'domain_redemption' ),
};
},
{
recordPaymentSettingsClick,
}
)( withLocalizedMoment( localize( RegisteredDomainType ) ) );