1- import { useCallback , useEffect , useMemo , useState } from 'react ' ;
2- import { useNavigate , useParams } from 'react-router-dom ' ;
3- import { Button , Container , Group , Loader , Text , Title } from '@mantine/core' ;
1+ import { FhirPathTable , FhirPathTableField } from '@/components/FhirPathTable/FhirPathTable ' ;
2+ import { SAMPLE_MED_LOCATION_NAME } from '@/constants ' ;
3+ import { Alert , Button , Container , Group , Loader , Text , Title } from '@mantine/core' ;
44import { modals } from '@mantine/modals' ;
5- import { PropertyType } from '@medplum/core' ;
5+ import { normalizeErrorString , PropertyType } from '@medplum/core' ;
66import { Location } from '@medplum/fhirtypes' ;
77import { useMedplum } from '@medplum/react' ;
8- import { FhirPathTable , FhirPathTableField } from '@/components/FhirPathTable/FhirPathTable ' ;
9- import { SAMPLE_MED_LOCATION_NAME } from '@/constants ' ;
8+ import { useCallback , useEffect , useMemo , useState } from 'react ' ;
9+ import { useNavigate , useParams } from 'react-router-dom ' ;
1010
1111export function LocationsPage ( ) : JSX . Element {
1212 const navigate = useNavigate ( ) ;
@@ -15,6 +15,7 @@ export function LocationsPage(): JSX.Element {
1515 const [ refresh , setRefresh ] = useState ( false ) ;
1616 const medplum = useMedplum ( ) ;
1717 const [ rootLocation , setRootLocation ] = useState < Location > ( ) ;
18+ const [ error , setError ] = useState < string > ( ) ;
1819
1920 useEffect ( ( ) => {
2021 if ( ! id ) {
@@ -27,7 +28,7 @@ export function LocationsPage(): JSX.Element {
2728 setRootLocation ( location ) ;
2829 } )
2930 . catch ( ( err ) => {
30- console . error ( 'Failed to load root location:' , err ) ;
31+ setError ( normalizeErrorString ( err ) ) ;
3132 } ) ;
3233 }
3334 } , [ id , medplum ] ) ;
@@ -126,7 +127,6 @@ export function LocationsPage(): JSX.Element {
126127 }` ;
127128 }
128129 if ( ! rootLocation ?. id ) return '' ;
129- console . log ( 'Using root location ID:' , rootLocation . id ) ;
130130 return `{
131131 ResourceList: LocationList(partof: "Location/${ rootLocation . id } ", physical_type: "lvl", _sort: "name", _count: 40) {
132132 id
@@ -143,6 +143,16 @@ export function LocationsPage(): JSX.Element {
143143 navigate ( id ? `/Location/${ id } /new` : '/Location/new' ) ;
144144 }
145145
146+ if ( error ) {
147+ return (
148+ < Container fluid >
149+ < Alert color = "red" title = "Error loading location" >
150+ { error }
151+ </ Alert >
152+ </ Container >
153+ ) ;
154+ }
155+
146156 if ( ! id && ! rootLocation ) {
147157 return (
148158 < Container fluid >
0 commit comments