@automattic/data-stores 3.1.1 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -9
- package/dist/cjs/add-ons/hooks/use-add-on-prices.js +3 -3
- package/dist/cjs/add-ons/hooks/use-add-on-prices.js.map +1 -1
- package/dist/cjs/add-ons/icons/custom-design.js +1 -1
- package/dist/cjs/add-ons/icons/custom-design.js.map +1 -1
- package/dist/cjs/add-ons/icons/unlimited-themes.js +1 -1
- package/dist/cjs/add-ons/icons/unlimited-themes.js.map +1 -1
- package/dist/cjs/contextual-help/admin-sections.js +1 -1
- package/dist/cjs/contextual-help/admin-sections.js.map +1 -1
- package/dist/cjs/domain-suggestions/utils.js +2 -2
- package/dist/cjs/domain-suggestions/utils.js.map +1 -1
- package/dist/cjs/help-center/actions.js +33 -36
- package/dist/cjs/help-center/actions.js.map +1 -1
- package/dist/cjs/help-center/index.js +13 -12
- package/dist/cjs/help-center/index.js.map +1 -1
- package/dist/cjs/help-center/reducer.js +14 -7
- package/dist/cjs/help-center/reducer.js.map +1 -1
- package/dist/cjs/help-center/resolvers.js +4 -0
- package/dist/cjs/help-center/resolvers.js.map +1 -1
- package/dist/cjs/help-center/selectors.js +5 -3
- package/dist/cjs/help-center/selectors.js.map +1 -1
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/onboard/actions.js +1 -11
- package/dist/cjs/onboard/actions.js.map +1 -1
- package/dist/cjs/onboard/index.js +0 -1
- package/dist/cjs/onboard/index.js.map +1 -1
- package/dist/cjs/onboard/reducer.js +0 -20
- package/dist/cjs/onboard/reducer.js.map +1 -1
- package/dist/cjs/onboard/selectors.js +1 -5
- package/dist/cjs/onboard/selectors.js.map +1 -1
- package/dist/cjs/plans/resolvers.js +4 -4
- package/dist/cjs/plans/resolvers.js.map +1 -1
- package/dist/cjs/purchases/lib/assembler.js +4 -0
- package/dist/cjs/purchases/lib/assembler.js.map +1 -1
- package/dist/cjs/purchases/queries/lib/use-query-keys-factory.js +1 -0
- package/dist/cjs/purchases/queries/lib/use-query-keys-factory.js.map +1 -1
- package/dist/cjs/purchases/queries/use-get-jetpack-transferred-license-purchases.js +33 -0
- package/dist/cjs/purchases/queries/use-get-jetpack-transferred-license-purchases.js.map +1 -0
- package/dist/cjs/queries/use-launchpad.js +3 -2
- package/dist/cjs/queries/use-launchpad.js.map +1 -1
- package/dist/cjs/queries/use-site-domains-query.js.map +1 -1
- package/dist/cjs/queries/use-site-intent.js.map +1 -1
- package/dist/cjs/reader/mutations/use-site-subscribe-mutation.js +1 -1
- package/dist/cjs/reader/mutations/use-site-subscribe-mutation.js.map +1 -1
- package/dist/cjs/reader/mutations/use-site-unsubscribe-mutation.js +4 -0
- package/dist/cjs/reader/mutations/use-site-unsubscribe-mutation.js.map +1 -1
- package/dist/cjs/site/actions.js +1 -1
- package/dist/cjs/site/actions.js.map +1 -1
- package/dist/cjs/site/constants.js +2 -1
- package/dist/cjs/site/constants.js.map +1 -1
- package/dist/cjs/site/types.js.map +1 -1
- package/dist/esm/add-ons/hooks/use-add-on-prices.js +1 -1
- package/dist/esm/add-ons/hooks/use-add-on-prices.js.map +1 -1
- package/dist/esm/add-ons/icons/custom-design.js +2 -2
- package/dist/esm/add-ons/icons/custom-design.js.map +1 -1
- package/dist/esm/add-ons/icons/unlimited-themes.js +2 -2
- package/dist/esm/add-ons/icons/unlimited-themes.js.map +1 -1
- package/dist/esm/contextual-help/admin-sections.js +1 -1
- package/dist/esm/contextual-help/admin-sections.js.map +1 -1
- package/dist/esm/domain-suggestions/utils.js +1 -1
- package/dist/esm/domain-suggestions/utils.js.map +1 -1
- package/dist/esm/help-center/actions.js +29 -33
- package/dist/esm/help-center/actions.js.map +1 -1
- package/dist/esm/help-center/index.js +11 -10
- package/dist/esm/help-center/index.js.map +1 -1
- package/dist/esm/help-center/reducer.js +14 -7
- package/dist/esm/help-center/reducer.js.map +1 -1
- package/dist/esm/help-center/resolvers.js +4 -0
- package/dist/esm/help-center/resolvers.js.map +1 -1
- package/dist/esm/help-center/selectors.js +2 -1
- package/dist/esm/help-center/selectors.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/onboard/actions.js +0 -8
- package/dist/esm/onboard/actions.js.map +1 -1
- package/dist/esm/onboard/index.js +0 -1
- package/dist/esm/onboard/index.js.map +1 -1
- package/dist/esm/onboard/reducer.js +0 -20
- package/dist/esm/onboard/reducer.js.map +1 -1
- package/dist/esm/onboard/selectors.js +0 -2
- package/dist/esm/onboard/selectors.js.map +1 -1
- package/dist/esm/plans/resolvers.js +1 -1
- package/dist/esm/plans/resolvers.js.map +1 -1
- package/dist/esm/purchases/lib/assembler.js +4 -0
- package/dist/esm/purchases/lib/assembler.js.map +1 -1
- package/dist/esm/purchases/queries/lib/use-query-keys-factory.js +1 -0
- package/dist/esm/purchases/queries/lib/use-query-keys-factory.js.map +1 -1
- package/dist/esm/purchases/queries/use-get-jetpack-transferred-license-purchases.js +29 -0
- package/dist/esm/purchases/queries/use-get-jetpack-transferred-license-purchases.js.map +1 -0
- package/dist/esm/queries/use-launchpad.js +2 -2
- package/dist/esm/queries/use-launchpad.js.map +1 -1
- package/dist/esm/queries/use-site-domains-query.js.map +1 -1
- package/dist/esm/queries/use-site-intent.js.map +1 -1
- package/dist/esm/reader/mutations/use-site-subscribe-mutation.js +1 -1
- package/dist/esm/reader/mutations/use-site-subscribe-mutation.js.map +1 -1
- package/dist/esm/reader/mutations/use-site-unsubscribe-mutation.js +4 -0
- package/dist/esm/reader/mutations/use-site-unsubscribe-mutation.js.map +1 -1
- package/dist/esm/site/actions.js +1 -1
- package/dist/esm/site/actions.js.map +1 -1
- package/dist/esm/site/constants.js +1 -0
- package/dist/esm/site/constants.js.map +1 -1
- package/dist/esm/site/types.js.map +1 -1
- package/dist/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/add-ons/icons/custom-design.d.ts.map +1 -1
- package/dist/types/add-ons/icons/unlimited-themes.d.ts.map +1 -1
- package/dist/types/help-center/actions.d.ts +25 -18
- package/dist/types/help-center/actions.d.ts.map +1 -1
- package/dist/types/help-center/index.d.ts +1 -1
- package/dist/types/help-center/index.d.ts.map +1 -1
- package/dist/types/help-center/reducer.d.ts +8 -2
- package/dist/types/help-center/reducer.d.ts.map +1 -1
- package/dist/types/help-center/resolvers.d.ts +11 -0
- package/dist/types/help-center/resolvers.d.ts.map +1 -1
- package/dist/types/help-center/selectors.d.ts +5 -1
- package/dist/types/help-center/selectors.d.ts.map +1 -1
- package/dist/types/help-center/types.d.ts +2 -1
- package/dist/types/help-center/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/onboard/actions.d.ts +1 -24
- package/dist/types/onboard/actions.d.ts.map +1 -1
- package/dist/types/onboard/index.d.ts.map +1 -1
- package/dist/types/onboard/reducer.d.ts +0 -4
- package/dist/types/onboard/reducer.d.ts.map +1 -1
- package/dist/types/onboard/selectors.d.ts +0 -4
- package/dist/types/onboard/selectors.d.ts.map +1 -1
- package/dist/types/purchases/lib/assembler.d.ts.map +1 -1
- package/dist/types/purchases/queries/lib/use-query-keys-factory.d.ts +1 -0
- package/dist/types/purchases/queries/lib/use-query-keys-factory.d.ts.map +1 -1
- package/dist/types/purchases/queries/use-get-jetpack-transferred-license-purchases.d.ts +18 -0
- package/dist/types/purchases/queries/use-get-jetpack-transferred-license-purchases.d.ts.map +1 -0
- package/dist/types/purchases/types.d.ts +16 -0
- package/dist/types/purchases/types.d.ts.map +1 -1
- package/dist/types/queries/use-launchpad.d.ts +1 -0
- package/dist/types/queries/use-launchpad.d.ts.map +1 -1
- package/dist/types/queries/use-site-domains-query.d.ts +1 -0
- package/dist/types/queries/use-site-domains-query.d.ts.map +1 -1
- package/dist/types/queries/use-site-intent.d.ts +2 -1
- package/dist/types/queries/use-site-intent.d.ts.map +1 -1
- package/dist/types/reader/index.d.ts +3 -1
- package/dist/types/reader/index.d.ts.map +1 -1
- package/dist/types/reader/mutations/use-site-subscribe-mutation.d.ts +1 -1
- package/dist/types/reader/mutations/use-site-subscribe-mutation.d.ts.map +1 -1
- package/dist/types/reader/mutations/use-site-unsubscribe-mutation.d.ts +2 -0
- package/dist/types/reader/mutations/use-site-unsubscribe-mutation.d.ts.map +1 -1
- package/dist/types/site/actions.d.ts.map +1 -1
- package/dist/types/site/constants.d.ts +1 -0
- package/dist/types/site/constants.d.ts.map +1 -1
- package/dist/types/site/types.d.ts +10 -2
- package/dist/types/site/types.d.ts.map +1 -1
- package/dist/types/user/types.d.ts +4 -2
- package/dist/types/user/types.d.ts.map +1 -1
- package/package.json +25 -14
- package/src/add-ons/hooks/use-add-on-prices.ts +1 -1
- package/src/add-ons/icons/custom-design.tsx +3 -11
- package/src/add-ons/icons/unlimited-themes.tsx +3 -12
- package/src/contextual-help/admin-sections.ts +1 -1
- package/src/domain-suggestions/utils.ts +1 -1
- package/src/help-center/actions.ts +40 -39
- package/src/help-center/index.ts +10 -8
- package/src/help-center/reducer.ts +19 -10
- package/src/help-center/resolvers.ts +10 -0
- package/src/help-center/selectors.ts +2 -1
- package/src/help-center/types.ts +2 -1
- package/src/index.ts +6 -3
- package/src/newsletter-categories/test/index.tsx +5 -7
- package/src/onboard/actions.ts +0 -25
- package/src/onboard/index.ts +0 -1
- package/src/onboard/reducer.ts +0 -26
- package/src/onboard/selectors.ts +0 -2
- package/src/plans/resolvers.ts +1 -1
- package/src/purchases/lib/assembler.ts +5 -0
- package/src/purchases/queries/lib/use-query-keys-factory.ts +1 -0
- package/src/purchases/queries/use-get-jetpack-transferred-license-purchases.tsx +43 -0
- package/src/purchases/types.ts +20 -0
- package/src/queries/use-launchpad.ts +2 -2
- package/src/queries/use-site-domains-query.ts +1 -0
- package/src/queries/use-site-intent.ts +2 -1
- package/src/reader/mutations/use-site-subscribe-mutation.ts +2 -2
- package/src/reader/mutations/use-site-unsubscribe-mutation.ts +7 -0
- package/src/reader/queries/test/use-read-feed-search-query.tsx +1 -1
- package/src/site/actions.ts +1 -1
- package/src/site/constants.ts +1 -0
- package/src/site/test/selectors.ts +0 -1
- package/src/site/types.ts +10 -2
- package/src/user/types.ts +4 -2
- package/dist/cjs/analyzer/actions.js +0 -38
- package/dist/cjs/analyzer/actions.js.map +0 -1
- package/dist/cjs/analyzer/constants.js +0 -5
- package/dist/cjs/analyzer/constants.js.map +0 -1
- package/dist/cjs/analyzer/index.js +0 -19
- package/dist/cjs/analyzer/index.js.map +0 -1
- package/dist/cjs/analyzer/reducers.js +0 -27
- package/dist/cjs/analyzer/reducers.js.map +0 -1
- package/dist/cjs/analyzer/selectors.js +0 -15
- package/dist/cjs/analyzer/selectors.js.map +0 -1
- package/dist/cjs/analyzer/types.js +0 -3
- package/dist/cjs/analyzer/types.js.map +0 -1
- package/dist/esm/analyzer/actions.js +0 -35
- package/dist/esm/analyzer/actions.js.map +0 -1
- package/dist/esm/analyzer/constants.js +0 -2
- package/dist/esm/analyzer/constants.js.map +0 -1
- package/dist/esm/analyzer/index.js +0 -15
- package/dist/esm/analyzer/index.js.map +0 -1
- package/dist/esm/analyzer/reducers.js +0 -25
- package/dist/esm/analyzer/reducers.js.map +0 -1
- package/dist/esm/analyzer/selectors.js +0 -9
- package/dist/esm/analyzer/selectors.js.map +0 -1
- package/dist/esm/analyzer/types.js +0 -2
- package/dist/esm/analyzer/types.js.map +0 -1
- package/dist/types/analyzer/actions.d.ts +0 -37
- package/dist/types/analyzer/actions.d.ts.map +0 -1
- package/dist/types/analyzer/constants.d.ts +0 -2
- package/dist/types/analyzer/constants.d.ts.map +0 -1
- package/dist/types/analyzer/index.d.ts +0 -38
- package/dist/types/analyzer/index.d.ts.map +0 -1
- package/dist/types/analyzer/reducers.d.ts +0 -11
- package/dist/types/analyzer/reducers.d.ts.map +0 -1
- package/dist/types/analyzer/selectors.d.ts +0 -7
- package/dist/types/analyzer/selectors.d.ts.map +0 -1
- package/dist/types/analyzer/types.d.ts +0 -35
- package/dist/types/analyzer/types.d.ts.map +0 -1
- package/src/analyzer/actions.ts +0 -49
- package/src/analyzer/constants.ts +0 -1
- package/src/analyzer/index.ts +0 -17
- package/src/analyzer/reducers.ts +0 -36
- package/src/analyzer/selectors.ts +0 -11
- package/src/analyzer/types.ts +0 -37
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { default as apiFetchPromise } from '@wordpress/api-fetch';
|
|
2
2
|
import { select } from '@wordpress/data';
|
|
3
|
-
import { apiFetch } from '@wordpress/data-controls';
|
|
4
3
|
import { addQueryArgs } from '@wordpress/url';
|
|
5
4
|
import { default as wpcomRequestPromise, canAccessWpcomApis } from 'wpcom-proxy-request';
|
|
6
5
|
import { GeneratorReturnType } from '../mapped-types';
|
|
7
6
|
import { SiteDetails } from '../site';
|
|
8
|
-
import { wpcomRequest } from '../wpcom-request-controls';
|
|
9
7
|
import { STORE_KEY } from './constants';
|
|
10
8
|
import { isE2ETest } from '.';
|
|
11
9
|
import type {
|
|
@@ -15,37 +13,7 @@ import type {
|
|
|
15
13
|
HelpCenterShowOptions,
|
|
16
14
|
} from './types';
|
|
17
15
|
import type { SupportInteraction } from '@automattic/odie-client/src/types';
|
|
18
|
-
|
|
19
|
-
export const receiveHasSeenWhatsNewModal = ( value: boolean | undefined ) =>
|
|
20
|
-
( {
|
|
21
|
-
type: 'HELP_CENTER_SET_SEEN_WHATS_NEW_MODAL',
|
|
22
|
-
value,
|
|
23
|
-
} ) as const;
|
|
24
|
-
|
|
25
|
-
export function* setHasSeenWhatsNewModal( value: boolean ) {
|
|
26
|
-
let response: {
|
|
27
|
-
has_seen_whats_new_modal: boolean;
|
|
28
|
-
};
|
|
29
|
-
if ( canAccessWpcomApis() ) {
|
|
30
|
-
response = yield wpcomRequest( {
|
|
31
|
-
path: '/block-editor/has-seen-whats-new-modal',
|
|
32
|
-
apiNamespace: 'wpcom/v2',
|
|
33
|
-
method: 'PUT',
|
|
34
|
-
body: {
|
|
35
|
-
has_seen_whats_new_modal: value,
|
|
36
|
-
},
|
|
37
|
-
} );
|
|
38
|
-
} else {
|
|
39
|
-
response = yield apiFetch( {
|
|
40
|
-
global: true,
|
|
41
|
-
path: '/wpcom/v2/block-editor/has-seen-whats-new-modal',
|
|
42
|
-
method: 'PUT',
|
|
43
|
-
data: { has_seen_whats_new_modal: value },
|
|
44
|
-
} as APIFetchOptions );
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return receiveHasSeenWhatsNewModal( response.has_seen_whats_new_modal );
|
|
48
|
-
}
|
|
16
|
+
import type { Location } from 'history';
|
|
49
17
|
|
|
50
18
|
export function setCurrentSupportInteraction( supportInteraction: SupportInteraction ) {
|
|
51
19
|
return {
|
|
@@ -54,6 +22,15 @@ export function setCurrentSupportInteraction( supportInteraction: SupportInterac
|
|
|
54
22
|
} as const;
|
|
55
23
|
}
|
|
56
24
|
|
|
25
|
+
export function setHelpCenterRouterHistory(
|
|
26
|
+
history: { entries: Location[]; index: number } | undefined
|
|
27
|
+
) {
|
|
28
|
+
return {
|
|
29
|
+
type: 'HELP_CENTER_SET_HELP_CENTER_ROUTER_HISTORY',
|
|
30
|
+
history,
|
|
31
|
+
} as const;
|
|
32
|
+
}
|
|
33
|
+
|
|
57
34
|
export const setNavigateToRoute = ( route?: string ) =>
|
|
58
35
|
( {
|
|
59
36
|
type: 'HELP_CENTER_SET_NAVIGATE_TO_ROUTE',
|
|
@@ -120,6 +97,12 @@ export const setMessage = ( message: string ) =>
|
|
|
120
97
|
message,
|
|
121
98
|
} ) as const;
|
|
122
99
|
|
|
100
|
+
export const setContextTerm = ( contextTerm: string ) =>
|
|
101
|
+
( {
|
|
102
|
+
type: 'HELP_CENTER_SET_CONTEXT_TERM',
|
|
103
|
+
contextTerm,
|
|
104
|
+
} ) as const;
|
|
105
|
+
|
|
123
106
|
export const setAllowPremiumSupport = ( allow: boolean ) =>
|
|
124
107
|
( {
|
|
125
108
|
type: 'HELP_CENTER_SET_ALLOW_PREMIUM_SUPPORT',
|
|
@@ -134,7 +117,7 @@ export const setHelpCenterOptions = ( options: HelpCenterOptions ) => ( {
|
|
|
134
117
|
export const setShowHelpCenter = function* (
|
|
135
118
|
show: boolean,
|
|
136
119
|
allowPremiumSupport = false,
|
|
137
|
-
options: HelpCenterShowOptions = { hideBackButton: false,
|
|
120
|
+
options: HelpCenterShowOptions = { hideBackButton: false, contextTerm: '' }
|
|
138
121
|
): Generator< unknown, { type: 'HELP_CENTER_SET_SHOW'; show: boolean }, unknown > {
|
|
139
122
|
const isMinimized = ( select( STORE_KEY ) as HelpCenterSelect ).getIsMinimized();
|
|
140
123
|
|
|
@@ -155,7 +138,11 @@ export const setShowHelpCenter = function* (
|
|
|
155
138
|
apiNamespace: 'wpcom/v2',
|
|
156
139
|
method: 'PUT',
|
|
157
140
|
body: {
|
|
158
|
-
calypso_preferences: {
|
|
141
|
+
calypso_preferences: {
|
|
142
|
+
help_center_open: show,
|
|
143
|
+
// Delete the remote version of the navigation history when closing the help center
|
|
144
|
+
...( ! show ? { help_center_router_history: null } : {} ),
|
|
145
|
+
},
|
|
159
146
|
},
|
|
160
147
|
} ).catch( () => {} );
|
|
161
148
|
} else {
|
|
@@ -164,18 +151,23 @@ export const setShowHelpCenter = function* (
|
|
|
164
151
|
global: true,
|
|
165
152
|
path: '/help-center/open-state',
|
|
166
153
|
method: 'PUT',
|
|
167
|
-
data: {
|
|
154
|
+
data: {
|
|
155
|
+
help_center_open: show, // Delete the remote version of the navigation history when closing the help center
|
|
156
|
+
...( ! show ? { help_center_router_history: null } : {} ),
|
|
157
|
+
},
|
|
168
158
|
} as APIFetchOptions ).catch( () => {} );
|
|
169
159
|
}
|
|
170
160
|
}
|
|
171
161
|
|
|
172
162
|
if ( ! show ) {
|
|
173
163
|
yield setNavigateToRoute( undefined );
|
|
164
|
+
// Reset the local navigation history when closing the help center
|
|
165
|
+
yield setHelpCenterRouterHistory( undefined );
|
|
174
166
|
} else {
|
|
175
167
|
yield setShowMessagingWidget( false );
|
|
176
168
|
}
|
|
177
169
|
|
|
178
|
-
yield
|
|
170
|
+
yield setContextTerm( options?.contextTerm || '' );
|
|
179
171
|
yield setIsMinimized( false );
|
|
180
172
|
|
|
181
173
|
if ( allowPremiumSupport ) {
|
|
@@ -220,11 +212,13 @@ export const setNewMessagingChat = function* ( {
|
|
|
220
212
|
section,
|
|
221
213
|
siteUrl,
|
|
222
214
|
siteId,
|
|
215
|
+
userFieldFlowName,
|
|
223
216
|
}: {
|
|
224
217
|
initialMessage: string;
|
|
225
218
|
section?: string;
|
|
226
219
|
siteUrl?: string;
|
|
227
220
|
siteId?: string;
|
|
221
|
+
userFieldFlowName?: string;
|
|
228
222
|
} ) {
|
|
229
223
|
const url = addQueryArgs( '/odie', {
|
|
230
224
|
provider: 'zendesk',
|
|
@@ -232,11 +226,17 @@ export const setNewMessagingChat = function* ( {
|
|
|
232
226
|
section,
|
|
233
227
|
siteUrl,
|
|
234
228
|
siteId,
|
|
229
|
+
userFieldFlowName,
|
|
235
230
|
} );
|
|
236
231
|
yield setNavigateToRoute( url );
|
|
237
232
|
yield setShowHelpCenter( true );
|
|
238
233
|
};
|
|
239
234
|
|
|
235
|
+
export const setNavigateToOdie = function* () {
|
|
236
|
+
yield setNavigateToRoute( '/odie' );
|
|
237
|
+
yield setShowHelpCenter( true );
|
|
238
|
+
};
|
|
239
|
+
|
|
240
240
|
export const setShowSupportDoc = function* ( link: string, postId?: number, blogId?: number ) {
|
|
241
241
|
const params = new URLSearchParams( {
|
|
242
242
|
link,
|
|
@@ -255,12 +255,13 @@ export type HelpCenterAction =
|
|
|
255
255
|
| typeof setShowMessagingWidget
|
|
256
256
|
| typeof setSubject
|
|
257
257
|
| typeof resetStore
|
|
258
|
-
| typeof receiveHasSeenWhatsNewModal
|
|
259
258
|
| typeof setMessage
|
|
259
|
+
| typeof setContextTerm
|
|
260
260
|
| typeof setUserDeclaredSite
|
|
261
261
|
| typeof setUserDeclaredSiteUrl
|
|
262
262
|
| typeof setUnreadCount
|
|
263
263
|
| typeof setIsMinimized
|
|
264
|
+
| typeof setHelpCenterRouterHistory
|
|
264
265
|
| typeof setIsChatLoaded
|
|
265
266
|
| typeof setAreSoundNotificationsEnabled
|
|
266
267
|
| typeof setZendeskClientId
|
|
@@ -271,4 +272,4 @@ export type HelpCenterAction =
|
|
|
271
272
|
| typeof setAllowPremiumSupport
|
|
272
273
|
| typeof setHelpCenterOptions
|
|
273
274
|
>
|
|
274
|
-
| GeneratorReturnType< typeof setShowHelpCenter
|
|
275
|
+
| GeneratorReturnType< typeof setShowHelpCenter >;
|
package/src/help-center/index.ts
CHANGED
|
@@ -9,7 +9,9 @@ import { isHelpCenterShown } from './resolvers';
|
|
|
9
9
|
import * as selectors from './selectors';
|
|
10
10
|
export type { State };
|
|
11
11
|
|
|
12
|
-
declare const helpCenterData: { isProxied: boolean } | undefined;
|
|
12
|
+
declare const helpCenterData: { isProxied: boolean; isSU: boolean; isSSP: boolean } | undefined;
|
|
13
|
+
declare const isSupportSession: boolean;
|
|
14
|
+
declare const isSSP: boolean;
|
|
13
15
|
|
|
14
16
|
let isRegistered = false;
|
|
15
17
|
|
|
@@ -19,10 +21,9 @@ const E2E_USER_AGENT = 'wp-e2e-tests';
|
|
|
19
21
|
export const isE2ETest = () =>
|
|
20
22
|
typeof window !== 'undefined' && window.navigator.userAgent.includes( E2E_USER_AGENT );
|
|
21
23
|
|
|
22
|
-
export const
|
|
24
|
+
export const isInSupportSession = () => {
|
|
23
25
|
if ( typeof window !== 'undefined' ) {
|
|
24
26
|
return (
|
|
25
|
-
'disableHelpCenterAutoOpen' in window ||
|
|
26
27
|
// A bit hacky but much easier than passing down data from PHP in Jetpack
|
|
27
28
|
// Simple
|
|
28
29
|
!! document.querySelector( '#wp-admin-bar-support-session-details' ) ||
|
|
@@ -30,16 +31,17 @@ export const isSupportSession = () => {
|
|
|
30
31
|
// Atomic
|
|
31
32
|
document.body.classList.contains( 'support-session' ) ||
|
|
32
33
|
document.querySelector( '#wpcom > .is-support-session' ) ||
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
( typeof helpCenterData !== 'undefined' && helpCenterData?.
|
|
34
|
+
( typeof isSupportSession !== 'undefined' && !! isSupportSession ) ||
|
|
35
|
+
( typeof helpCenterData !== 'undefined' && helpCenterData?.isSU ) ||
|
|
36
|
+
( typeof helpCenterData !== 'undefined' && helpCenterData?.isSSP ) ||
|
|
37
|
+
( typeof isSSP !== 'undefined' && !! isSSP )
|
|
36
38
|
);
|
|
37
39
|
}
|
|
38
40
|
return false;
|
|
39
41
|
};
|
|
40
42
|
|
|
41
43
|
export function register(): typeof STORE_KEY {
|
|
42
|
-
const
|
|
44
|
+
const enabledPersistedOpenState = ! isE2ETest() && ! isInSupportSession();
|
|
43
45
|
|
|
44
46
|
registerPlugins();
|
|
45
47
|
|
|
@@ -51,7 +53,7 @@ export function register(): typeof STORE_KEY {
|
|
|
51
53
|
selectors,
|
|
52
54
|
persist: [ 'message', 'userDeclaredSite', 'userDeclaredSiteUrl', 'subject' ],
|
|
53
55
|
// Don't persist the open state for e2e users, because parallel tests will start interfering with each other.
|
|
54
|
-
resolvers:
|
|
56
|
+
resolvers: enabledPersistedOpenState ? { isHelpCenterShown } : undefined,
|
|
55
57
|
} );
|
|
56
58
|
isRegistered = true;
|
|
57
59
|
}
|
|
@@ -3,6 +3,7 @@ import { SiteDetails } from '../site';
|
|
|
3
3
|
import type { HelpCenterAction } from './actions';
|
|
4
4
|
import type { HelpCenterOptions } from './types';
|
|
5
5
|
import type { SupportInteraction } from '@automattic/odie-client/src/types';
|
|
6
|
+
import type { Location } from 'history';
|
|
6
7
|
import type { Reducer } from 'redux';
|
|
7
8
|
|
|
8
9
|
const showHelpCenter: Reducer< boolean | undefined, HelpCenterAction > = ( state, action ) => {
|
|
@@ -24,21 +25,21 @@ const showMessagingLauncher: Reducer< boolean | undefined, HelpCenterAction > =
|
|
|
24
25
|
return state;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
const
|
|
28
|
+
const helpCenterRouterHistory: Reducer<
|
|
29
|
+
{ entries: Location[]; index: number } | undefined,
|
|
30
|
+
HelpCenterAction
|
|
31
|
+
> = ( state, action ) => {
|
|
28
32
|
switch ( action.type ) {
|
|
29
|
-
case '
|
|
30
|
-
return action.
|
|
33
|
+
case 'HELP_CENTER_SET_HELP_CENTER_ROUTER_HISTORY':
|
|
34
|
+
return action.history;
|
|
31
35
|
}
|
|
32
36
|
return state;
|
|
33
37
|
};
|
|
34
38
|
|
|
35
|
-
const
|
|
36
|
-
state,
|
|
37
|
-
action
|
|
38
|
-
) => {
|
|
39
|
+
const showMessagingWidget: Reducer< boolean | undefined, HelpCenterAction > = ( state, action ) => {
|
|
39
40
|
switch ( action.type ) {
|
|
40
|
-
case '
|
|
41
|
-
return action.
|
|
41
|
+
case 'HELP_CENTER_SET_SHOW_MESSAGING_WIDGET':
|
|
42
|
+
return action.show;
|
|
42
43
|
}
|
|
43
44
|
return state;
|
|
44
45
|
};
|
|
@@ -168,6 +169,13 @@ const allowPremiumSupport: Reducer< boolean, HelpCenterAction > = ( state = fals
|
|
|
168
169
|
return state;
|
|
169
170
|
};
|
|
170
171
|
|
|
172
|
+
const contextTerm: Reducer< string | undefined, HelpCenterAction > = ( state, action ) => {
|
|
173
|
+
if ( action.type === 'HELP_CENTER_SET_CONTEXT_TERM' ) {
|
|
174
|
+
return action.contextTerm;
|
|
175
|
+
}
|
|
176
|
+
return state;
|
|
177
|
+
};
|
|
178
|
+
|
|
171
179
|
const helpCenterOptions: Reducer< HelpCenterOptions, HelpCenterAction > = (
|
|
172
180
|
state = {},
|
|
173
181
|
action
|
|
@@ -187,7 +195,6 @@ const reducer = combineReducers( {
|
|
|
187
195
|
message,
|
|
188
196
|
userDeclaredSite,
|
|
189
197
|
userDeclaredSiteUrl,
|
|
190
|
-
hasSeenWhatsNewModal,
|
|
191
198
|
isMinimized,
|
|
192
199
|
isChatLoaded,
|
|
193
200
|
areSoundNotificationsEnabled,
|
|
@@ -196,7 +203,9 @@ const reducer = combineReducers( {
|
|
|
196
203
|
navigateToRoute,
|
|
197
204
|
odieInitialPromptText,
|
|
198
205
|
odieBotNameSlug,
|
|
206
|
+
helpCenterRouterHistory,
|
|
199
207
|
allowPremiumSupport,
|
|
208
|
+
contextTerm,
|
|
200
209
|
helpCenterOptions,
|
|
201
210
|
} );
|
|
202
211
|
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { apiFetch } from '@wordpress/data-controls';
|
|
2
2
|
import { canAccessWpcomApis } from 'wpcom-proxy-request';
|
|
3
3
|
import { wpcomRequest } from '../wpcom-request-controls';
|
|
4
|
+
import { setHelpCenterRouterHistory } from './actions';
|
|
4
5
|
import type { APIFetchOptions } from './types';
|
|
6
|
+
import type { Location } from 'history';
|
|
5
7
|
|
|
6
8
|
export function* isHelpCenterShown() {
|
|
7
9
|
try {
|
|
8
10
|
const preferences: {
|
|
9
11
|
help_center_open: boolean;
|
|
12
|
+
help_center_router_history: {
|
|
13
|
+
entries: Location[];
|
|
14
|
+
index: number;
|
|
15
|
+
};
|
|
10
16
|
} = canAccessWpcomApis()
|
|
11
17
|
? yield wpcomRequest( {
|
|
12
18
|
path: '/me/preferences',
|
|
@@ -17,6 +23,10 @@ export function* isHelpCenterShown() {
|
|
|
17
23
|
path: '/help-center/open-state',
|
|
18
24
|
} as APIFetchOptions );
|
|
19
25
|
|
|
26
|
+
if ( preferences.help_center_router_history ) {
|
|
27
|
+
yield setHelpCenterRouterHistory( preferences.help_center_router_history );
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
// We only want to auto-open, we don't want to auto-close (and potentially overrule the user's action).
|
|
21
31
|
if ( preferences.help_center_open ) {
|
|
22
32
|
return {
|
|
@@ -13,10 +13,11 @@ export const getIsChatLoaded = ( state: State ) => state.isChatLoaded;
|
|
|
13
13
|
export const getAreSoundNotificationsEnabled = ( state: State ) =>
|
|
14
14
|
state.areSoundNotificationsEnabled;
|
|
15
15
|
export const getZendeskClientId = ( state: State ) => state.zendeskClientId;
|
|
16
|
-
export const
|
|
16
|
+
export const getHelpCenterRouterHistory = ( state: State ) => state.helpCenterRouterHistory;
|
|
17
17
|
export const getNavigateToRoute = ( state: State ) => state.navigateToRoute;
|
|
18
18
|
export const getOdieInitialPromptText = ( state: State ) => state.odieInitialPromptText;
|
|
19
19
|
export const getOdieBotNameSlug = ( state: State ) => state.odieBotNameSlug;
|
|
20
20
|
export const getCurrentSupportInteraction = ( state: State ) => state.currentSupportInteraction;
|
|
21
21
|
export const getAllowPremiumSupport = ( state: State ) => state.allowPremiumSupport;
|
|
22
22
|
export const getHelpCenterOptions = ( state: State ) => state.helpCenterOptions;
|
|
23
|
+
export const getContextTerm = ( state: State ) => state.contextTerm;
|
package/src/help-center/types.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type Location = {
|
|
|
11
11
|
};
|
|
12
12
|
export interface HelpCenterShowOptions {
|
|
13
13
|
hideBackButton: boolean;
|
|
14
|
-
|
|
14
|
+
contextTerm: string;
|
|
15
15
|
}
|
|
16
16
|
export interface SiteLogo {
|
|
17
17
|
id: number;
|
|
@@ -32,6 +32,7 @@ export interface HelpCenterSite {
|
|
|
32
32
|
is_wpcom_atomic: boolean;
|
|
33
33
|
jetpack: boolean;
|
|
34
34
|
logo: SiteLogo;
|
|
35
|
+
site_owner: number;
|
|
35
36
|
options: {
|
|
36
37
|
launchpad_screen: string;
|
|
37
38
|
site_intent: string;
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as AddOns from './add-ons';
|
|
2
|
-
import * as Analyzer from './analyzer';
|
|
3
2
|
import * as DomainSuggestions from './domain-suggestions';
|
|
4
3
|
import * as HelpCenter from './help-center';
|
|
5
4
|
import * as Onboard from './onboard';
|
|
@@ -38,7 +37,6 @@ const { SubscriptionManager } = Reader;
|
|
|
38
37
|
|
|
39
38
|
export {
|
|
40
39
|
AddOns,
|
|
41
|
-
Analyzer,
|
|
42
40
|
User,
|
|
43
41
|
DomainSuggestions,
|
|
44
42
|
HelpCenter,
|
|
@@ -63,9 +61,14 @@ export type { Section } from './contextual-help/contextual-help';
|
|
|
63
61
|
export { generateAdminSections } from './contextual-help/admin-sections';
|
|
64
62
|
export type { LinksForSection } from './contextual-help/contextual-help';
|
|
65
63
|
export * from './contextual-help/constants';
|
|
66
|
-
export type {
|
|
64
|
+
export type {
|
|
65
|
+
HelpCenterSite,
|
|
66
|
+
HelpCenterSelect,
|
|
67
|
+
Dispatch as HelpCenterDispatch,
|
|
68
|
+
} from './help-center/types';
|
|
67
69
|
export type { OnboardSelect, OnboardActions } from './onboard';
|
|
68
70
|
export type { StepperInternalSelect } from './stepper-internal';
|
|
69
71
|
export type { SiteActions } from './site';
|
|
70
72
|
export type { UserActions } from './user';
|
|
71
73
|
export type { Member, UseQuery, UsersQuery } from './users/types';
|
|
74
|
+
export { isInSupportSession } from './help-center';
|
|
@@ -14,7 +14,7 @@ describe( 'useNewsletterCategories', () => {
|
|
|
14
14
|
let wrapper: React.FC< { children: React.ReactNode } >;
|
|
15
15
|
|
|
16
16
|
beforeEach( () => {
|
|
17
|
-
|
|
17
|
+
jest.mocked( request ).mockReset();
|
|
18
18
|
|
|
19
19
|
queryClient = new QueryClient( {
|
|
20
20
|
defaultOptions: {
|
|
@@ -34,7 +34,7 @@ describe( 'useNewsletterCategories', () => {
|
|
|
34
34
|
} );
|
|
35
35
|
|
|
36
36
|
it( 'should return expected data when successful', async () => {
|
|
37
|
-
|
|
37
|
+
jest.mocked( request ).mockResolvedValue( {
|
|
38
38
|
enabled: true,
|
|
39
39
|
newsletter_categories: [
|
|
40
40
|
{ id: 1, name: 'Category 1', slug: 'Slug 1', description: 'Description 1', parent: 1 },
|
|
@@ -56,7 +56,7 @@ describe( 'useNewsletterCategories', () => {
|
|
|
56
56
|
} );
|
|
57
57
|
|
|
58
58
|
it( 'should handle empty response', async () => {
|
|
59
|
-
|
|
59
|
+
jest.mocked( request ).mockResolvedValue( {
|
|
60
60
|
enabled: false,
|
|
61
61
|
newsletter_categories: [],
|
|
62
62
|
} );
|
|
@@ -69,7 +69,7 @@ describe( 'useNewsletterCategories', () => {
|
|
|
69
69
|
} );
|
|
70
70
|
|
|
71
71
|
it( 'should call request with correct arguments', async () => {
|
|
72
|
-
|
|
72
|
+
jest.mocked( request ).mockResolvedValue( {
|
|
73
73
|
enabled: true,
|
|
74
74
|
newsletter_categories: [],
|
|
75
75
|
} );
|
|
@@ -88,9 +88,7 @@ describe( 'useNewsletterCategories', () => {
|
|
|
88
88
|
|
|
89
89
|
it( 'should handle error response', async () => {
|
|
90
90
|
const errorMessage = 'API Error';
|
|
91
|
-
( request
|
|
92
|
-
new Error( errorMessage )
|
|
93
|
-
);
|
|
91
|
+
jest.mocked( request ).mockRejectedValue( new Error( errorMessage ) );
|
|
94
92
|
|
|
95
93
|
const { result } = renderHook( () => useNewsletterCategories( { siteId: 123 } ), { wrapper } );
|
|
96
94
|
|
package/src/onboard/actions.ts
CHANGED
|
@@ -34,19 +34,6 @@ export const setSiteUrl = ( siteUrl: string ) => ( {
|
|
|
34
34
|
siteUrl,
|
|
35
35
|
} );
|
|
36
36
|
|
|
37
|
-
export interface CreateSiteBaseActionParameters {
|
|
38
|
-
username: string;
|
|
39
|
-
languageSlug: string;
|
|
40
|
-
visibility: number;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface CreateSiteActionParameters extends CreateSiteBaseActionParameters {
|
|
44
|
-
bearerToken?: string;
|
|
45
|
-
anchorFmPodcastId: string | null;
|
|
46
|
-
anchorFmEpisodeId: string | null;
|
|
47
|
-
anchorFmSpotifyUrl: string | null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
37
|
export function* createSenseiSite( {
|
|
51
38
|
username = '',
|
|
52
39
|
languageSlug = '',
|
|
@@ -356,11 +343,6 @@ export const setHidePlansFeatureComparison = ( hidePlansFeatureComparison: boole
|
|
|
356
343
|
hidePlansFeatureComparison,
|
|
357
344
|
} );
|
|
358
345
|
|
|
359
|
-
export const setIsMigrateFromWp = ( isMigrateFromWp: boolean ) => ( {
|
|
360
|
-
type: 'SET_IS_MIGRATE_FROM_WP' as const,
|
|
361
|
-
isMigrateFromWp,
|
|
362
|
-
} );
|
|
363
|
-
|
|
364
346
|
export const setPluginsToVerify = ( pluginSlugs: string[] ) => ( {
|
|
365
347
|
type: 'SET_PLUGIN_SLUGS_TO_VERIFY' as const,
|
|
366
348
|
pluginSlugs,
|
|
@@ -381,11 +363,6 @@ export const setPartnerBundle = ( partnerBundle: string | null ) => ( {
|
|
|
381
363
|
partnerBundle,
|
|
382
364
|
} );
|
|
383
365
|
|
|
384
|
-
export const setCreateWithBigSky = ( createWithBigSky: boolean ) => ( {
|
|
385
|
-
type: 'SET_CREATE_WITH_BIG_SKY' as const,
|
|
386
|
-
createWithBigSky,
|
|
387
|
-
} );
|
|
388
|
-
|
|
389
366
|
export type OnboardAction = ReturnType<
|
|
390
367
|
| typeof addFeature
|
|
391
368
|
| typeof removeFeature
|
|
@@ -442,9 +419,7 @@ export type OnboardAction = ReturnType<
|
|
|
442
419
|
| typeof setHidePlansFeatureComparison
|
|
443
420
|
| typeof setProductCartItems
|
|
444
421
|
| typeof setPlanCartItem
|
|
445
|
-
| typeof setIsMigrateFromWp
|
|
446
422
|
| typeof setPaidSubscribers
|
|
447
423
|
| typeof setPartnerBundle
|
|
448
424
|
| typeof setSignupDomainOrigin
|
|
449
|
-
| typeof setCreateWithBigSky
|
|
450
425
|
>;
|
package/src/onboard/index.ts
CHANGED
package/src/onboard/reducer.ts
CHANGED
|
@@ -489,16 +489,6 @@ const domainCartItems: Reducer< MinimalRequestCartProduct[] | undefined, Onboard
|
|
|
489
489
|
return state;
|
|
490
490
|
};
|
|
491
491
|
|
|
492
|
-
const isMigrateFromWp: Reducer< boolean, OnboardAction > = ( state = false, action ) => {
|
|
493
|
-
if ( action.type === 'SET_IS_MIGRATE_FROM_WP' ) {
|
|
494
|
-
return action.isMigrateFromWp;
|
|
495
|
-
}
|
|
496
|
-
if ( action.type === 'RESET_ONBOARD_STORE' ) {
|
|
497
|
-
return false;
|
|
498
|
-
}
|
|
499
|
-
return state;
|
|
500
|
-
};
|
|
501
|
-
|
|
502
492
|
const pluginsToVerify: Reducer< string[] | undefined, OnboardAction > = ( state, action ) => {
|
|
503
493
|
if ( action.type === 'SET_PLUGIN_SLUGS_TO_VERIFY' ) {
|
|
504
494
|
return action.pluginSlugs;
|
|
@@ -622,20 +612,6 @@ const signupDomainOrigin: Reducer< string | undefined, OnboardAction > = (
|
|
|
622
612
|
return state;
|
|
623
613
|
};
|
|
624
614
|
|
|
625
|
-
const createWithBigSky: Reducer< boolean | undefined, OnboardAction > = (
|
|
626
|
-
state = undefined,
|
|
627
|
-
action
|
|
628
|
-
) => {
|
|
629
|
-
if ( action.type === 'SET_CREATE_WITH_BIG_SKY' ) {
|
|
630
|
-
return action.createWithBigSky;
|
|
631
|
-
}
|
|
632
|
-
if ( action.type === 'RESET_ONBOARD_STORE' ) {
|
|
633
|
-
return undefined;
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
return state;
|
|
637
|
-
};
|
|
638
|
-
|
|
639
615
|
const reducer = combineReducers( {
|
|
640
616
|
domain,
|
|
641
617
|
domainCartItem,
|
|
@@ -678,14 +654,12 @@ const reducer = combineReducers( {
|
|
|
678
654
|
storageAddonSlug,
|
|
679
655
|
planCartItem,
|
|
680
656
|
productCartItems,
|
|
681
|
-
isMigrateFromWp,
|
|
682
657
|
domainCartItems,
|
|
683
658
|
pluginsToVerify,
|
|
684
659
|
profilerData,
|
|
685
660
|
paidSubscribers,
|
|
686
661
|
partnerBundle,
|
|
687
662
|
signupDomainOrigin,
|
|
688
|
-
createWithBigSky,
|
|
689
663
|
} );
|
|
690
664
|
|
|
691
665
|
export type State = ReturnType< typeof reducer >;
|
package/src/onboard/selectors.ts
CHANGED
|
@@ -77,9 +77,7 @@ export const getSignupDomainOrigin = ( state: State ) => state.signupDomainOrigi
|
|
|
77
77
|
export const getSiteUrl = ( state: State ) => state.siteUrl;
|
|
78
78
|
export const getHideFreePlan = ( state: State ) => state.hideFreePlan;
|
|
79
79
|
export const getHidePlansFeatureComparison = ( state: State ) => state.hidePlansFeatureComparison;
|
|
80
|
-
export const getIsMigrateFromWp = ( state: State ) => state.isMigrateFromWp;
|
|
81
80
|
export const getPluginsToVerify = ( state: State ) => state.pluginsToVerify;
|
|
82
81
|
export const getProfilerData = ( state: State ) => state.profilerData;
|
|
83
82
|
export const getPaidSubscribers = ( state: State ) => state.paidSubscribers;
|
|
84
83
|
export const getPartnerBundle = ( state: State ) => state.partnerBundle;
|
|
85
|
-
export const getCreateWithBigSky = ( state: State ) => state.createWithBigSky;
|
package/src/plans/resolvers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatCurrency } from '
|
|
1
|
+
import { formatCurrency } from '@automattic/number-formatters';
|
|
2
2
|
import { stringify } from 'qs';
|
|
3
3
|
import { fetchAndParse, wpcomRequest } from '../wpcom-request-controls';
|
|
4
4
|
import { setFeatures, setFeaturesByType, setPlanProducts, setPlans } from './actions';
|
|
@@ -114,6 +114,7 @@ export function createPurchaseObject( purchase: RawPurchase | RawPurchaseCreditC
|
|
|
114
114
|
saleAmountInteger: purchase.sale_amount_integer,
|
|
115
115
|
siteId: Number( purchase.blog_id ),
|
|
116
116
|
siteName: purchase.blogname,
|
|
117
|
+
siteSlug: purchase.site_slug,
|
|
117
118
|
subscribedDate: purchase.subscribed_date,
|
|
118
119
|
subscriptionStatus: purchase.subscription_status,
|
|
119
120
|
tagLine: purchase.tag_line,
|
|
@@ -124,6 +125,10 @@ export function createPurchaseObject( purchase: RawPurchase | RawPurchaseCreditC
|
|
|
124
125
|
isAutoRenewEnabled: parseInt( purchase.auto_renew ?? '' ) === 1,
|
|
125
126
|
};
|
|
126
127
|
|
|
128
|
+
if ( purchase.purchaser_id ) {
|
|
129
|
+
object.purchaserId = Number( purchase.purchaser_id );
|
|
130
|
+
}
|
|
131
|
+
|
|
127
132
|
if ( isCreditCardPurchase( purchase ) ) {
|
|
128
133
|
object.payment.creditCard = {
|
|
129
134
|
id: Number( purchase.payment_card_id ),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const useQueryKeysFactory = () => ( {
|
|
2
2
|
sitePurchases: ( siteId?: string | number | null ) => [ 'site-purchases', siteId ],
|
|
3
|
+
transferredPurchases: ( userId?: string | number | null ) => [ 'transferred-purchases', userId ],
|
|
3
4
|
} );
|
|
4
5
|
|
|
5
6
|
export default useQueryKeysFactory;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import wpcomRequest from 'wpcom-proxy-request';
|
|
3
|
+
import { createPurchaseObject } from '../lib/assembler';
|
|
4
|
+
import useQueryKeysFactory from './lib/use-query-keys-factory';
|
|
5
|
+
import type { RawPurchase, Purchase } from '../types';
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
userId?: string | number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getUseTransferredPurchasesOptions(
|
|
12
|
+
{ userId }: Props,
|
|
13
|
+
queryKey: ( string | number | null | undefined )[]
|
|
14
|
+
) {
|
|
15
|
+
return {
|
|
16
|
+
queryKey,
|
|
17
|
+
queryFn: async (): Promise< Purchase[] > => {
|
|
18
|
+
const purchases: RawPurchase[] = await wpcomRequest( {
|
|
19
|
+
path: '/me/purchases/transferred',
|
|
20
|
+
apiVersion: '1.1',
|
|
21
|
+
} );
|
|
22
|
+
|
|
23
|
+
return purchases.map( ( rawPurchase ) => createPurchaseObject( rawPurchase ) );
|
|
24
|
+
},
|
|
25
|
+
enabled: !! userId,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Fetches all purchases for a given site, transformed into a map of purchaseId => Purchase
|
|
31
|
+
* @param {Object} props - The properties for the function
|
|
32
|
+
* @param props.userId Site ID
|
|
33
|
+
* @returns Query result
|
|
34
|
+
*/
|
|
35
|
+
function useGetJetpackTransferredLicensePurchases( { userId }: Props ) {
|
|
36
|
+
const queryKeys = useQueryKeysFactory();
|
|
37
|
+
|
|
38
|
+
return useQuery< Purchase[] >(
|
|
39
|
+
getUseTransferredPurchasesOptions( { userId }, queryKeys.transferredPurchases( userId ) )
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default useGetJetpackTransferredLicensePurchases;
|