Skip to content

Commit a9716e6

Browse files
committed
Portal pages use landing page layout
1 parent cfcb24e commit a9716e6

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

src/app/components/shell/router-helpers/fallback-to.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function FallbackTo({name}) {
2222
}
2323

2424
export const isFlexPage = (data) => (
25-
typeof data.meta?.type === 'string' &&
25+
typeof data?.meta?.type === 'string' &&
2626
['pages.FlexPage', 'pages.RootPage'].includes(data.meta.type)
2727
);
2828

src/app/components/shell/router.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ function useLoading(name) {
5858
}
5959

6060
function DefaultLayout({children}) {
61+
const {portal} = useParams();
6162
const {setLayoutParameters, layoutParameters} = useLayoutContext();
6263

63-
useEffect(
64-
() => setLayoutParameters(),
65-
[setLayoutParameters]
66-
);
6764

68-
return layoutParameters.name === 'default' ? children : null;
65+
if (portal) {
66+
setLayoutParameters({name: 'landing', data: layoutParameters.data});
67+
}
68+
69+
return layoutParameters.name ? children : null;
6970
}
7071

7172
function usePage(name) {

src/app/layouts/landing/landing.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { isFlexPage } from '~/components/shell/router-helpers/fallback-to';
1313
import './landing.scss';
1414

1515
type Props = {
16-
data: {
16+
data?: {
1717
title: string;
1818
meta?: {
1919
type: string;
@@ -39,14 +39,15 @@ export default function LandingLayout({
3939
children,
4040
data
4141
}: React.PropsWithChildren<Props>) {
42-
const showGive = data.layout[0]?.value.showGive;
42+
const layoutValue = data?.layout[0]?.value;
43+
const showGive = layoutValue?.showGive;
4344

4445
// BrowserRouter has to include everything that uses useLocation
4546
return (
4647
<React.Fragment>
4748
<header className="landing-page-header">
4849
<Header
49-
links={data.layout[0]?.value.navLinks ?? []}
50+
links={layoutValue?.navLinks ?? []}
5051
showGive={showGive}
5152
/>
5253
</header>
@@ -75,7 +76,7 @@ function Main({children, data}: React.PropsWithChildren<Props>) {
7576
<div
7677
id="main"
7778
className={cn('lang', 'layout-landing', language, classes)}
78-
data-analytics-nav={`Landing page (${data.title})`}
79+
data-analytics-nav={data ? `Landing page (${data.title})` : undefined}
7980
ref={ref}
8081
tabIndex={-1}
8182
>

test/src/layouts/layouts.test.tsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import LandingLayout from '~/layouts/landing/landing';
77
// @ts-expect-error does not exist on
88
const {routerFuture} = global;
99

10-
type Layout = Parameters<typeof LandingLayout>[0]['data']['layout'];
10+
type Data = Parameters<typeof LandingLayout>[0]['data'];
11+
type Layout = Exclude<Data, undefined>['layout'];
1112

1213
describe('layouts/landing', () => {
1314
function Component({layout}: {layout: Layout}) {
@@ -25,6 +26,15 @@ describe('layouts/landing', () => {
2526
);
2627
}
2728

29+
it('renders without data object', () => {
30+
render(<MemoryRouter initialEntries={['']} future={routerFuture}>
31+
<LandingLayout>
32+
<div>child contents</div>
33+
</LandingLayout>
34+
</MemoryRouter>);
35+
expect(screen.getAllByRole('img')).toHaveLength(2);
36+
expect(screen.getAllByRole('link')).toHaveLength(1);
37+
});
2838
it('renders without layout values', () => {
2939
render(<Component layout={[]} />);
3040
expect(screen.getAllByRole('img')).toHaveLength(2);
@@ -68,7 +78,7 @@ describe('layouts/landing', () => {
6878
const data = {title, layout, meta} as const;
6979

7080
render(
71-
<MemoryRouter initialEntries={['']}>
81+
<MemoryRouter initialEntries={['']} future={routerFuture}>
7282
<LandingLayout data={data}>
7383
<div>child contents</div>
7484
</LandingLayout>
@@ -88,7 +98,7 @@ describe('layouts/landing', () => {
8898
const data = {title, layout, meta} as const;
8999

90100
render(
91-
<MemoryRouter initialEntries={['']}>
101+
<MemoryRouter initialEntries={['']} future={routerFuture}>
92102
<LandingLayout data={data}>
93103
<div>child contents</div>
94104
</LandingLayout>

yarn.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -5041,7 +5041,7 @@
50415041
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.7.tgz#50ae4353eaaddc04044279812f52c8c65857dbcb"
50425042
integrity sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==
50435043

5044-
"@types/react-dom@^18", "@types/react-dom@^18.3.0":
5044+
"@types/react-dom@^18":
50455045
version "18.3.6"
50465046
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.3.6.tgz#fa59a5e9a33499a792af6c1130f55921ef49d268"
50475047
integrity sha512-nf22//wEbKXusP6E9pfOCDwFdHAX4u172eaJI4YkDRQEZiorm6KfYnSC2SWLDMVWUOWPERmJnN0ujeAfTBLvrw==
@@ -5068,7 +5068,7 @@
50685068
dependencies:
50695069
"@types/react" "*"
50705070

5071-
"@types/react@*", "@types/react@16 || 17 || 18", "@types/react@^18", "@types/react@^18.3.3":
5071+
"@types/react@*", "@types/react@16 || 17 || 18", "@types/react@^18":
50725072
version "18.3.20"
50735073
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.3.20.tgz#b0dccda9d2f1bc24d2a04b1d0cb5d0b9a3576ad3"
50745074
integrity sha512-IPaCZN7PShZK/3t6Q87pfTkRm6oLTd4vztyoj+cbHUF1g3FfVb2tFIL79uCRKEfv16AhqDMBywP2VW3KIZUvcg==

0 commit comments

Comments
 (0)