Skip to main content
Glama
CreateTaskModal.tsx1.43 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { Modal, Text } from '@mantine/core'; import { getReferenceString } from '@medplum/core'; import type { Resource } from '@medplum/fhirtypes'; import { ResourceForm, useMedplum } from '@medplum/react'; import type { JSX } from 'react'; import { useLocation, useNavigate } from 'react-router'; interface CreateTaskModalProps { readonly opened: boolean; readonly onClose: () => void; } export function CreateTaskModal(props: CreateTaskModalProps): JSX.Element { const navigate = useNavigate(); const medplum = useMedplum(); const location = useLocation(); const resourceType = location.pathname.split('/')[1]; // Create a default resource with the correct resourceType const defaultResource = { resourceType } as Resource; // Function to create the resource and navigate to the resource page when the form is submitted const handleSubmit = (newResource: Resource): void => { medplum .createResource(newResource) .then((result) => navigate(`/${getReferenceString(result)}`)?.catch(console.error)) .catch((error) => console.error(error)); }; return ( <Modal opened={props.opened} onClose={props.onClose}> <Text>New {resourceType}</Text> <ResourceForm defaultValue={defaultResource} onSubmit={handleSubmit}></ResourceForm> </Modal> ); }

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