Skip to main content
Glama
ResourceAvatar.tsx1.51 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import type { AvatarProps } from '@mantine/core'; import { Avatar } from '@mantine/core'; import { getDisplayString, getImageSrc } from '@medplum/core'; import type { Reference, Resource } from '@medplum/fhirtypes'; import { useCachedBinaryUrl, useResource } from '@medplum/react-hooks'; import type { JSX } from 'react'; import { MedplumLink } from '../MedplumLink/MedplumLink'; import { getInitials } from './ResourceAvatar.utils'; export interface ResourceAvatarProps extends AvatarProps { readonly value?: Reference | Resource; readonly link?: boolean; } export function ResourceAvatar(props: ResourceAvatarProps): JSX.Element { const resource = useResource(props.value); const text = resource ? getDisplayString(resource) : (props.alt ?? ''); const initials = getInitials(text); const uncachedImageUrl = (resource && getImageSrc(resource)) ?? props.src; const imageUrl = useCachedBinaryUrl(uncachedImageUrl ?? undefined); const radius = props.radius ?? 'xl'; const avatarProps = { ...props, value: undefined, link: undefined }; if (props.link) { return ( <MedplumLink to={resource}> <Avatar src={imageUrl} alt={text} radius={radius} {...avatarProps}> {initials} </Avatar> </MedplumLink> ); } return ( <Avatar src={imageUrl} alt={text} radius={radius} {...avatarProps}> {initials} </Avatar> ); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/medplum/medplum'

If you have feedback or need assistance with the MCP directory API, please join our Discord server