diff --git a/package-lock.json b/package-lock.json index 032c9c399..5d61bf81f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,8 +18,8 @@ "@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", "dayjs": "^1.11.11", "framer-motion": "^11.2.10", @@ -4807,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", @@ -5742,6 +5720,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 +6311,6 @@ }, "node_modules/call-bind": { "version": "1.0.7", - "dev": true, "license": "MIT", "dependencies": { "es-define-property": "^1.0.0", @@ -7075,7 +7062,6 @@ }, "node_modules/define-data-property": { "version": "1.1.4", - "dev": true, "license": "MIT", "dependencies": { "es-define-property": "^1.0.0", @@ -7388,7 +7374,6 @@ }, "node_modules/es-define-property": { "version": "1.0.0", - "dev": true, "license": "MIT", "dependencies": { "get-intrinsic": "^1.2.4" @@ -7399,7 +7384,6 @@ }, "node_modules/es-errors": { "version": "1.3.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -8377,7 +8361,6 @@ }, "node_modules/get-intrinsic": { "version": "1.2.4", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -8520,7 +8503,6 @@ }, "node_modules/gopd": { "version": "1.0.1", - "dev": true, "license": "MIT", "dependencies": { "get-intrinsic": "^1.1.3" @@ -8742,7 +8724,6 @@ }, "node_modules/has-property-descriptors": { "version": "1.0.2", - "dev": true, "license": "MIT", "dependencies": { "es-define-property": "^1.0.0" @@ -8753,7 +8734,6 @@ }, "node_modules/has-proto": { "version": "1.0.3", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -8764,7 +8744,6 @@ }, "node_modules/has-symbols": { "version": "1.0.3", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -11539,7 +11518,6 @@ }, "node_modules/object-inspect": { "version": "1.13.1", - "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -12288,6 +12266,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 +12912,6 @@ }, "node_modules/set-function-length": { "version": "1.2.2", - "dev": true, "license": "MIT", "dependencies": { "define-data-property": "^1.1.4", @@ -13014,7 +13006,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..9516f9f18 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,8 @@ "@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", "dayjs": "^1.11.11", "framer-motion": "^11.2.10", 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/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/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({