generated from goitacademy/react-homework-template
-
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.
- Loading branch information
1 parent
accb903
commit 40f8f20
Showing
12 changed files
with
104 additions
and
30 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
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,19 +1,26 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { authSelectors } from '../../redux/auth/authSelectors'; | ||
|
||
import { | ||
NavigationMenu, | ||
NavItem, | ||
StyledLink, | ||
} from 'components/AppBar/AppBar.styled'; | ||
|
||
export const Navigation = () => { | ||
const isLoggedIn = useSelector(authSelectors.selectIsLoggedIn); | ||
|
||
return ( | ||
<NavigationMenu> | ||
<NavItem> | ||
<StyledLink to="/">Home</StyledLink> | ||
</NavItem> | ||
|
||
<NavItem> | ||
<StyledLink to="contacts">Contacts</StyledLink> | ||
</NavItem> | ||
{isLoggedIn && ( | ||
<NavItem> | ||
<StyledLink to="contacts">Contacts</StyledLink> | ||
</NavItem> | ||
)} | ||
</NavigationMenu> | ||
); | ||
}; |
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,18 +1,12 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { | ||
selectUser, | ||
selectIsLoggedIn, | ||
selectIsRefreshing, | ||
} from '../redux/auth/selectors'; | ||
import { authSelectors } from '../redux/auth/authSelectors'; | ||
|
||
export const useAuth = () => { | ||
const isLoggedIn = useSelector(selectIsLoggedIn); | ||
const isRefreshing = useSelector(selectIsRefreshing); | ||
const user = useSelector(selectUser); | ||
const isLoggedIn = useSelector(authSelectors.selectIsLoggedIn); | ||
const user = useSelector(authSelectors.selectUserName); | ||
|
||
return { | ||
isLoggedIn, | ||
isRefreshing, | ||
user, | ||
}; | ||
}; |
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,12 +1,12 @@ | ||
import { useSelector } from 'react-redux'; | ||
import authSelectors from '../../redux/auth/authSelectors'; | ||
import { authSelectors } from '../../redux/auth/authSelectors'; | ||
|
||
import { Title } from './HomePage.styled'; | ||
|
||
const HomePage = () => { | ||
const name = useSelector(authSelectors.selectUserName); | ||
|
||
return <Title>Hello {name}</Title>; | ||
return <Title>Wellcome to Our Application {name}</Title>; | ||
}; | ||
|
||
export default HomePage; |
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,20 @@ | ||
import { | ||
NotAuthContainer, | ||
Title, | ||
Text, | ||
StyledLink, | ||
} from './NotAuthPage.styled'; | ||
|
||
const NotAuthPage = () => { | ||
return ( | ||
<NotAuthContainer> | ||
<Title>Unauthorized user</Title> | ||
<Text>You have profile</Text> | ||
<StyledLink to="login">Log in</StyledLink> | ||
<Text>Register now</Text> | ||
<StyledLink to="register">Register</StyledLink> | ||
</NotAuthContainer> | ||
); | ||
}; | ||
|
||
export default NotAuthPage; |
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 styled from '@emotion/styled'; | ||
import { NavLink } from 'react-router-dom'; | ||
|
||
export const NotAuthContainer = styled.div` | ||
text-align: center; | ||
background-color: #1dacd6; | ||
padding: 20px; | ||
border-radius: 4px; | ||
`; | ||
|
||
export const Title = styled.h1` | ||
font-size: 60px; | ||
`; | ||
|
||
export const Text = styled.p` | ||
font-size: 18px; | ||
`; | ||
|
||
export const StyledLink = styled(NavLink)` | ||
color: #000000; | ||
font-size: 44px; | ||
`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Navigate } from 'react-router-dom'; | ||
import { useAuth } from '../hooks/useAuth'; | ||
|
||
export const PrivateRoute = ({ component: Component, redirectTo = '/' }) => { | ||
const { isLoggedIn, isRefreshing } = useAuth(); | ||
const shouldRedirect = !isLoggedIn && !isRefreshing; | ||
|
||
return shouldRedirect ? <Navigate to={redirectTo} /> : Component; | ||
}; |