From 7dfbd445526b28fedac63d59676df06c02e1be32 Mon Sep 17 00:00:00 2001 From: Eugene Dyudyunov Date: Fri, 24 Feb 2023 11:07:09 +0200 Subject: [PATCH] fix: post sharing URL When MFE uses path-based deployment (common domain for all MFEs divided by path) - the copied link leads to 404 error. The fix: - construct a Post URL using MFE's `PUBLIC_PATH` env var - works for both subdomain and subdirectory-based deployments Note: LMS recently started to use the discussions sidebar which has the same button "Copy Link", but it uses its own env variable `DISCUSSIONS_MFE_BASE_URL` --- src/discussions/posts/post/Post.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/discussions/posts/post/Post.jsx b/src/discussions/posts/post/Post.jsx index 870cfedf..07ed12cd 100644 --- a/src/discussions/posts/post/Post.jsx +++ b/src/discussions/posts/post/Post.jsx @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'; import { useDispatch, useSelector } from 'react-redux'; import { useHistory, useLocation } from 'react-router-dom'; +import { getConfig } from '@edx/frontend-platform'; import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; import { Hyperlink, useToggle } from '@edx/paragon'; @@ -35,6 +36,9 @@ function Post({ const { reasonCodesEnabled } = useSelector(selectModerationSettings); const [isDeleting, showDeleteConfirmation, hideDeleteConfirmation] = useToggle(false); const [isClosing, showClosePostModal, hideClosePostModal] = useToggle(false); + + const postURL = new URL(`${getConfig().PUBLIC_PATH}${courseId}/posts/${post.id}`, window.location.origin); + const actionHandlers = { [ContentActions.EDIT_CONTENT]: () => history.push({ ...location, @@ -50,7 +54,7 @@ function Post({ dispatch(updateExistingThread(post.id, { closed: true })); } }, - [ContentActions.COPY_LINK]: () => { navigator.clipboard.writeText(`${window.location.origin}/${courseId}/posts/${post.id}`); }, + [ContentActions.COPY_LINK]: () => { navigator.clipboard.writeText(postURL.href); }, [ContentActions.PIN]: () => dispatch(updateExistingThread(post.id, { pinned: !post.pinned })), [ContentActions.REPORT]: () => dispatch(updateExistingThread(post.id, { flagged: !post.abuseFlagged })), };