@@ -34,8 +34,9 @@ import BaseMap from '#components/domain/BaseMap';
3434import Link , { type Props as LinkProps } from '#components/Link' ;
3535import MapContainerWithDisclaimer from '#components/MapContainerWithDisclaimer' ;
3636import MapPopup from '#components/MapPopup' ;
37- import usePermissions from '#hooks/domain/usePermissions ' ;
37+ import useAuth from '#hooks/domain/useAuth ' ;
3838import useFilterState from '#hooks/useFilterState' ;
39+ import { chooseName } from '#utils/common' ;
3940import {
4041 COLOR_DARK_GREY ,
4142 COLOR_PRIMARY_BLUE ,
@@ -131,21 +132,17 @@ function LocalUnitsMap() {
131132 [ limit , filter , countryResponse ] ,
132133 ) ;
133134
134- const { isCountryAdmin , isSuperUser } = usePermissions ( ) ;
135+ const { isAuthenticated } = useAuth ( ) ;
135136
136137 const requestType = useMemo (
137138 ( ) => {
138- if ( isSuperUser ) {
139- return 'authenticated' ;
140- }
141-
142- if ( isCountryAdmin ( countryResponse ?. id ) ) {
139+ if ( isAuthenticated ) {
143140 return 'authenticated' ;
144141 }
145142
146143 return 'public' ;
147144 } ,
148- [ countryResponse , isSuperUser , isCountryAdmin ] ,
145+ [ isAuthenticated ] ,
149146 ) ;
150147
151148 const {
@@ -166,7 +163,7 @@ function LocalUnitsMap() {
166163 query : urlQuery ,
167164 } ) ;
168165
169- const localUnits = ( isSuperUser || isCountryAdmin ( countryResponse ?. id ) )
166+ const localUnits = requestType === AUTHENTICATED
170167 ? localUnitsResponse : publicLocalUnitsResponse ;
171168 const pending = publicLocalUnitsPending || localUnitsPending ;
172169
@@ -334,6 +331,16 @@ function LocalUnitsMap() {
334331 && countryResponse . emails . length > 0 ;
335332 const hasContactDetails = hasAddress || hasEmails ;
336333
334+ const localUnitName = useMemo ( ( ) => chooseName (
335+ localUnitDetail ?. local_branch_name ,
336+ localUnitDetail ?. english_branch_name ,
337+ ) , [ localUnitDetail ?. local_branch_name , localUnitDetail ?. english_branch_name ] ) ;
338+
339+ const localUnitAddress = useMemo ( ( ) => chooseName (
340+ localUnitDetail ?. address_loc ,
341+ localUnitDetail ?. address_en ,
342+ ) , [ localUnitDetail ?. address_loc , localUnitDetail ?. address_en ] ) ;
343+
337344 return (
338345 < Container
339346 className = { styles . localUnitsMap }
@@ -414,9 +421,7 @@ function LocalUnitsMap() {
414421 popupClassName = { styles . mapPopup }
415422 coordinates = { clickedPointProperties . lngLat }
416423 onCloseButtonClick = { handlePointClose }
417- heading = { isTruthyString ( localUnitDetail ?. english_branch_name )
418- ? localUnitDetail ?. english_branch_name
419- : localUnitDetail ?. local_branch_name ?? '--' }
424+ heading = { localUnitName }
420425 contentViewType = "vertical"
421426 pending = { localUnitDetailPending }
422427 errored = { isDefined ( localUnitDetailError ) }
@@ -433,8 +438,7 @@ function LocalUnitsMap() {
433438 < TextOutput
434439 label = { strings . localUnitDetailAddress }
435440 strongLabel
436- value = { localUnitDetail ?. address_en
437- ?? localUnitDetail ?. address_loc }
441+ value = { localUnitAddress }
438442 />
439443 < TextOutput
440444 label = { strings . localUnitLocalUnitType }
@@ -511,48 +515,50 @@ function LocalUnitsMap() {
511515 </ Container >
512516 ) }
513517 </ div >
514- { isDefined ( localUnitsOptions ) && (
515- < Container
516- contentViewType = "vertical"
517- spacing = "comfortable"
518- >
519- < Container
520- heading = { strings . localUnitLegendLocalUnitTitle }
521- headingLevel = { 4 }
522- contentViewType = "grid"
523- numPreferredGridContentColumns = { 5 }
524- spacing = "compact"
525- >
526- { localUnitsOptions ?. type . map ( ( legendItem ) => (
527- < LegendItem
528- key = { legendItem . id }
529- iconSrc = { legendItem . image_url }
530- iconClassName = { styles . legendIcon }
531- color = { legendItem . colour ?? COLOR_DARK_GREY }
532- label = { legendItem . name }
533- />
534- ) ) }
535- </ Container >
518+ {
519+ isDefined ( localUnitsOptions ) && (
536520 < Container
537- heading = { strings . localUnitLegendHealthCareTitle }
538- headingLevel = { 5 }
539- contentViewType = "grid"
540- numPreferredGridContentColumns = { 5 }
541- spacing = "compact"
521+ contentViewType = "vertical"
522+ spacing = "comfortable"
542523 >
543- { localUnitsOptions ?. health_facility_type . map ( ( legendItem ) => (
544- < LegendItem
545- key = { legendItem . id }
546- // FIXME: use color from server
547- color = { COLOR_PRIMARY_BLUE }
548- iconSrc = { legendItem . image_url }
549- iconClassName = { styles . legendIcon }
550- label = { legendItem . name }
551- />
552- ) ) }
524+ < Container
525+ heading = { strings . localUnitLegendLocalUnitTitle }
526+ headingLevel = { 4 }
527+ contentViewType = "grid"
528+ numPreferredGridContentColumns = { 5 }
529+ spacing = "compact"
530+ >
531+ { localUnitsOptions ?. type . map ( ( legendItem ) => (
532+ < LegendItem
533+ key = { legendItem . id }
534+ iconSrc = { legendItem . image_url }
535+ iconClassName = { styles . legendIcon }
536+ color = { legendItem . colour ?? COLOR_DARK_GREY }
537+ label = { legendItem . name }
538+ />
539+ ) ) }
540+ </ Container >
541+ < Container
542+ heading = { strings . localUnitLegendHealthCareTitle }
543+ headingLevel = { 5 }
544+ contentViewType = "grid"
545+ numPreferredGridContentColumns = { 5 }
546+ spacing = "compact"
547+ >
548+ { localUnitsOptions ?. health_facility_type . map ( ( legendItem ) => (
549+ < LegendItem
550+ key = { legendItem . id }
551+ // FIXME: use color from server
552+ color = { COLOR_PRIMARY_BLUE }
553+ iconSrc = { legendItem . image_url }
554+ iconClassName = { styles . legendIcon }
555+ label = { legendItem . name }
556+ />
557+ ) ) }
558+ </ Container >
553559 </ Container >
554- </ Container >
555- ) }
560+ )
561+ }
556562 </ Container >
557563 ) ;
558564}
0 commit comments