Skip to content

Commit 980d800

Browse files
alshakeroescapemanuele
authored andcommitted
Progress
1 parent 104b2fc commit 980d800

File tree

8 files changed

+19
-26
lines changed

8 files changed

+19
-26
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/data/use-get-support-interactions.ts

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

78
/**
@@ -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: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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/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' );

packages/odie-client/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ export type { Conversations, OdieConversation, OdieMessage, SupportInteraction }
3737
export type { ZendeskConversation, ZendeskMessage } from '@automattic/zendesk-client';
3838
export { useManagedOdieChat } from './data/use-managed-odie-chat';
3939
export { convertOdieChatToOdieConversation } from './utils/chat-utils';
40+
export * from './types';

0 commit comments

Comments
 (0)