From c89f854a1b6fa1a32d485c01302be95c4186ae2e Mon Sep 17 00:00:00 2001 From: Rutik Kulkarni <86470947+RutikKulkarni@users.noreply.github.com> Date: Thu, 8 Aug 2024 18:57:37 +0530 Subject: [PATCH] Revert "Add feature to display user's first name and location" --- frontend/src/components/Widget/User/User.jsx | 37 ++++++++----------- .../components/Widget/User/imports/index.js | 4 +- frontend/src/utility/exports/index.js | 1 - frontend/src/utility/userPersistence.js | 27 +------------- 4 files changed, 19 insertions(+), 50 deletions(-) diff --git a/frontend/src/components/Widget/User/User.jsx b/frontend/src/components/Widget/User/User.jsx index 1749def..b716288 100644 --- a/frontend/src/components/Widget/User/User.jsx +++ b/frontend/src/components/Widget/User/User.jsx @@ -1,6 +1,15 @@ -import React, { useContext, useEffect, useState } from 'react'; -import { useNavigate } from 'react-router-dom'; -import { userStyles as styles, BiUser, FiLogOut, HiOutlineLightBulb, LuLifeBuoy, ThemeContext, ToggleThemeSwitcher, UserSvg, clearUserData, fetchUserData } from './imports/index'; // Ensure this path is correct +import { React, useContext, useNavigate } from "../imports/index"; +import { + userStyles as styles, + BiUser, + FiLogOut, + HiOutlineLightBulb, + LuLifeBuoy, + ThemeContext, + ToggleThemeSwitcher, + UserSvg, + clearUserData, +} from "./imports/index"; /** * User widget component displaying user information and actions. @@ -12,27 +21,13 @@ import { userStyles as styles, BiUser, FiLogOut, HiOutlineLightBulb, LuLifeBuoy, const Widget = React.forwardRef((props, ref) => { const { theme } = useContext(ThemeContext); const navigate = useNavigate(); - const [userData, setUserData] = useState({ firstName: 'Name', location: 'Location' }); - - useEffect(() => { - const loadUserData = async () => { - const data = await fetchUserData(); - if (data) { - setUserData({ - firstName: data.firstName || 'Name', - location: data.location || 'Location', - }); - } - }; - loadUserData(); - }, []); /** * Handles user logout action, clearing user data from local storage. */ const handleLogout = () => { clearUserData(); - navigate('/login'); + navigate("/login"); props.closeWidget(); }; @@ -40,7 +35,7 @@ const Widget = React.forwardRef((props, ref) => { * Navigates to the user's account page. */ const handleMyAccount = () => { - navigate('/MyAccount'); + navigate("/MyAccount"); props.closeWidget(); }; @@ -51,8 +46,8 @@ const Widget = React.forwardRef((props, ref) => {
-

{userData.firstName}

-

{userData.location}

+

Name

+

Pune, Maharashtra

diff --git a/frontend/src/components/Widget/User/imports/index.js b/frontend/src/components/Widget/User/imports/index.js index a0f56d0..0b6a875 100644 --- a/frontend/src/components/Widget/User/imports/index.js +++ b/frontend/src/components/Widget/User/imports/index.js @@ -1,4 +1,4 @@ -// ./imports/index.js +// For ../User/User.jsx export { default as userStyles } from "../User.module.css"; export { ReactComponent as UserSvg } from "../../../../assets/svg/user.svg"; export { BiUser } from "react-icons/bi"; @@ -6,5 +6,5 @@ export { LuLifeBuoy } from "react-icons/lu"; export { FiLogOut } from "react-icons/fi"; export { HiOutlineLightBulb } from "react-icons/hi"; export { ThemeContext } from "../../../../context/exports"; -export { clearUserData, fetchUserData } from "../../../../utility/exports"; +export { clearUserData } from "../../../../utility/exports"; export { ToggleThemeSwitcher } from "../../../Buttons/ThemeSwitcher/ThemeSwitcher"; diff --git a/frontend/src/utility/exports/index.js b/frontend/src/utility/exports/index.js index fea6b88..6a988f1 100644 --- a/frontend/src/utility/exports/index.js +++ b/frontend/src/utility/exports/index.js @@ -11,6 +11,5 @@ export { clearUserData, isLoggedIn, getCookie, - fetchUserData, } from "../userPersistence"; export { validateUserData } from "../validateUserInput"; diff --git a/frontend/src/utility/userPersistence.js b/frontend/src/utility/userPersistence.js index 3412dbd..a33ca7a 100644 --- a/frontend/src/utility/userPersistence.js +++ b/frontend/src/utility/userPersistence.js @@ -1,9 +1,3 @@ -import axios from 'axios'; -import { getConfig } from './exports'; - -// Retrieve configuration -const Config = getConfig(); - /** * Sets a cookie with the given name, value, and expiration days. * @@ -78,23 +72,4 @@ const isLoggedIn = () => { return getCookie("token") !== null; }; -/** - * Fetches user data from the backend. - * - * @returns {Promise} The user data. - */ -const fetchUserData = async () => { - try { - const response = await axios.get(`${Config.endpoint}/user`, { - headers: { - 'Authorization': `Bearer ${getCookie('token')}` - } - }); - return response.data; - } catch (error) { - console.error('Error fetching user data:', error); - return null; - } -}; - -export { persistUser, clearUserData, isLoggedIn, getCookie, fetchUserData }; +export { persistUser, clearUserData, isLoggedIn, getCookie };