Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help Center: Open Zendesk with link #96448

Merged
merged 24 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6e85c69
Open Zendesk with link
escapemanuele Nov 15, 2024
859e69e
Update chat thread
arcangelini Dec 2, 2024
12e45fd
Sort of works... small bug causing refresh
arcangelini Dec 2, 2024
3651de6
Merge remote-tracking branch 'origin/trunk' into hc-zendesk-link
heavyweight Jan 15, 2025
e594703
add missing isChatLoaded
heavyweight Jan 15, 2025
729f0fc
minor fixes
heavyweight Jan 15, 2025
eb97113
minimize hook changes
heavyweight Jan 15, 2025
585c0db
remove unused selectedConversationId
heavyweight Jan 15, 2025
fb1bc0b
Wire initial message and correct site and siteId
heavyweight Jan 15, 2025
e8f7aae
Don't display transfer message for direct zd chat
heavyweight Jan 16, 2025
6f3daa1
Wire direct zd chat for cancellations
heavyweight Jan 16, 2025
155cd91
Merge branch 'trunk' into hc-zendesk-link
heavyweight Jan 16, 2025
3a89434
Change variable name and remove unused ones
escapemanuele Jan 17, 2025
e0011b6
Fix useEffect
escapemanuele Jan 17, 2025
e6e8c2b
Change state variable name
escapemanuele Jan 17, 2025
9915273
Avoid transfer
escapemanuele Jan 17, 2025
694d292
Ensure one chat is created
heavyweight Jan 20, 2025
e44d55a
Default to first open interaction only if there is no interaction set
heavyweight Jan 20, 2025
58826c7
Minimize re-rendering
heavyweight Jan 20, 2025
57e09a8
Ensure conversation is created once with the correct support interaction
heavyweight Jan 21, 2025
11313a0
Fix back nav for direct chats
heavyweight Jan 21, 2025
d44e8a3
Merge branch 'trunk' into hc-zendesk-link
heavyweight Jan 21, 2025
2348a2b
Fix jump to recent visible for direct chats
heavyweight Jan 21, 2025
7c12cc1
Merge branch 'trunk' into hc-zendesk-link
heavyweight Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions client/components/chat-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,25 @@ const ChatButton: FC< Props > = ( {

const handleClick = () => {
if ( canConnectToZendesk ) {
openZendeskWidget( {
message: initialMessage,
siteUrl,
siteId,
onError,
onSuccess: () => {
onClick?.();
resetStore();
setShowHelpCenter( false );
},
} );
if ( chatIntent === 'PRECANCELLATION' ) {
onClick?.();
setShowHelpCenter( true );
setNavigateToRoute(
`/odie?provider=zendesk&initialMessage=${ initialMessage }&siteUrl=${ siteUrl }&siteId=${ siteId }`
);
} else {
openZendeskWidget( {
message: initialMessage,
siteUrl,
siteId,
onError,
onSuccess: () => {
onClick?.();
resetStore();
setShowHelpCenter( false );
},
} );
}
} else {
setNavigateToRoute( '/contact-form?mode=CHAT' );
setShowHelpCenter( true );
Expand Down
13 changes: 4 additions & 9 deletions client/me/purchases/cancel-purchase/support-link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ const CancelPurchaseSupportLink = ( { purchase } ) => {

const getHelp = useCallback( () => {
if ( isMessagingAvailable && canConnectToZendeskMessaging ) {
openZendeskWidget( {
siteUrl: siteUrl,
siteId: siteId,
message: `${ status }: Purchase cancellation flow`,
onSuccess: () => {
resetStore();
setShowHelpCenter( false );
},
} );
setShowHelpCenter( true );
setNavigateToRoute(
`/odie?provider=zendesk&initialMessage=Purchase cancellation flow&siteUrl=${ siteUrl }&siteId=${ siteId }`
);
} else {
setNavigateToRoute( '/contact-options' );
setShowHelpCenter( true );
Expand Down
14 changes: 9 additions & 5 deletions packages/help-center/src/components/help-center-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { recordTracksEvent } from '@automattic/calypso-analytics';
import OdieAssistantProvider, { OdieAssistant } from '@automattic/odie-client';
import { useEffect } from '@wordpress/element';
import { useNavigate, useParams } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { useHelpCenterContext } from '../contexts/HelpCenterContext';
import { useShouldUseWapuu } from '../hooks';
import { ExtraContactOptions } from './help-center-extra-contact-option';
Expand All @@ -24,7 +24,11 @@ export function HelpCenterChat( {
const shouldUseWapuu = useShouldUseWapuu();
const preventOdieAccess = ! shouldUseWapuu && ! isUserEligibleForPaidSupport;
const { currentUser, site, canConnectToZendesk } = useHelpCenterContext();
const { id: conversationId = null } = useParams();
const { search } = useLocation();
const params = new URLSearchParams( search );
const initialMessage = params.get( 'initialMessage' );
const siteUrl = params.get( 'siteUrl' );
const siteId = params.get( 'siteId' );

useEffect( () => {
if ( preventOdieAccess ) {
Expand All @@ -40,9 +44,9 @@ export function HelpCenterChat( {
<OdieAssistantProvider
currentUser={ currentUser }
canConnectToZendesk={ canConnectToZendesk }
selectedSiteId={ site?.ID as number }
selectedSiteURL={ site?.URL as string }
selectedConversationId={ conversationId }
selectedSiteId={ Number( siteId ) || ( site?.ID as number ) }
selectedSiteURL={ siteUrl || ( site?.URL as string ) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting here that this happened to me

image

initialMessage={ initialMessage }
isUserEligibleForPaidSupport={ isUserEligibleForPaidSupport }
extraContactOptions={
<ExtraContactOptions isUserEligible={ isUserEligibleForPaidSupport } />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { recordTracksEvent } from '@automattic/calypso-analytics';
import { GetSupport } from '@automattic/odie-client/src/components/message/get-support';
import { useManageSupportInteraction } from '@automattic/odie-client/src/data';
import { useI18n } from '@wordpress/react-i18n';
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { v4 as uuidv4 } from 'uuid';
import { useHelpCenterContext } from '../contexts/HelpCenterContext';
import { useSupportStatus } from '../data/use-support-status';
import { useResetSupportInteraction } from '../hooks/use-reset-support-interaction';
Expand All @@ -23,7 +21,6 @@ const HelpCenterFeedbackForm = ( { postId }: { postId: number } ) => {
const { site } = useHelpCenterContext();
const navigate = useNavigate();
const resetSupportInteraction = useResetSupportInteraction();
const { startNewInteraction } = useManageSupportInteraction();

const handleFeedbackClick = ( value: number ) => {
setStartedFeedback( true );
Expand Down Expand Up @@ -61,10 +58,6 @@ const HelpCenterFeedbackForm = ( { postId }: { postId: number } ) => {
generateContactOnClickEvent( 'chat', 'calypso_helpcenter_feedback_contact_support' );
if ( isUserEligibleForPaidSupport ) {
await resetSupportInteraction();
startNewInteraction( {
event_source: 'help-center',
event_external_id: uuidv4(),
} );
heavyweight marked this conversation as resolved.
Show resolved Hide resolved
navigate( '/odie' );
}
};
Expand Down
7 changes: 0 additions & 7 deletions packages/help-center/src/components/help-center-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { recordTracksEvent } from '@automattic/calypso-analytics';
import { Gridicon } from '@automattic/components';
import { EllipsisMenu } from '@automattic/odie-client';
import { useManageSupportInteraction } from '@automattic/odie-client/src/data';
import { clearHelpCenterZendeskConversationStarted } from '@automattic/odie-client/src/utils/storage-utils';
import { CardHeader, Button, Flex } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
Expand All @@ -11,7 +10,6 @@ import { closeSmall, chevronUp, lineSolid, commentContent, page, Icon } from '@w
import { useI18n } from '@wordpress/react-i18n';
import clsx from 'clsx';
import { Route, Routes, useLocation, useSearchParams } from 'react-router-dom';
import { v4 as uuidv4 } from 'uuid';
import { usePostByUrl } from '../hooks';
import { useResetSupportInteraction } from '../hooks/use-reset-support-interaction';
import { DragIcon } from '../icons';
Expand Down Expand Up @@ -68,14 +66,9 @@ const SupportModeTitle = () => {
const ChatEllipsisMenu = () => {
const { __ } = useI18n();
const resetSupportInteraction = useResetSupportInteraction();
const { startNewInteraction } = useManageSupportInteraction();

const clearChat = async () => {
await resetSupportInteraction();
startNewInteraction( {
event_source: 'help-center',
event_external_id: uuidv4(),
} );
clearHelpCenterZendeskConversationStarted();
recordTracksEvent( 'calypso_inlinehelp_clear_conversation' );
};
Expand Down
15 changes: 15 additions & 0 deletions packages/help-center/src/hooks/use-action-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const useActionHooks = () => {
);
},
},

/**
* Open Help Center.
*/
Expand All @@ -37,6 +38,7 @@ export const useActionHooks = () => {
setShowHelpCenter( true );
},
},

/**
* Open to Wapuu chat.
*/
Expand All @@ -49,6 +51,19 @@ export const useActionHooks = () => {
setShowHelpCenter( true );
},
},

/**
* Open to Chat with Happiness Engineer.
*/
{
condition() {
return queryParams.get( 'help-center' ) === 'happiness-engineer';
},
action() {
setNavigateToRoute( '/odie?provider=zendesk' );
setShowHelpCenter( true );
},
},
];

useEffect( () => {
Expand Down
17 changes: 10 additions & 7 deletions packages/help-center/src/hooks/use-reset-support-interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { HelpCenterSelect } from '@automattic/data-stores';
import { HELP_CENTER_STORE } from '@automattic/help-center/src/stores';
import { useManageSupportInteraction } from '@automattic/odie-client/src/data';
import { useQueryClient } from '@tanstack/react-query';
import { useSelect, useDispatch } from '@wordpress/data';
import { useSelect } from '@wordpress/data';
import { v4 as uuidv4 } from 'uuid';

export const useResetSupportInteraction = () => {
const { currentSupportInteraction } = useSelect( ( select ) => {
Expand All @@ -11,19 +12,21 @@ export const useResetSupportInteraction = () => {
currentSupportInteraction: store.getCurrentSupportInteraction(),
};
}, [] );
const { setCurrentSupportInteraction } = useDispatch( HELP_CENTER_STORE );
const { resolveInteraction } = useManageSupportInteraction();
const { startNewInteraction, resolveInteraction } = useManageSupportInteraction();
const queryClient = useQueryClient();

const reset = async () => {
return async () => {
if ( currentSupportInteraction ) {
resolveInteraction( { interactionId: currentSupportInteraction.uuid } );

await queryClient.invalidateQueries( {
queryKey: [ 'support-interactions', 'get-interactions', 'help-center' ],
} );
setCurrentSupportInteraction( null );

await startNewInteraction( {
event_source: 'help-center',
event_external_id: uuidv4(),
} );
}
};

return reset;
};
53 changes: 42 additions & 11 deletions packages/odie-client/src/components/message/messages-container.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { useResetSupportInteraction } from '@automattic/help-center/src/hooks/use-reset-support-interaction';
import { getShortDateString } from '@automattic/i18n-utils';
import { Spinner } from '@wordpress/components';
import { useEffect, useRef, useState } from 'react';
import { useSearchParams } from 'react-router-dom';
import { ThumbsDown } from '../../assets/thumbs-down';
import { useOdieAssistantContext } from '../../context';
import { useAutoScroll, useZendeskMessageListener } from '../../hooks';
import {
useAutoScroll,
useCreateZendeskConversation,
useZendeskMessageListener,
} from '../../hooks';
import { getOdieInitialMessage } from '../../utils';
import { DislikeFeedbackMessage } from './dislike-feedback-message';
import { JumpToRecent } from './jump-to-recent';
Expand All @@ -18,6 +24,7 @@ const DislikeThumb = () => {
</div>
);
};

const LoadingChatSpinner = () => {
return (
<div className="chatbox-loading-chat__spinner">
Expand All @@ -38,14 +45,36 @@ interface ChatMessagesProps {
}

export const MessagesContainer = ( { currentUser }: ChatMessagesProps ) => {
const { chat, botNameSlug } = useOdieAssistantContext();
const { chat, botNameSlug, isChatLoaded } = useOdieAssistantContext();
const createZendeskConversation = useCreateZendeskConversation();
const resetSupportInteraction = useResetSupportInteraction();
const [ searchParams ] = useSearchParams();
const isForwardingToZendesk =
searchParams.get( 'provider' ) === 'zendesk' && chat.provider !== 'zendesk';
const [ chatMessagesLoaded, setChatLoaded ] = useState( false );
heavyweight marked this conversation as resolved.
Show resolved Hide resolved
const messagesContainerRef = useRef< HTMLDivElement >( null );
useZendeskMessageListener();
useAutoScroll( messagesContainerRef );

useEffect( () => {
( chat?.status === 'loaded' || chat?.status === 'closed' ) &&
setChatLoaded( ! isForwardingToZendesk );
}, [ chat, isForwardingToZendesk ] );

/**
* Handle the case where we are forwarding to Zendesk.
*/
useEffect( () => {
( chat?.status === 'loaded' || chat?.status === 'closed' ) && setChatLoaded( true );
}, [ chat ] );
if ( isForwardingToZendesk && ! chat.conversationId ) {
resetSupportInteraction().then( () => {
if ( isChatLoaded ) {
createZendeskConversation().then( () => {
setChatLoaded( true );
} );
}
} );
}
}, [ isForwardingToZendesk, isChatLoaded ] );

// Used to apply the correct styling on messages
const isNextMessageFromSameSender = ( currentMessage: string, nextMessage: string ) => {
Expand All @@ -60,13 +89,15 @@ export const MessagesContainer = ( { currentUser }: ChatMessagesProps ) => {
<LoadingChatSpinner />
) : (
<>
<ChatMessage
message={ getOdieInitialMessage( botNameSlug ) }
key={ 0 }
currentUser={ currentUser }
isNextMessageFromSameSender={ false }
displayChatWithSupportLabel={ false }
/>
{ ( chat.odieId || chat.provider === 'odie' ) && (
<ChatMessage
message={ getOdieInitialMessage( botNameSlug ) }
key={ 0 }
currentUser={ currentUser }
isNextMessageFromSameSender={ false }
displayChatWithSupportLabel={ false }
/>
) }
{ chat.messages.map( ( message, index ) => (
<ChatMessage
message={ message }
Expand Down
2 changes: 2 additions & 0 deletions packages/odie-client/src/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const OdieAssistantProvider: React.FC< OdieAssistantProviderProps > = ( {
extraContactOptions,
selectedSiteId,
selectedSiteURL,
initialMessage,
heavyweight marked this conversation as resolved.
Show resolved Hide resolved
version = null,
currentUser,
children,
Expand Down Expand Up @@ -180,6 +181,7 @@ export const OdieAssistantProvider: React.FC< OdieAssistantProviderProps > = ( {
odieBroadcastClientId,
selectedSiteId,
selectedSiteURL,
initialMessage,
setChatStatus,
setMessageLikedStatus,
setWaitAnswerToFirstMessageFromHumanSupport,
Expand Down
10 changes: 6 additions & 4 deletions packages/odie-client/src/data/use-get-zendesk-conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,29 @@ export const useGetZendeskConversation = () => {
chatId,
conversationId,
}: {
chatId: number | string | null | undefined;
chatId?: number | string | null | undefined;
conversationId?: string | null | undefined;
} ) => {
if ( ! chatId ) {
if ( ! chatId && ! conversationId ) {
return null;
}

const conversation = Smooch.getConversations().find( ( conversation ) => {
if ( conversationId ) {
return conversation.id === conversationId;
} else if ( chatId ) {
return Number( conversation.metadata[ 'odieChatId' ] ) === Number( chatId );
}

return Number( conversation.metadata[ 'odieChatId' ] ) === Number( chatId );
return false;
} );

if ( ! conversation ) {
return null;
}

// We need to ensure that more than one message is loaded
return Smooch.getConversationById( conversation.id )
return Smooch.getConversationById( conversation.id || conversationId! )
.then( ( conversation ) => {
Smooch.markAllAsRead( conversation.id );
getUnreadNotifications();
Expand Down
Loading
Loading