Skip to main content
Glama
ContactDetailInput.tsx2.43 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { Group, TextInput } from '@mantine/core'; import type { ContactDetail, ContactPoint } from '@medplum/fhirtypes'; import type { JSX } from 'react'; import { useContext, useMemo, useRef, useState } from 'react'; import { ContactPointInput } from '../ContactPointInput/ContactPointInput'; import { ElementsContext } from '../ElementsInput/ElementsInput.utils'; import type { ComplexTypeInputProps } from '../ResourcePropertyInput/ResourcePropertyInput.utils'; export type ContactDetailInputProps = ComplexTypeInputProps<ContactDetail>; export function ContactDetailInput(props: ContactDetailInputProps): JSX.Element { const [contactDetail, setContactDetail] = useState(props.defaultValue); const ref = useRef<ContactDetail>(contactDetail); ref.current = contactDetail; const { getExtendedProps } = useContext(ElementsContext); const [nameProps, telecomProps] = useMemo( () => ['name', 'telecom'].map((field) => getExtendedProps(props.path + '.' + field)), [getExtendedProps, props.path] ); function setContactDetailWrapper(newValue: ContactDetail): void { setContactDetail(newValue); if (props.onChange) { props.onChange(newValue); } } function setName(name: string): void { const newValue: ContactDetail = { ...ref.current, name }; if (!name) { delete newValue.name; } setContactDetailWrapper(newValue); } function setTelecom(telecom: ContactPoint | undefined): void { const newValue: ContactDetail = { ...ref.current, telecom: telecom && [telecom] }; if (!telecom) { delete newValue.telecom; } setContactDetailWrapper(newValue); } return ( <Group gap="xs" grow wrap="nowrap"> <TextInput disabled={props.disabled || nameProps?.readonly} data-testid={props.name + '-name'} name={props.name + '-name'} placeholder="Name" style={{ width: 180 }} defaultValue={contactDetail?.name} onChange={(e) => setName(e.currentTarget.value)} /> <ContactPointInput disabled={props.disabled || telecomProps?.readonly} name={props.name + '-telecom'} path={props.path + '.telecom'} defaultValue={contactDetail?.telecom?.[0]} onChange={setTelecom} outcome={props.outcome} /> </Group> ); }

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