diff --git a/frontend/src/components/helpers/custom-markdown/CustomMarkdown.jsx b/frontend/src/components/helpers/custom-markdown/CustomMarkdown.jsx index ff9bfe73e..9e895674b 100644 --- a/frontend/src/components/helpers/custom-markdown/CustomMarkdown.jsx +++ b/frontend/src/components/helpers/custom-markdown/CustomMarkdown.jsx @@ -3,6 +3,8 @@ import PropTypes from "prop-types"; import { useMemo } from "react"; import { Link as RouterLink } from "react-router-dom"; +import { useSessionStore } from "../../../store/session-store"; + const { Text, Link, Paragraph } = Typography; const CustomMarkdown = ({ @@ -11,6 +13,8 @@ const CustomMarkdown = ({ isSecondary = false, styleClassName, }) => { + const { sessionDetails } = useSessionStore(); + const orgName = sessionDetails?.orgName; const textType = isSecondary ? "secondary" : undefined; /* @@ -52,7 +56,8 @@ const CustomMarkdown = ({ case "link": { const isInternal = url?.startsWith("/"); if (isInternal) { - return {content}; + const resolvedUrl = orgName ? `/${orgName}${url}` : url; + return {content}; } return ( @@ -99,7 +104,7 @@ const CustomMarkdown = ({ }); return elements; - }, [text, renderNewLines, textType]); + }, [text, renderNewLines, textType, orgName]); return ( diff --git a/frontend/src/hooks/useExceptionHandler.jsx b/frontend/src/hooks/useExceptionHandler.jsx index 54037820f..1a43811d3 100644 --- a/frontend/src/hooks/useExceptionHandler.jsx +++ b/frontend/src/hooks/useExceptionHandler.jsx @@ -1,30 +1,12 @@ import PropTypes from "prop-types"; import { useNavigate } from "react-router-dom"; -import { useSessionStore } from "../store/session-store.js"; - const useExceptionHandler = () => { const navigate = useNavigate(); - const { sessionDetails } = useSessionStore(); - - // Resolves relative markdown links [text](/path) to [text](/{orgName}/path) - const enrichMarkdownLinks = (message) => { - if (typeof message !== "string") { - return message; - } - const orgName = sessionDetails?.orgName; - if (!orgName) { - return message; - } - return message.replace( - /\[([^\]]+)\]\(\/((?!\/)[^)]+)\)/g, - (_, text, path) => `[${text}](/${orgName}/${path})`, - ); - }; const buildAlert = (content, title, duration) => ({ type: "error", - content: enrichMarkdownLinks(content), + content, title, duration, });