Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leftDrawerOrg: Fixed the org not found error on viewing admin profile. #2386

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand All @@ -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 () => {
Expand Down
44 changes: 30 additions & 14 deletions src/components/LeftDrawerOrg/LeftDrawerOrg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
sethdivyansh marked this conversation as resolved.
Show resolved Hide resolved
const [showDropdown, setShowDropdown] = useState(false);

const [organization, setOrganization] =
useState<InterfaceQueryOrganizationsListObject>();
const {
Expand All @@ -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);
sethdivyansh marked this conversation as resolved.
Show resolved Hide resolved
}
return () => {
isMounted = false;
};
}, [data]);
}, [data, location]);
sethdivyansh marked this conversation as resolved.
Show resolved Hide resolved

/**
* Handles link click to hide the drawer on smaller screens.
Expand Down Expand Up @@ -104,17 +118,19 @@ const leftDrawerOrg = ({
/>
</>
) : organization == undefined ? (
<>
<button
className={`${styles.profileContainer} bg-danger text-start text-white`}
disabled
>
<div className="px-3">
<WarningAmberOutlined />
</div>
{tErrors('errorLoading', { entity: 'Organization' })}
</button>
</>
!isProfilePage && (
<>
<button
className={`${styles.profileContainer} bg-danger text-start text-white`}
disabled
>
<div className="px-3">
<WarningAmberOutlined />
</div>
{tErrors('errorLoading', { entity: 'Organization' })}
</button>
</>
)
) : (
<button className={styles.profileContainer} data-testid="OrgBtn">
<div className={styles.imageContainer}>
Expand Down