Skip to content

Commit

Permalink
Diverse kodeforbedring etter Sonarcloud-rapport
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeofnorway committed Jul 25, 2024
1 parent bfd0a1d commit 03b5a25
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 18 deletions.
6 changes: 3 additions & 3 deletions example/src/components/SprakVelger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export const SprakVelger = (props: Props) => {
const { locales, valgtLocale, settValgtLocale } = props;
return (
<div className="example__velger">
{locales.map((locale, i) =>
{locales.map((locale) =>
valgtLocale === locale ? (
<span key={i} className="example__sprak">
<span key={locale} className="example__sprak">
<b>{locale}</b>
</span>
) : (
<button key={i} className="example__sprak" onClick={() => settValgtLocale(locale)}>
<button key={locale} className="example__sprak" onClick={() => settValgtLocale(locale)}>
{locale}
</button>
)
Expand Down
6 changes: 3 additions & 3 deletions src/clients/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ const hentJsonOgSjekkAuth = (url: string, headers?: object) =>

export const hentListeMedArbeidsforhold = (customApiUrl?: string) => {
const defaultApiUrl = `${Environment.apiUrl}/arbeidsforhold`;
return hentJsonOgSjekkAuth(customApiUrl || defaultApiUrl);
return hentJsonOgSjekkAuth(customApiUrl ?? defaultApiUrl);
};

// Henter fødselsnummer fra token
export const hentDetaljertArbeidsforholdArbeidstaker = (id: number, customApiUrl?: string) => {
const defaultApiUrl = `${Environment.apiUrl}/arbeidsforholdinnslag/arbeidstaker/{id}`;
const apiUrl = (customApiUrl || defaultApiUrl).replace('{id}', id.toString());
const apiUrl = (customApiUrl ?? defaultApiUrl).replace('{id}', id.toString());
return hentJsonOgSjekkAuth(apiUrl);
};

// Bruker tokenet til arbeidsgiver
export const hentDetaljertArbeidsforholdArbeidsgiver = (fnr: string, id: number, customApiUrl?: string) => {
const defaultApiUrl = `${Environment.apiUrl}/arbeidsforholdinnslag/arbeidsgiver/{id}`;
const apiUrl = (customApiUrl || defaultApiUrl).replace('{id}', id.toString());
const apiUrl = (customApiUrl ?? defaultApiUrl).replace('{id}', id.toString());
return hentJsonOgSjekkAuth(apiUrl, { 'Fnr-Arbeidstaker': `${fnr}` });
};
1 change: 0 additions & 1 deletion src/components/arbeidsgiver/ArbeidsgiverTittel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { fnr } from '@/utils/fnr';

interface Props {
arbeidsgiver: AFArbeidsgiver;
overskrift?: boolean;
}

export const ArbeidsgiverTittel = (props: Props) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/check-date-and-print/CheckDateAndPrint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const CheckDateAndPrint = (props: Props) => {

const date = dayjs(props.data)
.locale(locale)
.format(props.dateFormat || 'DD.MM.YYYY');
.format(props.dateFormat ?? 'DD.MM.YYYY');

const formattedDate = props.format ? parse(props.format, date) : date;

Expand Down
5 changes: 0 additions & 5 deletions src/modules/af-detaljert/print/pdf/GenerellOversiktPDF.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import { useLocale } from '@/modules/common/useLocale';

interface Props {
arbeidsforhold: AFUtvidet;
printGenerellOversikt: boolean;
printTimerTimelonnet: boolean;
printPermisjon: boolean;
printUtenlandsopphold: boolean;
printHistorikk: boolean;
printName: string;
printSSO: string;
}
Expand Down
6 changes: 5 additions & 1 deletion src/modules/af-detaljert/print/pdf/tabs/PermisjonPDF.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ interface Props {
permisjoner: AFPermisjonPermittering[];
}

const sortPermisjoner = (left: AFPermisjonPermittering, right: AFPermisjonPermittering) => {
return sortPeriodeFraDesc(left.periode, right.periode);
};

export const PermisjonPDF = (props: Props) => {
const { locale } = useLocale();

const sortedPermisjoner = props.permisjoner.sort((left, right) => sortPeriodeFraDesc(left.periode, right.periode));
const sortedPermisjoner = props.permisjoner.sort(sortPermisjoner);

return (
<>
Expand Down
3 changes: 1 addition & 2 deletions src/modules/common/useIsPdf.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import { useContext } from 'react';
import React, { useContext } from 'react';

const IsPdfContext = React.createContext<boolean>(false);

Expand Down
3 changes: 1 addition & 2 deletions src/modules/common/useLocale.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import React, { useContext } from 'react';
import { Locale } from '@/types/locale';
import { useContext } from 'react';

const LocaleContext = React.createContext<Locale>('nb');

Expand Down

0 comments on commit 03b5a25

Please sign in to comment.