-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwrap-with-provider.js
72 lines (64 loc) · 1.94 KB
/
wrap-with-provider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, { Fragment } from "react";
import { navigate } from "gatsby";
import { useLocation } from "@reach/router";
import {
setLayoutBase,
setFirebaseClass,
setWithAuthorizationWrapper,
WithAuthorizationClass,
} from "upe-react-components";
import Firebase from "./src/components/API/Firebase";
import Header from "./src/components/Header";
import Footer from "./src/components/Footer";
import Logo from "./src/components/Logo";
import TextDisplay from "./src/components/TextDisplay";
import GlobalStyle from "./src/styles/global";
import { pathPrefix } from "./gatsby-config";
import "bootstrap/dist/css/bootstrap.min.css";
import "react-bootstrap-range-slider/dist/react-bootstrap-range-slider.css";
export default ({ element }) => {
setFirebaseClass(Firebase);
const WithAuthorizationWrapper = (props) => {
const location = useLocation();
const savePathname = () =>
window.localStorage.setItem(
"pathname",
location.pathname.replace(pathPrefix, "")
);
return (
<WithAuthorizationClass
firebaseAuthNext={(authUser) => {
if (!authUser) {
savePathname();
navigate("/login");
}
}}
firebaseAuthFallback={() => {
savePathname();
navigate("/login");
}}
authorizationFailed=
{<div style={{width: "100%"}}>
<TextDisplay
name={"No Permissions"}
text={"If you believe you should have access, please contact an admin."}
displayBack={true} />
</div>}
{...props}
/>
);
};
// would've preferred to call this in gatsby-browser onClientEntry, but can't do Queries in there
setWithAuthorizationWrapper(WithAuthorizationWrapper);
const LayoutBase = ({ children }) => (
<Fragment>
<GlobalStyle />
<Header />
{children}
<Footer />
</Fragment>
);
LayoutBase.displayName = "LayoutBase";
setLayoutBase(LayoutBase);
return element;
};