Skip to content

Commit

Permalink
feat(container): add function to close SNOW session
Browse files Browse the repository at this point in the history
ref: MANAGER-15587

Signed-off-by: Dustin Kroger <[email protected]>
  • Loading branch information
aottr committed Jan 31, 2025
1 parent 57bad7e commit 56d00a3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type ChatDialogProps = {
url: string;
visible: boolean;
title: string;
chatIFrame: React.MutableRefObject<HTMLIFrameElement>;
showHeader?: boolean;
};

Expand All @@ -20,10 +21,10 @@ export default function ChatDialog({
url,
visible,
title,
chatIFrame,
showHeader = true,
}: Readonly<ChatDialogProps>): JSX.Element {
const chatDialog = useRef(null);
const chatIFrame = useRef<HTMLIFrameElement>(null);

useEffect(() => {
if (chatDialog.current) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { v6 } from '@ovh-ux/manager-core-api';
import { Environment } from '@ovh-ux/manager-config';
import { OsdsButton, OsdsText, OsdsIcon } from '@ovhcloud/ods-components/react';
Expand All @@ -20,6 +20,7 @@ import {
LiveChatType,
LiveChatState,
ApiV6AuthToken,
SnowChatContext
} from '@/types/live-chat.type';
import {
ADRIELLY_CHAT_URL_TEMPLATE,
Expand All @@ -45,18 +46,6 @@ const fetchAuthToken = async (): Promise<string | null> => {
}
};

export type SnowChatContext = {
skip_load_history?: string;
live_agent_only?: string;
language?: string;
region?: string;
queue: string;
branding_key?: string;
session_id: string;
interface_type?: string;
interface_name?: string;
};

export default function LiveChat({
closeLiveChat,
}: Readonly<LiveChatProps>): JSX.Element {
Expand All @@ -74,6 +63,7 @@ export default function LiveChat({
const region = environment.getRegion();
const language = environment.getUserLanguage();
const { ovhSubsidiary, supportLevel } = environment.getUser();
const chatIFrame = useRef<HTMLIFrameElement>(null);

const [
snowChatQueue,
Expand All @@ -100,6 +90,13 @@ export default function LiveChat({
const handleCloseChat = () => {
setChatbotReduced(false);

if (chatType === 'SNOW' && chatIFrame.current) {
chatIFrame.current.contentWindow?.postMessage(

Check failure

Code scanning / SonarCloud

Origins should be verified during cross-origin communications High

Specify a target origin for this message. See more on SonarQube Cloud
{ action: 'endConversation' },
'*',
);
}

clearSnowChatQueue();
clearChatType();
clearChatState();
Expand Down Expand Up @@ -177,6 +174,7 @@ export default function LiveChat({
{chatType === 'Adrielly' && (
<ChatDialog
title="OVHcloud Chat"
chatIFrame={chatIFrame}
visible={!chatbotReduced}
url={`https://chat.${'ovh'.toLocaleLowerCase()}.com/system/templates/pre-prod/prepa_prod/STD/FR_fr/docs/index2.html`}
key={chatType}
Expand All @@ -185,6 +183,7 @@ export default function LiveChat({
{chatType === 'SNOW' && snowContext.session_id && snowContext.queue && (
<ChatDialog
title={chatType}
chatIFrame={chatIFrame}
showHeader={false}
visible={!chatbotReduced}
url={generateSnowChatUrl(SNOW_INSTANCE_URL, snowContext)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SnowChatContext } from './LiveChat.component';
import { SnowChatContext } from '@/types/live-chat.type';

/**
* Utility function to construct query parameters
Expand Down
12 changes: 12 additions & 0 deletions packages/manager/apps/container/src/types/live-chat.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@ export type LiveChatState = 'open' | 'reduced';
export type ApiV6AuthToken = {
token: string;
};

export type SnowChatContext = {
skip_load_history?: string;
live_agent_only?: string;
language?: string;
region?: string;
queue: string;
branding_key?: string;
session_id: string;
interface_type?: string;
interface_name?: string;
};

0 comments on commit 56d00a3

Please sign in to comment.