diff --git a/package.json b/package.json
index 7d29ba4..78e6771 100644
--- a/package.json
+++ b/package.json
@@ -11,9 +11,12 @@
"@types/node": "^16.11.56",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
+ "@types/react-redux": "^7.1.24",
"axios": "^0.27.2",
"bootstrap": "^5.2.0",
+ "jwt-decode": "^3.1.2",
"react": "^18.2.0",
+ "react-bootstrap": "^2.5.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.2",
"react-router-dom": "^6.3.0",
diff --git a/src/App.tsx b/src/App.tsx
index 5bd4013..ceff8d7 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,32 +1,21 @@
import 'bootstrap/dist/css/bootstrap.min.css'
import { BrowserRouter, Link, Navigate, Outlet, Route, Routes } from 'react-router-dom'
import './App.css'
-import DSAuth from '../src/Services/Auth/Auth.Services'
import { Login } from './Components/Login/Login'
import { RptViajesPendientes } from './Components/Reportes/RptViajesPendientes'
import { Home } from './Components/Home/Home'
-import { Protected } from './Components/Home/Protected/Protected'
import { useEffect } from 'react'
-import ProtectedRoute, { ProtectedRouteProps } from './Components/ProtectedRoute/ProtectedRoute'
+import { useSelector } from 'react-redux'
+import { RootState } from './store/store'
+import Navbar from './Components/Navbar/Navbar'
+import { Logout } from './Components/Logout/Logout'
function App() {
- const Userlogued = (): boolean => {
- DSAuth.Validate()
- .then((response) => {
- console.log('Crednciales validas')
- return true
- })
- .catch((e: Error) => {
- console.log('Credenciales apocrifas')
- return false
- })
- return false
- }
+ const UserLogued = useSelector((state: RootState) => state.UserProfile.UserProfile.logueado)
useEffect(() => {
- Userlogued()
console.log('Entro al proceso de router')
- }, [])
+ }, [UserLogued])
function PageNotFound() {
return (
@@ -40,20 +29,21 @@ function App() {
if (!auth) {
return
}
-
return
}
return (
- login
-
- Reporte de viajes
+
+ {/* login
+
+ {UserLogued ? Reporte de viajes : null}*/}
}>
}>
- }>
+ }>
+ }>
} />
} />
@@ -64,8 +54,3 @@ function App() {
}
export default App
-
-/* export default App
-function useSessionContext(): [any, any] {
- throw new Error('Function not implemented.')
-} */
diff --git a/src/Components/Home/Home.tsx b/src/Components/Home/Home.tsx
index 6f7f2c9..6cc24ea 100644
--- a/src/Components/Home/Home.tsx
+++ b/src/Components/Home/Home.tsx
@@ -6,7 +6,7 @@ interface IProps {}
export const Home: FC = (props) => {
return (
-
This is the Guest Layout Page
+ This is the Alpha Omega Logistics landing page
)
diff --git a/src/Components/Login/Login.tsx b/src/Components/Login/Login.tsx
index 9ad854c..a54296f 100644
--- a/src/Components/Login/Login.tsx
+++ b/src/Components/Login/Login.tsx
@@ -2,11 +2,17 @@ import { FC, useEffect, useState } from 'react'
import { Navigate, useNavigate } from 'react-router-dom'
import IAuth from '../../Interfaces/Auth/IAuth'
import DSAuth from '../../Services/Auth/Auth.Services'
+import { useDispatch, useSelector } from 'react-redux'
+import { MenuItemsSlice, populateMenuItems } from '../../store/features/Auth/MenuItemsSlice'
+import { UserProfileSlice, populateUserProfile } from '../../store/features/Auth/UserProfileSlice'
+import { RootState } from '../../store/store'
interface IProps {}
export const Login: FC = (props) => {
+ const MenuItems = useSelector((state: RootState) => state.MenuItems.MenuItems)
const navigate = useNavigate()
+ const dispatch = useDispatch()
const [Usuario, setUsuario] = useState('')
const [Contrasena, setContrasena] = useState('')
const [token, setToken] = useState(
@@ -22,6 +28,8 @@ export const Login: FC = (props) => {
.then((response) => {
localStorage.setItem('token', response.data.token)
setToken(response.data.token)
+ dispatch(populateMenuItems(response.data.menu))
+ dispatch(populateUserProfile(response.data.token))
window.location.href = 'http://localhost:3000/login'
})
.catch((e: Error) => {
@@ -33,6 +41,7 @@ export const Login: FC = (props) => {
if (token.length > 10) {
DSAuth.Validate()
.then((response) => {
+ dispatch(populateUserProfile(token))
navigate('../RptViajesPendientes', { replace: true })
})
.catch((e: Error) => {
@@ -45,13 +54,8 @@ export const Login: FC = (props) => {
ValidateToken()
}, [])
- useEffect(() => {
- ValidateToken()
- }, [])
-
return (