Skip to content

Commit 86cdd95

Browse files
committed
Use separate end point for super user in ns local unit popup
1 parent 658de2f commit 86cdd95

File tree

3 files changed

+48
-16
lines changed
  • app/src/views

3 files changed

+48
-16
lines changed

app/src/views/AccountDetails/GenerateMontandonTokenModal/i18n.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"strings": {
44
"title": "Generate token for Montandon",
55
"description": "By clicking 'Accept & Generate' button, you'll accept the {termsLink} of the Montandon API. Please make sure to review it.",
6-
"termsAndConditionLabel": "Terms & Condition",
6+
"termsAndConditionLabel": "Terms & Conditions",
77
"cancelButtonLabel": "Cancel",
88
"acceptButtonLabel": "Accept & Generate",
99
"doneButtonLabel": "Done",

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsMap/index.tsx

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
>

app/src/views/ThreeWProjectDetail/styles.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
.yearly-disaggregated-people-list {
2323
display: flex;
2424
flex-direction: column;
25-
border: 1px solid red;
2625
gap: var(--go-ui-spacing-lg);
2726
}
2827
}

0 commit comments

Comments
 (0)