diff --git a/src/GraphQl/Mutations/mutations.ts b/src/GraphQl/Mutations/mutations.ts index 62e305c501..b8b7836221 100644 --- a/src/GraphQl/Mutations/mutations.ts +++ b/src/GraphQl/Mutations/mutations.ts @@ -84,21 +84,13 @@ export const ADDRESS_DETAILS_FRAGMENT = gql` export const UPDATE_USER_MUTATION = gql` mutation UpdateUserProfile( - $id: ID $firstName: String $lastName: String $email: EmailAddress - $applangcode: String $file: String ) { updateUserProfile( - data: { - firstName: $firstName - lastName: $lastName - email: $email - id: $id - applangcode: $applangcode - } + data: { firstName: $firstName, lastName: $lastName, email: $email } file: $file ) { _id diff --git a/src/components/UserPortal/UserNavbar/UserNavbar.test.tsx b/src/components/UserPortal/UserNavbar/UserNavbar.test.tsx index 9b579d2920..59e3585aa0 100644 --- a/src/components/UserPortal/UserNavbar/UserNavbar.test.tsx +++ b/src/components/UserPortal/UserNavbar/UserNavbar.test.tsx @@ -12,7 +12,6 @@ import { StaticMockLink } from 'utils/StaticMockLink'; import UserNavbar from './UserNavbar'; import userEvent from '@testing-library/user-event'; import { REVOKE_REFRESH_TOKEN } from 'GraphQl/Mutations/mutations'; -import { CHECK_AUTH } from 'GraphQl/Queries/Queries'; async function wait(ms = 100): Promise { await act(() => { @@ -29,23 +28,6 @@ const MOCKS = [ }, result: {}, }, - { - request: { - query: CHECK_AUTH, - }, - result: { - data: { - checkAuth: { - _id: '123', - firstName: 'John', - lastName: 'Doe', - image: 'https://example.com/profile.jpg', - email: 'john.doe@example.com', - userType: 'user', - }, - }, - }, - }, ]; const link = new StaticMockLink(MOCKS, true); diff --git a/src/components/UserPortal/UserNavbar/UserNavbar.tsx b/src/components/UserPortal/UserNavbar/UserNavbar.tsx index 0f113ed2d5..93c5b08556 100644 --- a/src/components/UserPortal/UserNavbar/UserNavbar.tsx +++ b/src/components/UserPortal/UserNavbar/UserNavbar.tsx @@ -8,12 +8,13 @@ import cookies from 'js-cookie'; import PermIdentityIcon from '@mui/icons-material/PermIdentity'; import LanguageIcon from '@mui/icons-material/Language'; import { useTranslation } from 'react-i18next'; -import { useMutation, useQuery } from '@apollo/client'; +import { useMutation } from '@apollo/client'; import { REVOKE_REFRESH_TOKEN } from 'GraphQl/Mutations/mutations'; import { useHistory } from 'react-router-dom'; -import { CHECK_AUTH } from 'GraphQl/Queries/Queries'; +import useLocalStorage from 'utils/useLocalstorage'; function userNavbar(): JSX.Element { + const { getItem } = useLocalStorage(); const history = useHistory(); const { t } = useTranslation('translation', { @@ -27,21 +28,13 @@ function userNavbar(): JSX.Element { cookies.get('i18next') || 'en', ); - const [userName, setUserName] = React.useState(''); - - const { data } = useQuery(CHECK_AUTH); - - React.useEffect(() => { - if (data) { - setUserName(`${data.checkAuth.firstName} ${data.checkAuth.lastName}`); - } - }, [data]); + const userName = getItem('name'); /* istanbul ignore next */ const handleLogout = (): void => { revokeRefreshToken(); localStorage.clear(); - window.location.replace('/user'); + history.push('/user'); }; return ( diff --git a/src/screens/UserPortal/Organizations/Organizations.tsx b/src/screens/UserPortal/Organizations/Organizations.tsx index 636942f703..b6dd7c994a 100644 --- a/src/screens/UserPortal/Organizations/Organizations.tsx +++ b/src/screens/UserPortal/Organizations/Organizations.tsx @@ -5,6 +5,7 @@ import UserSidebar from 'components/UserPortal/UserSidebar/UserSidebar'; import { Dropdown, Form, InputGroup } from 'react-bootstrap'; import PaginationList from 'components/PaginationList/PaginationList'; import { + CHECK_AUTH, USER_CREATED_ORGANIZATIONS, USER_JOINED_ORGANIZATIONS, USER_ORGANIZATION_CONNECTION, @@ -16,7 +17,7 @@ import { useTranslation } from 'react-i18next'; import HourglassBottomIcon from '@mui/icons-material/HourglassBottom'; import useLocalStorage from 'utils/useLocalstorage'; -const { getItem } = useLocalStorage(); +const { getItem, setItem } = useLocalStorage(); interface InterfaceOrganizationCardProps { id: string; @@ -59,6 +60,10 @@ export default function organizations(): JSX.Element { variables: { id: userId }, }); + const { data: userData, loading } = useQuery(CHECK_AUTH, { + fetchPolicy: 'network-only', + }); + /* istanbul ignore next */ const handleChangePage = ( _event: React.MouseEvent | null, @@ -121,6 +126,24 @@ export default function organizations(): JSX.Element { } }, [mode]); + /* istanbul ignore next */ + React.useEffect(() => { + if (userData) { + setItem( + 'name', + `${userData.checkAuth.firstName} ${userData.checkAuth.lastName}`, + ); + setItem('id', userData.checkAuth._id); + setItem('email', userData.checkAuth.email); + setItem('IsLoggedIn', 'TRUE'); + setItem('UserType', userData.checkAuth.userType); + setItem('FirstName', userData.checkAuth.firstName); + setItem('LastName', userData.checkAuth.lastName); + setItem('UserImage', userData.checkAuth.image); + setItem('Email', userData.checkAuth.email); + } + }, [userData, loading]); + return ( <> diff --git a/src/screens/UserPortal/Settings/Settings.tsx b/src/screens/UserPortal/Settings/Settings.tsx index 0e32f81fae..441e9c4ca8 100644 --- a/src/screens/UserPortal/Settings/Settings.tsx +++ b/src/screens/UserPortal/Settings/Settings.tsx @@ -20,7 +20,7 @@ export default function settings(): JSX.Element { const { setItem } = useLocalStorage(); - const { data } = useQuery(CHECK_AUTH); + const { data } = useQuery(CHECK_AUTH, { fetchPolicy: 'network-only' }); const [image, setImage] = React.useState(''); const [updateUserDetails] = useMutation(UPDATE_USER_MUTATION); const [firstName, setFirstName] = React.useState('');