1
+ import { recordTracksEvent } from '@automattic/calypso-analytics' ;
2
+ import { CompactCard } from '@automattic/components' ;
1
3
import { SiteDetails } from '@automattic/data-stores' ;
2
4
import { isValueTruthy } from '@automattic/wpcom-checkout' ;
3
- import { LocalizeProps , localize } from 'i18n-calypso' ;
5
+ import { LocalizeProps , localize , useTranslate } from 'i18n-calypso' ;
4
6
import { Component } from 'react' ;
5
7
import { connect } from 'react-redux' ;
8
+ import noSitesIllustration from 'calypso/assets/images/illustrations/illustration-nosites.svg' ;
6
9
import QueryConciergeInitial from 'calypso/components/data/query-concierge-initial' ;
7
10
import QueryMembershipsSubscriptions from 'calypso/components/data/query-memberships-subscriptions' ;
8
11
import QueryUserPurchases from 'calypso/components/data/query-user-purchases' ;
12
+ import EmptyContent from 'calypso/components/empty-content' ;
9
13
import NoSitesMessage from 'calypso/components/empty-content/no-sites-message' ;
10
14
import InlineSupportLink from 'calypso/components/inline-support-link' ;
11
15
import Main from 'calypso/components/main' ;
12
16
import NavigationHeader from 'calypso/components/navigation-header' ;
13
17
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker' ;
14
- import { getSubscriptionsBySite } from 'calypso/lib/purchases ' ;
18
+ import TrackComponentView from 'calypso/lib/analytics/track-component-view ' ;
15
19
import { MembershipSubscription , Purchase } from 'calypso/lib/purchases/types' ;
16
20
import { PurchaseListConciergeBanner } from 'calypso/me/purchases/purchases-list/purchase-list-concierge-banner' ;
17
21
import PurchasesNavigation from 'calypso/me/purchases/purchases-navigation' ;
@@ -34,9 +38,8 @@ import getConciergeUserBlocked from 'calypso/state/selectors/get-concierge-user-
34
38
import getSites from 'calypso/state/selectors/get-sites' ;
35
39
import { getSiteId } from 'calypso/state/sites/selectors' ;
36
40
import { AppState } from 'calypso/types' ;
37
- import MembershipSite from '../membership-site' ;
38
41
import PurchasesSite from '../purchases-site' ;
39
- import { PurchasesDataViews } from './purchases-data-view' ;
42
+ import { PurchasesDataViews , MembershipsDataViews } from './purchases-data-view' ;
40
43
import './style.scss' ;
41
44
42
45
export interface PurchasesListProps {
@@ -55,17 +58,35 @@ export interface PurchasesListConnectedProps {
55
58
siteId : number | null ;
56
59
}
57
60
58
- class PurchasesListDataView extends Component <
59
- PurchasesListProps & PurchasesListConnectedProps & WithStoredPaymentMethodsProps & LocalizeProps
60
- > {
61
- isDataLoading ( ) {
62
- if ( this . props . isFetchingUserPurchases && ! this . props . hasLoadedUserPurchasesFromServer ) {
63
- return true ;
64
- }
61
+ function MembershipSubscriptions ( {
62
+ memberships,
63
+ } : {
64
+ memberships : Array < MembershipSubscription > ;
65
+ } ) {
66
+ const translate = useTranslate ( ) ;
65
67
66
- return ! this . props . sites . length && ! this . props . subscriptions . length ;
68
+ if ( ! memberships . length ) {
69
+ return null ;
67
70
}
68
71
72
+ return < MembershipsDataViews memberships = { memberships } translate = { translate } /> ;
73
+ }
74
+
75
+ function isDataLoading ( {
76
+ isFetchingUserPurchases,
77
+ hasLoadedUserPurchasesFromServer,
78
+ } : {
79
+ hasLoadedUserPurchasesFromServer : boolean ;
80
+ isFetchingUserPurchases : boolean ;
81
+ } ) {
82
+ if ( isFetchingUserPurchases && ! hasLoadedUserPurchasesFromServer ) {
83
+ return true ;
84
+ }
85
+ }
86
+
87
+ class PurchasesListDataView extends Component <
88
+ PurchasesListProps & PurchasesListConnectedProps & WithStoredPaymentMethodsProps & LocalizeProps
89
+ > {
69
90
renderConciergeBanner ( ) {
70
91
const { nextAppointment, availableSessions, isUserBlocked } = this . props ;
71
92
return (
@@ -77,23 +98,17 @@ class PurchasesListDataView extends Component<
77
98
) ;
78
99
}
79
100
80
- renderMembershipSubscriptions ( ) {
81
- const { subscriptions } = this . props ;
82
-
83
- if ( ! subscriptions . length || this . isDataLoading ( ) ) {
84
- return null ;
85
- }
86
-
87
- return getSubscriptionsBySite ( subscriptions ) . map ( ( site ) => (
88
- < MembershipSite site = { site } key = { site . id } />
89
- ) ) ;
90
- }
91
-
92
101
render ( ) {
93
102
const { purchases, sites, translate, subscriptions } = this . props ;
103
+ const commonEventProps = { context : 'me' } ;
94
104
let content ;
95
105
96
- if ( this . isDataLoading ( ) ) {
106
+ if (
107
+ isDataLoading ( {
108
+ isFetchingUserPurchases : this . props . isFetchingUserPurchases ,
109
+ hasLoadedUserPurchasesFromServer : this . props . hasLoadedUserPurchasesFromServer ,
110
+ } )
111
+ ) {
97
112
content = < PurchasesSite isPlaceholder /> ;
98
113
}
99
114
@@ -112,6 +127,33 @@ class PurchasesListDataView extends Component<
112
127
</ Main >
113
128
) ;
114
129
}
130
+ content = (
131
+ < >
132
+ { this . renderConciergeBanner ( ) }
133
+ < CompactCard className = "purchases-list__no-content" >
134
+ < >
135
+ < TrackComponentView
136
+ eventName = "calypso_no_purchases_upgrade_nudge_impression"
137
+ eventProperties = { commonEventProps }
138
+ />
139
+ { /* this.renderPurchasesByOtherAdminsNotice() to-do: render this as functional component */ }
140
+ < EmptyContent
141
+ title = { translate ( 'Looking to upgrade?' ) }
142
+ line = { translate (
143
+ 'Our plans give your site the power to thrive. ' +
144
+ 'Find the plan that works for you.'
145
+ ) }
146
+ action = { translate ( 'Upgrade now' ) }
147
+ actionURL = "/plans"
148
+ illustration = { noSitesIllustration }
149
+ actionCallback = { ( ) => {
150
+ recordTracksEvent ( 'calypso_no_purchases_upgrade_nudge_click' , commonEventProps ) ;
151
+ } }
152
+ />
153
+ </ >
154
+ </ CompactCard >
155
+ </ >
156
+ ) ;
115
157
}
116
158
117
159
return (
@@ -134,7 +176,7 @@ class PurchasesListDataView extends Component<
134
176
/>
135
177
< PurchasesNavigation section = "activeUpgrades" />
136
178
{ content }
137
- { this . renderMembershipSubscriptions ( ) }
179
+ < MembershipSubscriptions memberships = { subscriptions } />
138
180
< QueryConciergeInitial />
139
181
</ Main >
140
182
) ;
0 commit comments