@aslaluroba/help-center-react 3.0.6 → 3.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ import React, { ReactNode } from "react";
2
+ interface LanguageContextType {
3
+ language: string;
4
+ }
5
+ interface LanguageProviderProps {
6
+ children: ReactNode;
7
+ language: string;
8
+ }
9
+ export declare const LanguageProvider: React.FC<LanguageProviderProps>;
10
+ export declare const useLanguage: () => LanguageContextType | null;
11
+ export {};
@@ -1 +1,2 @@
1
- export * from './utils';
1
+ export * from "./LanguageContext";
2
+ export * from "./utils";
@@ -4,5 +4,5 @@ interface ConfirmationModalProps {
4
4
  onCancel: () => void;
5
5
  onConfirm: () => void;
6
6
  }
7
- declare const ConfirmationModal: ({ title, message, onCancel, onConfirm, }: ConfirmationModalProps) => import("react/jsx-runtime").JSX.Element;
7
+ declare const ConfirmationModal: ({ title, message, onCancel, onConfirm }: ConfirmationModalProps) => import("react/jsx-runtime").JSX.Element;
8
8
  export default ConfirmationModal;
@@ -1,4 +1,4 @@
1
- export declare const useLocalTranslation: (languageFromProps?: string) => {
1
+ export declare const useLocalTranslation: () => {
2
2
  t: (key: string) => string;
3
3
  dir: "ltr" | "rtl";
4
4
  i18n: import("i18next").i18n;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "dist/index.js",
4
4
  "module": "dist/index.esm.js",
5
5
  "types": "dist/index.d.ts",
6
- "version": "3.0.6",
6
+ "version": "3.0.7",
7
7
  "description": "BabylAI Help Center Widget for React and Next.js",
8
8
  "private": false,
9
9
  "exports": {
@@ -59,7 +59,6 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@ably/chat": "^0.8.0",
62
- "@microsoft/signalr": "^7.0.14",
63
62
  "@tabler/icons-react": "^3.34.1",
64
63
  "clsx": "^2.1.1",
65
64
  "tailwind-merge": "^3.3.1",
package/src/index.ts CHANGED
@@ -3,7 +3,6 @@ import { TokenResponse } from './lib/types';
3
3
 
4
4
  export type HelpCenterConfig = {
5
5
  baseUrl?: string;
6
- hubUrl?: string;
7
6
  getToken?: () => Promise<TokenResponse>;
8
7
  };
9
8
 
@@ -0,0 +1,28 @@
1
+ import React, { createContext, ReactNode, useContext } from "react";
2
+
3
+ interface LanguageContextType {
4
+ language: string;
5
+ }
6
+
7
+ const LanguageContext = createContext<LanguageContextType | null>(null);
8
+
9
+ interface LanguageProviderProps {
10
+ children: ReactNode;
11
+ language: string;
12
+ }
13
+
14
+ export const LanguageProvider: React.FC<LanguageProviderProps> = ({
15
+ children,
16
+ language,
17
+ }) => {
18
+ return (
19
+ <LanguageContext.Provider value={{ language }}>
20
+ {children}
21
+ </LanguageContext.Provider>
22
+ );
23
+ };
24
+
25
+ export const useLanguage = () => {
26
+ const context = useContext(LanguageContext);
27
+ return context;
28
+ };
package/src/lib/index.ts CHANGED
@@ -1 +1,2 @@
1
- export * from './utils'
1
+ export * from "./LanguageContext";
2
+ export * from "./utils";
@@ -43,7 +43,7 @@ const ChatWindowHeader: React.FC<ChatWindowHeaderProps> = (props) => {
43
43
  </Button>
44
44
 
45
45
  {showMenu && (
46
- <div className="babylai-absolute babylai-top-10 babylai-start-0 babylai-w-48 babylai-rounded-md babylai-shadow-lg babylai-bg-white dark:!babylai-bg-storm-dust-950 babylai-ring-1 babylai-ring-black babylai-ring-opacity-5 babylai-z-10">
46
+ <div className="babylai-absolute babylai-top-10 babylai-start-0 babylai-w-48 babylai-rounded-md babylai-shadow-lg babylai-bg-white dark:!babylai-bg-storm-dust-950 babylai-ring-1 babylai-ring-black-white-700 babylai-ring-opacity-5 babylai-z-10">
47
47
  <div
48
48
  className="babylai-py-1"
49
49
  role="menu"
@@ -8,7 +8,7 @@ interface ConfirmationModalProps {
8
8
  onConfirm: () => void;
9
9
  }
10
10
 
11
- const ConfirmationModal = ({ title, message, onCancel, onConfirm, }: ConfirmationModalProps) => {
11
+ const ConfirmationModal = ({ title, message, onCancel, onConfirm }: ConfirmationModalProps) => {
12
12
  const { t } = useLocalTranslation();
13
13
 
14
14
  return (
@@ -13,7 +13,7 @@ export function FloatingMessage({ message, onClose }: FloatingMessageProps) {
13
13
  <div className="babylai-bg-primary-500 babylai-text-white babylai-py-3 babylai-px-4 babylai-rounded-3xl babylai-shadow-lg babylai-mb-4 babylai-max-w-[200px] babylai-relative after:babylai-content-[''] after:babylai-absolute after:babylai--bottom-[10px] after:babylai-right-5 after:babylai-w-0 after:babylai-h-0 after:babylai-border-l-[10px] after:babylai-border-r-[10px] after:babylai-border-t-[10px] after:babylai-border-l-transparent after:babylai-border-r-transparent after:babylai-border-t-primary-500">
14
14
  <p className="babylai-text-xs babylai-font-bold babylai-m-0">{message}</p>
15
15
  <button
16
- className="babylai-absolute babylai--top-2 babylai--right-2 babylai-w-5 babylai-h-5 babylai-rounded-full babylai-bg-white babylai-border-none babylai-cursor-pointer babylai-flex babylai-items-center babylai-justify-center babylai-text-black babylai-p-[3px] babylai-hover:bg-primary-400 babylai-hover:text-white shadow-md"
16
+ className="babylai-absolute babylai--top-2 babylai--right-2 babylai-w-5 babylai-h-5 babylai-rounded-full babylai-bg-white babylai-border-none babylai-cursor-pointer babylai-flex babylai-items-center babylai-justify-center babylai-text-black-white-700 babylai-p-[3px] babylai-hover:bg-primary-400 babylai-hover:text-white shadow-md"
17
17
  onClick={onClose}
18
18
  >
19
19
  <CloseIcon className="babylai-w-8 babylai-h-8" />
@@ -9,6 +9,7 @@ import { FloatingMessage } from './floating-message';
9
9
  import { HelpButton } from './help-button';
10
10
  import { HelpPopup } from './help-popup';
11
11
  import { defaultLanguage } from '@/i18n';
12
+ import { LanguageProvider } from '@/lib/LanguageContext';
12
13
 
13
14
  interface HelpCenterProps {
14
15
  helpScreenId: string;
@@ -24,15 +25,14 @@ interface HelpCenterProps {
24
25
  showHelpScreen?: boolean;
25
26
  }
26
27
 
27
- export function HelpCenter({
28
+ function HelpCenterContent({
28
29
  helpScreenId,
29
30
  user,
30
31
  showArrow = true,
31
- language = defaultLanguage,
32
32
  messageLabel = null,
33
33
  showHelpScreen = false,
34
- }: HelpCenterProps) {
35
- const { t } = useLocalTranslation(language);
34
+ }: Omit<HelpCenterProps, 'language'>) {
35
+ const { t } = useLocalTranslation();
36
36
  const [isOpen, setIsOpen] = useState(false);
37
37
  const [showArrowAnimation, setShowArrowAnimation] = useState(showArrow);
38
38
  const [helpScreenData, setHelpScreenData] = useState<HelpScreenData | null>(null);
@@ -309,3 +309,25 @@ export function HelpCenter({
309
309
  </div>
310
310
  );
311
311
  }
312
+
313
+ // Main HelpCenter component that provides the language context
314
+ export function HelpCenter({
315
+ helpScreenId,
316
+ user,
317
+ showArrow = true,
318
+ language = defaultLanguage,
319
+ messageLabel = null,
320
+ showHelpScreen = false,
321
+ }: HelpCenterProps) {
322
+ return (
323
+ <LanguageProvider language={language}>
324
+ <HelpCenterContent
325
+ helpScreenId={helpScreenId}
326
+ user={user}
327
+ showArrow={showArrow}
328
+ messageLabel={messageLabel}
329
+ showHelpScreen={showHelpScreen}
330
+ />
331
+ </LanguageProvider>
332
+ );
333
+ }
@@ -1,12 +1,13 @@
1
1
  import { useMemo } from "react";
2
- import { createHelpCenterI18n, defaultLanguage } from "./i18n";
2
+ import { createHelpCenterI18n, defaultLanguage } from "@/i18n";
3
+ import { useLanguage } from "@/lib/LanguageContext";
3
4
 
4
- export const useLocalTranslation = (languageFromProps?: string) => {
5
- const language =
6
- languageFromProps || localStorage.getItem("app-language") || defaultLanguage;
5
+ export const useLocalTranslation = () => {
6
+ // Get language from context, fallback to default if not available
7
+ const context = useLanguage();
8
+ const language = context?.language || defaultLanguage;
7
9
 
8
10
  const i18n = useMemo(() => createHelpCenterI18n(language), [language]);
9
-
10
11
  const t = (key: string) => i18n.t(key);
11
12
  const dir = i18n.dir();
12
13
 
@@ -1,11 +0,0 @@
1
- export declare class ClientSignalRService {
2
- private static connection;
3
- private static isConnected;
4
- private static hubUrl;
5
- static initialize(hubUrl: string): void;
6
- static startConnection(sessionId: string, apiKey: string, onMessageReceived: Function): Promise<void>;
7
- static joinGroup(sessionId: string): Promise<void>;
8
- static leaveGroup(sessionId: string): Promise<void>;
9
- static stopConnection(): Promise<void>;
10
- static isConnectionActive(): boolean;
11
- }
@@ -1,83 +0,0 @@
1
- import * as signalR from '@microsoft/signalr';
2
-
3
- export class ClientSignalRService {
4
- private static connection: signalR.HubConnection | null = null;
5
- private static isConnected: boolean = false;
6
- private static hubUrl: string = '';
7
-
8
- static initialize(hubUrl: string) {
9
- this.hubUrl = hubUrl;
10
- }
11
-
12
- static async startConnection(sessionId: string, apiKey: string, onMessageReceived: Function) {
13
- // Prevent multiple connections
14
- if (this.isConnected) return;
15
-
16
- // Build the SignalR connection
17
- this.connection = new signalR.HubConnectionBuilder()
18
- .withUrl(`${this.hubUrl}/clientHub?access_token=${encodeURIComponent(apiKey)}`, {
19
- withCredentials: true, // Ensure credentials are passed with the WebSocket request
20
- transport: signalR.HttpTransportType.WebSockets | signalR.HttpTransportType.LongPolling,
21
- headers: {
22
- Authorization: `Bearer ${apiKey}`,
23
- },
24
- })
25
- .configureLogging(signalR.LogLevel.Information)
26
- .build();
27
-
28
- // Define callback function for receiving messages
29
- this.connection.on('ReceiveMessage', (message: any, senderType: number, needsAgent: boolean) => {
30
- onMessageReceived(message, senderType, needsAgent);
31
- });
32
-
33
- try {
34
- // Start the connection
35
- await this.connection.start();
36
-
37
- // Set the isConnected flag after the connection is fully established
38
- this.isConnected = true;
39
-
40
- // Join the session group after connection is fully established
41
- await this.joinGroup(sessionId);
42
- } catch (error) {
43
- this.isConnected = false; // Ensure isConnected is false if connection fails
44
- throw error;
45
- }
46
- }
47
-
48
- static async joinGroup(sessionId: string) {
49
- if (this.connection) {
50
- try {
51
- await this.connection.invoke('JoinGroup', sessionId);
52
- } catch (error) {
53
- throw error;
54
- }
55
- }
56
- }
57
-
58
- static async leaveGroup(sessionId: string) {
59
- if (this.connection && this.isConnected) {
60
- try {
61
- await this.connection.invoke('LeaveGroup', sessionId);
62
- } catch (error) {
63
- throw error;
64
- }
65
- }
66
- }
67
-
68
- static async stopConnection() {
69
- if (this.connection && this.isConnected) {
70
- try {
71
- await this.connection.stop();
72
- this.isConnected = false;
73
- this.connection = null;
74
- } catch (error) {
75
- throw error;
76
- }
77
- }
78
- }
79
-
80
- static isConnectionActive(): boolean {
81
- return this.isConnected;
82
- }
83
- }