|
1 | | -import { Link, Navigate } from 'react-router'; |
2 | | -import { useSelector } from 'react-redux'; |
| 1 | +import { useDispatch, useSelector } from 'react-redux'; |
| 2 | +import { Link } from 'react-router'; |
3 | 3 |
|
4 | 4 | import { userSelectors } from '@/shared/store/features/user/user-selectors'; |
| 5 | +import { logoutAction } from '@/shared/store/features/user/user-slices'; |
5 | 6 | import { APP_ROUTES } from '@/shared/constants'; |
6 | 7 |
|
7 | 8 | export function LandingPage() { |
| 9 | + const dispatch = useDispatch(); |
8 | 10 | const { isAuthenticated } = useSelector(userSelectors.userInfo); |
9 | 11 |
|
10 | | - if (isAuthenticated) { |
11 | | - return <Navigate to={APP_ROUTES.main} replace />; |
12 | | - } |
| 12 | + const handleLogout = () => { |
| 13 | + dispatch(logoutAction()); |
| 14 | + }; |
13 | 15 |
|
14 | 16 | return ( |
15 | 17 | <main className='flex flex-col items-center justify-center h-dvh gap-6'> |
16 | | - <h3>Landing Page</h3> |
| 18 | + <h3 className='text-2xl'>Landing Page</h3> |
| 19 | + {isAuthenticated && <p className='text-slate-400'>You Are Logged In Now</p>} |
17 | 20 | <div className='flex items-center justify-center gap-4 flex-wrap'> |
18 | | - <Link className='border py-3 px-4 rounded' to={APP_ROUTES.login}> |
19 | | - Login Sample |
20 | | - </Link> |
21 | | - <Link className='border py-3 px-4 rounded' to={APP_ROUTES.main}> |
22 | | - Protected Route |
| 21 | + {isAuthenticated ? ( |
| 22 | + <button className='border py-3 px-4 rounded' onClick={handleLogout}> |
| 23 | + Logout |
| 24 | + </button> |
| 25 | + ) : ( |
| 26 | + <Link className='border py-3 px-4 rounded' to={APP_ROUTES.login}> |
| 27 | + Login Page |
| 28 | + </Link> |
| 29 | + )} |
| 30 | + |
| 31 | + <Link className='flex gap-2 border py-3 px-4 rounded' to={APP_ROUTES.main}> |
| 32 | + Main Page |
| 33 | + {isAuthenticated ? ( |
| 34 | + <span className='text-green-500'>( Allowed )</span> |
| 35 | + ) : ( |
| 36 | + <span className='text-red-500'>( Protected )</span> |
| 37 | + )} |
23 | 38 | </Link> |
| 39 | + |
24 | 40 | <Link className='border py-3 px-4 rounded' to={APP_ROUTES.notFound}> |
25 | 41 | Not Found Page |
26 | 42 | </Link> |
|
0 commit comments