-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from weaponsforge/feature/weaponsforge-76
Feature/weaponsforge 76
- Loading branch information
Showing
21 changed files
with
411 additions
and
55 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
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,43 @@ | ||
import { useEffect } from 'react' | ||
import { useRouter } from 'next/router' | ||
import { useAuth } from '@/lib/hooks/useAuth' | ||
|
||
import LoadingCover from '@/common/layout/loadingcover' | ||
|
||
/** | ||
* HOC that listens for the Firebase user auth info from the global "user" redux states set by the useAuth() hook. | ||
* Displays a loading cover page while waiting for the remote authentication info to settle in. | ||
* Displays and returns the Component parameter if there is user data from the remote auth. | ||
* Redirect to the /login page if there is no user info after the remote auth settles in. | ||
* @param {Component} Component | ||
* @returns {Component} (Component parameter or a Loading placeholder component) | ||
* Usage: export default ProtectedPage(MyComponent) | ||
*/ | ||
function ProtectedPage (Component) { | ||
function AuthListener (props) { | ||
const router = useRouter() | ||
const { authLoading, authError, authUser } = useAuth() | ||
|
||
useEffect(() => { | ||
if (!authLoading && !authUser) { | ||
router.push('/login') | ||
} | ||
}, [authUser, authLoading, router]) | ||
|
||
const ItemComponent = () => { | ||
if (authLoading) { | ||
return <LoadingCover /> | ||
} else if (authUser) { | ||
return <Component {...props} /> | ||
} else { | ||
return <LoadingCover authError={authError} /> | ||
} | ||
} | ||
|
||
return (<ItemComponent />) | ||
} | ||
|
||
return AuthListener | ||
} | ||
|
||
export default ProtectedPage |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Box from '@mui/material/Box' | ||
import Typography from '@mui/material/Typography' | ||
import CircularProgress from '@mui/material/CircularProgress' | ||
|
||
import Page from '@/common/layout/page' | ||
import TransparentBox from '@/common/ui/transparentbox' | ||
import { useSyncLocalStorage } from '@/lib/hooks/useSync' | ||
|
||
function LoadingCover ({ authError }) { | ||
const [activeTheme] = useSyncLocalStorage('activeTheme') | ||
|
||
return ( | ||
<Page> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
placeContent: 'center', | ||
height: '100vh' | ||
}} | ||
> | ||
<TransparentBox> | ||
<span> | ||
<Typography variant='h6' color='#000'> | ||
Loading... | ||
</Typography> | ||
</span> | ||
|
||
<span> | ||
<CircularProgress | ||
color={(activeTheme === 'light') ? 'dark' : 'primary'} | ||
/> | ||
</span> | ||
|
||
{authError && | ||
<Typography variant='label' color='error'> | ||
{authError} | ||
</Typography> | ||
} | ||
</TransparentBox> | ||
</Box> | ||
</Page> | ||
) | ||
} | ||
|
||
export default LoadingCover |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Box from '@mui/material/Box' | ||
|
||
function TransparentBox ({ children }) { | ||
return ( | ||
<Box sx={{ | ||
width: { | ||
md: '800px', | ||
}, | ||
backgroundColor: 'rgba(255, 255, 255, 0.5)', | ||
borderRadius: '8px', | ||
boxShadow: 'box-shadow: 0 10px 40px rgb(0 0 0 / 14%)', | ||
textAlign: 'center', | ||
padding: '24px', | ||
display: 'grid', | ||
placeContent: 'center' | ||
}}> | ||
{children} | ||
</Box> | ||
) | ||
} | ||
|
||
export default TransparentBox |
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,11 @@ | ||
import Page from '@/common/layout/page' | ||
|
||
function DashboardComponent () { | ||
return ( | ||
<Page> | ||
<h1>Dashboard</h1> | ||
</Page> | ||
) | ||
} | ||
|
||
export default DashboardComponent |
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.