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