mirror of
https://github.com/hexastack/hexabot
synced 2025-05-31 10:57:06 +00:00
fix(frontend): enhance web-socket connection
This commit is contained in:
parent
d3ef4ea448
commit
476ffb6143
@ -11,6 +11,7 @@ import UiChatWidget from "hexabot-widget/src/UiChatWidget";
|
||||
import { usePathname } from "next/navigation";
|
||||
|
||||
import { getAvatarSrc } from "@/components/inbox/helpers/mapMessages";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useConfig } from "@/hooks/useConfig";
|
||||
import i18n from "@/i18n/config";
|
||||
import { EntityType, RouterType } from "@/services/types";
|
||||
@ -20,9 +21,10 @@ import { ChatWidgetHeader } from "./ChatWidgetHeader";
|
||||
export const ChatWidget = () => {
|
||||
const pathname = usePathname();
|
||||
const { apiUrl } = useConfig();
|
||||
const { isAuthenticated } = useAuth();
|
||||
const isVisualEditor = pathname === `/${RouterType.VISUAL_EDITOR}`;
|
||||
|
||||
return (
|
||||
return isAuthenticated ? (
|
||||
<Box
|
||||
sx={{
|
||||
display: isVisualEditor ? "block" : "none",
|
||||
@ -44,5 +46,5 @@ export const ChatWidget = () => {
|
||||
)}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
) : null;
|
||||
};
|
||||
|
@ -12,6 +12,7 @@ import { useMutation, useQuery, useQueryClient } from "react-query";
|
||||
import { EntityType, TMutationOptions } from "@/services/types";
|
||||
import { ILoginAttributes } from "@/types/auth/login.types";
|
||||
import { IUser, IUserAttributes, IUserStub } from "@/types/user.types";
|
||||
import { useSocket } from "@/websocket/socket-hooks";
|
||||
|
||||
import { useFind } from "../crud/useFind";
|
||||
import { useApiClient } from "../useApiClient";
|
||||
@ -45,10 +46,13 @@ export const useLogout = (
|
||||
>,
|
||||
) => {
|
||||
const { apiClient } = useApiClient();
|
||||
const { socket } = useSocket();
|
||||
|
||||
return useMutation({
|
||||
...options,
|
||||
async mutationFn() {
|
||||
socket?.disconnect();
|
||||
|
||||
return await apiClient.logout();
|
||||
},
|
||||
onSuccess: () => {},
|
||||
|
Loading…
Reference in New Issue
Block a user