Skip to content

Commit

Permalink
feat. korrige komma i desimaltall flere steder
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikv committed Dec 19, 2024
1 parent 0c99b75 commit 5580cf2
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/AvtaleSide/steg/BeregningTilskudd/Arbeidsgiveravgift.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useContext } from 'react';
import { Column, Row } from '@/komponenter/NavGrid/Grid';
import SelectInput from '@/komponenter/form/SelectInput';
import { parseFloatIfFloatable } from '@/utils';
import { formaterNorskeTall, parseFloatIfFloatable } from '@/utils';
import { BEMWrapper } from '@/utils/bem';
import { AvtaleContext } from '@/AvtaleProvider';

Expand All @@ -17,7 +17,7 @@ const Arbeidsgiveravgift: React.FC<Props> = ({ cls }: Props) => {
const satserVerdier = [{ label: 'Velg', value: '' }];
satser.forEach((sats: number) =>
satserVerdier.push({
label: (sats * 100).toFixed(1) + ' %',
label: formaterNorskeTall(sats * 100) + ' %',
value: sats.toString(),
}),
);
Expand Down
4 changes: 2 additions & 2 deletions src/AvtaleSide/steg/BeregningTilskudd/Feriepenger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Column, Row } from '@/komponenter/NavGrid/Grid';
import { BEMWrapper } from '@/utils/bem';
import { AvtaleContext } from '@/AvtaleProvider';
import SelectInput from '@/komponenter/form/SelectInput';
import { parseFloatIfFloatable } from '@/utils';
import { formaterNorskeTall, parseFloatIfFloatable } from '@/utils';

