From bc9ce558c19aedc7dc6a115b822b8ec96ebd5a3b Mon Sep 17 00:00:00 2001 From: prajwalism Date: Wed, 17 Jul 2024 17:22:07 +0545 Subject: [PATCH 1/9] feat: create a util function that parses the object from localstorage and returns value --- src/frontend/src/utils/getLocalStorageValue.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/frontend/src/utils/getLocalStorageValue.ts diff --git a/src/frontend/src/utils/getLocalStorageValue.ts b/src/frontend/src/utils/getLocalStorageValue.ts new file mode 100644 index 00000000..7e6f6cb4 --- /dev/null +++ b/src/frontend/src/utils/getLocalStorageValue.ts @@ -0,0 +1,18 @@ +/* eslint-disable no-console */ +/* eslint-disable import/prefer-default-export */ + +/** + * Gets and parses a value from localStorage. + * @param {string} key - The localStorage key. + * @param {*} [defaultValue=null] - Value to return if key not found. + * @returns {*} Parsed value or defaultValue. + */ +export function getLocalStorageValue(key: string, defaultValue = null) { + try { + const item = localStorage.getItem(key); + return item ? JSON.parse(item) : defaultValue; + } catch (error) { + console.error(`Error reading ${key} from localStorage:`, error); + return defaultValue; + } +} From 96cb4c6389602d44edba5661e371ec09bffee531 Mon Sep 17 00:00:00 2001 From: prajwalism Date: Wed, 17 Jul 2024 17:23:01 +0545 Subject: [PATCH 2/9] feat: use userDetails from google-login in profile section --- .../components/Dashboard/DashboardSidebar/index.tsx | 12 ++++++++---- .../UserProfile/FormContents/BasicDetails/index.tsx | 7 +++++-- .../src/components/common/UserAvatar/index.tsx | 12 ++++++------ .../src/components/common/UserProfile/index.tsx | 8 +++++++- src/frontend/src/views/UserProfile/index.tsx | 4 ++-- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/frontend/src/components/Dashboard/DashboardSidebar/index.tsx b/src/frontend/src/components/Dashboard/DashboardSidebar/index.tsx index 0d7253a6..b7a733e8 100644 --- a/src/frontend/src/components/Dashboard/DashboardSidebar/index.tsx +++ b/src/frontend/src/components/Dashboard/DashboardSidebar/index.tsx @@ -1,16 +1,20 @@ import { useNavigate } from 'react-router-dom'; import { Flex, FlexColumn } from '@Components/common/Layouts'; import { Button } from '@Components/RadixComponents/Button'; +import { getLocalStorageValue } from '@Utils/getLocalStorageValue'; export default function DashboardSidebar() { const navigate = useNavigate(); + + const userDetails = getLocalStorageValue('userprofile'); + return ( - -

PK

+ + profile -
Kylan Gentry
-

kylan_gentry22

+
{userDetails?.name}
+

{userDetails?.email}