From d5dab8a3599bfe419d978b32a81a501ab243a38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20J=2E=20Over=C3=A5?= Date: Thu, 6 Jun 2024 16:17:40 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=9A=A7=20Test=20apollo-rest-link=20[s?= =?UTF-8?q?kip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 38 ++++++++++----- package.json | 1 + src/app/apollo/apolloClient.ts | 10 ++++ ...03\270nnsfastsettingSykepengegrunnlag.tsx" | 47 ++++++++++++------- src/routes/saksbilde/timeline/Timeline.tsx | 3 +- 5 files changed, 69 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 032c9c399..921440cbc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "@navikt/oasis": "^3.3.0", "@tanstack/react-query": "^5.40.0", "@types/uuid": "^9.0.8", + "apollo-link-rest": "^0.9.0", "classnames": "^2.5.1", "dayjs": "^1.11.11", "framer-motion": "^11.2.10", @@ -5742,6 +5743,16 @@ "node": ">= 8" } }, + "node_modules/apollo-link-rest": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/apollo-link-rest/-/apollo-link-rest-0.9.0.tgz", + "integrity": "sha512-kuXjR56Y12w0TZcqwVaONKlipB6g3Ya1dAy4NMCaylPpNXq6tO+qzQFPUyDJC7B0JoJPIFjxPV2rAet4uGM4UQ==", + "peerDependencies": { + "@apollo/client": ">=3", + "graphql": ">=0.11", + "qs": ">=6" + } + }, "node_modules/arg": { "version": "4.1.3", "dev": true, @@ -6323,7 +6334,6 @@ }, "node_modules/call-bind": { "version": "1.0.7", - "dev": true, "license": "MIT", "dependencies": { "es-define-property": "^1.0.0", @@ -7075,7 +7085,6 @@ }, "node_modules/define-data-property": { "version": "1.1.4", - "dev": true, "license": "MIT", "dependencies": { "es-define-property": "^1.0.0", @@ -7388,7 +7397,6 @@ }, "node_modules/es-define-property": { "version": "1.0.0", - "dev": true, "license": "MIT", "dependencies": { "get-intrinsic": "^1.2.4" @@ -7399,7 +7407,6 @@ }, "node_modules/es-errors": { "version": "1.3.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -8377,7 +8384,6 @@ }, "node_modules/get-intrinsic": { "version": "1.2.4", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -8520,7 +8526,6 @@ }, "node_modules/gopd": { "version": "1.0.1", - "dev": true, "license": "MIT", "dependencies": { "get-intrinsic": "^1.1.3" @@ -8742,7 +8747,6 @@ }, "node_modules/has-property-descriptors": { "version": "1.0.2", - "dev": true, "license": "MIT", "dependencies": { "es-define-property": "^1.0.0" @@ -8753,7 +8757,6 @@ }, "node_modules/has-proto": { "version": "1.0.3", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -8764,7 +8767,6 @@ }, "node_modules/has-symbols": { "version": "1.0.3", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -11539,7 +11541,6 @@ }, "node_modules/object-inspect": { "version": "1.13.1", - "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -12288,6 +12289,21 @@ "node": ">=6.0.0" } }, + "node_modules/qs": { + "version": "6.12.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.12.1.tgz", + "integrity": "sha512-zWmv4RSuB9r2mYQw3zxQuHWeU+42aKi1wWig/j4ele4ygELZ7PEO6MM7rim9oAQH2A5MWfsAVf/jPvTPgCbvUQ==", + "peer": true, + "dependencies": { + "side-channel": "^1.0.6" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/querystringify": { "version": "2.2.0", "dev": true, @@ -12919,7 +12935,6 @@ }, "node_modules/set-function-length": { "version": "1.2.2", - "dev": true, "license": "MIT", "dependencies": { "define-data-property": "^1.1.4", @@ -13014,7 +13029,6 @@ }, "node_modules/side-channel": { "version": "1.0.6", - "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.7", diff --git a/package.json b/package.json index 29cc61986..38c9c9ee6 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "@navikt/oasis": "^3.3.0", "@tanstack/react-query": "^5.40.0", "@types/uuid": "^9.0.8", + "apollo-link-rest": "^0.9.0", "classnames": "^2.5.1", "dayjs": "^1.11.11", "framer-motion": "^11.2.10", diff --git a/src/app/apollo/apolloClient.ts b/src/app/apollo/apolloClient.ts index 37ff841e5..51ef62a16 100644 --- a/src/app/apollo/apolloClient.ts +++ b/src/app/apollo/apolloClient.ts @@ -1,3 +1,5 @@ +import { RestLink } from 'apollo-link-rest'; + import possibletypes from '@/app/apollo/possibletypes'; import { erLokal } from '@/env'; import { ApolloClient, HttpLink, InMemoryCache, TypePolicies, from } from '@apollo/client'; @@ -47,9 +49,17 @@ const getTypePolicies = (): TypePolicies => { }; }; +const restLink = new RestLink({ + endpoints: { + sanity: 'https://z9kr8ddn.api.sanity.io/v2023-08-01/data/query/production', + flexjar: '/api/flexjar', + }, +}); + export const createApolloClient = () => new ApolloClient({ link: from([ + restLink, new RetryLink({ attempts: { max: 5 }, }), diff --git "a/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/Skj\303\270nnsfastsettingSykepengegrunnlag.tsx" "b/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/Skj\303\270nnsfastsettingSykepengegrunnlag.tsx" index 94537cceb..4ba274d43 100644 --- "a/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/Skj\303\270nnsfastsettingSykepengegrunnlag.tsx" +++ "b/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/Skj\303\270nnsfastsettingSykepengegrunnlag.tsx" @@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react'; import { useSetRecoilState } from 'recoil'; import { erProd } from '@/env'; +import { gql, useQuery } from '@apollo/client'; import { Arbeidsgiverinntekt, Sykepengegrunnlagsgrense } from '@io/graphql'; import { SykepengegrunnlagsgrenseView } from '../InntektsgrunnlagTable/SykepengegrunnlagsgrenseView/SykepengegrunnlagsgrenseView'; @@ -39,25 +40,37 @@ export const SkjønnsfastsettingSykepengegrunnlag = ({ const { aktiveArbeidsgivere } = useSkjønnsfastsettingDefaults(inntekter); const arbeidsforholdMal = (aktiveArbeidsgivere?.length ?? 0) > 1 ? 'FLERE_ARBEIDSGIVERE' : 'EN_ARBEIDSGIVER'; - useEffect(() => { - const response = fetch('https://z9kr8ddn.api.sanity.io/v2023-08-01/data/query/production', { - method: 'post', - headers: { 'content-type': 'application/json' }, - body: JSON.stringify({ query: `*[_type == "skjonnsfastsettelseMal"]` }), - }); - response - .then((response) => response.json()) - .then((it) => { - setMaler( - it.result - .filter((it: SkjønnsfastsettingMal) => + const { data, error, loading } = useQuery( + gql` + query SanityStuff($input: QueryPayload!) { + sanity(input: $input) + @rest(type: "SanityFoo", endpoint: "sanity", path: "/", method: "POST", bodyKey: "input") { + result + query + } + } + `, + { + variables: { + input: { query: `*[_type == "skjonnsfastsettelseMal"]` }, + }, + onCompleted: (result) => { + console.log('SETTING MALER'); + const mals = + result?.sanity?.result + ?.filter((it: SkjønnsfastsettingMal) => avviksprosent <= 25 ? it.lovhjemmel.ledd !== '2' : true, ) - .filter((it: SkjønnsfastsettingMal) => it.arbeidsforholdMal.includes(arbeidsforholdMal)) - .filter((it: SkjønnsfastsettingMal) => (erProd ? it.iProd : true)), - ); - }); - }, []); + ?.filter((it: SkjønnsfastsettingMal) => it.arbeidsforholdMal.includes(arbeidsforholdMal)) + ?.filter((it: SkjønnsfastsettingMal) => (erProd ? it.iProd : true)) ?? []; + + console.log(mals); + setMaler(mals); + }, + }, + ); + + console.log(data, error, loading); useEffect(() => { setEndretSykepengegrunnlag(null); diff --git a/src/routes/saksbilde/timeline/Timeline.tsx b/src/routes/saksbilde/timeline/Timeline.tsx index 30f1822eb..17103f24d 100644 --- a/src/routes/saksbilde/timeline/Timeline.tsx +++ b/src/routes/saksbilde/timeline/Timeline.tsx @@ -4,10 +4,11 @@ import React, { memo, useEffect } from 'react'; import { BodyShort } from '@navikt/ds-react'; +import { useSuspenseQuery } from '@apollo/client'; import { ErrorBoundary } from '@components/ErrorBoundary'; import { LoadingShimmer } from '@components/LoadingShimmer'; import { Key, useKeyboard } from '@hooks/useKeyboard'; -import { Arbeidsgiver, Infotrygdutbetaling } from '@io/graphql'; +import { Arbeidsgiver, FetchPersonDocument, Infotrygdutbetaling } from '@io/graphql'; import { useActivePeriod } from '@state/periode'; import { useCurrentPerson, useFetchPersonQuery } from '@state/person'; import { isBeregnetPeriode } from '@utils/typeguards'; From 757d356418d2f3fdef05b8252fe2a9566fe0f0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20J=2E=20Over=C3=A5?= Date: Thu, 6 Jun 2024 17:48:31 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20Fetch=20sanity=20gj?= =?UTF-8?q?ennom=20apollo-rest-link?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/external/sanity.ts | 75 +++++++++++++++++++ .../Skj\303\270nnsfastsettingHeader.tsx" | 12 +-- ...03\270nnsfastsettingSykepengegrunnlag.tsx" | 43 ++--------- .../Skj\303\270nnsfastsettingBegrunnelse.tsx" | 20 ++--- .../Skj\303\270nnsfastsettingForm.tsx" | 8 +- .../skj\303\270nnsfastsettingFormToDto.tsx" | 2 +- ...Skj\303\270nnsfastsetting\303\205rsak.tsx" | 10 ++- .../skj\303\270nnsfastsetting/state.ts" | 19 ----- .../SykepengegrunnlagFraSpleis.test.tsx | 15 +--- src/routes/saksbilde/timeline/Timeline.tsx | 3 +- 10 files changed, 110 insertions(+), 97 deletions(-) create mode 100644 src/external/sanity.ts delete mode 100644 "src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/state.ts" diff --git a/src/external/sanity.ts b/src/external/sanity.ts new file mode 100644 index 000000000..b4f80a737 --- /dev/null +++ b/src/external/sanity.ts @@ -0,0 +1,75 @@ +import { erProd } from '@/env'; +import { Lovhjemmel } from '@/routes/saksbilde/sykepengegrunnlag/overstyring/overstyring.types'; +import { gql, useQuery } from '@apollo/client'; + +export type ArbeidsforholdMal = 'EN_ARBEIDSGIVER' | 'FLERE_ARBEIDSGIVERE'; + +export interface SkjønnsfastsettingMal { + _id: string; + begrunnelse: string; + konklusjon: string; + arsak: string; + iProd: boolean; + lovhjemmel: Lovhjemmel; + arbeidsforholdMal: ArbeidsforholdMal[]; +} + +type SanityQueryResult = { + sanity: { + result: SkjønnsfastsettingMal[]; + }; +}; + +type SanityQueryVariables = { + input: { + query: string; + }; +}; + +export function useSkjønnsfastsettelsesMaler(avviksprosent: number, harFlereArbeidsgivere: boolean) { + const { data, error, loading } = useQuery( + gql` + query SkjonnsfastsettelsesMaler($input: QueryPayload!) { + sanity(input: $input) + @rest( + type: "SkjonnsfastsettelsesMalResult" + endpoint: "sanity" + path: "/" + method: "POST" + bodyKey: "input" + ) { + result + } + } + `, + { + variables: { + input: { query: `*[_type == "skjonnsfastsettelseMal"]` }, + }, + }, + ); + + return { + maler: data + ? filterRelevantMaler(data.sanity.result, { + avviksprosent, + arbeidsforholdMal: harFlereArbeidsgivere ? 'FLERE_ARBEIDSGIVERE' : 'EN_ARBEIDSGIVER', + }) + : undefined, + loading, + error, + }; +} + +function filterRelevantMaler( + sanityResult: SkjønnsfastsettingMal[], + opts: { + avviksprosent: number; + arbeidsforholdMal: ArbeidsforholdMal; + }, +): SkjønnsfastsettingMal[] { + return sanityResult + .filter((it: SkjønnsfastsettingMal) => (opts.avviksprosent <= 25 ? it.lovhjemmel.ledd !== '2' : true)) + .filter((it: SkjønnsfastsettingMal) => it.arbeidsforholdMal.includes(opts.arbeidsforholdMal)) + .filter((it: SkjønnsfastsettingMal) => (erProd ? it.iProd : true)); +} diff --git "a/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/Skj\303\270nnsfastsettingHeader.tsx" "b/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/Skj\303\270nnsfastsettingHeader.tsx" index 4fb2ad345..319ffd060 100644 --- "a/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/Skj\303\270nnsfastsettingHeader.tsx" +++ "b/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/Skj\303\270nnsfastsettingHeader.tsx" @@ -4,6 +4,7 @@ import { useRecoilValue } from 'recoil'; import { CaseworkerFilled } from '@navikt/ds-icons'; import { BodyShort } from '@navikt/ds-react'; +import { SkjønnsfastsettingMal } from '@/external/sanity'; import { Bold } from '@components/Bold'; import { EditButton } from '@components/EditButton'; import { Endringstrekant } from '@components/Endringstrekant'; @@ -13,8 +14,6 @@ import { useActivePeriod } from '@state/periode'; import { useCurrentPerson } from '@state/person'; import { somPenger, toKronerOgØre } from '@utils/locale'; -import { skjønnsfastsettingMaler } from './state'; - import styles from './SkjønnsfastsettingHeader.module.css'; interface SkjønnsfastsettingHeaderProps { @@ -24,6 +23,7 @@ interface SkjønnsfastsettingHeaderProps { sykepengegrunnlagsgrense: Sykepengegrunnlagsgrense; editing: boolean; setEditing: (state: boolean) => void; + maler: SkjønnsfastsettingMal[] | undefined; } export const SkjønnsfastsettingHeader = ({ @@ -33,15 +33,11 @@ export const SkjønnsfastsettingHeader = ({ sykepengegrunnlagsgrense, editing, setEditing, + maler, }: SkjønnsfastsettingHeaderProps) => { const person = useCurrentPerson(); const aktivPeriode = useActivePeriod(); - const maler = useRecoilValue(skjønnsfastsettingMaler); - const [harMaler, setHarMaler] = useState(false); - - useEffect(() => { - setHarMaler(maler.length > 0); - }, [maler]); + const harMaler = maler && maler.length > 0; if (!person || !aktivPeriode) return <>; diff --git "a/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/Skj\303\270nnsfastsettingSykepengegrunnlag.tsx" "b/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/Skj\303\270nnsfastsettingSykepengegrunnlag.tsx" index 4ba274d43..8d79d7dc3 100644 --- "a/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/Skj\303\270nnsfastsettingSykepengegrunnlag.tsx" +++ "b/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/Skj\303\270nnsfastsettingSykepengegrunnlag.tsx" @@ -2,8 +2,7 @@ import classNames from 'classnames'; import React, { useEffect, useState } from 'react'; import { useSetRecoilState } from 'recoil'; -import { erProd } from '@/env'; -import { gql, useQuery } from '@apollo/client'; +import { useSkjønnsfastsettelsesMaler } from '@/external/sanity'; import { Arbeidsgiverinntekt, Sykepengegrunnlagsgrense } from '@io/graphql'; import { SykepengegrunnlagsgrenseView } from '../InntektsgrunnlagTable/SykepengegrunnlagsgrenseView/SykepengegrunnlagsgrenseView'; @@ -11,7 +10,6 @@ import { SkjønnsfastsettingHeader } from './SkjønnsfastsettingHeader'; import { SkjønnsfastsettingSammendrag } from './SkjønnsfastsettingSammendrag'; import { SkjønnsfastsettingForm } from './form/SkjønnsfastsettingForm/SkjønnsfastsettingForm'; import { useSkjønnsfastsettingDefaults } from './form/SkjønnsfastsettingForm/useSkjønnsfastsettingDefaults'; -import { SkjønnsfastsettingMal, skjønnsfastsettingMaler } from './state'; import styles from './SkjønnsfastsettingSykepengegrunnlag.module.css'; @@ -35,43 +33,14 @@ export const SkjønnsfastsettingSykepengegrunnlag = ({ avviksprosent, }: SkjønnsfastsettingSykepengegrunnlagProps) => { const [editing, setEditing] = useState(false); - const setMaler = useSetRecoilState(skjønnsfastsettingMaler); const [endretSykepengegrunnlag, setEndretSykepengegrunnlag] = useState>(null); const { aktiveArbeidsgivere } = useSkjønnsfastsettingDefaults(inntekter); - const arbeidsforholdMal = (aktiveArbeidsgivere?.length ?? 0) > 1 ? 'FLERE_ARBEIDSGIVERE' : 'EN_ARBEIDSGIVER'; - const { data, error, loading } = useQuery( - gql` - query SanityStuff($input: QueryPayload!) { - sanity(input: $input) - @rest(type: "SanityFoo", endpoint: "sanity", path: "/", method: "POST", bodyKey: "input") { - result - query - } - } - `, - { - variables: { - input: { query: `*[_type == "skjonnsfastsettelseMal"]` }, - }, - onCompleted: (result) => { - console.log('SETTING MALER'); - const mals = - result?.sanity?.result - ?.filter((it: SkjønnsfastsettingMal) => - avviksprosent <= 25 ? it.lovhjemmel.ledd !== '2' : true, - ) - ?.filter((it: SkjønnsfastsettingMal) => it.arbeidsforholdMal.includes(arbeidsforholdMal)) - ?.filter((it: SkjønnsfastsettingMal) => (erProd ? it.iProd : true)) ?? []; - - console.log(mals); - setMaler(mals); - }, - }, + const { maler, loading, error } = useSkjønnsfastsettelsesMaler( + avviksprosent, + (aktiveArbeidsgivere?.length ?? 0) > 1, ); - console.log(data, error, loading); - useEffect(() => { setEndretSykepengegrunnlag(null); }, [editing]); @@ -86,9 +55,10 @@ export const SkjønnsfastsettingSykepengegrunnlag = ({ sykepengegrunnlagsgrense={sykepengegrunnlagsgrense} editing={editing} setEditing={setEditing} + maler={maler} /> {!editing && skjønnsmessigFastsattÅrlig !== null && } - {editing && omregnetÅrsinntekt != null && sammenligningsgrunnlag != null && ( + {editing && maler && omregnetÅrsinntekt != null && sammenligningsgrunnlag != null && ( )} diff --git "a/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/form/Skj\303\270nnsfastsettingBegrunnelse.tsx" "b/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/form/Skj\303\270nnsfastsettingBegrunnelse.tsx" index 0fd794585..9e28c03fa 100644 --- "a/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/form/Skj\303\270nnsfastsettingBegrunnelse.tsx" +++ "b/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/form/Skj\303\270nnsfastsettingBegrunnelse.tsx" @@ -1,31 +1,30 @@ import styles from './SkjønnsfastsettingBegrunnelse.module.scss'; import React, { useState } from 'react'; -import { useFormContext, useWatch } from 'react-hook-form'; -import { useRecoilValue } from 'recoil'; +import { useFormContext } from 'react-hook-form'; import { BodyLong, BodyShort, Textarea } from '@navikt/ds-react'; +import { SkjønnsfastsettingMal } from '@/external/sanity'; import { Button } from '@components/Button'; import { Modal } from '@components/Modal'; import { SortInfoikon } from '@components/ikoner/SortInfoikon'; import { toKronerOgØre } from '@utils/locale'; import { Skjønnsfastsettingstype } from '../skjønnsfastsetting'; -import { skjønnsfastsettingMaler } from '../state'; import { ExpandableSkjønnsfastsettingBegrunnelseContent } from './ExpandableSkjønnsfastsettingBegrunnelse'; interface SkjønnsfastsettingBegrunnelseProps { omregnetÅrsinntekt: number; sammenligningsgrunnlag: number; + valgtMal: SkjønnsfastsettingMal | undefined; } export const SkjønnsfastsettingBegrunnelse = ({ omregnetÅrsinntekt, sammenligningsgrunnlag, + valgtMal, }: SkjønnsfastsettingBegrunnelseProps) => { const { formState, register, watch } = useFormContext(); - const valgtÅrsak = useWatch({ name: 'årsak' }); - const malFraSanity = useRecoilValue(skjønnsfastsettingMaler).find((it) => it.arsak === valgtÅrsak); const [showModal, setShowModal] = useState(false); const begrunnelseType = watch('type'); const arbeidsgivere = watch('arbeidsgivere', []); @@ -45,9 +44,9 @@ export const SkjønnsfastsettingBegrunnelse = ({ Begrunnelse (teksten vises til bruker) - {malFraSanity?.begrunnelse && ( + {valgtMal?.begrunnelse && ( - {malFraSanity.begrunnelse + {valgtMal.begrunnelse .replace('${omregnetÅrsinntekt}', toKronerOgØre(omregnetÅrsinntekt)) .replace('${omregnetMånedsinntekt}', toKronerOgØre(omregnetÅrsinntekt / 12)) .replace('${sammenligningsgrunnlag}', toKronerOgØre(sammenligningsgrunnlag))} @@ -76,12 +75,9 @@ export const SkjønnsfastsettingBegrunnelse = ({ } resize /> - {malFraSanity?.konklusjon && ( + {valgtMal?.konklusjon && ( - {malFraSanity.konklusjon.replace( - '${skjønnsfastsattÅrsinntekt}', - toKronerOgØre(skjønnsfastsatt), - )} + {valgtMal.konklusjon.replace('${skjønnsfastsattÅrsinntekt}', toKronerOgØre(skjønnsfastsatt))} )} diff --git "a/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/form/Skj\303\270nnsfastsettingForm/Skj\303\270nnsfastsettingForm.tsx" "b/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/form/Skj\303\270nnsfastsettingForm/Skj\303\270nnsfastsettingForm.tsx" index 605eea22e..c33b02f15 100644 --- "a/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/form/Skj\303\270nnsfastsettingForm/Skj\303\270nnsfastsettingForm.tsx" +++ "b/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/form/Skj\303\270nnsfastsettingForm/Skj\303\270nnsfastsettingForm.tsx" @@ -4,6 +4,7 @@ import { useRecoilValue } from 'recoil'; import { Button, Loader } from '@navikt/ds-react'; +import { SkjønnsfastsettingMal } from '@/external/sanity'; import { ErrorMessage } from '@components/ErrorMessage'; import { TimeoutModal } from '@components/TimeoutModal'; import { useIsReadOnlyOppgave } from '@hooks/useIsReadOnlyOppgave'; @@ -17,7 +18,6 @@ import { Skjønnsfastsettingstype, usePostSkjønnsfastsattSykepengegrunnlag, } from '../../skjønnsfastsetting'; -import { skjønnsfastsettingMaler } from '../../state'; import { SkjønnsfastsettingBegrunnelse } from '../SkjønnsfastsettingBegrunnelse'; import { SkjønnsfastsettingType } from '../SkjønnsfastsettingType'; import { SkjønnsfastsettingÅrsak } from '../SkjønnsfastsettingÅrsak'; @@ -41,6 +41,7 @@ interface SkjønnsfastsettingFormProps { sykepengegrunnlagsgrense: Sykepengegrunnlagsgrense; onEndretSykepengegrunnlag: (endretSykepengegrunnlag: Maybe) => void; setEditing: (state: boolean) => void; + maler: SkjønnsfastsettingMal[]; } export const SkjønnsfastsettingForm = ({ @@ -50,12 +51,12 @@ export const SkjønnsfastsettingForm = ({ sykepengegrunnlagsgrense, onEndretSykepengegrunnlag, setEditing, + maler, }: SkjønnsfastsettingFormProps) => { const period = useActivePeriod(); const person = useCurrentPerson(); const { aktiveArbeidsgivere, aktiveArbeidsgivereInntekter, defaults } = useSkjønnsfastsettingDefaults(inntekter); const erReadonly = useIsReadOnlyOppgave(); - const maler = useRecoilValue(skjønnsfastsettingMaler); const feiloppsummeringRef = useRef(null); const avrundetSammenligningsgrunnlag = Math.round((sammenligningsgrunnlag + Number.EPSILON) * 100) / 100; const cancelEditing = () => { @@ -134,7 +135,7 @@ export const SkjønnsfastsettingForm = ({
- + {harValgt25Avvik && } {((harValgt25Avvik && valgtType) || (valgtÅrsak !== '' && !harValgt25Avvik)) && ( <> @@ -146,6 +147,7 @@ export const SkjønnsfastsettingForm = ({ {visFeilOppsummering && ( { +export const SkjønnsfastsettingÅrsak = ({ maler }: Props) => { const { formState, register, setValue, resetField, getValues } = useFormContext(); - const årsaker = useRecoilValue(skjønnsfastsettingMaler).flatMap((it) => it.arsak); + const årsaker = maler?.flatMap((it) => it.arsak) ?? []; const { ref, ...årsakValidation } = register('årsak', { required: 'Du må velge en årsak' }); const resetType = () => { diff --git "a/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/state.ts" "b/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/state.ts" deleted file mode 100644 index 45b90ee20..000000000 --- "a/src/routes/saksbilde/sykepengegrunnlag/skj\303\270nnsfastsetting/state.ts" +++ /dev/null @@ -1,19 +0,0 @@ -import { Lovhjemmel } from '../overstyring/overstyring.types'; -import { atom } from 'recoil'; - -export type ArbeidsforholdMal = 'EN_ARBEIDSGIVER' | 'FLERE_ARBEIDSGIVERE'; - -export interface SkjønnsfastsettingMal { - _id: string; - begrunnelse: string; - konklusjon: string; - arsak: string; - iProd: boolean; - lovhjemmel: Lovhjemmel; - arbeidsforholdMal: ArbeidsforholdMal[]; -} - -export const skjønnsfastsettingMaler = atom({ - key: 'skjønnsfastsettingMaler', - default: [], -}); diff --git a/src/routes/saksbilde/sykepengegrunnlag/sykepengegrunnlagvisninger/spleis/SykepengegrunnlagFraSpleis.test.tsx b/src/routes/saksbilde/sykepengegrunnlag/sykepengegrunnlagvisninger/spleis/SykepengegrunnlagFraSpleis.test.tsx index e5b1aacdd..0e930fc5a 100644 --- a/src/routes/saksbilde/sykepengegrunnlag/sykepengegrunnlagvisninger/spleis/SykepengegrunnlagFraSpleis.test.tsx +++ b/src/routes/saksbilde/sykepengegrunnlag/sykepengegrunnlagvisninger/spleis/SykepengegrunnlagFraSpleis.test.tsx @@ -1,4 +1,4 @@ -import { RecoilWrapper } from '@test-wrappers'; +import { ApolloWrapper } from '@test-wrappers'; import fetchMock from 'jest-fetch-mock'; import React from 'react'; @@ -62,7 +62,7 @@ describe('SykepengegrunnlagFraSpleis', () => { render( , - { wrapper: RecoilWrapper }, + { wrapper: ApolloWrapper }, ); expect(screen.getByText('Inntektsgrunnlag')).toBeVisible(); @@ -96,7 +96,7 @@ describe('SykepengegrunnlagFraSpleis', () => { render( , - { wrapper: RecoilWrapper }, + { wrapper: ApolloWrapper }, ); expect(screen.getByText('Inntektsgrunnlag')).toBeVisible(); @@ -107,12 +107,3 @@ describe('SykepengegrunnlagFraSpleis', () => { expect(screen.getAllByText(arbeidsgiver.navn)).toHaveLength(3); }); }); - -export function mockFetch(data: string) { - return jest.fn().mockImplementation(() => - Promise.resolve({ - ok: true, - json: () => data, - }), - ); -} diff --git a/src/routes/saksbilde/timeline/Timeline.tsx b/src/routes/saksbilde/timeline/Timeline.tsx index 17103f24d..30f1822eb 100644 --- a/src/routes/saksbilde/timeline/Timeline.tsx +++ b/src/routes/saksbilde/timeline/Timeline.tsx @@ -4,11 +4,10 @@ import React, { memo, useEffect } from 'react'; import { BodyShort } from '@navikt/ds-react'; -import { useSuspenseQuery } from '@apollo/client'; import { ErrorBoundary } from '@components/ErrorBoundary'; import { LoadingShimmer } from '@components/LoadingShimmer'; import { Key, useKeyboard } from '@hooks/useKeyboard'; -import { Arbeidsgiver, FetchPersonDocument, Infotrygdutbetaling } from '@io/graphql'; +import { Arbeidsgiver, Infotrygdutbetaling } from '@io/graphql'; import { useActivePeriod } from '@state/periode'; import { useCurrentPerson, useFetchPersonQuery } from '@state/person'; import { isBeregnetPeriode } from '@utils/typeguards'; From d9a5952f540f246e9d6beac04d2088edb0141881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20J=2E=20Over=C3=A5?= Date: Thu, 6 Jun 2024 18:40:54 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=A5=20Fjern=20react-query?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 23 ------- package.json | 1 - src/app/api/flexjar/oppdater/[id]/route.ts | 16 ++++- src/app/api/flexjar/route.ts | 9 +++ src/app/providers.tsx | 8 +-- src/components/flexjar/FlexjarFelles.tsx | 34 +++++++--- src/external/flexjar/types.ts | 5 ++ .../flexjar/useOppdaterFlexjarFeedback.ts | 27 ++++++++ .../flexjar/useOpprettFlexjarFeedback.ts | 26 ++++++++ src/external/sanity.ts | 2 +- src/hooks/useOppdaterFlexjarFeedback.ts | 64 ------------------- src/hooks/useOpprettFlexjarFeedback.ts | 46 ------------- 12 files changed, 109 insertions(+), 152 deletions(-) create mode 100644 src/external/flexjar/types.ts create mode 100644 src/external/flexjar/useOppdaterFlexjarFeedback.ts create mode 100644 src/external/flexjar/useOpprettFlexjarFeedback.ts delete mode 100644 src/hooks/useOppdaterFlexjarFeedback.ts delete mode 100644 src/hooks/useOpprettFlexjarFeedback.ts diff --git a/package-lock.json b/package-lock.json index 921440cbc..5d61bf81f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,6 @@ "@navikt/ds-icons": "^3.4.3", "@navikt/ds-react": "^6.8.0", "@navikt/oasis": "^3.3.0", - "@tanstack/react-query": "^5.40.0", "@types/uuid": "^9.0.8", "apollo-link-rest": "^0.9.0", "classnames": "^2.5.1", @@ -4808,28 +4807,6 @@ "tslib": "^2.4.0" } }, - "node_modules/@tanstack/query-core": { - "version": "5.40.0", - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/tannerlinsley" - } - }, - "node_modules/@tanstack/react-query": { - "version": "5.40.0", - "license": "MIT", - "dependencies": { - "@tanstack/query-core": "5.40.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/tannerlinsley" - }, - "peerDependencies": { - "react": "^18.0.0" - } - }, "node_modules/@tanstack/react-virtual": { "version": "3.5.0", "license": "MIT", diff --git a/package.json b/package.json index 38c9c9ee6..9516f9f18 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,6 @@ "@navikt/ds-icons": "^3.4.3", "@navikt/ds-react": "^6.8.0", "@navikt/oasis": "^3.3.0", - "@tanstack/react-query": "^5.40.0", "@types/uuid": "^9.0.8", "apollo-link-rest": "^0.9.0", "classnames": "^2.5.1", diff --git a/src/app/api/flexjar/oppdater/[id]/route.ts b/src/app/api/flexjar/oppdater/[id]/route.ts index 851e70abf..9592cf590 100644 --- a/src/app/api/flexjar/oppdater/[id]/route.ts +++ b/src/app/api/flexjar/oppdater/[id]/route.ts @@ -1,7 +1,17 @@ import { postOppdater } from '@/app/api/flexjar/flexjar'; +import { erLokal } from '@/env'; +import logger from '@/logger'; + +export const dynamic = 'force-dynamic'; -export const dynamic = 'force-dynamic'; // defaults to auto export async function POST(request: Request, { params }: { params: { id: string } }) { - const id = params.id; // 'a', 'b', or 'c' - return postOppdater(id, request); + if (erLokal) { + logger.info(`Mocker flexjar lokalt, mottok OPPDATERT feedback: ${JSON.stringify(request.json(), null, 2)}`); + + return Response.json({ + id: 'fake-lokal-flexjar-id', + }); + } + + return postOppdater(params.id, request); } diff --git a/src/app/api/flexjar/route.ts b/src/app/api/flexjar/route.ts index f53972aba..4a05db852 100644 --- a/src/app/api/flexjar/route.ts +++ b/src/app/api/flexjar/route.ts @@ -1,7 +1,16 @@ import { postOpprett } from '@/app/api/flexjar/flexjar'; +import { erLokal } from '@/env'; +import logger from '@/logger'; export const dynamic = 'force-dynamic'; export async function POST(request: Request) { + if (erLokal) { + logger.info(`Mocker flexjar lokalt, mottok feedback: ${JSON.stringify(request.json(), null, 2)}`); + return Response.json({ + id: 'fake-lokal-flexjar-id', + }); + } + return postOpprett(request); } diff --git a/src/app/providers.tsx b/src/app/providers.tsx index 4d5705cf2..c7123d4e1 100644 --- a/src/app/providers.tsx +++ b/src/app/providers.tsx @@ -24,7 +24,6 @@ import { ApolloProvider } from '@apollo/client'; import { useLoadingToast } from '@hooks/useLoadingToast'; import { useFetchPersonQuery } from '@state/person'; import { useSetVarsler } from '@state/varsler'; -import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; dayjs.extend(relativeTime); dayjs.extend(minMax); @@ -42,7 +41,6 @@ type Props = { export const Providers = ({ children, bruker }: PropsWithChildren): ReactElement => { const [apolloClient] = useState(() => createApolloClient()); - const [queryClient] = useState(() => new QueryClient()); const initializeState = useCallback( ({ set }: { set: SetRecoilState }) => { @@ -52,7 +50,7 @@ export const Providers = ({ children, bruker }: PropsWithChildren): React hydrateAllFilters(set, bruker.grupper); hydrateSorteringForTab(set); }, - [bruker.grupper], + [bruker.grupper, bruker.ident], ); useLayoutEffect(() => { @@ -65,9 +63,7 @@ export const Providers = ({ children, bruker }: PropsWithChildren): React - - {children} - + {children} diff --git a/src/components/flexjar/FlexjarFelles.tsx b/src/components/flexjar/FlexjarFelles.tsx index 3742285f3..da10f0af5 100644 --- a/src/components/flexjar/FlexjarFelles.tsx +++ b/src/components/flexjar/FlexjarFelles.tsx @@ -4,9 +4,10 @@ import React, { useCallback, useEffect, useRef, useState } from 'react'; import { BodyShort, Button, Textarea } from '@navikt/ds-react'; +import { FeedbackPayload } from '@/external/flexjar/types'; +import { useOppdaterFlexjarFeedback } from '@/external/flexjar/useOppdaterFlexjarFeedback'; +import { useOpprettFlexjarFeedback } from '@/external/flexjar/useOpprettFlexjarFeedback'; import { Bold } from '@components/Bold'; -import { useOppdaterFlexjarFeedback } from '@hooks/useOppdaterFlexjarFeedback'; -import { useOpprettFlexjarFeedback } from '@hooks/useOpprettFlexjarFeedback'; interface FlexjarFellesProps { feedbackId: string; @@ -38,8 +39,8 @@ export function FlexjarFelles({ const [textValue, setTextValue] = useState(''); const [errorMsg, setErrorMsg] = useState(null); const textAreaRef = useRef(null); - const { mutate: giFeedback, data, reset } = useOpprettFlexjarFeedback(); - const { mutate: oppdaterFeedback } = useOppdaterFlexjarFeedback(); + const { mutate: giFeedback, data, error: opprettError, reset } = useOpprettFlexjarFeedback(); + const { mutate: oppdaterFeedback, error: oppdaterError } = useOppdaterFlexjarFeedback(); const fetchFeedback = useCallback( async (knappeklikk?: () => void): Promise => { @@ -47,17 +48,28 @@ export function FlexjarFelles({ return false; } - const body = { + const payload: FeedbackPayload = { feedback: textValue, feedbackId: feedbackId, svar: activeState, ...feedbackProps, }; + if (data?.id) { - oppdaterFeedback({ body, id: data.id, cb: knappeklikk }); + oppdaterFeedback({ + variables: { + id: data.id, + payload, + }, + onCompleted: knappeklikk, + }); return true; } else { - giFeedback(body); + giFeedback({ + variables: { + payload, + }, + }); return false; } }, @@ -112,7 +124,13 @@ export function FlexjarFelles({