diff --git a/app/src/components/domain/BaseMapPointInput/index.tsx b/app/src/components/domain/BaseMapPointInput/index.tsx index 5c11ba9ac..bca0a6bec 100644 --- a/app/src/components/domain/BaseMapPointInput/index.tsx +++ b/app/src/components/domain/BaseMapPointInput/index.tsx @@ -219,12 +219,15 @@ function BaseMapPointInput(props: Props) { const [searchResult, setSearchResult] = useState(); const center = useMemo(() => { - if (isNotDefined(searchResult)) { - return undefined; + if (isDefined(value?.lng) && isDefined(value?.lat)) { + return [value.lng, value.lat] satisfies [number, number]; + } + if (isDefined(searchResult)) { + return [+searchResult.lon, +searchResult.lat] satisfies [number, number]; } - return [+searchResult.lon, +searchResult.lat] satisfies [number, number]; - }, [searchResult]); + return undefined; + }, [searchResult, value?.lng, value?.lat]); return (
diff --git a/app/src/hooks/domain/usePermissions.ts b/app/src/hooks/domain/usePermissions.ts index 9c0e19523..c1cd95fcd 100644 --- a/app/src/hooks/domain/usePermissions.ts +++ b/app/src/hooks/domain/usePermissions.ts @@ -1,8 +1,16 @@ import { useMemo } from 'react'; -import { isDefined } from '@togglecorp/fujs'; +import { + isDefined, + isNotDefined, +} from '@togglecorp/fujs'; +import { type GlobalEnums } from '#contexts/domain'; import useUserMe from '#hooks/domain/useUserMe'; +type OrganizationType = NonNullable[number]['key']; + +const canEditLocalUnitOrganization: OrganizationType[] = ['NTLS', 'DLGN', 'SCRT']; + function usePermissions() { const userMe = useUserMe(); @@ -96,6 +104,19 @@ function usePermissions() { ) ); + const canEditLocalUnit = ( + countryId: number | undefined, + ) => { + if (isGuestUser + || isNotDefined(countryId) + || isNotDefined(userMe?.profile.org_type)) return false; + + return ( + userMe?.profile.country?.id === countryId + && canEditLocalUnitOrganization.includes(userMe?.profile.org_type) + ); + }; + const isPerAdmin = !isGuestUser && ((userMe?.is_per_admin_for_countries.length ?? 0) > 0 || (userMe?.is_per_admin_for_regions.length ?? 0) > 0); @@ -126,6 +147,7 @@ function usePermissions() { isSuperUser, isGuestUser, isRegionalOrCountryAdmin, + canEditLocalUnit, }; }, [userMe], diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitImportModal/i18n.json b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitImportModal/i18n.json index 9779b4f1a..756d0bca1 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitImportModal/i18n.json +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitImportModal/i18n.json @@ -7,11 +7,13 @@ "closeButtonLabel": "Close", "localUnitTypeInputLabel": "Local unit type", "uploadFileSectionTitle": "Upload xlsx file", - "uploadFileSectionDescription": "Please make sure to select a supported file format (xlsx) with size less than 10MB", + "uploadFileSectionDescription": "Please make sure to select a supported file format (xlsx, xlsm) with size less than 10MB", "selectFileButtonLabel": "Select a file", "cancelUploadButtonLabel": "Cancel", "startUploadButtonLabel": "Upload", "contentStructureDescription": "The contents in the xlsx should follow the structure provided in {templateLink}.", + "contentStructureNoteLabel": "Note", + "contentStructureNote": "To enable multi-select functionality in certain fields, please click \"Enable Macros\" when prompted after opening the downloaded template file.", "templateLinkLabel": "this template", "noPermissionBothDescription": "You don't have permission and this unit is not externally managed.", "noPermissionErrorDescription": "You do not have the permission to upload local unit data", diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitImportModal/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitImportModal/index.tsx index fa61aabb9..ba9d95a73 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitImportModal/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitImportModal/index.tsx @@ -14,6 +14,7 @@ import { Modal, RawFileInput, SelectInput, + TextOutput, } from '@ifrc-go/ui'; import { useTranslation } from '@ifrc-go/ui/hooks'; import { @@ -230,24 +231,32 @@ function LocalUnitBulkUploadModal(props: Props) { withInternalPadding footerContent={(
- {resolveToComponent( - strings.contentStructureDescription, - { - templateLink: ( - - {strings.templateLinkLabel} - - ), - }, - )} + + {resolveToComponent( + strings.contentStructureDescription, + { + templateLink: ( + + {strings.templateLinkLabel} + + ), + }, + )} + +
)} > @@ -258,7 +267,7 @@ function LocalUnitBulkUploadModal(props: Props) { {isNotDefined(bulkUploadFile) && ( - Review + {strings.localUnitReviewButtonLabel} ); } diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx index 255ff4caa..661d9eaec 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx @@ -159,6 +159,7 @@ function LocalUnitsForm(props: Props) { isLocalUnitGlobalValidatorByType, isLocalUnitRegionValidatorByType, isLocalUnitCountryValidatorByType, + canEditLocalUnit, } = usePermissions(); const { api_visibility_choices: visibilityOptions } = useGlobalEnums(); @@ -382,19 +383,18 @@ function LocalUnitsForm(props: Props) { }, }); - const hasValidatePermission = isAuthenticated && ( - isSuperUser - || isLocalUnitGlobalValidatorByType(value.type) - || isLocalUnitCountryValidatorByType(countryResponse?.id, value.type) - || isLocalUnitRegionValidatorByType(countryResponse?.region, value.type) - ); + const hasValidatePermission = isAuthenticated + && !isExternallyManaged + && (isSuperUser + || isLocalUnitGlobalValidatorByType(value.type) + || isLocalUnitCountryValidatorByType(countryResponse?.id, value.type) + || isLocalUnitRegionValidatorByType(countryResponse?.region, value.type) + ); const hasUpdatePermission = isCountryAdmin(countryResponse?.id) || isRegionAdmin(countryResponse?.region) - || hasValidatePermission; - - const hasDeletePermission = isCountryAdmin(countryResponse?.id) - || hasValidatePermission; + || hasValidatePermission + || canEditLocalUnit(countryResponse?.id); const handleFormSubmit = useCallback( () => { @@ -543,21 +543,21 @@ function LocalUnitsForm(props: Props) { {isDefined(localUnitDetailsResponse) && ( <> - {hasDeletePermission && ( - - )} {hasValidatePermission && ( - + <> + + + )} {readOnlyFromProps && isEditable @@ -1439,6 +1439,7 @@ function LocalUnitsForm(props: Props) { className={styles.diffContainer} > {strings.localUnitActionsView} - {((hasValidatePermission || countryAdmin) + {(hasValidatePermission && !isBulkUploadLocalUnit) && ( )} - {hasAddEditLocalUnitPermission && ( + {(hasAddEditLocalUnitPermission) && ( item.type_details.name, { columnClassName: styles.type }, ), - createStringColumn( - 'focal', - strings.localUnitsTableFocal, - (item) => getFirstTruthyString(item.focal_person_loc, item.focal_person_en), - ), - createStringColumn( - 'phone', - strings.localUnitsTablePhoneNumber, - (item) => item.phone, - ), - createStringColumn( - 'email', - strings.localUnitsTableEmail, - (item) => item.email, - ), createElementColumn( 'status', strings.localUnitsTableStatus, @@ -227,9 +212,6 @@ function LocalUnitsTable(props: Props) { strings.localUnitsTableAddress, strings.localUnitsTableName, strings.localUnitsTableType, - strings.localUnitsTableFocal, - strings.localUnitsTablePhoneNumber, - strings.localUnitsTableEmail, strings.localUnitsTableStatus, refetchLocalUnits, ]); diff --git a/go-api b/go-api index e818755e8..86ea0fa6a 160000 --- a/go-api +++ b/go-api @@ -1 +1 @@ -Subproject commit e818755e8c4119fadaeb820f70c1fd5df28b5d67 +Subproject commit 86ea0fa6a114094b7766cc23f446de5d1ea136d3