-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AccountPage and navigation from ProfilePage
- Loading branch information
1 parent
ad5ee70
commit 011d57f
Showing
5 changed files
with
97 additions
and
48 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 |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import React, { useContext } from "react"; | ||
import { Route, Redirect } from "react-router-dom"; | ||
|
||
import AuthContext from "../../contexts/AuthContext"; | ||
import { LOGIN_PAGE } from "../../constants/Routes"; | ||
|
||
type PrivateRouteProps = { | ||
component: React.FC; | ||
path: string; | ||
exact: boolean; | ||
allowedRoles: Set<string>; | ||
}; | ||
|
||
const PrivateRoute: React.FC<PrivateRouteProps> = ({ | ||
component, | ||
exact, | ||
path, | ||
allowedRoles, | ||
}: PrivateRouteProps) => { | ||
const { authenticatedUser } = useContext(AuthContext); | ||
|
||
if (!authenticatedUser) { | ||
return <Redirect to={LOGIN_PAGE} />; | ||
} | ||
if (!allowedRoles.has(authenticatedUser.role)) { | ||
return <Redirect to="*" />; | ||
} | ||
|
||
return <Route path={path} exact={exact} component={component} />; | ||
}; | ||
|
||
export default PrivateRoute; | ||
import React, { useContext } from "react"; | ||
import { Route, Redirect } from "react-router-dom"; | ||
|
||
import AuthContext from "../../contexts/AuthContext"; | ||
import { LOGIN_PAGE } from "../../constants/Routes"; | ||
|
||
type PrivateRouteProps = { | ||
component: React.FC; | ||
path: string; | ||
exact: boolean; | ||
allowedRoles: Set<string>; | ||
}; | ||
|
||
const PrivateRoute: React.FC<PrivateRouteProps> = ({ | ||
component, | ||
exact, | ||
path, | ||
allowedRoles, | ||
}: PrivateRouteProps) => { | ||
const { authenticatedUser } = useContext(AuthContext); | ||
|
||
if (!authenticatedUser) { | ||
return <Redirect to={LOGIN_PAGE} />; | ||
} | ||
if (!allowedRoles.has(authenticatedUser.role)) { | ||
return <Redirect to="*" />; | ||
} | ||
|
||
return <Route path={path} exact={exact} component={component} />; | ||
}; | ||
|
||
export default PrivateRoute; |
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,28 @@ | ||
import React from "react"; | ||
import { Text } from "@chakra-ui/react"; | ||
import { useHistory } from "react-router-dom"; | ||
import NavBar from "../common/navbar/NavBar"; | ||
import { PROFILE_PAGE } from "../../constants/Routes"; | ||
|
||
const AccountPage = (): React.ReactElement => { | ||
const history = useHistory(); | ||
const navigateTo = () => history.push(PROFILE_PAGE); | ||
return ( | ||
<div style={{ textAlign: "center" }}> | ||
<NavBar pageName="Profile" /> | ||
<Text textStyle="h3" mt={{ base: "6.375rem", md: "9.375rem" }}> | ||
Account Page ⚙️ | ||
</Text> | ||
<button | ||
onClick={navigateTo} | ||
className="btn btn-primary" | ||
type="button" | ||
style={{ textAlign: "center" }} | ||
> | ||
My profile | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AccountPage; |
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 |
---|---|---|
@@ -1,16 +1,28 @@ | ||
import React from "react"; | ||
import { Text } from "@chakra-ui/react"; | ||
import NavBar from "../common/navbar/NavBar"; | ||
|
||
const ProfilePage = (): React.ReactElement => { | ||
return ( | ||
<div style={{ textAlign: "center" }}> | ||
<NavBar pageName="Profile" /> | ||
<Text textStyle="h3" mt={{ base: "6.375rem", md: "9.375rem" }}> | ||
Profile Page 🫨 | ||
</Text> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProfilePage; | ||
import React from "react"; | ||
import { Text } from "@chakra-ui/react"; | ||
import { useHistory } from "react-router-dom"; | ||
import NavBar from "../common/navbar/NavBar"; | ||
import { ACCOUNT_PAGE } from "../../constants/Routes"; | ||
|
||
const ProfilePage = (): React.ReactElement => { | ||
const history = useHistory(); | ||
const navigateTo = () => history.push(ACCOUNT_PAGE); | ||
return ( | ||
<div style={{ textAlign: "center" }}> | ||
<NavBar pageName="Profile" /> | ||
<Text textStyle="h3" mt={{ base: "6.375rem", md: "9.375rem" }}> | ||
Profile Page 🫨 | ||
</Text> | ||
<button | ||
onClick={navigateTo} | ||
className="btn btn-primary" | ||
type="button" | ||
style={{ textAlign: "center" }} | ||
> | ||
My Account | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProfilePage; |
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