feat(client): ts-migrate layoutSelector component (#42748)

This commit is contained in:
ABHINAV SHARMA
2021-07-12 12:35:01 +05:30
committed by GitHub
parent a33584fd5b
commit e2ca65c803
4 changed files with 18 additions and 12 deletions

View File

@ -0,0 +1,51 @@
import React from 'react';
import {
CertificationLayout,
DefaultLayout
} from '../../src/components/layouts';
import FourOhFourPage from '../../src/pages/404';
import { isChallenge } from '../../src/utils/path-parsers';
interface Location {
pathname: string;
}
interface LayoutSelectorProps {
props: {
location: Location;
};
element: React.ReactElement;
}
export default function layoutSelector({
element,
props
}: LayoutSelectorProps): React.ReactElement {
const {
location: { pathname }
} = props;
if (element.type === FourOhFourPage) {
return (
<DefaultLayout pathname={pathname} showFooter={true}>
{element}
</DefaultLayout>
);
} else if (/\/certification\//.test(pathname)) {
return (
<CertificationLayout pathname={pathname}>{element}</CertificationLayout>
);
} else if (isChallenge(pathname)) {
return (
<DefaultLayout pathname={pathname} showFooter={false}>
{element}
</DefaultLayout>
);
} else {
return (
<DefaultLayout pathname={pathname} showFooter={true}>
{element}
</DefaultLayout>
);
}
}