Skip to content

Commit

Permalink
feat(fa): When access to one municipality default will select one (#7132
Browse files Browse the repository at this point in the history
)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
MargretFinnboga and kodiakhq[bot] authored Apr 8, 2022
1 parent 800a919 commit b339f94
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react'
import React, { useContext, useEffect } from 'react'
import { Box, Select, Text, Icon } from '@island.is/island-ui/core'
import {
ReactSelectOption,
StaffRole,
} from '@island.is/financial-aid/shared/lib'
import { isString } from 'lodash'
import { ValueType } from 'react-select'
import { mapMuniToOption } from '@island.is/financial-aid-web/veita/src/utils/formHelper'
import { AdminContext } from '@island.is/financial-aid-web/veita/src/components/AdminProvider/AdminProvider'

import * as styles from './MultiSelection.css'

Expand All @@ -27,8 +27,38 @@ const MultiSelectionMunicipality = <T extends unknown>({
selectionUpdate,
state,
}: Props<T>) => {
const { municipality } = useContext(AdminContext)

useEffect(() => {
if (municipality && municipality.length === 1) {
selectionUpdate(
municipality[0].municipalityId,
municipality[0].name,
'add',
)
}
}, [municipality])

if (municipality.length === 1) {
return <></>
}

const { municipalityIds, hasError } = state

const mapMuniToOption = (filterArr: string[], active: boolean) => {
const { municipality } = useContext(AdminContext)

return municipality
.filter((el) =>
active
? filterArr.includes(el.municipalityId)
: !filterArr.includes(el.municipalityId),
)
.map((el) => {
return { label: el.name, value: el.municipalityId }
})
}

return (
<Box display="block">
<Text
Expand Down
16 changes: 0 additions & 16 deletions apps/financial-aid/web-veita/src/utils/formHelper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useContext } from 'react'
import differenceInMinutes from 'date-fns/differenceInMinutes'
import differenceInHours from 'date-fns/differenceInHours'
import differenceInDays from 'date-fns/differenceInDays'
import differenceInYears from 'date-fns/differenceInYears'
import differenceInWeeks from 'date-fns/differenceInWeeks'
import { ApplicationState } from '@island.is/financial-aid/shared/lib'
import { AdminContext } from '@island.is/financial-aid-web/veita/src/components/AdminProvider/AdminProvider'

export const isPluralInIcelandic = (value: number): boolean =>
value % 10 !== 1 || value % 100 === 11
Expand Down Expand Up @@ -63,17 +61,3 @@ export const getTagByState = (state: ApplicationState) => {
return 'outDatedOrDenied'
}
}

export const mapMuniToOption = (filterArr: string[], active: boolean) => {
const { municipality } = useContext(AdminContext)

return municipality
.filter((el) =>
active
? filterArr.includes(el.municipalityId)
: !filterArr.includes(el.municipalityId),
)
.map((el) => {
return { label: el.name, value: el.municipalityId }
})
}

0 comments on commit b339f94

Please sign in to comment.