Skip to content

Commit

Permalink
Merge pull request #3327 from navikt/feature/nytt-landkode-valuta-kod…
Browse files Browse the repository at this point in the history
…everk

Feature/nytt landkode valuta kodeverk
  • Loading branch information
stigus authored Nov 10, 2023
2 parents dee0732 + 27ae619 commit 5ae9cba
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 294 deletions.
618 changes: 350 additions & 268 deletions apps/dolly-frontend/src/main/js/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/dolly-frontend/src/main/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dolly",
"version": "2.5.33",
"version": "2.5.34",
"description": "",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -34,7 +34,7 @@
"immer": "^10.0.1",
"lodash": "^4.17.21",
"lodash.throttle": "^4.1.1",
"pdfjs-dist": "^3.0.279",
"pdfjs-dist": "^4.0.189",
"prop-types": "^15.8.1",
"rc-progress": "^3.4.0",
"rc-tooltip": "^6.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const NorskBankkonto = ({ formikBag }: { formikBag: FormikProps<{}> }) =>
<FormikCheckbox
name={`${path}.tilfeldigKontonummer`}
label="Har tilfeldig kontonummer"
size="x-small"
size="medium"
isDisabled={kontonummer}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const UtenlandskBankkonto = ({ formikBag }: any) => {
swift = 'BANK' + mappedLandkode + '11222'
}
formikBag.setFieldValue(`${path}.swift`, swift, false)
formikBag.setFieldTouched(`${path}.swift`, true)
}
}

Expand All @@ -46,7 +47,7 @@ export const UtenlandskBankkonto = ({ formikBag }: any) => {
<FormikCheckbox
name={`${path}.tilfeldigKontonummer`}
label="Har tilfeldig kontonummer"
size="x-small"
size="medium"
isDisabled={disableTilfeldigKontonummer}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,27 @@ const day = new Date().getDate()
const weekDay = new Date().getDay()

const isHalloween = (month === 9 && day > 14) || (month === 10 && day === 0)
const isSpring = month >= 2 && month <= 4
const isSummer = month >= 5 && month <= 7
const isFall = month >= 8 && month <= 10
const isWinter = month === 0 || month === 1
const isChristmas = month === 11
const isEaster = (month === 2 && day > 21) || (month === 3 && day === 1)
const isFaarikaal = month === 8 && day > 23 && weekDay === 4

const DefaultBackground = styled.div`
background-image: url(${() => {
if (isEaster) {
return Paaske
} else if (month >= 2 && month <= 4) {
} else if (isSpring) {
return Spring
} else if (month >= 5 && month <= 7) {
} else if (isSummer) {
return Sommer
} else if (isHalloween) {
return Halloween
} else if (month === 8 && day > 23 && weekDay === 4) {
} else if (isFaarikaal) {
return Faarikaal
} else if (month >= 8 && month <= 10) {
} else if (isFall) {
return Fall
} else if (isWinter) {
return Winter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { Vis } from '@/components/bestillingsveileder/VisAttributt'
import { Label } from '@/components/ui/form/inputs/label/Label'
import { InputWrapper } from '@/components/ui/form/inputWrapper/InputWrapper'
import { fieldError, SyntEvent } from '@/components/ui/form/formUtils'
import KodeverkConnector from '@/components/kodeverk/KodeverkConnector'
import './Select.less'
import MenuList from '@/components/ui/form/inputs/select/MenuList'
import Option from '@/components/ui/form/inputs/select/Option'
import * as _ from 'lodash-es'
import { useKodeverk } from '@/utils/hooks/useKodeverk'

type SelectProps = {
id?: string
Expand Down Expand Up @@ -55,8 +55,8 @@ export const Select = ({
...rest
}: SelectProps) => {
let _value = isMulti
? options.filter((o) => value?.some((el) => el === o.value))
: options.filter((o) => o.value === value)
? options?.filter?.((o) => value?.some((el) => el === o.value))
: options?.filter?.((o) => o.value === value)

return (
<ReactSelect
Expand Down Expand Up @@ -85,6 +85,7 @@ export const Select = ({
}

export const SelectMedKodeverk = ({ kodeverk, label, isLoading, ...rest }: SelectProps) => {
const { kodeverk: kodeverkListe, loading } = useKodeverk(kodeverk)
const getSortedKodeverk = (kodeverkVerdier) => {
if (label === 'Bostedskommune') {
const kodeverkClone = _.cloneDeep(kodeverkVerdier)
Expand All @@ -97,15 +98,11 @@ export const SelectMedKodeverk = ({ kodeverk, label, isLoading, ...rest }: Selec
}

return (
<KodeverkConnector navn={kodeverk}>
{(kodeverkVerdier) => (
<Select
{...rest}
isLoading={!kodeverkVerdier || isLoading}
options={getSortedKodeverk(kodeverkVerdier)}
/>
)}
</KodeverkConnector>
<Select
{...rest}
isLoading={!kodeverkListe || isLoading}
options={getSortedKodeverk(kodeverkListe)}
/>
)
}

Expand Down
4 changes: 4 additions & 0 deletions apps/dolly-frontend/src/main/js/src/styles/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ a {
margin-bottom: 6px;
}

.navds-checkbox--medium > .navds-checkbox__input + .navds-checkbox__label > .navds-checkbox__icon {
margin-top: 2px;
}

.navds-checkboxes {
margin-bottom: 1rem;
}
Expand Down
32 changes: 26 additions & 6 deletions apps/dolly-frontend/src/main/js/src/utils/hooks/useKodeverk.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
import useSWR from 'swr'
import { fetcher } from '@/api'
import * as _ from 'lodash'

type KodeverkListe = {
koder: Array<KodeverkType>
land?: string
landkode?: string
valuta?: string
valutakode?: string
}

type KodeverkType = {
label: string
value: string
label?: string
value?: string
}

const getKodeverkUrl = (kodeverkNavn) => `/dolly-backend/api/v1/kodeverk/${kodeverkNavn}`
const getKodeverkUrl = (kodeverkNavn) =>
kodeverkNavn.includes('Valuta')
? `/testnav-kontoregister-person-proxy/api/system/v1/hent-valutakoder`
: `/dolly-backend/api/v1/kodeverk/${kodeverkNavn}`

export const useKodeverk = (kodeverkNavn) => {
const { data, isLoading, error } = useSWR<KodeverkListe, Error>(
getKodeverkUrl(kodeverkNavn),
fetcher
[
getKodeverkUrl(kodeverkNavn),
{ accept: 'application/json', 'Content-Type': 'application/json' },
],
([url, headers]) => fetcher(url, headers),
)

const koder =
(_.isArray(data) &&
data[0]?.valutakode &&
data.map((kode) => ({
label: kode.valuta + ` (${kode.valutakode})`,
value: kode.valutakode,
}))) ||
data?.koder

return {
kodeverk: data,
kodeverk: koder || [],
loading: isLoading,
error: error,
}
Expand Down

0 comments on commit 5ae9cba

Please sign in to comment.