@@ -217,14 +217,44 @@ function LocalUnitsMap() {
217217 countryResponse ? getBbox ( countryResponse . bbox ) : undefined
218218 ) , [ countryResponse ] ) ;
219219
220- const { response : localUnitDetailResponse } = useRequest ( {
221- skip : isNotDefined ( clickedPointProperties ?. localUnitId ) ,
220+ const {
221+ response : publicLocalUnitDetailResponse ,
222+ pending : publicLocalUnitDetailPending ,
223+ error : publicLocalUnitDetailError ,
224+ } = useRequest ( {
225+ skip : isNotDefined ( clickedPointProperties ?. localUnitId ) || meResponse ?. is_superuser ,
226+ url : '/api/v2/public-local-units/{id}/' ,
227+ pathVariables : isDefined ( clickedPointProperties ) ? ( {
228+ id : clickedPointProperties . localUnitId ,
229+ } ) : undefined ,
230+ } ) ;
231+
232+ const {
233+ response : superLocalUnitDetailResponse ,
234+ pending : superLocalUnitDetailPending ,
235+ error : superLocalUnitDetailError ,
236+ } = useRequest ( {
237+ skip : isNotDefined ( clickedPointProperties ?. localUnitId )
238+ || isNotDefined ( meResponse )
239+ || ! meResponse . is_superuser ,
222240 url : '/api/v2/local-units/{id}/' ,
223241 pathVariables : isDefined ( clickedPointProperties ) ? ( {
224242 id : clickedPointProperties . localUnitId ,
225243 } ) : undefined ,
226244 } ) ;
227245
246+ const localUnitDetail = meResponse ?. is_superuser
247+ ? superLocalUnitDetailResponse
248+ : publicLocalUnitDetailResponse ;
249+
250+ const localUnitDetailPending = meResponse ?. is_superuser
251+ ? superLocalUnitDetailPending
252+ : publicLocalUnitDetailPending ;
253+
254+ const localUnitDetailError = meResponse ?. is_superuser
255+ ? superLocalUnitDetailError
256+ : publicLocalUnitDetailError ;
257+
228258 const localUnitsGeoJson = useMemo < GeoJSON . FeatureCollection < GeoJSON . Geometry > > (
229259 ( ) => ( {
230260 type : 'FeatureCollection' as const ,
@@ -379,45 +409,48 @@ function LocalUnitsMap() {
379409 padding = { DEFAULT_MAP_PADDING }
380410 bounds = { countryBounds }
381411 />
382- { clickedPointProperties ?. lngLat && localUnitDetailResponse && (
412+ { isDefined ( clickedPointProperties ) && clickedPointProperties . lngLat && (
383413 < MapPopup
384414 coordinates = { clickedPointProperties . lngLat }
385415 onCloseButtonClick = { handlePointClose }
386- heading = { isTruthyString ( localUnitDetailResponse ?. english_branch_name )
387- ? localUnitDetailResponse ?. english_branch_name
388- : localUnitDetailResponse ?. local_branch_name }
416+ heading = { isTruthyString ( localUnitDetail ?. english_branch_name )
417+ ? localUnitDetail ?. english_branch_name
418+ : localUnitDetail ?. local_branch_name ?? '--' }
389419 contentViewType = "vertical"
420+ pending = { localUnitDetailPending }
421+ errored = { isDefined ( localUnitDetailError ) }
422+ errorMessage = { localUnitDetailError ?. value . messageForNotification }
390423 >
391424 < TextOutput
392425 label = { strings . localUnitDetailLastUpdate }
393- value = { localUnitDetailResponse ?. modified_at }
426+ value = { localUnitDetail ?. modified_at }
394427 strongLabel
395428 valueType = "date"
396429 />
397430 < TextOutput
398431 label = { strings . localUnitDetailAddress }
399432 strongLabel
400- value = { localUnitDetailResponse ?. address_en
401- ?? localUnitDetailResponse ?. address_loc }
433+ value = { localUnitDetail ?. address_en
434+ ?? localUnitDetail ?. address_loc }
402435 />
403436 < TextOutput
404437 label = { strings . localUnitLocalUnitType }
405438 strongLabel
406- value = { localUnitDetailResponse ?. type_details . name }
439+ value = { localUnitDetail ?. type_details . name }
407440 />
408- { isDefined ( localUnitDetailResponse ?. health ) && (
441+ { isDefined ( localUnitDetail ?. health ) && (
409442 < TextOutput
410443 label = { strings . localUnitHealthFacilityType }
411444 strongLabel
412445 value = {
413- localUnitDetailResponse
446+ localUnitDetail
414447 ?. health ?. health_facility_type_details . name
415448 }
416449 />
417450 ) }
418- { isTruthyString ( localUnitDetailResponse ?. link ) && (
451+ { isTruthyString ( localUnitDetail ?. link ) && (
419452 < Link
420- href = { localUnitDetailResponse ?. link }
453+ href = { localUnitDetail ?. link }
421454 external
422455 withLinkIcon
423456 >
0 commit comments