From f6d356c00ca49eb26f5412a11bd59f1fa994af20 Mon Sep 17 00:00:00 2001 From: DiegoEMartinezZ Date: Thu, 24 Apr 2025 08:52:50 -0500 Subject: [PATCH 1/2] adding to new files for the auth and conection with the backend --- src/services/authService.js | 31 +++++++++++++++++++++++++++++++ src/services/index.js | 4 ++++ 2 files changed, 35 insertions(+) create mode 100644 src/services/authService.js create mode 100644 src/services/index.js diff --git a/src/services/authService.js b/src/services/authService.js new file mode 100644 index 0000000..1de585a --- /dev/null +++ b/src/services/authService.js @@ -0,0 +1,31 @@ +import api from "./api"; + +const authService = { + // Register a new client + registerClient: async (userData) => { + try { + const res = await api.post("/auth/register", userData); + return res.data; + } catch (error) { + throw error.res?.data || error.message; + } + }, + // Login a client + login: async (credentials) => { + try { + const res = await api.post("/auth/login", credentials); + if (res.data.token) { + localStorage.setItem("token", res.data.token); + } + return res.data; + } catch (error) { + throw error.res?.data || error.message; + } + }, + // logout a client + logout: () => { + localStorage.removeItem("token"); + }, +}; + +export default authService; diff --git a/src/services/index.js b/src/services/index.js new file mode 100644 index 0000000..0fbf7c8 --- /dev/null +++ b/src/services/index.js @@ -0,0 +1,4 @@ +import api from "./api"; +import authService from "./authService"; + +export { api, authService }; From b496716f3c873bbf9d6dc1c9dbe871fc91167658 Mon Sep 17 00:00:00 2001 From: DiegoEMartinezZ Date: Thu, 24 Apr 2025 08:54:04 -0500 Subject: [PATCH 2/2] fixing some design problems, cretae a client navbar to login the user that had an account, delete some menu options and fix some buttons events --- src/App.jsx | 8 ++++---- src/UI/buttons/MenuButton.jsx | 8 +++++--- src/UI/forms/login/LoginForm.jsx | 14 +++++++------- src/UI/navbar/ClientNavBar.jsx | 22 ++++++++++++++++++++++ src/UI/navbar/Navbar.jsx | 2 +- src/UI/sections/TitleSection.jsx | 17 +++++------------ src/components/menu/MenuAdmin.jsx | 12 ++++-------- src/components/menu/MenuClient.jsx | 8 ++------ src/context/ClickMeetContext.jsx | 25 +++++++++++++++++++++++++ src/pages/Admin.jsx | 2 +- src/pages/Client.jsx | 4 ++-- src/pages/Landing.jsx | 2 +- src/pages/{Login.jsx => LoginPage.jsx} | 8 +++++--- src/routes.jsx | 4 ++-- src/services/api.js | 26 +++++++++++++++++++++----- 15 files changed, 107 insertions(+), 55 deletions(-) create mode 100644 src/UI/navbar/ClientNavBar.jsx rename src/pages/{Login.jsx => LoginPage.jsx} (74%) diff --git a/src/App.jsx b/src/App.jsx index 4c9cfcb..9319ee4 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -4,15 +4,15 @@ import { ClickMeetProvider } from "./context/ClickMeetContext"; const App = () => { return ( - - + + {routes.map((route) => ( ))} - - + + ); }; diff --git a/src/UI/buttons/MenuButton.jsx b/src/UI/buttons/MenuButton.jsx index 8c041cc..136746a 100644 --- a/src/UI/buttons/MenuButton.jsx +++ b/src/UI/buttons/MenuButton.jsx @@ -13,13 +13,15 @@ const MenuButton = ({ icon: Icon, text, url }) => { return (
  • - {Icon && } + {Icon && ( + + )}

    {text}

  • ); }; -export default MenuButton; \ No newline at end of file +export default MenuButton; diff --git a/src/UI/forms/login/LoginForm.jsx b/src/UI/forms/login/LoginForm.jsx index 1aa8d29..1573111 100644 --- a/src/UI/forms/login/LoginForm.jsx +++ b/src/UI/forms/login/LoginForm.jsx @@ -1,14 +1,14 @@ -import React, { useState } from 'react'; +import React, { useState } from "react"; import { FaUserPlus } from "react-icons/fa"; import { FaSignInAlt } from "react-icons/fa"; const LoginForm = ({ onSwitchForm }) => { - const [email, setEmail] = useState(''); - const [password, setPassword] = useState(''); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); const handleLogin = (e) => { e.preventDefault(); - console.log('Login attempted with:', { email, password }); + console.log("Login attempted with:", { email, password }); // TODO: Autentication logic }; @@ -40,7 +40,7 @@ const LoginForm = ({ onSwitchForm }) => {