diff --git a/webapp/src/App.js b/webapp/src/App.js index c37a947f..c382f9b6 100644 --- a/webapp/src/App.js +++ b/webapp/src/App.js @@ -1,41 +1,38 @@ import React, { useState } from 'react'; -import Authenticate from './pages/Authenticate/Authenticate.js'; -import Home from './pages/Home/Home.js'; -import Clasico from './pages/Clasico/Clasico.js'; -import WrongRoute from './pages/WrongRoute/WrongRoute.js'; -import './App.css'; +import Register from './components/Register/Register'; +import Login from './components/Login/Login'; +import CssBaseline from '@mui/material/CssBaseline'; +import Container from '@mui/material/Container'; +import Typography from '@mui/material/Typography'; +import Link from '@mui/material/Link'; -import {BrowserRouter, Routes, Route} from "react-router-dom"; -import AuthProvider from 'react-auth-kit'; -import AuthOutlet from '@auth-kit/react-router/AuthOutlet'; -import createStore from 'react-auth-kit/createStore'; +function App() { + const [showLogin, setShowLogin] = useState(true); -const store = createStore({ - authName:'_auth', - authType:'cookie', - cookieDomain: window.location.hostname, - cookieSecure: window.location.protocol === 'https:' -}) - - const App = () => { - return ( - - - - {/** Rutas públicas */} - }/> - - {/** Rutas privadas */} - }> - } /> - } /> - + const handleToggleView = () => { + setShowLogin(!showLogin); + }; - } /> - - - - ); - }; + return ( + + + + Welcome to wiq_es1a + + {showLogin ? : } + + {showLogin ? ( + + Don't have an account? Register here. + + ) : ( + + Already have an account? Login here. + + )} + + + ); +} -export default App; +export default App; \ No newline at end of file diff --git a/webapp/src/App.test.js b/webapp/src/App.test.js index 5e3b7314..6f8bec64 100644 --- a/webapp/src/App.test.js +++ b/webapp/src/App.test.js @@ -3,6 +3,6 @@ import App from './App'; test('renders learn react link', () => { render(); - const linkElement = screen.getByText(/Welcome to the 2024 edition of the Software Architecture course/i); + const linkElement = screen.getByText(/Welcome to wiq_es1a/i); expect(linkElement).toBeInTheDocument(); -}); +}); \ No newline at end of file diff --git a/webapp/src/components/Login/Login.js b/webapp/src/components/Login/Login.js index e6a85166..46b2b5d8 100644 --- a/webapp/src/components/Login/Login.js +++ b/webapp/src/components/Login/Login.js @@ -2,48 +2,30 @@ import React, { useState } from 'react'; import axios from 'axios'; import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; -import { useNavigate } from "react-router-dom"; -import useSignIn from 'react-auth-kit/hooks/useSignIn'; -import './Login.css'; const Login = () => { - const signIn = useSignIn(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); - const [token, setToken] = useState(''); const [error, setError] = useState(''); const [loginSuccess, setLoginSuccess] = useState(false); const [createdAt, setCreatedAt] = useState(''); const [openSnackbar, setOpenSnackbar] = useState(false); - const navigate = useNavigate(); - const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; const loginUser = async () => { try { const response = await axios.post(`${apiEndpoint}/login`, { username, password }); - console.log(response); + // Extract data from the response const { createdAt: userCreatedAt } = response.data; - setToken(response.data.token); - - signIn({ - auth: { - token: token - }, - userState: {name: username} - }) setCreatedAt(userCreatedAt); setLoginSuccess(true); setOpenSnackbar(true); - - navigate('/home') } catch (error) { - //console.log(error); - //setError(error.response.data.error); + setError(error.response.data.error); } }; @@ -52,50 +34,47 @@ const Login = () => { }; return ( -
+ {loginSuccess ? (
-

+ Hello {username}! -

-

+ + Your account was created on {new Date(createdAt).toLocaleDateString()}. -

+
) : ( - <> -

Login

- + + Login + + setUsername(e.target.value)} /> - setPassword(e.target.value)} /> - - {openSnackbar && ( -
- Login successful -
- )} + + {error && ( -
- Error: {error} -
+ setError('')} message={`Error: ${error}`} /> )} - +
)} - - ) -} + + ); +}; -export default Login; +export default Login; \ No newline at end of file diff --git a/webapp/src/components/Login/Login.test.js b/webapp/src/components/Login/Login.test.js index af102dcf..a844eae4 100644 --- a/webapp/src/components/Login/Login.test.js +++ b/webapp/src/components/Login/Login.test.js @@ -59,4 +59,4 @@ describe('Login component', () => { expect(screen.queryByText(/Hello testUser!/i)).toBeNull(); expect(screen.queryByText(/Your account was created on/i)).toBeNull(); }); -}); +}); \ No newline at end of file diff --git a/webapp/src/components/Register/Register.test.js b/webapp/src/components/Register/Register.test.js index 87334886..c2272b0d 100644 --- a/webapp/src/components/Register/Register.test.js +++ b/webapp/src/components/Register/Register.test.js @@ -2,7 +2,7 @@ import React from 'react'; import { render, fireEvent, screen, waitFor } from '@testing-library/react'; import axios from 'axios'; import MockAdapter from 'axios-mock-adapter'; -import AddUser from './AddUser'; +import Register from './Register'; const mockAxios = new MockAdapter(axios); @@ -12,7 +12,7 @@ describe('AddUser component', () => { }); it('should add user successfully', async () => { - render(); + render(); const usernameInput = screen.getByLabelText(/Username/i); const passwordInput = screen.getByLabelText(/Password/i); @@ -35,7 +35,7 @@ describe('AddUser component', () => { }); it('should handle error when adding user', async () => { - render(); + render(); const usernameInput = screen.getByLabelText(/Username/i); const passwordInput = screen.getByLabelText(/Password/i); @@ -56,4 +56,4 @@ describe('AddUser component', () => { expect(screen.getByText(/Error: Internal Server Error/i)).toBeInTheDocument(); }); }); -}); +}); \ No newline at end of file