diff --git a/src/layouts/authentication/sign-in/index.js b/src/layouts/authentication/sign-in/index.js index a04d1a2..bff917a 100644 --- a/src/layouts/authentication/sign-in/index.js +++ b/src/layouts/authentication/sign-in/index.js @@ -60,6 +60,44 @@ function Basic() { }); }; + // const handleLogin = () => { + // if (!email || !password) { + // alert("Please enter both email and password"); + // return; + // } + // fetch("/login", { + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // }, + // body: JSON.stringify({ + // email: email, + // password: password, + // }), + // }) + // .then((response) => { + // if (!response.ok) { + // throw response.status; + // } + // return response.json(); + // }) + // .then((data) => { + // console.log(data); + // // Display a success message if applicable + // login({ name: email, role: "user" }); + // navigate("/dashboard"); + // }) + // .catch((status) => { + // console.log(status, "error"); + // if (status === 400) { + // alert("Email and password are required."); + // } else if (status === 401) { + // alert("Invalid User Name or Incorrect Password."); + // } else { + // alert("An error occurred during login."); + // } + // }); + // }; const handleLogin = () => { if (!email || !password) { alert("Please enter both email and password"); @@ -82,10 +120,25 @@ function Basic() { return response.json(); }) .then((data) => { - console.log(data); - // Display a success message if applicable - login({ name: email, role: "user" }); - navigate("/dashboard"); + if (data && data.user) { + // Display a success message if applicable + const userData = data.user; + console.log(userData); + login({ + name: userData.User_Name, + full_name: userData.Full_Name, + role: "user", + email: userData.email, + phone_Number: userData.Contact_Number, + profession: userData.Profession, + }); + // Now you can use userData as needed in your frontend + // For example, you can store it in state or context for later use + // login({ name: userData.User_Name, role: "user" }); + navigate("/dashboard"); + } else { + alert("User data not found in the response."); + } }) .catch((status) => { console.log(status, "error"); diff --git a/src/layouts/profile/components/Header/index.js b/src/layouts/profile/components/Header/index.js index 59bd407..9a8fc4c 100644 --- a/src/layouts/profile/components/Header/index.js +++ b/src/layouts/profile/components/Header/index.js @@ -37,10 +37,12 @@ import breakpoints from "assets/theme/base/breakpoints"; // Images import burceMars from "assets/images/bruce-mars.jpg"; import backgroundImage from "assets/images/bg-profile.jpeg"; +import { useUser } from "utils/userContext"; function Header({ children }) { const [tabsOrientation, setTabsOrientation] = useState("horizontal"); const [tabValue, setTabValue] = useState(0); + const { user } = useUser(); useEffect(() => { // A function that sets the orientation state of the tabs. @@ -110,10 +112,10 @@ function Header({ children }) { - Richard Davis + {user.name} - CEO / Co-Founder + {user.profession} diff --git a/src/layouts/profile/index.js b/src/layouts/profile/index.js index 982a1aa..9c82c2f 100644 --- a/src/layouts/profile/index.js +++ b/src/layouts/profile/index.js @@ -50,8 +50,10 @@ import team1 from "assets/images/team-1.jpg"; import team2 from "assets/images/team-2.jpg"; import team3 from "assets/images/team-3.jpg"; import team4 from "assets/images/team-4.jpg"; +import { useUser } from "utils/userContext"; function Overview() { + const { user } = useUser(); return ( @@ -68,24 +70,27 @@ function Overview() { title="profile information" description="Hi, I’m Alec Thompson, Decisions: If you can’t decide, the answer is no. If two equally difficult paths, choose the one more painful in the short term (pain avoidance is creating an illusion of equality)." info={{ - fullName: "Alec M. Thompson", - mobile: "(44) 123 1234 123", - email: "alecthompson@mail.com", - location: "USA", + // fullName: "Alec M. Thompson", + fullName: user.full_name, + // mobile: "(44) 123 1234 123", + mobile: user.phone_Number, + // email: "alecthompson@mail.com", + email: user.email, + location: "Sri Lanka", }} social={[ { - link: "https://www.facebook.com/CreativeTim/", + link: "https://www.facebook.com", icon: , color: "facebook", }, { - link: "https://twitter.com/creativetim", + link: "https://twitter.com", icon: , color: "twitter", }, { - link: "https://www.instagram.com/creativetimofficial/", + link: "https://www.instagram.com", icon: , color: "instagram", },