interface Props {
cls: BEMWrapper;
Expand All @@ -13,7 +13,7 @@ const Feriepenger: React.FC<Props> = ({ cls }: Props) => {

const feriepengeAlternativer = [{ label: 'Velg', value: '' }].concat(
[0, 0.102, 0.12, 0.125, 0.143].map((sats: number) => ({
label: (sats * 100).toFixed(1) + ' %',
label: formaterNorskeTall(sats * 100) + ' %',
value: sats.toString(),
})),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Column, Row } from '@/komponenter/NavGrid/Grid';
import ProsentInput from '@/komponenter/form/ProsentInput';
import { BEMWrapper } from '@/utils/bem';
import { AvtaleContext } from '@/AvtaleProvider';
import { formaterNorskeTall } from '@/utils';

interface Props {
cls: BEMWrapper;
Expand All @@ -22,7 +23,7 @@ const ObligatoriskTjenestepensjon: React.FC<Props> = ({ cls }: Props) => {
autoComplete={'off'}
value={
avtale.gjeldendeInnhold.otpSats !== undefined && avtale.gjeldendeInnhold.otpSats !== null
? (avtale.gjeldendeInnhold.otpSats * 100).toFixed(2)
? formaterNorskeTall(avtale.gjeldendeInnhold.otpSats * 100)
: ''
}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import EtikettStatus from '@/BeslutterSide/EtikettStatus';
import { TilskuddsPeriode } from '@/types/avtale';
import BEMHelper from '@/utils/bem';
import { formatterPeriode } from '@/utils/datoUtils';
import { formatterProsent } from '@/utils/formatterProsent';
import { formaterProsent } from '@/utils/formaterProsent';
import { formaterPenger } from '@/utils/PengeUtils';
import { FunctionComponent } from 'react';
import './tilskuddsPerioder.less';
Expand Down Expand Up @@ -36,7 +36,7 @@ const TilskuddsPerioderVeileder: FunctionComponent<Props> = (props) => {
<td aria-label={`Startdato ${periode.startDato} og sluttdato ${periode.sluttDato}`}>
{formatterPeriode(periode.startDato, periode.sluttDato)}
</td>
<td>{formatterProsent(periode.lonnstilskuddProsent)}</td>
<td>{formaterProsent(periode.lonnstilskuddProsent)}</td>
<td>{formaterPenger(periode.beløp)}</td>
<td>
<EtikettStatus tilskuddsperiodestatus={periode.status} size="small" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import StillingsTittelVelger, { StillingOptions } from '@/AvtaleSide/steg/Stilli
import useStilling from '@/AvtaleSide/steg/StillingSteg/useStilling';
import StillingsprosentInput from '@/AvtaleSide/steg/VarighetSteg/StillingsprosentInput/StillingsprosentInput';
import BekreftelseModal from '@/komponenter/modal/BekreftelseModal';
import PakrevdInput from '@/komponenter/PakrevdInput/PakrevdInput';
import PakrevdTextarea from '@/komponenter/PakrevdTextarea/PakrevdTextarea';
import { EndreStilling, oppdatereStillingbeskrivelse } from '@/services/rest-service';
import BEMHelper from '@/utils/bem';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Task } from '@navikt/ds-icons/cjs';
import { BodyShort, Link } from '@navikt/ds-react';
import React, { FunctionComponent, useContext, useState } from 'react';
import './EndreTilskuddsberegning.less';
import { formaterNorskeTall } from '@/utils';

export type EndreBeregning = Pick<
Beregningsgrunnlag & Varighet,
Expand Down Expand Up @@ -123,7 +124,7 @@ const EndreTilskuddsberegning: FunctionComponent = () => {
autoComplete={'off'}
value={
nyBeregning.otpSats !== undefined && nyBeregning.otpSats !== null
? (nyBeregning.otpSats * 100).toFixed(0)
? formaterNorskeTall(nyBeregning.otpSats * 100)
: ''
}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const schema = z.object({
invalid_type_error: 'Antall dager være et tall',
required_error: 'Antall dager er påkrevd',
})
.multipleOf(0.01, 'Antall dager kan maks ha 2 desimaler')
.min(0.1, 'Antall dager må være større enn 0')
.max(7, 'Antall dager må være mindre enn eller lik 7'),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const schema = z.object({
invalid_type_error: 'Stillingsprosent være et tall',
required_error: 'Stillingsprosent er påkrevd',
})
.multipleOf(0.01, 'Stillingsprosent kan maks ha 2 desimaler')
.min(0.1, 'Stillingsprosent må være større enn 0')
.max(100, 'Stillingsprosent må være mindre enn eller lik 100'),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AvtaleContext, Context } from '@/AvtaleProvider';
import { formatterDato, formatterPeriode, NORSK_DATO_FORMAT } from '@/utils/datoUtils';
import { formatterProsent } from '@/utils/formatterProsent';
import { formaterProsent } from '@/utils/formaterProsent';
import { formaterPenger } from '@/utils/PengeUtils';
import React, { FunctionComponent, useContext, useRef, useState, useEffect } from 'react';
import EtikettStatus from '../EtikettStatus';
Expand Down Expand Up @@ -100,7 +100,7 @@ const BeslutterTilskuddsPerioder: FunctionComponent<Props> = (props) => {
{formatterPeriode(periode.startDato, periode.sluttDato, 'DD.MM.YY')}
</td>
<td>{formaterPenger(periode.beløp)}</td>
<td>{formatterProsent(periode.lonnstilskuddProsent)}</td>
<td>{formaterProsent(periode.lonnstilskuddProsent)}</td>
<td>{formatterDato(periode.kanBesluttesFom, NORSK_DATO_FORMAT)}</td>
<td>{periode.status === 'GODKJENT' ? periode.enhet : enhet}</td>
<td>
Expand Down
8 changes: 4 additions & 4 deletions src/komponenter/form/ProsentInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FormattedNumberInput from '@/komponenter/form/FormattedNumberInput';
import { formatterProsent } from '@/utils/formatterProsent';
import { formaterProsent } from '@/utils/formaterProsent';
import React, { PropsWithChildren } from 'react';
import { TextFieldProps } from '@navikt/ds-react';

Expand All @@ -25,12 +25,12 @@ const ProsentInput: React.FunctionComponent<InputProps> = (props: PropsWithChild
},
(v: any) => {
if (v && min && v < min) {
return 'Må være over ' + formatterProsent(min);
return 'Må være over ' + formaterProsent(min);
}
},
(v: any) => {
if (v && max && v > max) {
return 'Må være under ' + formatterProsent(max);
return 'Må være under ' + formaterProsent(max);
}
},
];
Expand All @@ -41,7 +41,7 @@ const ProsentInput: React.FunctionComponent<InputProps> = (props: PropsWithChild
step={step}
validatorer={validatorer}
maxLength={3}
toFormatted={formatterProsent}
toFormatted={formaterProsent}
max={max}
min={min}
{...other}
Expand Down
9 changes: 9 additions & 0 deletions src/utils/formaterProsent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { formaterNorskeTall, parseNorskeTallFraInput } from '@/utils/tallUtils';

export const formaterProsent = <T>(value: T): string => {
const valueSomTall = parseNorskeTallFraInput(value);
if (!valueSomTall && valueSomTall !== 0) {
return '';
}
return `${formaterNorskeTall(valueSomTall)} %`;
};
6 changes: 0 additions & 6 deletions src/utils/formatterProsent.ts

This file was deleted.

0 comments on commit 5580cf2

Please sign in to comment.