Skip to content

Commit c97cb28

Browse files
authored
CORE-903: Go to Rex portal URL from portal Details page (#2738)
[CORE-903] Rewrite TOC links
1 parent d6be176 commit c97cb28

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/app/helpers/rex-portal.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import usePortalContext from '~/contexts/portal';
2+
3+
export function useRexPortalLinkOrNot(link: string) {
4+
const {portalPrefix} = usePortalContext();
5+
6+
if (!portalPrefix) {
7+
return link;
8+
}
9+
return link.replace('books/', `portal${portalPrefix}/books/`);
10+
}

src/app/pages/details/common/get-this-title-files/options.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import RecommendedCallout from './recommended-callout/recommended-callout';
1818
import {useOpenGiveDialog} from './give-before-pdf/use-give-dialog';
1919
import useCalloutCounter from './recommended-callout/use-callout-counter';
2020
import trackLink from '../track-link';
21+
import {useRexPortalLinkOrNot} from '~/helpers/rex-portal';
2122
import type {Model} from '../get-this-title';
2223
import type {TrackedMouseEvent} from '~/components/shell/router-helpers/use-link-handler';
2324

@@ -104,7 +105,6 @@ export function TocOption({model}: {model: Model}) {
104105
);
105106
}
106107

107-
108108
export function WebviewOption({model}: {model: Model}) {
109109
const [showCallout, hideForever] = useCalloutCounter(model.slug);
110110

@@ -113,7 +113,7 @@ export function WebviewOption({model}: {model: Model}) {
113113
link: intl.formatMessage({id: 'getit.webview.link'})
114114
};
115115
const isRex = Boolean(model.webviewRexLink);
116-
const webviewLink = model.webviewRexLink || model.webviewLink;
116+
const webviewLink = useRexPortalLinkOrNot(model.webviewRexLink) || model.webviewLink;
117117
const iconAndTextArgs = {
118118
icon: faLaptop,
119119
text: $.isPolish(model.title) ? 'Zobacz w przeglądarce' : texts.link

src/app/pages/details/common/hooks.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import partnerFeaturePromise from '~/models/salesforce-partners';
44
import shuffle from 'lodash/shuffle';
55
import {camelCaseKeys} from '~/helpers/page-data-utils';
66
import useDetailsContext from '../context';
7+
import {useRexPortalLinkOrNot} from '~/helpers/rex-portal';
78

89
export function useTableOfContents() {
910
const model = useDetailsContext();
10-
const webviewLink = model.webviewRexLink;
11+
const webviewLink = useRexPortalLinkOrNot(model.webviewRexLink);
1112
const [tocHtml, setTocHtml] = useState<string>('');
1213

1314
if (webviewLink) {

0 commit comments

Comments
 (0)