fix(react): Fix authenticated user profile (#2128)

This commit is contained in:
John Joyce 2021-02-20 12:01:42 -08:00 committed by GitHub
parent 2a184dd3d5
commit 1b96cd8c26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import { useEntityRegistry } from '../useEntityRegistry';
import { useGetAutoCompleteResultsLazyQuery } from '../../graphql/search.generated';
import { navigateToSearchUrl } from './utils/navigateToSearchUrl';
import { EntityType } from '../../types.generated';
import { useGetAuthenticatedUser } from '../useGetAuthenticatedUser';
const ALL_ENTITIES_SEARCH_TYPE_NAME = 'All Entities';
@ -29,6 +30,9 @@ export const SearchablePage = ({ selectedType, initialQuery, children }: Props)
const entityRegistry = useEntityRegistry();
const searchTypes = entityRegistry.getSearchEntityTypes();
const { data: userData } = useGetAuthenticatedUser();
const searchTypeNames = [
ALL_ENTITIES_SEARCH_TYPE_NAME,
...searchTypes.map((entityType) => entityRegistry.getCollectionName(entityType)),
@ -78,7 +82,8 @@ export const SearchablePage = ({ selectedType, initialQuery, children }: Props)
}
onSearch={search}
onQueryChange={autoComplete}
authenticatedUserUrn="urn:li:corpuser:0"
authenticatedUserUrn={userData?.corpUser?.urn || ''}
authenticatedUserPictureLink={userData?.corpUser?.editableInfo?.pictureLink || ''}
/>
<div style={{ marginTop: 64 }}>{children}</div>
</Layout>

View File

@ -0,0 +1,8 @@
import { useGetUserQuery } from '../graphql/user.generated';
/**
* Fetch a CorpUser object corresponding to the currently authenticated user.
*/
export function useGetAuthenticatedUser() {
return useGetUserQuery({ variables: { urn: localStorage.getItem('userUrn') as string } });
}