-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicitly use global layout for each page instead of handling relate…
…d stuff in ApplicationArea component
- Loading branch information
1 parent
e4350f0
commit a65f5f5
Showing
32 changed files
with
398 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
57 changes: 57 additions & 0 deletions
57
client/app/components/ApplicationArea/layout/DefaultAuthenticated.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { Auth } from "@/services/auth"; | ||
import organizationStatus from "@/services/organizationStatus"; | ||
import ApplicationHeader from "./ApplicationHeader"; | ||
|
||
export default function DefaultAuthenticated({ bodyClass, children }) { | ||
const [isAuthenticated, setIsAuthenticated] = useState(!!Auth.isAuthenticated()); | ||
|
||
useEffect(() => { | ||
let isCancelled = false; | ||
Promise.all([Auth.requireSession(), organizationStatus.refresh()]) | ||
.then(() => { | ||
if (!isCancelled) { | ||
setIsAuthenticated(!!Auth.isAuthenticated()); | ||
} | ||
}) | ||
.catch(() => { | ||
if (!isCancelled) { | ||
setIsAuthenticated(false); | ||
} | ||
}); | ||
return () => { | ||
isCancelled = true; | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (bodyClass) { | ||
document.body.classList.toggle(bodyClass, true); | ||
return () => { | ||
document.body.classList.toggle(bodyClass, false); | ||
}; | ||
} | ||
}, [bodyClass]); | ||
|
||
if (!isAuthenticated) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<ApplicationHeader /> | ||
{children} | ||
</> | ||
); | ||
} | ||
|
||
DefaultAuthenticated.propTypes = { | ||
bodyClass: PropTypes.string, | ||
children: PropTypes.node, | ||
}; | ||
|
||
DefaultAuthenticated.defaultProps = { | ||
bodyClass: null, | ||
children: null, | ||
}; |
41 changes: 41 additions & 0 deletions
41
client/app/components/ApplicationArea/layout/DefaultSignedOut.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useEffect, useState } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { Auth } from "@/services/auth"; | ||
|
||
export default function DefaultSignedOut({ apiKey, children }) { | ||
const [isAuthenticated, setIsAuthenticated] = useState(false); | ||
|
||
useEffect(() => { | ||
let isCancelled = false; | ||
Auth.setApiKey(apiKey); | ||
Auth.loadConfig() | ||
.then(() => { | ||
if (!isCancelled) { | ||
setIsAuthenticated(true); | ||
} | ||
}) | ||
.catch(() => { | ||
if (!isCancelled) { | ||
setIsAuthenticated(false); | ||
} | ||
}); | ||
return () => { | ||
isCancelled = true; | ||
}; | ||
}, [apiKey]); | ||
|
||
if (!isAuthenticated) { | ||
return null; | ||
} | ||
|
||
return children; | ||
} | ||
|
||
DefaultSignedOut.propTypes = { | ||
apiKey: PropTypes.string.isRequired, | ||
children: PropTypes.node, | ||
}; | ||
|
||
DefaultSignedOut.defaultProps = { | ||
children: null, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.