From 54bd3e77862d2040641188d37d3948a5723c4b49 Mon Sep 17 00:00:00 2001 From: Divyansh Seth Date: Wed, 30 Oct 2024 15:45:21 +0530 Subject: [PATCH 01/12] leftDrawerOrg:Fixed the org not found error on viewing admin profile. --- .../LeftDrawerOrg/LeftDrawerOrg.test.tsx | 6 ++- .../LeftDrawerOrg/LeftDrawerOrg.tsx | 44 +++++++++++++------ 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx b/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx index 2a0ef3815d..c73d3c36f2 100644 --- a/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx +++ b/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx @@ -291,8 +291,7 @@ describe('Testing LeftDrawerOrg component for SUPERADMIN', () => { test('Testing Profile Page & Organization Detail Modal', async () => { setItem('UserImage', ''); setItem('SuperAdmin', true); - setItem('FirstName', 'John'); - setItem('LastName', 'Doe'); + setItem('id', '1234'); render( @@ -306,6 +305,9 @@ describe('Testing LeftDrawerOrg component for SUPERADMIN', () => { ); await wait(); expect(screen.getByTestId(/orgBtn/i)).toBeInTheDocument(); + expect( + screen.queryByText(/Error occured while loading Organization data/i), + ).not.toBeInTheDocument(); }); test('Testing Menu Buttons', async () => { diff --git a/src/components/LeftDrawerOrg/LeftDrawerOrg.tsx b/src/components/LeftDrawerOrg/LeftDrawerOrg.tsx index 3a3ba378cf..dd43248c74 100644 --- a/src/components/LeftDrawerOrg/LeftDrawerOrg.tsx +++ b/src/components/LeftDrawerOrg/LeftDrawerOrg.tsx @@ -6,13 +6,14 @@ import IconComponent from 'components/IconComponent/IconComponent'; import React, { useEffect, useState } from 'react'; import Button from 'react-bootstrap/Button'; import { useTranslation } from 'react-i18next'; -import { NavLink } from 'react-router-dom'; +import { NavLink, useLocation } from 'react-router-dom'; import type { TargetsType } from 'state/reducers/routesReducer'; import type { InterfaceQueryOrganizationsListObject } from 'utils/interfaces'; import AngleRightIcon from 'assets/svgs/angleRight.svg?react'; import TalawaLogo from 'assets/svgs/talawa.svg?react'; import styles from './LeftDrawerOrg.module.css'; import Avatar from 'components/Avatar/Avatar'; +import useLocalStorage from 'utils/useLocalstorage'; export interface InterfaceLeftDrawerProps { orgId: string; @@ -38,8 +39,13 @@ const leftDrawerOrg = ({ }: InterfaceLeftDrawerProps): JSX.Element => { const { t: tCommon } = useTranslation('common'); const { t: tErrors } = useTranslation('errors'); + const location = useLocation(); + const { getItem } = useLocalStorage(); + const userId = getItem('id'); + const id = location.pathname.split('/')[2] || ''; + // if param id is equal to userId, then it is a profile page + const [isProfilePage, setIsProfilePage] = useState(id === userId); const [showDropdown, setShowDropdown] = useState(false); - const [organization, setOrganization] = useState(); const { @@ -54,16 +60,24 @@ const leftDrawerOrg = ({ variables: { id: orgId }, }); + // Check if the current page is admin profile page + useEffect(() => { + const newId = location.pathname.split('/')[2] || ''; + setIsProfilePage(newId === userId); + }, [location]); + // Set organization data when query data is available useEffect(() => { let isMounted = true; if (data && isMounted) { setOrganization(data?.organizations[0]); + } else { + setOrganization(undefined); } return () => { isMounted = false; }; - }, [data]); + }, [data, location]); /** * Handles link click to hide the drawer on smaller screens. @@ -104,17 +118,19 @@ const leftDrawerOrg = ({ /> ) : organization == undefined ? ( - <> - - + !isProfilePage && ( + <> + + + ) ) : ( - + ) ) : (