Skip to content

Commit

Permalink
handled condition for undefined values
Browse files Browse the repository at this point in the history
Signed-off-by: bhavanakarwade <[email protected]>
  • Loading branch information
bhavanakarwade committed Dec 4, 2024
1 parent c00f22a commit a64a6dc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
31 changes: 24 additions & 7 deletions src/components/Profile/DisplayProfileImg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,33 @@ import { storageKeys } from "../../config/CommonConstant.ts";

const DisplayProfileImg = () => {
const [userObj, setUserObj] = useState<IUserProfile | null>(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 () => {
const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE)
const orgRoles = await getFromLocalStorage(storageKeys.ORG_ROLES)
const parsedUser = userProfile ? JSON.parse(userProfile) : null;
try {
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);
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);
}
}
};

useEffect(() => {
getUserDetails()
Expand Down
32 changes: 25 additions & 7 deletions src/components/Profile/DisplayUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,34 @@ 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 () => {
const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE)
const orgRoles = await getFromLocalStorage(storageKeys.ORG_ROLES)
const parsedUser = userProfile ? JSON.parse(userProfile) : null
try {
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);
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);
}
}
};

useEffect(() => {
const fetchData = async () => {
await getUserDetails();
Expand Down
2 changes: 1 addition & 1 deletion src/components/User/UserDashBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ const UserDashBoard = () => {
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const orgAgentsList = data?.data?.org_agents;
if (orgAgentsList && orgAgentsList.length > 0) {
const orgDid = orgAgentsList[0].orgDid;
const orgDid = orgAgentsList[0]?.orgDid;
setWalletData(data?.data?.org_agents);

if(orgDid?.includes(DidMethod.INDY)){
Expand Down

0 comments on commit a64a6dc

Please sign in to comment.