Skip to content

Commit

Permalink
fix: null error at useRouteMatch when running on tutor
Browse files Browse the repository at this point in the history
tutor sets the PUBLIC_PATH to '/discussions' which causes frontend-platform to
treat all URLs for matching etc to be relative to this path. Since many places
include '/discussions' in the match it causes those matches to break.

This change makes the default PUBLIC_PATH in .env.development to match the one
set by tutor and removes it from the base path of the router letting frontend
platform handle the prefix.

This also allows for deployments to customise this path to be something other
then 'discussions'.
  • Loading branch information
xitij2000 committed Nov 30, 2023
1 parent a479f5a commit 90bb152
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ USER_INFO_COOKIE_NAME='edx-user-info'
SUPPORT_URL='https://support.edx.org'
LEARNER_FEEDBACK_URL=''
STAFF_FEEDBACK_URL=''
PUBLIC_PATH='/discussions'
5 changes: 4 additions & 1 deletion src/data/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { getConfig } from '@edx/frontend-platform';

export const getApiBaseUrl = () => getConfig().LMS_BASE_URL;
export const getFullUrl = (path) => (
new URL(`${getConfig().PUBLIC_PATH.replace(/\/$/, '')}/${path}`, window.location.origin).href
);

/**
* Enum for thread types.
Expand Down Expand Up @@ -137,7 +140,7 @@ export const DiscussionProvider = {
OPEN_EDX: 'openedx',
};

const BASE_PATH = `${getConfig().PUBLIC_PATH}:courseId`;
const BASE_PATH = '/:courseId';

export const Routes = {
DISCUSSIONS: {
Expand Down
5 changes: 2 additions & 3 deletions src/discussions/posts/post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useIntl } from '@edx/frontend-platform/i18n';
import { Hyperlink, useToggle } from '@edx/paragon';

import HTMLLoader from '../../../components/HTMLLoader';
import { ContentActions } from '../../../data/constants';
import { ContentActions, getFullUrl } from '../../../data/constants';
import { selectorForUnitSubsection, selectTopicContext } from '../../../data/selectors';
import { AlertBanner, Confirmation } from '../../common';
import { DiscussionContext } from '../../common/context';
Expand Down Expand Up @@ -78,8 +78,7 @@ const Post = ({ handleAddResponseButton }) => {
}, [closed, postId, reasonCodesEnabled, showClosePostModal]);

const handlePostCopyLink = useCallback(() => {
const postURL = new URL(`${getConfig().PUBLIC_PATH}${courseId}/posts/${postId}`, window.location.origin);
navigator.clipboard.writeText(postURL.href);
navigator.clipboard.writeText(getFullUrl(`${courseId}/posts/${postId}`));
}, [window.location.origin, postId, courseId]);

const handlePostPin = useCallback(() => dispatch(
Expand Down

0 comments on commit 90bb152

Please sign in to comment.