Skip to content

Commit

Permalink
Fix panEuropean countries select
Browse files Browse the repository at this point in the history
  • Loading branch information
sorja committed Nov 9, 2023
1 parent a3e98ad commit 2e3badf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/client/components/EditUserForm/CountryRoles/CountryRoles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next'
import classNames from 'classnames'

import { CountryIso, Region, RegionCode } from 'meta/area'
import { AssessmentNames } from 'meta/assessment'
import { RoleName, User, UserRole, Users } from 'meta/user'

import { useAppDispatch } from 'client/store'
Expand Down Expand Up @@ -82,6 +83,11 @@ const CountryRoles: React.FC<{ user: User }> = ({ user }) => {
}
}, [dispatch, t, user])

const excludeRegions = useMemo(() => {
if (assessment.props.name === AssessmentNames.panEuropean) return []
return [RegionCode.FE, ...secondaryRegions.regions.map((r: Region) => r.regionCode)]
}, [assessment.props.name, secondaryRegions.regions])

return (
<div className="edit-user__form-item edit-user__form-item-roles">
<div className="edit-user__form-label">{t('editUser.role')}</div>
Expand Down Expand Up @@ -133,10 +139,7 @@ const CountryRoles: React.FC<{ user: User }> = ({ user }) => {
<CountrySelectModal
open={modalOptions.open}
countries={countries}
excludedRegions={[
RegionCode.FE,
...(secondaryRegions ? secondaryRegions.regions.map((r: Region) => r.regionCode) : []),
]}
excludedRegions={excludeRegions}
headerLabel={t(Users.getI18nRoleLabelKey(modalOptions.role as RoleName))}
onClose={() => setModalOptions(initialModalState)}
initialSelection={modalOptions.initialSelection}
Expand Down
11 changes: 10 additions & 1 deletion src/client/components/UserListFilters/UserListFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import React, { useState } from 'react'
import { useTranslation } from 'react-i18next'

import { CountryIso, Region, RegionCode } from 'meta/area'
import { AssessmentNames } from 'meta/assessment'
import { RoleName } from 'meta/user'

import { useAppDispatch } from 'client/store'
import { useCountries, useSecondaryRegion } from 'client/store/area'
import { useFilters, UserManagementActions, useRoleNames } from 'client/store/ui/userManagement'
import { useCountryRouteParams } from 'client/hooks/useRouteParams'

import CountrySelectModal from '../CountrySelectModal'
import MultiSelect from '../MultiSelect'

const UserListFilters: React.FC = () => {
const { assessmentName } = useCountryRouteParams()
const dispatch = useAppDispatch()
const roleNames = useRoleNames()
const { t } = useTranslation()
Expand All @@ -23,6 +26,12 @@ const UserListFilters: React.FC = () => {

const [modalOpen, setModalOpen] = useState(false)

const isPanEuropean = assessmentName === AssessmentNames.panEuropean

const excludeRegions = isPanEuropean
? []
: [RegionCode.FE, ...secondaryRegions.regions.map((r: Region) => r.regionCode)]

return (
<div className="users__table-filter">
<div className="users__table-filter-title">
Expand Down Expand Up @@ -77,7 +86,7 @@ const UserListFilters: React.FC = () => {
<CountrySelectModal
open={modalOpen}
countries={countries}
excludedRegions={[RegionCode.FE, ...secondaryRegions.regions.map((r: Region) => r.regionCode)]}
excludedRegions={excludeRegions}
headerLabel={t('common.select')}
initialSelection={filters.countries}
onClose={(selectionUpdate: Array<string>) => {
Expand Down

0 comments on commit 2e3badf

Please sign in to comment.