Skip to content

Commit

Permalink
Scroll to the begining of the block (#88711)
Browse files Browse the repository at this point in the history
Send site_id to wpcom
  • Loading branch information
AllTerrainDeveloper authored Mar 20, 2024
1 parent f6fa760 commit 4075c8e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/help-center/src/components/help-center-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useEffect, useRef } from '@wordpress/element';
import { useCallback, useState } from 'react';
import { useSelector } from 'react-redux';
import { Route, Routes, useLocation, useNavigate } from 'react-router-dom';
import { getSectionName } from 'calypso/state/ui/selectors';
import { getSectionName, getSelectedSiteId } from 'calypso/state/ui/selectors';
/**
* Internal Dependencies
*/
Expand Down Expand Up @@ -39,6 +39,7 @@ const HelpCenterContent: React.FC< { isRelative?: boolean; currentRoute?: string
isMinimized: store.getIsMinimized(),
};
}, [] );
const selectedSiteId = useSelector( getSelectedSiteId );

useEffect( () => {
recordTracksEvent( 'calypso_helpcenter_page_open', {
Expand Down Expand Up @@ -105,6 +106,7 @@ const HelpCenterContent: React.FC< { isRelative?: boolean; currentRoute?: string
initialUserMessage={ searchTerm }
logger={ trackEvent }
loggerEventNamePrefix="calypso_odie"
selectedSiteId={ selectedSiteId }
extraContactOptions={
<HelpCenterContactPage
hideHeaders
Expand Down
4 changes: 4 additions & 0 deletions packages/odie-client/src/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type OdieAssistantContextInterface = {
lastNudge: Nudge | null;
odieClientId: string;
sendNudge: ( nudge: Nudge ) => void;
selectedSiteId?: number | null;
setChat: ( chat: Chat ) => void;
setIsLoadingChat: ( isLoadingChat: boolean ) => void;
setMessageLikedStatus: ( message: Message, liked: boolean ) => void;
Expand Down Expand Up @@ -92,6 +93,7 @@ type OdieAssistantProviderProps = {
extraContactOptions?: ReactNode;
logger?: ( message: string, properties: Record< string, unknown > ) => void;
loggerEventNamePrefix?: string;
selectedSiteId?: number | null;
version?: string | null;
children?: ReactNode;
} & PropsWithChildren;
Expand All @@ -105,6 +107,7 @@ const OdieAssistantProvider: FC< OdieAssistantProviderProps > = ( {
enabled = true,
logger,
loggerEventNamePrefix,
selectedSiteId,
version = null,
children,
} ) => {
Expand Down Expand Up @@ -227,6 +230,7 @@ const OdieAssistantProvider: FC< OdieAssistantProviderProps > = ( {
isVisible,
lastNudge,
odieClientId,
selectedSiteId,
sendNudge: setLastNudge,
setChat,
setIsLoadingChat: noop,
Expand Down
4 changes: 2 additions & 2 deletions packages/odie-client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export const OdieAssistant: React.FC = () => {
if ( lastMessageElement?.target ) {
lastMessageElement.target.scrollIntoView( {
behavior: 'auto',
block: 'end',
inline: 'end',
block: 'start',
inline: 'nearest',
} );
}
} );
Expand Down
36 changes: 28 additions & 8 deletions packages/odie-client/src/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const buildSendChatMessage = async (
message: Message,
botNameSlug: OdieAllowedBots,
chat_id?: number | null,
version?: string | null
version?: string | null,
selectedSiteId?: number | null
) => {
const baseApiPath = '/help-center/odie/chat/';
const wpcomBaseApiPath = '/odie/chat/';
Expand All @@ -30,19 +31,24 @@ const buildSendChatMessage = async (
: `${ wpcomBaseApiPath }${ botNameSlug }`;

return canAccessWpcomApis()
? odieWpcomSendSupportMessage( message, wpcomApiPathWithIds, version )
? odieWpcomSendSupportMessage( message, wpcomApiPathWithIds, version, selectedSiteId )
: apiFetch( {
path: apiPathWithIds,
method: 'POST',
data: { message, version },
data: { message, version, context: { selectedSiteId } },
} );
};

function odieWpcomSendSupportMessage( message: Message, path: string, version?: string | null ) {
function odieWpcomSendSupportMessage(
message: Message,
path: string,
version?: string | null,
selectedSiteId?: number | null
) {
return wpcom.req.post( {
path,
apiNamespace: 'wpcom/v2',
body: { message: message.content, version },
body: { message: message.content, version, context: { selectedSiteId } },
} );
}

Expand Down Expand Up @@ -70,8 +76,16 @@ export const useOdieSendMessage = (): UseMutationResult<
{ message: Message },
{ internal_message_id: string }
> => {
const { chat, botNameSlug, setIsLoading, addMessage, updateMessage, odieClientId, version } =
useOdieAssistantContext();
const {
chat,
botNameSlug,
setIsLoading,
addMessage,
updateMessage,
odieClientId,
selectedSiteId,
version,
} = useOdieAssistantContext();
const queryClient = useQueryClient();
const userMessage = useRef< Message | null >( null );

Expand All @@ -83,7 +97,13 @@ export const useOdieSendMessage = (): UseMutationResult<
>( {
mutationFn: ( { message }: { message: Message } ) => {
broadcastOdieMessage( message, odieClientId );
return buildSendChatMessage( { ...message }, botNameSlug, chat.chat_id, version );
return buildSendChatMessage(
{ ...message },
botNameSlug,
chat.chat_id,
version,
selectedSiteId
);
},
onMutate: ( { message } ) => {
const internal_message_id = uuid();
Expand Down

0 comments on commit 4075c8e

Please sign in to comment.