@automattic/data-stores 3.1.2 → 3.2.0
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/CHANGELOG.md +14 -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/help-center/actions.js +79 -49
- package/dist/cjs/help-center/actions.js.map +1 -1
- package/dist/cjs/help-center/reducer.js +19 -10
- package/dist/cjs/help-center/reducer.js.map +1 -1
- package/dist/cjs/help-center/resolvers.js +2 -1
- package/dist/cjs/help-center/resolvers.js.map +1 -1
- package/dist/cjs/help-center/selectors.js +7 -5
- package/dist/cjs/help-center/selectors.js.map +1 -1
- package/dist/cjs/index.js +1 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/onboard/actions.js +11 -1
- package/dist/cjs/onboard/actions.js.map +1 -1
- package/dist/cjs/onboard/reducer.js +23 -1
- package/dist/cjs/onboard/reducer.js.map +1 -1
- package/dist/cjs/onboard/selectors.js +5 -1
- package/dist/cjs/onboard/selectors.js.map +1 -1
- package/dist/cjs/plans/queries/use-plans.js +20 -1
- package/dist/cjs/plans/queries/use-plans.js.map +1 -1
- package/dist/cjs/purchases/lib/assembler.js +6 -16
- package/dist/cjs/purchases/lib/assembler.js.map +1 -1
- package/dist/cjs/site/types.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/help-center/actions.js +74 -46
- package/dist/esm/help-center/actions.js.map +1 -1
- package/dist/esm/help-center/reducer.js +19 -10
- package/dist/esm/help-center/reducer.js.map +1 -1
- package/dist/esm/help-center/resolvers.js +3 -2
- package/dist/esm/help-center/resolvers.js.map +1 -1
- package/dist/esm/help-center/selectors.js +3 -2
- package/dist/esm/help-center/selectors.js.map +1 -1
- package/dist/esm/index.js +1 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/onboard/actions.js +8 -0
- package/dist/esm/onboard/actions.js.map +1 -1
- package/dist/esm/onboard/reducer.js +20 -0
- package/dist/esm/onboard/reducer.js.map +1 -1
- package/dist/esm/onboard/selectors.js +2 -0
- package/dist/esm/onboard/selectors.js.map +1 -1
- package/dist/esm/plans/queries/use-plans.js +20 -1
- package/dist/esm/plans/queries/use-plans.js.map +1 -1
- package/dist/esm/purchases/lib/assembler.js +6 -16
- package/dist/esm/purchases/lib/assembler.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/help-center/actions.d.ts +30 -14
- package/dist/types/help-center/actions.d.ts.map +1 -1
- package/dist/types/help-center/reducer.d.ts +6 -5
- package/dist/types/help-center/reducer.d.ts.map +1 -1
- package/dist/types/help-center/resolvers.d.ts +16 -8
- package/dist/types/help-center/resolvers.d.ts.map +1 -1
- package/dist/types/help-center/selectors.d.ts +3 -2
- package/dist/types/help-center/selectors.d.ts.map +1 -1
- package/dist/types/help-center/types.d.ts +1 -0
- package/dist/types/help-center/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +473 -43
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/onboard/actions.d.ts +14 -2
- package/dist/types/onboard/actions.d.ts.map +1 -1
- package/dist/types/onboard/reducer.d.ts +7 -1
- package/dist/types/onboard/reducer.d.ts.map +1 -1
- package/dist/types/onboard/selectors.d.ts +6 -2
- package/dist/types/onboard/selectors.d.ts.map +1 -1
- package/dist/types/onboard/types.d.ts +1 -1
- package/dist/types/onboard/types.d.ts.map +1 -1
- package/dist/types/plans/queries/use-plans.d.ts.map +1 -1
- package/dist/types/purchases/lib/assembler.d.ts +3 -3
- package/dist/types/purchases/lib/assembler.d.ts.map +1 -1
- package/dist/types/purchases/types.d.ts +3 -109
- package/dist/types/purchases/types.d.ts.map +1 -1
- package/dist/types/queries/use-all-domains-query.d.ts +1 -1
- package/dist/types/queries/use-all-domains-query.d.ts.map +1 -1
- package/dist/types/queries/use-site-domains-query.d.ts +1 -1
- package/dist/types/queries/use-site-domains-query.d.ts.map +1 -1
- package/dist/types/queries/use-site-query.d.ts +1 -1
- package/dist/types/queries/use-site-query.d.ts.map +1 -1
- package/dist/types/reader/index.d.ts +472 -40
- package/dist/types/reader/index.d.ts.map +1 -1
- package/dist/types/reader/queries/use-pending-post-subscriptions-query.d.ts +75 -7
- package/dist/types/reader/queries/use-pending-post-subscriptions-query.d.ts.map +1 -1
- package/dist/types/reader/queries/use-pending-site-subscriptions-query.d.ts +75 -7
- package/dist/types/reader/queries/use-pending-site-subscriptions-query.d.ts.map +1 -1
- package/dist/types/reader/queries/use-post-subscriptions-query.d.ts +143 -13
- package/dist/types/reader/queries/use-post-subscriptions-query.d.ts.map +1 -1
- package/dist/types/reader/queries/use-site-subscriptions-query.d.ts +103 -13
- package/dist/types/reader/queries/use-site-subscriptions-query.d.ts.map +1 -1
- package/dist/types/site/types.d.ts +2 -0
- package/dist/types/site/types.d.ts.map +1 -1
- package/dist/types/user/actions.d.ts +1 -1
- package/dist/types/user/reducer.d.ts +1 -1
- package/dist/types/user/resolvers.d.ts +2 -2
- package/dist/types/user/selectors.d.ts +2 -2
- package/dist/types/user/selectors.d.ts.map +1 -1
- package/dist/types/user/types.d.ts +2 -33
- package/dist/types/user/types.d.ts.map +1 -1
- package/package.json +4 -8
- package/src/contextual-help/admin-sections.ts +1 -1
- package/src/help-center/actions.ts +85 -50
- package/src/help-center/reducer.ts +27 -15
- package/src/help-center/resolvers.ts +15 -8
- package/src/help-center/selectors.ts +4 -2
- package/src/help-center/types.ts +1 -0
- package/src/index.ts +0 -3
- package/src/onboard/actions.ts +13 -1
- package/src/onboard/reducer.ts +26 -1
- package/src/onboard/selectors.ts +2 -0
- package/src/onboard/types.ts +1 -1
- package/src/plans/queries/use-plans.ts +29 -1
- package/src/purchases/lib/assembler.ts +10 -25
- package/src/purchases/types.ts +4 -116
- package/src/site/types.ts +2 -0
- package/src/user/types.ts +2 -38
- package/dist/cjs/domain-suggestions/actions.js +0 -33
- package/dist/cjs/domain-suggestions/actions.js.map +0 -1
- package/dist/cjs/domain-suggestions/constants.js +0 -12
- package/dist/cjs/domain-suggestions/constants.js.map +0 -1
- package/dist/cjs/domain-suggestions/index.js +0 -25
- package/dist/cjs/domain-suggestions/index.js.map +0 -1
- package/dist/cjs/domain-suggestions/queries.js +0 -78
- package/dist/cjs/domain-suggestions/queries.js.map +0 -1
- package/dist/cjs/domain-suggestions/reducer.js +0 -65
- package/dist/cjs/domain-suggestions/reducer.js.map +0 -1
- package/dist/cjs/domain-suggestions/resolvers.js +0 -91
- package/dist/cjs/domain-suggestions/resolvers.js.map +0 -1
- package/dist/cjs/domain-suggestions/selectors.js +0 -58
- package/dist/cjs/domain-suggestions/selectors.js.map +0 -1
- package/dist/cjs/domain-suggestions/types.js +0 -3
- package/dist/cjs/domain-suggestions/types.js.map +0 -1
- package/dist/cjs/domain-suggestions/utils.js +0 -47
- package/dist/cjs/domain-suggestions/utils.js.map +0 -1
- package/dist/esm/domain-suggestions/actions.js +0 -25
- package/dist/esm/domain-suggestions/actions.js.map +0 -1
- package/dist/esm/domain-suggestions/constants.js +0 -9
- package/dist/esm/domain-suggestions/constants.js.map +0 -1
- package/dist/esm/domain-suggestions/index.js +0 -20
- package/dist/esm/domain-suggestions/index.js.map +0 -1
- package/dist/esm/domain-suggestions/queries.js +0 -72
- package/dist/esm/domain-suggestions/queries.js.map +0 -1
- package/dist/esm/domain-suggestions/reducer.js +0 -61
- package/dist/esm/domain-suggestions/reducer.js.map +0 -1
- package/dist/esm/domain-suggestions/resolvers.js +0 -84
- package/dist/esm/domain-suggestions/resolvers.js.map +0 -1
- package/dist/esm/domain-suggestions/selectors.js +0 -47
- package/dist/esm/domain-suggestions/selectors.js.map +0 -1
- package/dist/esm/domain-suggestions/types.js +0 -2
- package/dist/esm/domain-suggestions/types.js.map +0 -1
- package/dist/esm/domain-suggestions/utils.js +0 -41
- package/dist/esm/domain-suggestions/utils.js.map +0 -1
- package/dist/types/domain-suggestions/actions.d.ts +0 -27
- package/dist/types/domain-suggestions/actions.d.ts.map +0 -1
- package/dist/types/domain-suggestions/constants.d.ts +0 -8
- package/dist/types/domain-suggestions/constants.d.ts.map +0 -1
- package/dist/types/domain-suggestions/index.d.ts +0 -10
- package/dist/types/domain-suggestions/index.d.ts.map +0 -1
- package/dist/types/domain-suggestions/queries.d.ts +0 -323
- package/dist/types/domain-suggestions/queries.d.ts.map +0 -1
- package/dist/types/domain-suggestions/reducer.d.ts +0 -16
- package/dist/types/domain-suggestions/reducer.d.ts.map +0 -1
- package/dist/types/domain-suggestions/resolvers.d.ts +0 -39
- package/dist/types/domain-suggestions/resolvers.d.ts.map +0 -1
- package/dist/types/domain-suggestions/selectors.d.ts +0 -18
- package/dist/types/domain-suggestions/selectors.d.ts.map +0 -1
- package/dist/types/domain-suggestions/types.d.ts +0 -206
- package/dist/types/domain-suggestions/types.d.ts.map +0 -1
- package/dist/types/domain-suggestions/utils.d.ts +0 -23
- package/dist/types/domain-suggestions/utils.d.ts.map +0 -1
- package/src/domain-suggestions/actions.ts +0 -51
- package/src/domain-suggestions/constants.ts +0 -8
- package/src/domain-suggestions/index.ts +0 -22
- package/src/domain-suggestions/queries.ts +0 -85
- package/src/domain-suggestions/reducer.ts +0 -77
- package/src/domain-suggestions/resolvers.ts +0 -110
- package/src/domain-suggestions/selectors.ts +0 -86
- package/src/domain-suggestions/test/reducer.ts +0 -105
- package/src/domain-suggestions/test/selectors.ts +0 -127
- package/src/domain-suggestions/types.ts +0 -254
- package/src/domain-suggestions/utils.ts +0 -50
|
@@ -12,15 +12,46 @@ import type {
|
|
|
12
12
|
HelpCenterSelect,
|
|
13
13
|
HelpCenterShowOptions,
|
|
14
14
|
} from './types';
|
|
15
|
-
import type { SupportInteraction } from '@automattic/odie-client/src/types';
|
|
16
15
|
import type { Location } from 'history';
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Save the open state of the help center to the remote user preferences.
|
|
19
|
+
* @param isShown - Whether the help center is shown.
|
|
20
|
+
* @param isMinimized - Whether the help center is minimized.
|
|
21
|
+
*/
|
|
22
|
+
export const saveOpenState = ( isShown: boolean | undefined, isMinimized: boolean | undefined ) => {
|
|
23
|
+
const saveState: Record< string, boolean | null > = {};
|
|
24
|
+
|
|
25
|
+
if ( typeof isShown === 'boolean' ) {
|
|
26
|
+
saveState.help_center_open = isShown;
|
|
27
|
+
if ( ! isShown ) {
|
|
28
|
+
// Delete the remote version of the navigation history when closing the help center
|
|
29
|
+
saveState.help_center_router_history = null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if ( typeof isMinimized === 'boolean' ) {
|
|
34
|
+
saveState.help_center_minimized = isMinimized;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if ( canAccessWpcomApis() ) {
|
|
38
|
+
// Use the promise version to do that action without waiting for the result.
|
|
39
|
+
wpcomRequestPromise( {
|
|
40
|
+
path: '/me/preferences',
|
|
41
|
+
apiNamespace: 'wpcom/v2',
|
|
42
|
+
method: 'PUT',
|
|
43
|
+
body: { calypso_preferences: saveState },
|
|
44
|
+
} ).catch( () => {} );
|
|
45
|
+
} else {
|
|
46
|
+
// Use the promise version to do that action without waiting for the result.
|
|
47
|
+
apiFetchPromise( {
|
|
48
|
+
global: true,
|
|
49
|
+
path: '/help-center/open-state',
|
|
50
|
+
method: 'PUT',
|
|
51
|
+
data: saveState,
|
|
52
|
+
} as APIFetchOptions ).catch( () => {} );
|
|
53
|
+
}
|
|
54
|
+
};
|
|
24
55
|
|
|
25
56
|
export function setHelpCenterRouterHistory(
|
|
26
57
|
history: { entries: Location[]; index: number } | undefined
|
|
@@ -55,11 +86,13 @@ export const setOdieBotNameSlug = ( odieBotNameSlug: string ) =>
|
|
|
55
86
|
odieBotNameSlug,
|
|
56
87
|
} ) as const;
|
|
57
88
|
|
|
58
|
-
export const setIsMinimized = ( minimized: boolean )
|
|
59
|
-
(
|
|
89
|
+
export const setIsMinimized = function* ( minimized: boolean ) {
|
|
90
|
+
yield saveOpenState( undefined, minimized );
|
|
91
|
+
return {
|
|
60
92
|
type: 'HELP_CENTER_SET_MINIMIZED',
|
|
61
93
|
minimized,
|
|
62
|
-
}
|
|
94
|
+
} as const;
|
|
95
|
+
};
|
|
63
96
|
|
|
64
97
|
export const setIsChatLoaded = ( isChatLoaded: boolean ) =>
|
|
65
98
|
( {
|
|
@@ -79,6 +112,21 @@ export const setZendeskClientId = ( zendeskClientId: string ) =>
|
|
|
79
112
|
zendeskClientId,
|
|
80
113
|
} ) as const;
|
|
81
114
|
|
|
115
|
+
export const setZendeskConnectionStatus = (
|
|
116
|
+
connectionStatus: 'disconnected' | 'reconnecting' | 'connected'
|
|
117
|
+
) =>
|
|
118
|
+
( {
|
|
119
|
+
type: 'HELP_CENTER_SET_ZENDESK_CONNECTION_STATUS',
|
|
120
|
+
connectionStatus,
|
|
121
|
+
} ) as const;
|
|
122
|
+
|
|
123
|
+
export const setSupportTypingStatus = ( conversationId: string, isTyping: false ) =>
|
|
124
|
+
( {
|
|
125
|
+
type: 'HELP_CENTER_SET_TYPING_STATUS',
|
|
126
|
+
conversationId,
|
|
127
|
+
isTyping,
|
|
128
|
+
} ) as const;
|
|
129
|
+
|
|
82
130
|
export const setShowMessagingLauncher = ( show: boolean ) =>
|
|
83
131
|
( {
|
|
84
132
|
type: 'HELP_CENTER_SET_SHOW_MESSAGING_LAUNCHER',
|
|
@@ -103,9 +151,9 @@ export const setContextTerm = ( contextTerm: string ) =>
|
|
|
103
151
|
contextTerm,
|
|
104
152
|
} ) as const;
|
|
105
153
|
|
|
106
|
-
export const
|
|
154
|
+
export const setHasPremiumSupport = ( allow: boolean ) =>
|
|
107
155
|
( {
|
|
108
|
-
type: '
|
|
156
|
+
type: 'HELP_CENTER_SET_HAS_PREMIUM_SUPPORT',
|
|
109
157
|
allow,
|
|
110
158
|
} ) as const;
|
|
111
159
|
|
|
@@ -116,13 +164,24 @@ export const setHelpCenterOptions = ( options: HelpCenterOptions ) => ( {
|
|
|
116
164
|
|
|
117
165
|
export const setShowHelpCenter = function* (
|
|
118
166
|
show: boolean,
|
|
119
|
-
|
|
120
|
-
|
|
167
|
+
options: HelpCenterShowOptions = {
|
|
168
|
+
hasPremiumSupport: false,
|
|
169
|
+
hideBackButton: false,
|
|
170
|
+
contextTerm: '',
|
|
171
|
+
},
|
|
172
|
+
/**
|
|
173
|
+
* When the Help Center is minimized and someone clicks the (?) toggle button, we should maximize it.
|
|
174
|
+
* But this means ignoring the `show=false` value the button will send. The problem is we'll also ignore the `show=false` when the close (x) buttons is clicked too.
|
|
175
|
+
* `forceClose` listens to the show value always. Which the (x) button sets to true.
|
|
176
|
+
*/
|
|
177
|
+
forceClose = false
|
|
121
178
|
): Generator< unknown, { type: 'HELP_CENTER_SET_SHOW'; show: boolean }, unknown > {
|
|
122
|
-
|
|
179
|
+
let isMinimized = ( select( STORE_KEY ) as HelpCenterSelect ).getIsMinimized();
|
|
123
180
|
|
|
124
|
-
|
|
181
|
+
// Opening or closing the Help Center should reset the minimized state.
|
|
182
|
+
if ( ! show && ! forceClose && isMinimized ) {
|
|
125
183
|
yield setIsMinimized( false );
|
|
184
|
+
isMinimized = false;
|
|
126
185
|
|
|
127
186
|
return {
|
|
128
187
|
type: 'HELP_CENTER_SET_SHOW',
|
|
@@ -131,37 +190,12 @@ export const setShowHelpCenter = function* (
|
|
|
131
190
|
}
|
|
132
191
|
|
|
133
192
|
if ( ! isE2ETest() ) {
|
|
134
|
-
|
|
135
|
-
// Use the promise version to do that action without waiting for the result.
|
|
136
|
-
wpcomRequestPromise( {
|
|
137
|
-
path: '/me/preferences',
|
|
138
|
-
apiNamespace: 'wpcom/v2',
|
|
139
|
-
method: 'PUT',
|
|
140
|
-
body: {
|
|
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
|
-
},
|
|
146
|
-
},
|
|
147
|
-
} ).catch( () => {} );
|
|
148
|
-
} else {
|
|
149
|
-
// Use the promise version to do that action without waiting for the result.
|
|
150
|
-
apiFetchPromise( {
|
|
151
|
-
global: true,
|
|
152
|
-
path: '/help-center/open-state',
|
|
153
|
-
method: 'PUT',
|
|
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
|
-
},
|
|
158
|
-
} as APIFetchOptions ).catch( () => {} );
|
|
159
|
-
}
|
|
193
|
+
saveOpenState( show, isMinimized );
|
|
160
194
|
}
|
|
161
195
|
|
|
162
196
|
if ( ! show ) {
|
|
163
197
|
yield setNavigateToRoute( undefined );
|
|
164
|
-
// Reset the local navigation history when closing the help center
|
|
198
|
+
// Reset the local navigation history when closing the help center.
|
|
165
199
|
yield setHelpCenterRouterHistory( undefined );
|
|
166
200
|
} else {
|
|
167
201
|
yield setShowMessagingWidget( false );
|
|
@@ -170,11 +204,11 @@ export const setShowHelpCenter = function* (
|
|
|
170
204
|
yield setContextTerm( options?.contextTerm || '' );
|
|
171
205
|
yield setIsMinimized( false );
|
|
172
206
|
|
|
173
|
-
if (
|
|
174
|
-
yield
|
|
207
|
+
if ( options?.hasPremiumSupport ) {
|
|
208
|
+
yield setHasPremiumSupport( true );
|
|
175
209
|
}
|
|
176
210
|
|
|
177
|
-
if ( options
|
|
211
|
+
if ( options ) {
|
|
178
212
|
yield setHelpCenterOptions( options );
|
|
179
213
|
}
|
|
180
214
|
|
|
@@ -260,16 +294,17 @@ export type HelpCenterAction =
|
|
|
260
294
|
| typeof setUserDeclaredSite
|
|
261
295
|
| typeof setUserDeclaredSiteUrl
|
|
262
296
|
| typeof setUnreadCount
|
|
263
|
-
| typeof setIsMinimized
|
|
264
297
|
| typeof setHelpCenterRouterHistory
|
|
265
298
|
| typeof setIsChatLoaded
|
|
266
299
|
| typeof setAreSoundNotificationsEnabled
|
|
267
300
|
| typeof setZendeskClientId
|
|
301
|
+
| typeof setSupportTypingStatus
|
|
302
|
+
| typeof setZendeskConnectionStatus
|
|
268
303
|
| typeof setNavigateToRoute
|
|
269
304
|
| typeof setOdieInitialPromptText
|
|
270
305
|
| typeof setOdieBotNameSlug
|
|
271
|
-
| typeof
|
|
272
|
-
| typeof setAllowPremiumSupport
|
|
306
|
+
| typeof setHasPremiumSupport
|
|
273
307
|
| typeof setHelpCenterOptions
|
|
274
308
|
>
|
|
275
|
-
| GeneratorReturnType< typeof setShowHelpCenter
|
|
309
|
+
| GeneratorReturnType< typeof setShowHelpCenter >
|
|
310
|
+
| GeneratorReturnType< typeof setIsMinimized >;
|
|
@@ -2,7 +2,6 @@ import { combineReducers } from '@wordpress/data';
|
|
|
2
2
|
import { SiteDetails } from '../site';
|
|
3
3
|
import type { HelpCenterAction } from './actions';
|
|
4
4
|
import type { HelpCenterOptions } from './types';
|
|
5
|
-
import type { SupportInteraction } from '@automattic/odie-client/src/types';
|
|
6
5
|
import type { Location } from 'history';
|
|
7
6
|
import type { Reducer } from 'redux';
|
|
8
7
|
|
|
@@ -14,6 +13,28 @@ const showHelpCenter: Reducer< boolean | undefined, HelpCenterAction > = ( state
|
|
|
14
13
|
return state;
|
|
15
14
|
};
|
|
16
15
|
|
|
16
|
+
const typingConversationStatus: Reducer<
|
|
17
|
+
Record< string, boolean > | undefined,
|
|
18
|
+
HelpCenterAction
|
|
19
|
+
> = ( state = undefined, action ) => {
|
|
20
|
+
switch ( action.type ) {
|
|
21
|
+
case 'HELP_CENTER_SET_TYPING_STATUS':
|
|
22
|
+
return { ...state, [ action.conversationId ]: action.isTyping };
|
|
23
|
+
}
|
|
24
|
+
return state;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const zendeskConnectionStatus: Reducer<
|
|
28
|
+
'disconnected' | 'reconnecting' | 'connected' | undefined,
|
|
29
|
+
HelpCenterAction
|
|
30
|
+
> = ( state = undefined, action ) => {
|
|
31
|
+
switch ( action.type ) {
|
|
32
|
+
case 'HELP_CENTER_SET_ZENDESK_CONNECTION_STATUS':
|
|
33
|
+
return action.connectionStatus;
|
|
34
|
+
}
|
|
35
|
+
return state;
|
|
36
|
+
};
|
|
37
|
+
|
|
17
38
|
const showMessagingLauncher: Reducer< boolean | undefined, HelpCenterAction > = (
|
|
18
39
|
state,
|
|
19
40
|
action
|
|
@@ -44,16 +65,6 @@ const showMessagingWidget: Reducer< boolean | undefined, HelpCenterAction > = (
|
|
|
44
65
|
return state;
|
|
45
66
|
};
|
|
46
67
|
|
|
47
|
-
const currentSupportInteraction: Reducer< SupportInteraction | undefined, HelpCenterAction > = (
|
|
48
|
-
state,
|
|
49
|
-
action
|
|
50
|
-
) => {
|
|
51
|
-
if ( action.type === 'HELP_CENTER_SET_CURRENT_SUPPORT_INTERACTION' ) {
|
|
52
|
-
return action.supportInteraction;
|
|
53
|
-
}
|
|
54
|
-
return state;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
68
|
const isMinimized: Reducer< boolean, HelpCenterAction > = ( state = false, action ) => {
|
|
58
69
|
switch ( action.type ) {
|
|
59
70
|
case 'HELP_CENTER_SET_MINIMIZED':
|
|
@@ -161,9 +172,9 @@ const odieBotNameSlug: Reducer< string | undefined, HelpCenterAction > = ( state
|
|
|
161
172
|
return state;
|
|
162
173
|
};
|
|
163
174
|
|
|
164
|
-
const
|
|
175
|
+
const hasPremiumSupport: Reducer< boolean, HelpCenterAction > = ( state = false, action ) => {
|
|
165
176
|
switch ( action.type ) {
|
|
166
|
-
case '
|
|
177
|
+
case 'HELP_CENTER_SET_HAS_PREMIUM_SUPPORT':
|
|
167
178
|
return action.allow;
|
|
168
179
|
}
|
|
169
180
|
return state;
|
|
@@ -187,16 +198,17 @@ const helpCenterOptions: Reducer< HelpCenterOptions, HelpCenterAction > = (
|
|
|
187
198
|
};
|
|
188
199
|
|
|
189
200
|
const reducer = combineReducers( {
|
|
190
|
-
currentSupportInteraction,
|
|
191
201
|
showHelpCenter,
|
|
192
202
|
showMessagingLauncher,
|
|
193
203
|
showMessagingWidget,
|
|
204
|
+
zendeskConnectionStatus,
|
|
194
205
|
subject,
|
|
195
206
|
message,
|
|
196
207
|
userDeclaredSite,
|
|
197
208
|
userDeclaredSiteUrl,
|
|
198
209
|
isMinimized,
|
|
199
210
|
isChatLoaded,
|
|
211
|
+
typingConversationStatus,
|
|
200
212
|
areSoundNotificationsEnabled,
|
|
201
213
|
zendeskClientId,
|
|
202
214
|
unreadCount,
|
|
@@ -204,7 +216,7 @@ const reducer = combineReducers( {
|
|
|
204
216
|
odieInitialPromptText,
|
|
205
217
|
odieBotNameSlug,
|
|
206
218
|
helpCenterRouterHistory,
|
|
207
|
-
|
|
219
|
+
hasPremiumSupport,
|
|
208
220
|
contextTerm,
|
|
209
221
|
helpCenterOptions,
|
|
210
222
|
} );
|
|
@@ -1,19 +1,24 @@
|
|
|
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
|
+
import { setHelpCenterRouterHistory, setIsMinimized } from './actions';
|
|
5
5
|
import type { APIFetchOptions } from './types';
|
|
6
6
|
import type { Location } from 'history';
|
|
7
7
|
|
|
8
|
+
type Preferences = {
|
|
9
|
+
calypso_preferences: {
|
|
10
|
+
help_center_open: boolean;
|
|
11
|
+
help_center_minimized: boolean;
|
|
12
|
+
help_center_router_history: {
|
|
13
|
+
entries: Location[];
|
|
14
|
+
index: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
8
19
|
export function* isHelpCenterShown() {
|
|
9
20
|
try {
|
|
10
|
-
const preferences:
|
|
11
|
-
help_center_open: boolean;
|
|
12
|
-
help_center_router_history: {
|
|
13
|
-
entries: Location[];
|
|
14
|
-
index: number;
|
|
15
|
-
};
|
|
16
|
-
} = canAccessWpcomApis()
|
|
21
|
+
const { calypso_preferences: preferences }: Preferences = canAccessWpcomApis()
|
|
17
22
|
? yield wpcomRequest( {
|
|
18
23
|
path: '/me/preferences',
|
|
19
24
|
apiNamespace: 'wpcom/v2',
|
|
@@ -27,6 +32,8 @@ export function* isHelpCenterShown() {
|
|
|
27
32
|
yield setHelpCenterRouterHistory( preferences.help_center_router_history );
|
|
28
33
|
}
|
|
29
34
|
|
|
35
|
+
yield setIsMinimized( preferences.help_center_minimized );
|
|
36
|
+
|
|
30
37
|
// We only want to auto-open, we don't want to auto-close (and potentially overrule the user's action).
|
|
31
38
|
if ( preferences.help_center_open ) {
|
|
32
39
|
return {
|
|
@@ -8,6 +8,7 @@ export const getMessage = ( state: State ) => state.message;
|
|
|
8
8
|
export const getUserDeclaredSiteUrl = ( state: State ) => state.userDeclaredSiteUrl;
|
|
9
9
|
export const getUserDeclaredSite = ( state: State ) => state.userDeclaredSite;
|
|
10
10
|
export const getUnreadCount = ( state: State ) => state.unreadCount;
|
|
11
|
+
export const getZendeskConnectionStatus = ( state: State ) => state.zendeskConnectionStatus;
|
|
11
12
|
export const getIsMinimized = ( state: State ) => state.isMinimized;
|
|
12
13
|
export const getIsChatLoaded = ( state: State ) => state.isChatLoaded;
|
|
13
14
|
export const getAreSoundNotificationsEnabled = ( state: State ) =>
|
|
@@ -17,7 +18,8 @@ export const getHelpCenterRouterHistory = ( state: State ) => state.helpCenterRo
|
|
|
17
18
|
export const getNavigateToRoute = ( state: State ) => state.navigateToRoute;
|
|
18
19
|
export const getOdieInitialPromptText = ( state: State ) => state.odieInitialPromptText;
|
|
19
20
|
export const getOdieBotNameSlug = ( state: State ) => state.odieBotNameSlug;
|
|
20
|
-
export const
|
|
21
|
-
export const getAllowPremiumSupport = ( state: State ) => state.allowPremiumSupport;
|
|
21
|
+
export const getHasPremiumSupport = ( state: State ) => state.hasPremiumSupport;
|
|
22
22
|
export const getHelpCenterOptions = ( state: State ) => state.helpCenterOptions;
|
|
23
23
|
export const getContextTerm = ( state: State ) => state.contextTerm;
|
|
24
|
+
export const getSupportTypingStatus = ( state: State, conversationId: string ) =>
|
|
25
|
+
state.typingConversationStatus?.[ conversationId ];
|
package/src/help-center/types.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as AddOns from './add-ons';
|
|
2
|
-
import * as DomainSuggestions from './domain-suggestions';
|
|
3
2
|
import * as HelpCenter from './help-center';
|
|
4
3
|
import * as Onboard from './onboard';
|
|
5
4
|
import * as Plans from './plans';
|
|
@@ -19,7 +18,6 @@ export * from './starter-designs-queries';
|
|
|
19
18
|
export * from './site/types';
|
|
20
19
|
export * from './templates';
|
|
21
20
|
export * from './onboard/types';
|
|
22
|
-
export * from './domain-suggestions/types';
|
|
23
21
|
export * from './plans/types';
|
|
24
22
|
export * from './theme';
|
|
25
23
|
export * from './user/types';
|
|
@@ -38,7 +36,6 @@ const { SubscriptionManager } = Reader;
|
|
|
38
36
|
export {
|
|
39
37
|
AddOns,
|
|
40
38
|
User,
|
|
41
|
-
DomainSuggestions,
|
|
42
39
|
HelpCenter,
|
|
43
40
|
Site,
|
|
44
41
|
Plans,
|
package/src/onboard/actions.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { Visibility, GlobalStyles } from '../site/types';
|
|
|
6
6
|
import { SiteGoal, STORE_KEY } from './constants';
|
|
7
7
|
import { ProfilerData, ReadymadeTemplate } from './types';
|
|
8
8
|
import type { DomainTransferData, State } from '.';
|
|
9
|
-
import type { DomainSuggestion } from '../domain-suggestions';
|
|
10
9
|
import type { FeatureId } from '../shared-types';
|
|
10
|
+
import type { DomainSuggestion } from '@automattic/api-core';
|
|
11
11
|
// somewhat hacky, but resolves the circular dependency issue
|
|
12
12
|
import type { Design, StyleVariation } from '@automattic/design-picker/src/types';
|
|
13
13
|
import type { MinimalRequestCartProduct } from '@automattic/shopping-cart';
|
|
@@ -363,6 +363,16 @@ export const setPartnerBundle = ( partnerBundle: string | null ) => ( {
|
|
|
363
363
|
partnerBundle,
|
|
364
364
|
} );
|
|
365
365
|
|
|
366
|
+
export const setGardenName = ( gardenName: string | null ) => ( {
|
|
367
|
+
type: 'SET_GARDEN_NAME' as const,
|
|
368
|
+
gardenName,
|
|
369
|
+
} );
|
|
370
|
+
|
|
371
|
+
export const setGardenPartnerName = ( gardenPartnerName: string | null ) => ( {
|
|
372
|
+
type: 'SET_GARDEN_PARTNER_NAME' as const,
|
|
373
|
+
gardenPartnerName,
|
|
374
|
+
} );
|
|
375
|
+
|
|
366
376
|
export type OnboardAction = ReturnType<
|
|
367
377
|
| typeof addFeature
|
|
368
378
|
| typeof removeFeature
|
|
@@ -422,4 +432,6 @@ export type OnboardAction = ReturnType<
|
|
|
422
432
|
| typeof setPaidSubscribers
|
|
423
433
|
| typeof setPartnerBundle
|
|
424
434
|
| typeof setSignupDomainOrigin
|
|
435
|
+
| typeof setGardenName
|
|
436
|
+
| typeof setGardenPartnerName
|
|
425
437
|
>;
|
package/src/onboard/reducer.ts
CHANGED
|
@@ -8,9 +8,9 @@ import type {
|
|
|
8
8
|
DomainTransferAuthCodes,
|
|
9
9
|
ReadymadeTemplate,
|
|
10
10
|
} from './types';
|
|
11
|
-
import type { DomainSuggestion } from '../domain-suggestions';
|
|
12
11
|
import type { FeatureId } from '../shared-types';
|
|
13
12
|
import type { GlobalStyles } from '../site';
|
|
13
|
+
import type { DomainSuggestion } from '@automattic/api-core';
|
|
14
14
|
// somewhat hacky, but resolves the circular dependency issue
|
|
15
15
|
import type { Design, StyleVariation } from '@automattic/design-picker/src/types';
|
|
16
16
|
import type { MinimalRequestCartProduct } from '@automattic/shopping-cart';
|
|
@@ -612,6 +612,29 @@ const signupDomainOrigin: Reducer< string | undefined, OnboardAction > = (
|
|
|
612
612
|
return state;
|
|
613
613
|
};
|
|
614
614
|
|
|
615
|
+
export const gardenName: Reducer< string | null, OnboardAction > = ( state = null, action ) => {
|
|
616
|
+
if ( action.type === 'SET_GARDEN_NAME' ) {
|
|
617
|
+
return action.gardenName;
|
|
618
|
+
}
|
|
619
|
+
if ( action.type === 'RESET_ONBOARD_STORE' ) {
|
|
620
|
+
return null;
|
|
621
|
+
}
|
|
622
|
+
return state;
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
export const gardenPartnerName: Reducer< string | null, OnboardAction > = (
|
|
626
|
+
state = null,
|
|
627
|
+
action
|
|
628
|
+
) => {
|
|
629
|
+
if ( action.type === 'SET_GARDEN_PARTNER_NAME' ) {
|
|
630
|
+
return action.gardenPartnerName;
|
|
631
|
+
}
|
|
632
|
+
if ( action.type === 'RESET_ONBOARD_STORE' ) {
|
|
633
|
+
return null;
|
|
634
|
+
}
|
|
635
|
+
return state;
|
|
636
|
+
};
|
|
637
|
+
|
|
615
638
|
const reducer = combineReducers( {
|
|
616
639
|
domain,
|
|
617
640
|
domainCartItem,
|
|
@@ -660,6 +683,8 @@ const reducer = combineReducers( {
|
|
|
660
683
|
paidSubscribers,
|
|
661
684
|
partnerBundle,
|
|
662
685
|
signupDomainOrigin,
|
|
686
|
+
gardenName,
|
|
687
|
+
gardenPartnerName,
|
|
663
688
|
} );
|
|
664
689
|
|
|
665
690
|
export type State = ReturnType< typeof reducer >;
|
package/src/onboard/selectors.ts
CHANGED
|
@@ -81,3 +81,5 @@ export const getPluginsToVerify = ( state: State ) => state.pluginsToVerify;
|
|
|
81
81
|
export const getProfilerData = ( state: State ) => state.profilerData;
|
|
82
82
|
export const getPaidSubscribers = ( state: State ) => state.paidSubscribers;
|
|
83
83
|
export const getPartnerBundle = ( state: State ) => state.partnerBundle;
|
|
84
|
+
export const getGardenName = ( state: State ) => state.gardenName;
|
|
85
|
+
export const getGardenPartnerName = ( state: State ) => state.gardenPartnerName;
|
package/src/onboard/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isEnabled } from '@automattic/calypso-config';
|
|
1
2
|
import { calculateMonthlyPriceForPlan } from '@automattic/calypso-products';
|
|
2
3
|
import { useLocale } from '@automattic/i18n-utils';
|
|
3
4
|
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
@@ -10,6 +11,28 @@ interface PlansIndex {
|
|
|
10
11
|
[ planSlug: string ]: PlanNext;
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
type RequestFunction = ( params: {
|
|
15
|
+
path: string;
|
|
16
|
+
apiVersion: string;
|
|
17
|
+
query: string;
|
|
18
|
+
} ) => Promise< PricedAPIPlan[] >;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Request function for Jetpack that bypasses proxy and goes directly to WordPress.com
|
|
22
|
+
*/
|
|
23
|
+
const jetpackRequestFunction: RequestFunction = async ( params ) => {
|
|
24
|
+
const queryParams = params.query ? `?${ params.query }` : '';
|
|
25
|
+
const url = `https://public-api.wordpress.com/rest/v${ params.apiVersion }${ params.path }${ queryParams }`;
|
|
26
|
+
const response = await fetch( url, {
|
|
27
|
+
method: 'GET',
|
|
28
|
+
credentials: 'omit', // Don't send cookies to avoid CORS issues
|
|
29
|
+
} );
|
|
30
|
+
if ( ! response.ok ) {
|
|
31
|
+
throw new Error( `API request failed: ${ response.status }` );
|
|
32
|
+
}
|
|
33
|
+
return response.json();
|
|
34
|
+
};
|
|
35
|
+
|
|
13
36
|
/**
|
|
14
37
|
* Plans from `/plans` endpoint, transformed into a map of planSlug => PlanNext
|
|
15
38
|
*/
|
|
@@ -27,10 +50,15 @@ function usePlans( {
|
|
|
27
50
|
coupon && params.append( 'coupon_code', coupon );
|
|
28
51
|
params.append( 'locale', locale );
|
|
29
52
|
|
|
53
|
+
// Auto-detect Jetpack context and use appropriate request function
|
|
54
|
+
const isJetpack = isEnabled( 'is_running_in_jetpack_site' );
|
|
55
|
+
|
|
56
|
+
const requestFn = isJetpack ? jetpackRequestFunction : wpcomRequest;
|
|
57
|
+
|
|
30
58
|
return useQuery( {
|
|
31
59
|
queryKey: queryKeys.plans( coupon ),
|
|
32
60
|
queryFn: async (): Promise< PlansIndex > => {
|
|
33
|
-
const data: PricedAPIPlan[] = await
|
|
61
|
+
const data: PricedAPIPlan[] = await requestFn( {
|
|
34
62
|
path: '/plans',
|
|
35
63
|
apiVersion: '1.5',
|
|
36
64
|
query: params.toString(),
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { snakeToCamelCase } from '@automattic/js-utils';
|
|
2
|
-
import type { PurchasePriceTier, Purchase, RawPurchase
|
|
2
|
+
import type { PurchasePriceTier, Purchase, RawPurchase } from '../types';
|
|
3
3
|
|
|
4
|
-
export function createPurchaseObject( purchase: RawPurchase
|
|
4
|
+
export function createPurchaseObject( purchase: RawPurchase ): Purchase {
|
|
5
5
|
const object: Purchase = {
|
|
6
6
|
id: Number( purchase.ID ),
|
|
7
|
-
active: Boolean( purchase.active ),
|
|
8
7
|
amount: Number( purchase.amount ),
|
|
9
8
|
attachedToPurchaseId: Number( purchase.attached_to_purchase_id ),
|
|
10
9
|
autoRenewCouponCode: purchase.auto_renew_coupon_code,
|
|
@@ -16,9 +15,6 @@ export function createPurchaseObject( purchase: RawPurchase | RawPurchaseCreditC
|
|
|
16
15
|
canDisableAutoRenew: Boolean( purchase.can_disable_auto_renew ),
|
|
17
16
|
canReenableAutoRenewal: Boolean( purchase.can_reenable_auto_renewal ),
|
|
18
17
|
canExplicitRenew: Boolean( purchase.can_explicit_renew ),
|
|
19
|
-
costToUnbundle: purchase.cost_to_unbundle
|
|
20
|
-
? Number( purchase.cost_to_unbundle )
|
|
21
|
-
: Number( purchase.amount ),
|
|
22
18
|
costToUnbundleText: purchase.cost_to_unbundle_display
|
|
23
19
|
? purchase.cost_to_unbundle_display
|
|
24
20
|
: purchase.price_text,
|
|
@@ -27,7 +23,6 @@ export function createPurchaseObject( purchase: RawPurchase | RawPurchaseCreditC
|
|
|
27
23
|
description: purchase.description,
|
|
28
24
|
domain: purchase.domain,
|
|
29
25
|
domainRegistrationAgreementUrl: purchase.domain_registration_agreement_url || null,
|
|
30
|
-
error: null,
|
|
31
26
|
blogCreatedDate: purchase.blog_created_date,
|
|
32
27
|
expiryDate: purchase.expiry_date,
|
|
33
28
|
expiryStatus: snakeToCamelCase( purchase.expiry_status ),
|
|
@@ -117,26 +112,20 @@ export function createPurchaseObject( purchase: RawPurchase | RawPurchaseCreditC
|
|
|
117
112
|
siteSlug: purchase.site_slug,
|
|
118
113
|
subscribedDate: purchase.subscribed_date,
|
|
119
114
|
subscriptionStatus: purchase.subscription_status,
|
|
120
|
-
tagLine: purchase.tag_line,
|
|
121
|
-
taxAmount: purchase.tax_amount,
|
|
122
|
-
taxText: purchase.tax_text,
|
|
123
115
|
purchaseRenewalQuantity: purchase.renewal_price_tier_usage_quantity || null,
|
|
124
116
|
userId: Number( purchase.user_id ),
|
|
125
|
-
isAutoRenewEnabled:
|
|
117
|
+
isAutoRenewEnabled: purchase.is_auto_renew_enabled,
|
|
118
|
+
isJetpackPlanOrProduct: purchase.is_jetpack_plan_or_product,
|
|
126
119
|
};
|
|
127
120
|
|
|
128
|
-
if ( purchase.purchaser_id ) {
|
|
129
|
-
object.purchaserId = Number( purchase.purchaser_id );
|
|
130
|
-
}
|
|
131
|
-
|
|
132
121
|
if ( isCreditCardPurchase( purchase ) ) {
|
|
133
122
|
object.payment.creditCard = {
|
|
134
123
|
id: Number( purchase.payment_card_id ),
|
|
135
|
-
type: purchase.payment_card_type,
|
|
124
|
+
type: purchase.payment_card_type ?? '',
|
|
136
125
|
displayBrand: purchase.payment_card_display_brand,
|
|
137
|
-
processor: purchase.payment_card_processor,
|
|
138
|
-
number: purchase.payment_details,
|
|
139
|
-
expiryDate: purchase.payment_expiry,
|
|
126
|
+
processor: purchase.payment_card_processor ?? '',
|
|
127
|
+
number: purchase.payment_details ?? '',
|
|
128
|
+
expiryDate: purchase.payment_expiry ?? '',
|
|
140
129
|
};
|
|
141
130
|
}
|
|
142
131
|
|
|
@@ -147,15 +136,11 @@ export function createPurchaseObject( purchase: RawPurchase | RawPurchaseCreditC
|
|
|
147
136
|
return object;
|
|
148
137
|
}
|
|
149
138
|
|
|
150
|
-
function isCreditCardPurchase(
|
|
151
|
-
purchase: RawPurchase | RawPurchaseCreditCard
|
|
152
|
-
): purchase is RawPurchaseCreditCard {
|
|
139
|
+
function isCreditCardPurchase( purchase: RawPurchase ): boolean {
|
|
153
140
|
return purchase.payment_type === 'credit_card';
|
|
154
141
|
}
|
|
155
142
|
|
|
156
|
-
export function createPurchasesArray(
|
|
157
|
-
dataTransferObject: undefined | ( RawPurchase | RawPurchaseCreditCard )[]
|
|
158
|
-
): Purchase[] {
|
|
143
|
+
export function createPurchasesArray( dataTransferObject: undefined | RawPurchase[] ): Purchase[] {
|
|
159
144
|
if ( ! Array.isArray( dataTransferObject ) ) {
|
|
160
145
|
return [];
|
|
161
146
|
}
|