From 5e252e0c8e9350b3bc32a3ae54ab4df1261808d4 Mon Sep 17 00:00:00 2001 From: bhavanakarwade Date: Wed, 4 Dec 2024 18:36:08 +0530 Subject: [PATCH] fix: user profile values Signed-off-by: bhavanakarwade --- src/components/Profile/DisplayUser.tsx | 31 ++++++-------------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/src/components/Profile/DisplayUser.tsx b/src/components/Profile/DisplayUser.tsx index 2715508b..4c9b14f6 100644 --- a/src/components/Profile/DisplayUser.tsx +++ b/src/components/Profile/DisplayUser.tsx @@ -9,33 +9,16 @@ const DisplayUser = () => { const [userObj, setUserObj] = useState(null) let timer:any= null - // const getUserDetails = async () => { - // const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE) - // const orgRoles = await getFromLocalStorage(storageKeys.ORG_ROLES) - // const parsedUser = userProfile ? JSON.parse(userProfile) : null - - // if (parsedUser) { - // parsedUser.roles = orgRoles; - // setUserObj(parsedUser); - // } - // } - const getUserDetails = async () => { - try { - const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE); - const orgRoles = await getFromLocalStorage(storageKeys.ORG_ROLES); - const parsedUser = userProfile ? JSON.parse(userProfile) : null; + const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE) + const orgRoles = await getFromLocalStorage(storageKeys.ORG_ROLES) + const parsedUser = userProfile ? JSON.parse(userProfile) : null - if (parsedUser) { - parsedUser.roles = orgRoles || []; // Default to an empty array if orgRoles is null - setUserObj(parsedUser); - } else { - console.warn("User profile is not available in local storage."); - } - } catch (error) { - console.error("Error fetching user details:", error); + if (parsedUser) { + parsedUser.roles = orgRoles; + setUserObj(parsedUser); } - }; + } useEffect(() => { const fetchData = async () => {