Skip to content

Commit 74f0bf9

Browse files
committed
Progress
1 parent d05eccc commit 74f0bf9

File tree

12 files changed

+24
-80
lines changed

12 files changed

+24
-80
lines changed

packages/data-stores/src/help-center/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Location } from 'history';
55
import { default as wpcomRequestPromise, canAccessWpcomApis } from 'wpcom-proxy-request';
66
import { GeneratorReturnType } from '../mapped-types';
77
import { SiteDetails } from '../site';
8-
import { isE2ETest, isLoggedIn } from '../utils';
8+
import { isE2ETest, isLoggedInHCUser } from '../utils';
99
import { STORE_KEY } from './constants';
1010
import type { HelpCenterOptions, HelpCenterSelect, HelpCenterShowOptions } from './types';
1111
import type { APIFetchOptions } from '../shared-types';
@@ -16,7 +16,7 @@ import type { APIFetchOptions } from '../shared-types';
1616
* @param isMinimized - Whether the help center is minimized.
1717
*/
1818
export const saveOpenState = ( isShown: boolean | undefined, isMinimized: boolean | undefined ) => {
19-
if ( ! isLoggedIn() ) {
19+
if ( ! isLoggedInHCUser() ) {
2020
return null;
2121
}
2222

packages/data-stores/src/help-center/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { registerStore } from '@wordpress/data';
22
import { controls } from '@wordpress/data-controls';
33
import { registerPlugins } from '../plugins';
4-
import { isE2ETest, isInSupportSession, isLoggedIn } from '../utils';
4+
import { isE2ETest, isInSupportSession, isLoggedInHCUser } from '../utils';
55
import { controls as wpcomRequestControls } from '../wpcom-request-controls';
66
import * as actions from './actions';
77
import { STORE_KEY } from './constants';
@@ -13,7 +13,7 @@ export type { State };
1313
let isRegistered = false;
1414

1515
export function register(): typeof STORE_KEY {
16-
const enabledPersistedOpenState = ! isE2ETest() && ! isInSupportSession() && isLoggedIn();
16+
const enabledPersistedOpenState = ! isE2ETest() && ! isInSupportSession() && isLoggedInHCUser();
1717

1818
registerPlugins();
1919

packages/data-stores/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ export type { StepperInternalSelect } from './stepper-internal';
7474
export type { SiteActions } from './site';
7575
export type { UserActions } from './user';
7676
export type { Member, UseQuery, UsersQuery } from './users/types';
77-
export { isE2ETest, isInSupportSession } from './utils';
77+
export { isE2ETest, isInSupportSession, isLoggedInHCUser } from './utils';

packages/data-stores/src/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ export const isInSupportSession = () => {
3333
return false;
3434
};
3535

36-
export const isLoggedIn = () => {
36+
/**
37+
* Check if the user is logged in in a synchronous way. Works in wp-admin and Calypso.
38+
* @returns True if the user is logged in, false otherwise.
39+
*/
40+
export const isLoggedInHCUser = () => {
3741
return (
3842
// Calypso
3943
( typeof window !== 'undefined' && !! window.currentUser?.ID ) ||

packages/help-center/src/components/help-center.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
import UnifiedAIAgent from '@automattic/agents-manager';
66
import { initializeAnalytics } from '@automattic/calypso-analytics';
7-
import { useGetSupportInteractions } from '@automattic/odie-client/src/data/use-get-support-interactions';
87
import { useCanConnectToZendeskMessaging } from '@automattic/zendesk-client';
98
import { useSelect } from '@wordpress/data';
109
import { createPortal, useEffect, useState } from '@wordpress/element';
@@ -16,6 +15,7 @@ import {
1615
useHelpCenterContext,
1716
type HelpCenterRequiredInformation,
1817
} from '../contexts/HelpCenterContext';
18+
import { useGetSupportInteractions } from '../data/use-get-support-interactions';
1919
import { useChatStatus, useShouldUseUnifiedAgent } from '../hooks';
2020
import { HELP_CENTER_STORE } from '../stores';
2121
import { Container } from '../types';

packages/odie-client/src/data/use-get-support-interactions.ts renamed to packages/help-center/src/data/use-get-support-interactions.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { isLoggedInHCUser } from '@automattic/data-stores';
2+
import { handleSupportInteractionsFetch } from '@automattic/odie-client/src/data/handle-support-interactions-fetch';
13
import { isTestModeEnvironment, useCanConnectToZendeskMessaging } from '@automattic/zendesk-client';
24
import { useQuery } from '@tanstack/react-query';
3-
import { useOdieAssistantContext } from '../context';
4-
import { handleSupportInteractionsFetch } from './handle-support-interactions-fetch';
5-
import type { SupportProvider } from '../types';
5+
import { useHelpCenterContext } from '../contexts/HelpCenterContext';
6+
import type { SupportProvider } from '@automattic/odie-client';
67

78
/**
89
* Get the support interactions.
@@ -13,8 +14,9 @@ export const useGetSupportInteractions = (
1314
enabled = true
1415
) => {
1516
const isTestMode = isTestModeEnvironment();
16-
const { currentUser } = useOdieAssistantContext();
17-
const { data: canConnectToZendesk } = useCanConnectToZendeskMessaging( !! currentUser?.ID );
17+
const { currentUser } = useHelpCenterContext();
18+
const { data: canConnectToZendesk } = useCanConnectToZendeskMessaging( isLoggedInHCUser() );
19+
1820
let shouldFetch = enabled && !! currentUser?.ID;
1921
// Only fetch Zendesk interactions if the user can connect to Zendesk.
2022
if ( ( provider === 'zendesk' || provider === 'zendesk-staging' ) && ! canConnectToZendesk ) {

packages/help-center/src/hooks/use-get-history-chats.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { HelpCenterSelect } from '@automattic/data-stores';
33
import { convertOdieChatToOdieConversation } from '@automattic/odie-client';
44
import { useGetOdieConversations } from '@automattic/odie-client/src/data/use-get-odie-conversations';
5-
import { useGetSupportInteractions } from '@automattic/odie-client/src/data/use-get-support-interactions';
65
import { useOdieChat } from '@automattic/odie-client/src/data/use-odie-chat';
76
import { useSelect } from '@wordpress/data';
87
import { useEffect, useMemo, useState } from '@wordpress/element';
@@ -11,6 +10,7 @@ import {
1110
getLastMessage,
1211
getZendeskConversations,
1312
} from '../components/utils';
13+
import { useGetSupportInteractions } from '../data/use-get-support-interactions';
1414
import { HELP_CENTER_STORE } from '../stores';
1515
import type {
1616
Conversations,
@@ -146,18 +146,6 @@ export const useGetHistoryChats = (): UseGetHistoryChatsResult => {
146146
loggedOutSession ? loggedOutSession.botSlug : undefined
147147
);
148148

149-
useEffect( () => {
150-
if ( loggedOutChat.data ) {
151-
setRecentConversations( [
152-
convertOdieChatToOdieConversation(
153-
loggedOutChat.data,
154-
loggedOutSession?.sessionId || '',
155-
loggedOutSession?.botSlug || ''
156-
),
157-
] );
158-
}
159-
}, [ loggedOutChat.data, loggedOutSession?.sessionId, loggedOutSession?.botSlug ] );
160-
161149
const { data: otherSupportInteractions, isLoading: isLoadingOtherSupportInteractions } =
162150
useGetSupportInteractions( 'zendesk' );
163151
const { data: odieSupportInteractions, isLoading: isLoadingOdieSupportInteractions } =

packages/help-center/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { HelpCenterSite, SiteDetails } from '@automattic/data-stores';
22
import type { ReactElement } from 'react';
33

4+
export type SupportProvider = 'zendesk' | 'odie' | 'zendesk-staging' | 'help-center';
45
export interface Container {
56
handleClose: () => void;
67
defaultFooterContent?: ReactElement;

packages/odie-client/src/data/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export { handleSupportInteractionsFetch } from './handle-support-interactions-fetch';
2-
export { useGetSupportInteractions } from './use-get-support-interactions';
32
export { useGetZendeskConversation, useGetUnreadConversations } from '@automattic/zendesk-client';
43
export { useManageSupportInteraction } from './use-manage-support-interaction';
54
export { broadcastOdieMessage, useOdieBroadcastWithCallbacks } from './broadcast-messages';

packages/odie-client/src/hooks/use-get-combined-chat.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { recordTracksEvent } from '@automattic/calypso-analytics';
2-
import { HelpCenterSelect } from '@automattic/data-stores';
2+
import { HelpCenterSelect, isLoggedInHCUser } from '@automattic/data-stores';
33
import { HELP_CENTER_STORE } from '@automattic/help-center/src/stores';
44
import { useIsMutating } from '@tanstack/react-query';
55
import { useSelect } from '@wordpress/data';
66
import { useState, useEffect, useRef } from '@wordpress/element';
77
import { useLocation } from 'react-router-dom';
88
import { getMessageUniqueIdentifier } from '../components/message/utils/get-message-unique-identifier';
99
import { getOdieTransferMessage } from '../constants';
10-
import { emptyChat, useOdieAssistantContext } from '../context';
10+
import { emptyChat } from '../context';
1111
import { useGetZendeskConversation, useManageSupportInteraction, useOdieChat } from '../data';
1212
import { useCurrentSupportInteraction } from '../data/use-current-support-interaction';
1313
import {
@@ -49,10 +49,8 @@ export const useGetCombinedChat = (
4949
const { data: currentSupportInteraction, isLoading: isLoadingCurrentSupportInteraction } =
5050
useCurrentSupportInteraction();
5151

52-
const { currentUser } = useOdieAssistantContext();
53-
5452
const location = useLocation();
55-
const isLoggedIn = !! currentUser?.ID;
53+
const isLoggedIn = isLoggedInHCUser();
5654
const params = new URLSearchParams( location.search );
5755
const loggedOutOdieChatId = params.get( 'chatId' );
5856
const loggedOutOdieSessionId = params.get( 'sessionId' );

0 commit comments

Comments
 (0)