fix(frontend): enhance web-socket connection

This commit is contained in:
yassinedorbozgithub 2024-10-10 19:21:25 +01:00
parent d3ef4ea448
commit 476ffb6143
2 changed files with 8 additions and 2 deletions

View File

@ -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;
};

View File

@ -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: () => {},