2019-02-28 15:44:35 +00:00
|
|
|
import React from 'react';
|
2021-08-09 01:30:31 -07:00
|
|
|
|
2019-02-28 15:44:35 +00:00
|
|
|
import {
|
|
|
|
CertificationLayout,
|
2019-07-25 13:53:42 +05:30
|
|
|
DefaultLayout
|
2019-02-28 15:44:35 +00:00
|
|
|
} from '../../src/components/layouts';
|
2019-05-14 17:29:27 +03:00
|
|
|
import FourOhFourPage from '../../src/pages/404';
|
2021-06-24 12:50:36 +03:00
|
|
|
import { isChallenge } from '../../src/utils/path-parsers';
|
2019-02-28 15:44:35 +00:00
|
|
|
|
2021-07-12 12:35:01 +05:30
|
|
|
interface LayoutSelectorProps {
|
2021-08-09 01:30:31 -07:00
|
|
|
element: JSX.Element;
|
|
|
|
props: { location: { pathname: string } };
|
2021-07-12 12:35:01 +05:30
|
|
|
}
|
|
|
|
export default function layoutSelector({
|
|
|
|
element,
|
|
|
|
props
|
2021-08-09 01:30:31 -07:00
|
|
|
}: LayoutSelectorProps): JSX.Element {
|
2019-02-28 15:44:35 +00:00
|
|
|
const {
|
|
|
|
location: { pathname }
|
|
|
|
} = props;
|
2020-12-28 20:52:41 -06:00
|
|
|
|
2019-05-14 17:29:27 +03:00
|
|
|
if (element.type === FourOhFourPage) {
|
2021-02-18 08:11:05 +03:00
|
|
|
return (
|
|
|
|
<DefaultLayout pathname={pathname} showFooter={true}>
|
|
|
|
{element}
|
|
|
|
</DefaultLayout>
|
|
|
|
);
|
2021-06-24 12:50:36 +03:00
|
|
|
} else if (/\/certification\//.test(pathname)) {
|
2019-12-02 15:48:53 +03:00
|
|
|
return (
|
|
|
|
<CertificationLayout pathname={pathname}>{element}</CertificationLayout>
|
|
|
|
);
|
2021-06-24 12:50:36 +03:00
|
|
|
} else if (isChallenge(pathname)) {
|
2019-02-28 15:44:35 +00:00
|
|
|
return (
|
|
|
|
<DefaultLayout pathname={pathname} showFooter={false}>
|
|
|
|
{element}
|
|
|
|
</DefaultLayout>
|
|
|
|
);
|
2021-06-24 12:50:36 +03:00
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<DefaultLayout pathname={pathname} showFooter={true}>
|
|
|
|
{element}
|
|
|
|
</DefaultLayout>
|
|
|
|
);
|
2019-02-28 15:44:35 +00:00
|
|
|
}
|
|
|
|
}
|