mirror of
https://github.com/hexastack/hexabot
synced 2025-04-24 00:04:17 +00:00
fix(frontend): Websocket connections issue
This commit is contained in:
parent
ddb5e896de
commit
6c558fb591
@ -6,6 +6,7 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import ChatIcon from "@mui/icons-material/Chat";
|
||||||
import MenuIcon from "@mui/icons-material/Menu";
|
import MenuIcon from "@mui/icons-material/Menu";
|
||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
@ -17,6 +18,8 @@ import {
|
|||||||
styled,
|
styled,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import MuiAppBar, { AppBarProps as MuiAppBarProps } from "@mui/material/AppBar";
|
import MuiAppBar, { AppBarProps as MuiAppBarProps } from "@mui/material/AppBar";
|
||||||
|
import UiChatWidget from "hexabot-widget/src/UiChatWidget";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
import { FC, useEffect, useRef, useState } from "react";
|
import { FC, useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
import { HexabotLogo } from "@/app-components/logos/HexabotLogo";
|
import { HexabotLogo } from "@/app-components/logos/HexabotLogo";
|
||||||
@ -25,7 +28,8 @@ import { getAvatarSrc } from "@/components/inbox/helpers/mapMessages";
|
|||||||
import { useAuth } from "@/hooks/useAuth";
|
import { useAuth } from "@/hooks/useAuth";
|
||||||
import { useConfig } from "@/hooks/useConfig";
|
import { useConfig } from "@/hooks/useConfig";
|
||||||
import { useTranslate } from "@/hooks/useTranslate";
|
import { useTranslate } from "@/hooks/useTranslate";
|
||||||
import { EntityType } from "@/services/types";
|
import i18n from "@/i18n/config";
|
||||||
|
import { EntityType, RouterType } from "@/services/types";
|
||||||
import { getRandom } from "@/utils/safeRandom";
|
import { getRandom } from "@/utils/safeRandom";
|
||||||
|
|
||||||
import { borderLine, theme } from "./themes/theme";
|
import { borderLine, theme } from "./themes/theme";
|
||||||
@ -72,8 +76,23 @@ export type HeaderProps = {
|
|||||||
isSideBarOpen: boolean;
|
isSideBarOpen: boolean;
|
||||||
onToggleSidebar: () => void;
|
onToggleSidebar: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CustomWidgetHeader = () => {
|
||||||
|
const { t } = useTranslate();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box display="flex" alignItems="center" ml={2}>
|
||||||
|
<ChatIcon />
|
||||||
|
<Typography component="h2" fontSize="1.5rem" ml={2}>
|
||||||
|
{t("title.live_chat_tester")}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const Header: FC<HeaderProps> = ({ isSideBarOpen, onToggleSidebar }) => {
|
export const Header: FC<HeaderProps> = ({ isSideBarOpen, onToggleSidebar }) => {
|
||||||
const { apiUrl, ssoEnabled } = useConfig();
|
const { apiUrl, ssoEnabled } = useConfig();
|
||||||
|
const pathname = usePathname();
|
||||||
const { t } = useTranslate();
|
const { t } = useTranslate();
|
||||||
const anchorRef = useRef(null);
|
const anchorRef = useRef(null);
|
||||||
const [isMenuPopoverOpen, setIsMenuPopoverOpen] = useState(false);
|
const [isMenuPopoverOpen, setIsMenuPopoverOpen] = useState(false);
|
||||||
@ -88,6 +107,8 @@ export const Header: FC<HeaderProps> = ({ isSideBarOpen, onToggleSidebar }) => {
|
|||||||
setRandomSeed(getRandom().toString());
|
setRandomSeed(getRandom().toString());
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
|
const isVisualEditor = pathname === `/${RouterType.VISUAL_EDITOR}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledAppBar open={isSideBarOpen}>
|
<StyledAppBar open={isSideBarOpen}>
|
||||||
<Grid container>
|
<Grid container>
|
||||||
@ -193,6 +214,24 @@ export const Header: FC<HeaderProps> = ({ isSideBarOpen, onToggleSidebar }) => {
|
|||||||
) : null}
|
) : null}
|
||||||
</Grid>
|
</Grid>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
<Grid sx={{ display: isVisualEditor ? "block" : "none" }}>
|
||||||
|
<UiChatWidget
|
||||||
|
config={{
|
||||||
|
apiUrl,
|
||||||
|
channel: "live-chat-tester",
|
||||||
|
token: "test",
|
||||||
|
language: i18n.language,
|
||||||
|
}}
|
||||||
|
CustomHeader={CustomWidgetHeader as any}
|
||||||
|
CustomAvatar={() => (
|
||||||
|
<Avatar
|
||||||
|
sx={{ width: "32px", height: "32px", fontSize: ".75rem" }}
|
||||||
|
src={getAvatarSrc(apiUrl, EntityType.USER, "bot")}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StyledAppBar>
|
</StyledAppBar>
|
||||||
);
|
);
|
||||||
|
@ -6,52 +6,15 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ChatIcon from "@mui/icons-material/Chat";
|
|
||||||
import { Avatar, Box, Typography } from "@mui/material";
|
|
||||||
import UiChatWidget from "hexabot-widget/src/UiChatWidget";
|
|
||||||
import { ReactElement } from "react";
|
import { ReactElement } from "react";
|
||||||
|
|
||||||
import { getAvatarSrc } from "@/components/inbox/helpers/mapMessages";
|
|
||||||
import { VisualEditor } from "@/components/visual-editor";
|
import { VisualEditor } from "@/components/visual-editor";
|
||||||
import { useConfig } from "@/hooks/useConfig";
|
|
||||||
import { useTranslate } from "@/hooks/useTranslate";
|
|
||||||
import i18n from "@/i18n/config";
|
|
||||||
import { Layout } from "@/layout";
|
import { Layout } from "@/layout";
|
||||||
import { EntityType } from "@/services/types";
|
|
||||||
|
|
||||||
const CustomWidgetHeader = () => {
|
|
||||||
const { t } = useTranslate();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box display="flex" alignItems="center" ml={2}>
|
|
||||||
<ChatIcon />
|
|
||||||
<Typography component="h2" fontSize="1.5rem" ml={2}>
|
|
||||||
{t("title.live_chat_tester")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
const VisualEditorPage = () => {
|
const VisualEditorPage = () => {
|
||||||
const { apiUrl } = useConfig();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<VisualEditor />
|
<VisualEditor />
|
||||||
<UiChatWidget
|
|
||||||
config={{
|
|
||||||
apiUrl,
|
|
||||||
channel: "live-chat-tester",
|
|
||||||
token: "test",
|
|
||||||
language: i18n.language,
|
|
||||||
}}
|
|
||||||
CustomHeader={CustomWidgetHeader as any}
|
|
||||||
CustomAvatar={() => (
|
|
||||||
<Avatar
|
|
||||||
sx={{ width: "32px", height: "32px", fontSize: ".75rem" }}
|
|
||||||
src={getAvatarSrc(apiUrl, EntityType.USER, "bot")}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user