diff --git a/packages/help-center/src/components/help-center.tsx b/packages/help-center/src/components/help-center.tsx index c0f311bb0031..3458ec94f0d6 100644 --- a/packages/help-center/src/components/help-center.tsx +++ b/packages/help-center/src/components/help-center.tsx @@ -4,7 +4,6 @@ */ import UnifiedAIAgent from '@automattic/agents-manager'; import { initializeAnalytics } from '@automattic/calypso-analytics'; -import { useGetSupportInteractions } from '@automattic/odie-client/src/data/use-get-support-interactions'; import { useCanConnectToZendeskMessaging } from '@automattic/zendesk-client'; import { useSelect } from '@wordpress/data'; import { createPortal, useEffect, useState } from '@wordpress/element'; @@ -16,6 +15,7 @@ import { useHelpCenterContext, type HelpCenterRequiredInformation, } from '../contexts/HelpCenterContext'; +import { useGetSupportInteractions } from '../data/use-get-support-interactions'; import { useChatStatus, useShouldUseUnifiedAgent } from '../hooks'; import { HELP_CENTER_STORE } from '../stores'; import { Container } from '../types'; diff --git a/packages/odie-client/src/data/use-get-support-interactions.ts b/packages/help-center/src/data/use-get-support-interactions.ts similarity index 92% rename from packages/odie-client/src/data/use-get-support-interactions.ts rename to packages/help-center/src/data/use-get-support-interactions.ts index be68b97286fa..f2fb96d5bcd4 100644 --- a/packages/odie-client/src/data/use-get-support-interactions.ts +++ b/packages/help-center/src/data/use-get-support-interactions.ts @@ -1,6 +1,6 @@ +import { handleSupportInteractionsFetch } from '@automattic/odie-client/src/data/handle-support-interactions-fetch'; import { isTestModeEnvironment, useCanConnectToZendeskMessaging } from '@automattic/zendesk-client'; import { useQuery } from '@tanstack/react-query'; -import { handleSupportInteractionsFetch } from './handle-support-interactions-fetch'; import type { SupportProvider } from '../types'; /** diff --git a/packages/help-center/src/hooks/use-get-history-chats.ts b/packages/help-center/src/hooks/use-get-history-chats.ts index 413093025846..0e6afac04ed4 100644 --- a/packages/help-center/src/hooks/use-get-history-chats.ts +++ b/packages/help-center/src/hooks/use-get-history-chats.ts @@ -1,7 +1,6 @@ /* eslint-disable no-restricted-imports */ import { HelpCenterSelect } from '@automattic/data-stores'; import { useGetOdieConversations } from '@automattic/odie-client/src/data/use-get-odie-conversations'; -import { useGetSupportInteractions } from '@automattic/odie-client/src/data/use-get-support-interactions'; import { useSelect } from '@wordpress/data'; import { useEffect, useMemo, useState } from '@wordpress/element'; import { @@ -9,6 +8,7 @@ import { getLastMessage, getZendeskConversations, } from '../components/utils'; +import { useGetSupportInteractions } from '../data/use-get-support-interactions'; import { HELP_CENTER_STORE } from '../stores'; import type { Conversations, diff --git a/packages/help-center/src/types.ts b/packages/help-center/src/types.ts index 99e320ffc8d7..f3e01a7325cf 100644 --- a/packages/help-center/src/types.ts +++ b/packages/help-center/src/types.ts @@ -1,6 +1,8 @@ import type { HelpCenterSite, SiteDetails } from '@automattic/data-stores'; import type { ReactElement } from 'react'; +export type SupportProvider = 'zendesk' | 'odie' | 'zendesk-staging'; + export interface Container { handleClose: () => void; defaultFooterContent?: ReactElement; diff --git a/packages/odie-client/src/components/message/index.tsx b/packages/odie-client/src/components/message/index.tsx index 5d2cd7d53089..7ac038c3a197 100644 --- a/packages/odie-client/src/components/message/index.tsx +++ b/packages/odie-client/src/components/message/index.tsx @@ -4,14 +4,11 @@ import { useState } from 'react'; import ReactDOM from 'react-dom'; import { useOdieAssistantContext } from '../../context'; import { MessageContent } from './message-content'; -import type { CurrentUser, Message } from '../../types'; +import type { Message } from '../../types'; import './style.scss'; export type ChatMessageProps = { message: Message; - currentUser: CurrentUser; - displayChatWithSupportLabel?: boolean; - displayCSAT?: boolean; header?: React.ReactNode; }; @@ -22,7 +19,7 @@ export type MessageIndicators = { isLastMessage: boolean; }; -const ChatMessage = ( { message, currentUser, header }: ChatMessageProps ) => { +const ChatMessage = ( { message, header }: ChatMessageProps ) => { const { botName } = useOdieAssistantContext(); const [ isFullscreen, setIsFullscreen ] = useState( false ); @@ -34,7 +31,7 @@ const ChatMessage = ( { message, currentUser, header }: ChatMessageProps ) => { event.stopPropagation(); }; - if ( ! currentUser || ! botName ) { + if ( ! botName ) { return null; } diff --git a/packages/odie-client/src/components/message/messages-cluster/messages-cluster.tsx b/packages/odie-client/src/components/message/messages-cluster/messages-cluster.tsx index 90d71e8f592c..b8bf6d57c15e 100644 --- a/packages/odie-client/src/components/message/messages-cluster/messages-cluster.tsx +++ b/packages/odie-client/src/components/message/messages-cluster/messages-cluster.tsx @@ -2,7 +2,6 @@ import { __ } from '@wordpress/i18n'; import cx from 'clsx'; import { Fragment } from 'react'; import ChatMessage from '..'; -import { useOdieAssistantContext } from '../../../context'; import { isCSATMessage } from '../../../utils'; import { hasFeedbackForm, @@ -109,7 +108,6 @@ function clusterMessagesBySender( messages: Message[] ) { export function MessagesClusterizer( { messages }: { messages: Message[] } ) { const groups = clusterMessagesBySender( messages ); - const { currentUser } = useOdieAssistantContext(); return groups.map( ( group ) => { const startingHumanSupport = group.messages.some( isTransitionToSupportMessage ); @@ -139,7 +137,6 @@ export function MessagesClusterizer( { messages }: { messages: Message[] } ) { ) ) } diff --git a/packages/odie-client/src/components/message/messages-container.tsx b/packages/odie-client/src/components/message/messages-container.tsx index c09d84106f39..766e0c7441fc 100644 --- a/packages/odie-client/src/components/message/messages-container.tsx +++ b/packages/odie-client/src/components/message/messages-container.tsx @@ -136,8 +136,6 @@ export const MessagesContainer = ( { currentUser }: ChatMessagesProps ) => { currentUser?.display_name ) } key={ 0 } - currentUser={ currentUser } - displayChatWithSupportLabel={ false } /> ) } { chat.messages?.length > 0 && } diff --git a/packages/odie-client/src/data/index.ts b/packages/odie-client/src/data/index.ts index a08355aecf69..8f78b4f83eb3 100644 --- a/packages/odie-client/src/data/index.ts +++ b/packages/odie-client/src/data/index.ts @@ -1,5 +1,4 @@ export { handleSupportInteractionsFetch } from './handle-support-interactions-fetch'; -export { useGetSupportInteractions } from './use-get-support-interactions'; export { useGetZendeskConversation, useGetUnreadConversations } from '@automattic/zendesk-client'; export { useManageSupportInteraction } from './use-manage-support-interaction'; export { broadcastOdieMessage, useOdieBroadcastWithCallbacks } from './broadcast-messages'; diff --git a/packages/odie-client/src/hooks/use-get-most-recent-open-conversation.tsx b/packages/odie-client/src/hooks/use-get-most-recent-open-conversation.tsx deleted file mode 100644 index 50936efcf9f6..000000000000 --- a/packages/odie-client/src/hooks/use-get-most-recent-open-conversation.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { HelpCenterSelect } from '@automattic/data-stores'; -import { HELP_CENTER_STORE } from '@automattic/help-center/src/stores'; -import { useGetSupportInteractions } from '@automattic/odie-client/src/data'; -import { useSelect } from '@wordpress/data'; -import Smooch from 'smooch'; - -export const useGetMostRecentOpenConversation = () => { - let mostRecentSupportInteractionId = null; - let totalNumberOfConversations = 0; - - const { isChatLoaded } = useSelect( - ( select ) => ( { - isChatLoaded: ( select( HELP_CENTER_STORE ) as HelpCenterSelect ).getIsChatLoaded(), - } ), - [] - ); - - const { data: supportInteractions, isLoading } = useGetSupportInteractions( 'zendesk' ); - - if ( supportInteractions?.length && isChatLoaded && ! isLoading ) { - const allConversations = Smooch?.getConversations?.() ?? []; - - const filteredConversations = allConversations.filter( ( conversation ) => - supportInteractions.some( - ( interaction ) => interaction.uuid === conversation.metadata?.supportInteractionId - ) - ); - - const sortedConversations = filteredConversations.sort( ( conversationA, conversationB ) => { - const aCreatedAt = conversationA?.metadata?.createdAt; - const bCreatedAt = conversationB?.metadata?.createdAt; - if ( - aCreatedAt && - bCreatedAt && - typeof aCreatedAt === 'number' && - typeof bCreatedAt === 'number' - ) { - return new Date( bCreatedAt ).getTime() - new Date( aCreatedAt ).getTime(); - } - return 0; - } ); - - if ( sortedConversations?.length > 0 ) { - mostRecentSupportInteractionId = sortedConversations[ 0 ]?.metadata?.supportInteractionId; - totalNumberOfConversations = sortedConversations.length; - } - } - return { mostRecentSupportInteractionId, totalNumberOfConversations }; -};