-
Notifications
You must be signed in to change notification settings - Fork 1
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 #11 from GooDeene/module7-task2
- Loading branch information
Showing
26 changed files
with
382 additions
and
98 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,23 +1,44 @@ | ||
import {Link} from 'react-router-dom'; | ||
import {AppRoute} from '../../const.ts'; | ||
import {useAuthorization} from '../../hooks/use-authorization.ts'; | ||
import {useAppDispatch, useAppSelector} from '../../hooks/redux.ts'; | ||
import {logoutAction} from '../../store/api-actions.ts'; | ||
|
||
function HeaderNavigation(): JSX.Element { | ||
const isAuthorized = useAuthorization(); | ||
const dispatch = useAppDispatch(); | ||
const userData = useAppSelector((state) => state.userData); | ||
|
||
const handleLinkClick = () => { | ||
dispatch(logoutAction()); | ||
}; | ||
|
||
return ( | ||
<nav className="header__nav"> | ||
<ul className="header__nav-list"> | ||
<li className="header__nav-item user"> | ||
<Link className="header__nav-link header__nav-link--profile" to={AppRoute.Favourites}> | ||
<div className="header__avatar-wrapper user__avatar-wrapper"> | ||
</div> | ||
<span className="header__user-name user__name">{'[email protected]'}</span> | ||
<span className="header__favorite-count">{3}</span> | ||
</Link> | ||
</li> | ||
<li className="header__nav-item"> | ||
<a className="header__nav-link" href="#"> | ||
<span className="header__signout">Sign out</span> | ||
</a> | ||
</li> | ||
{!isAuthorized && | ||
<li className="header__nav-item"> | ||
<Link className="header__nav-link" to={AppRoute.Login}> | ||
<div className="header__avatar-wrapper user__avatar-wrapper"/> | ||
<span className="header__signout">Sign in</span> | ||
</Link> | ||
</li>} | ||
{isAuthorized && | ||
<> | ||
<li className="header__nav-item user"> | ||
<Link className="header__nav-link header__nav-link--profile" to={AppRoute.Favourites}> | ||
<div className="header__avatar-wrapper user__avatar-wrapper"> | ||
</div> | ||
<span className="header__user-name user__name">{userData?.email}</span> | ||
<span className="header__favorite-count">{3}</span> | ||
</Link> | ||
</li> | ||
<li className="header__nav-item"> | ||
<Link className="header__nav-link" to={''} onClick={handleLinkClick}> | ||
<span className="header__signout">Sign out</span> | ||
</Link> | ||
</li> | ||
</>} | ||
</ul> | ||
</nav> | ||
); | ||
|
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,20 +1,14 @@ | ||
import {Navigate} from 'react-router-dom'; | ||
import {AppRoute, AuthStatus} from '../../const'; | ||
import {PropsWithChildren} from 'react'; | ||
import {PropsWithChildren, ReactNode} from 'react'; | ||
import {useAppSelector} from '../../hooks/redux.ts'; | ||
|
||
type PrivateRouteProps = { | ||
authorizationStatus: AuthStatus; | ||
children: JSX.Element; | ||
} | ||
|
||
function PrivateRoute(props: PropsWithChildren<PrivateRouteProps>): JSX.Element { | ||
const {authorizationStatus, children} = props; | ||
function PrivateRoute({children}: PropsWithChildren): ReactNode { | ||
const authorizationStatus = useAppSelector((state) => state.authorizationStatus); | ||
|
||
return ( | ||
authorizationStatus === AuthStatus.Auth | ||
? children | ||
: <Navigate to={AppRoute.Login} /> | ||
); | ||
return authorizationStatus === AuthStatus.Auth | ||
? children | ||
: <Navigate to={AppRoute.Login} />; | ||
} | ||
|
||
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
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,6 @@ | ||
import {useAppSelector} from './redux.ts'; | ||
import {AuthStatus} from '../const.ts'; | ||
|
||
export function useAuthorization() { | ||
return useAppSelector((state) => state.authorizationStatus) === AuthStatus.Auth; | ||
} |
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.