Skip to content

Commit

Permalink
handled 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 1a14d3b commit 069c2aa
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 42 deletions.
3 changes: 1 addition & 2 deletions src/components/Authentication/SignInUserPasskey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ const SignInUserPasskey = (signInUserProps: signInUserProps) => {

}
await setToLocalStorage(storageKeys.PERMISSIONS, permissionArray);
// await setToLocalStorage(storageKeys.USER_PROFILE, userProfile);
await setToLocalStorage(storageKeys.USER_PROFILE, JSON.stringify(userProfile));
await setToLocalStorage(storageKeys.USER_PROFILE, userProfile);
await setToLocalStorage(storageKeys.USER_EMAIL, data?.data?.email);
return {
role: role?.orgRole || ""
Expand Down
3 changes: 1 addition & 2 deletions src/components/Authentication/SignInUserPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ const SignInUserPassword = (signInUserProps: SignInUser3Props) => {
id, profileImg, firstName, email,

}
// await setToLocalStorage(storageKeys.USER_PROFILE, userProfile);
await setToLocalStorage(storageKeys.USER_PROFILE, JSON.stringify(userProfile));
await setToLocalStorage(storageKeys.USER_PROFILE, userProfile);
await setToLocalStorage(storageKeys.USER_EMAIL, data?.data?.email);
return {
role: role?.orgRole ?? '',
Expand Down
31 changes: 7 additions & 24 deletions src/components/Profile/DisplayProfileImg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,16 @@ 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 () => {
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(() => {
getUserDetails()
Expand Down
3 changes: 1 addition & 2 deletions src/components/Profile/EditUserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ const EditUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile }:
}

updateProfile(userData);
// await setToLocalStorage(storageKeys.USER_PROFILE, updatedUserData);
await setToLocalStorage(storageKeys.USER_PROFILE, JSON.stringify(updatedUserData));
await setToLocalStorage(storageKeys.USER_PROFILE, updatedUserData);
window.location.reload();
setLoading(false)
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/Profile/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const UserProfile = ({ noBreadcrumb }: { noBreadcrumb?: boolean }) => {
const userProfile = {
id, profileImg, firstName, email,
}
// await setToLocalStorage(storageKeys.USER_PROFILE, userProfile)
await setToLocalStorage(storageKeys.USER_PROFILE, JSON.stringify(userProfile))
await setToLocalStorage(storageKeys.USER_PROFILE, userProfile)
await setToLocalStorage(storageKeys.USER_EMAIL, data?.data?.email)
}
} catch (error) {
Expand Down
3 changes: 1 addition & 2 deletions src/components/User/UserDashBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ const UserDashBoard = () => {
await setToLocalStorage(storageKeys.ORG_ID, org.id.toString());
const roles: string[] = org?.userOrgRoles.map((role) => role.orgRole.name);

// await setToLocalStorage(storageKeys.ORG_ROLES, roles?.toString());
await setToLocalStorage(storageKeys.ORG_ROLES, JSON.stringify(roles));
await setToLocalStorage(storageKeys.ORG_ROLES, roles?.toString());

const { id, name, description, logoUrl } = org || {};
const orgInfo = {
Expand Down
9 changes: 3 additions & 6 deletions src/components/organization/OrgDropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ const OrgDropDown = () => {
? org?.userOrgRoles.map((role) => role?.orgRole?.name)
: [];
if (roles.length > 0) { // Added check
// await setToLocalStorage(storageKeys.ORG_ROLES, roles?.toString());
await setToLocalStorage(storageKeys.ORG_ROLES, JSON.stringify(roles));

await setToLocalStorage(storageKeys.ORG_ROLES, roles?.toString());
}
};

Expand All @@ -93,9 +91,8 @@ const OrgDropDown = () => {

setActiveOrg(activeOrgDetails);

await setToLocalStorage(storageKeys.ORG_ROLES, JSON.stringify(roles));

// await setToLocalStorage(storageKeys.ORG_ROLES, roles?.toString());

await setToLocalStorage(storageKeys.ORG_ROLES, roles?.toString());

}
if (activeOrgDetails) {
Expand Down
3 changes: 1 addition & 2 deletions src/components/organization/OrganizationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ const OrganizationsList = () => {
id, name, description, logoUrl, roles
}
await setToLocalStorage(storageKeys.ORG_INFO, orgInfo)
// await setToLocalStorage(storageKeys.ORG_ROLES, roles?.toString());
await setToLocalStorage(storageKeys.ORG_ROLES, JSON.stringify(roles));
await setToLocalStorage(storageKeys.ORG_ROLES, roles?.toString());
window.location.href = pathRoutes.organizations.dashboard;
};
let content: React.JSX.Element = <></>;
Expand Down

0 comments on commit 069c2aa

Please sign in to comment.