From 1289ba886bb3191834af95900d4c698d44fa5426 Mon Sep 17 00:00:00 2001 From: abdou6666 Date: Fri, 7 Feb 2025 14:17:15 +0100 Subject: [PATCH 1/4] fix: use pages router instead of app router --- frontend/src/app-components/widget/ChatWidget.tsx | 8 +++++--- frontend/src/hooks/useAuth.ts | 7 +++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/frontend/src/app-components/widget/ChatWidget.tsx b/frontend/src/app-components/widget/ChatWidget.tsx index 1d5a3568..ce98aee0 100644 --- a/frontend/src/app-components/widget/ChatWidget.tsx +++ b/frontend/src/app-components/widget/ChatWidget.tsx @@ -1,14 +1,15 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 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 { Avatar, Box } from "@mui/material"; import UiChatWidget from "hexabot-chat-widget/src/UiChatWidget"; -import { usePathname } from "next/navigation"; +import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import { getAvatarSrc } from "@/components/inbox/helpers/mapMessages"; @@ -24,7 +25,8 @@ import { ChatWidgetHeader } from "./ChatWidgetHeader"; const SETTING_TYPE = "console_channel" as const; export const ChatWidget = () => { - const pathname = usePathname(); + const router = useRouter(); + const pathname = router.pathname; const { apiUrl } = useConfig(); const { isAuthenticated } = useAuth(); const isVisualEditor = pathname.startsWith(`/${RouterType.VISUAL_EDITOR}`); diff --git a/frontend/src/hooks/useAuth.ts b/frontend/src/hooks/useAuth.ts index 1f9fb0df..77fd0f3b 100755 --- a/frontend/src/hooks/useAuth.ts +++ b/frontend/src/hooks/useAuth.ts @@ -1,12 +1,12 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 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 { usePathname } from "next/navigation"; + import { useRouter } from "next/router"; import { useContext } from "react"; @@ -33,12 +33,11 @@ export const useAuth = () => { export const useLogoutRedirection = () => { const router = useRouter(); - const pathname = usePathname(); const hasPublicPath = PUBLIC_PATHS.includes(router.pathname); const logoutRedirection = async (fullReload: boolean = false) => { if (!hasPublicPath) { const redirectUrl = `/${RouterType.LOGIN}?redirect=${encodeURIComponent( - pathname, + router.pathname, )}`; if (fullReload) { From 8089206df1457854b801479ce284bd51bb7c7c6c Mon Sep 17 00:00:00 2001 From: abdou6666 Date: Fri, 7 Feb 2025 17:24:02 +0100 Subject: [PATCH 2/4] fix: bug when we have dynamic route default redirection to '/' --- frontend/src/hooks/useAuth.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/src/hooks/useAuth.ts b/frontend/src/hooks/useAuth.ts index 77fd0f3b..4861cd3e 100755 --- a/frontend/src/hooks/useAuth.ts +++ b/frontend/src/hooks/useAuth.ts @@ -6,7 +6,6 @@ * 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 { useRouter } from "next/router"; import { useContext } from "react"; @@ -33,12 +32,14 @@ export const useAuth = () => { export const useLogoutRedirection = () => { const router = useRouter(); + const isDynamicPath = router.pathname.includes("["); const hasPublicPath = PUBLIC_PATHS.includes(router.pathname); + const encodedPath = isDynamicPath + ? encodeURIComponent("/settings") + : encodeURIComponent(router.pathname); const logoutRedirection = async (fullReload: boolean = false) => { if (!hasPublicPath) { - const redirectUrl = `/${RouterType.LOGIN}?redirect=${encodeURIComponent( - router.pathname, - )}`; + const redirectUrl = `/${RouterType.LOGIN}?redirect=${encodedPath}`; if (fullReload) { window.location.replace(redirectUrl); From 77ac209bf894e872cf11486e0774ae978241b428 Mon Sep 17 00:00:00 2001 From: abdou6666 Date: Fri, 7 Feb 2025 17:32:05 +0100 Subject: [PATCH 3/4] fix: redirection to dynamic path --- frontend/src/hooks/useAuth.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/frontend/src/hooks/useAuth.ts b/frontend/src/hooks/useAuth.ts index 4861cd3e..495cf91e 100755 --- a/frontend/src/hooks/useAuth.ts +++ b/frontend/src/hooks/useAuth.ts @@ -32,14 +32,12 @@ export const useAuth = () => { export const useLogoutRedirection = () => { const router = useRouter(); - const isDynamicPath = router.pathname.includes("["); const hasPublicPath = PUBLIC_PATHS.includes(router.pathname); - const encodedPath = isDynamicPath - ? encodeURIComponent("/settings") - : encodeURIComponent(router.pathname); const logoutRedirection = async (fullReload: boolean = false) => { if (!hasPublicPath) { - const redirectUrl = `/${RouterType.LOGIN}?redirect=${encodedPath}`; + const redirectUrl = `/${RouterType.LOGIN}?redirect=${encodeURIComponent( + router.asPath, + )}`; if (fullReload) { window.location.replace(redirectUrl); From 3f8f0cfc8cc188c25466e9b9f48d492ba609ed21 Mon Sep 17 00:00:00 2001 From: abdou6666 Date: Fri, 7 Feb 2025 18:20:14 +0100 Subject: [PATCH 4/4] fix: refactor --- frontend/src/app-components/widget/ChatWidget.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/src/app-components/widget/ChatWidget.tsx b/frontend/src/app-components/widget/ChatWidget.tsx index ce98aee0..201d5edd 100644 --- a/frontend/src/app-components/widget/ChatWidget.tsx +++ b/frontend/src/app-components/widget/ChatWidget.tsx @@ -6,7 +6,6 @@ * 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 { Avatar, Box } from "@mui/material"; import UiChatWidget from "hexabot-chat-widget/src/UiChatWidget"; import { useRouter } from "next/router"; @@ -25,8 +24,7 @@ import { ChatWidgetHeader } from "./ChatWidgetHeader"; const SETTING_TYPE = "console_channel" as const; export const ChatWidget = () => { - const router = useRouter(); - const pathname = router.pathname; + const { pathname } = useRouter(); const { apiUrl } = useConfig(); const { isAuthenticated } = useAuth(); const isVisualEditor = pathname.startsWith(`/${RouterType.VISUAL_EDITOR}`);