diff --git a/app/components/header-meny/HeaderMeny.tsx b/app/components/header-meny/HeaderMeny.tsx index 338aaf7f..b37db1ac 100644 --- a/app/components/header-meny/HeaderMeny.tsx +++ b/app/components/header-meny/HeaderMeny.tsx @@ -6,6 +6,10 @@ import { HeaderUtloggingMeny } from "~/components/header-meny/HeaderUtloggingMen import { Adventslys } from "~/components/jul/Adventslys"; import { useTypedRouteLoaderData } from "~/hooks/useTypedRouteLoaderData"; import type { ISaksbehandler } from "~/models/saksbehandler.server"; +import { oppgaverTilBehandlingDefaultParams } from "~/routes/_index"; +import { alleOppgaverDefaultParams } from "~/routes/alle-oppgaver"; +import { mineOppgaverDefaultParams } from "~/routes/mine-oppgaver"; +import { convertToQueryParamString } from "~/utils/url.utils"; import { PersonSok } from "../person-sok/PersonSok"; import styles from "./HeaderMeny.module.css"; @@ -21,7 +25,7 @@ export function HeaderMeny({ saksbehandler, antallOppgaverJegHarTilBehandling }:
classnames(styles.linkItem, { [styles.linkItemActive]: isActive }) } @@ -30,7 +34,7 @@ export function HeaderMeny({ saksbehandler, antallOppgaverJegHarTilBehandling }: classnames(styles.linkItem, { [styles.linkItemActive]: isActive }) } @@ -44,7 +48,7 @@ export function HeaderMeny({ saksbehandler, antallOppgaverJegHarTilBehandling }: classnames(styles.linkItem, { [styles.linkItemActive]: isActive }) } diff --git a/app/hooks/useTypedRouteLoaderData.tsx b/app/hooks/useTypedRouteLoaderData.tsx index f658e287..d87073e0 100644 --- a/app/hooks/useTypedRouteLoaderData.tsx +++ b/app/hooks/useTypedRouteLoaderData.tsx @@ -1,12 +1,10 @@ import { useRouteLoaderData } from "@remix-run/react"; import type { loader as rootLoader } from "~/root"; -import type { loader as oppgaverLoader } from "~/routes/_oppgaver"; import type { loader as oppgaveLoader } from "~/routes/oppgave.$oppgaveId"; type Loaders = { root: typeof rootLoader; - "routes/_oppgaver": typeof oppgaverLoader; "routes/oppgave.$oppgaveId": typeof oppgaveLoader; }; diff --git a/app/root.tsx b/app/root.tsx index df8da5fe..a7203426 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -21,6 +21,7 @@ import { MistelteinSvg } from "~/components/jul/MistelteinSvg"; import { AlertProvider } from "~/context/alert-context"; import globalCss from "~/global.css?url"; import meldingOmVedtakCss from "~/melding-om-vedtak.css?url"; +import { hentOppgaver } from "~/models/oppgave.server"; import { getSaksbehandler } from "~/models/saksbehandler.server"; import styles from "~/route-styles/root.module.css"; import { handleActions } from "~/server-side-actions/handle-actions"; @@ -82,10 +83,10 @@ export async function action({ request }: ActionFunctionArgs) { export async function loader({ request }: LoaderFunctionArgs) { const saksbehandler = await getSaksbehandler(request); - // const oppgaverJegHarTilBehandling = await hentOppgaver( - // request, - // "?mineOppgaver=true&tilstand=KLAR_TIL_BEHANDLING&tilstand=UNDER_BEHANDLING&tilstand=KLAR_TIL_KONTROLL&tilstand=UNDER_KONTROLL", - // ); + const oppgaverJegHarTilBehandling = await hentOppgaver( + request, + "?mineOppgaver=true&tilstand=KLAR_TIL_BEHANDLING&tilstand=UNDER_BEHANDLING&tilstand=KLAR_TIL_KONTROLL&tilstand=UNDER_KONTROLL", + ); const jul = unleash.isEnabled("dp-saksbehandling-frontend.jul"); const halloween = unleash.isEnabled("dp-saksbehandling-frontend.halloween"); @@ -97,7 +98,7 @@ export async function loader({ request }: LoaderFunctionArgs) { return json({ saksbehandler: saksbehandler, - antallOppgaverJegHarTilBehandling: 0, + antallOppgaverJegHarTilBehandling: oppgaverJegHarTilBehandling.totaltAntallOppgaver, featureFlags: { jul, halloween, diff --git a/app/routes/_oppgaver._index.tsx b/app/routes/_index.tsx similarity index 76% rename from app/routes/_oppgaver._index.tsx rename to app/routes/_index.tsx index 580c2b50..cbd18522 100644 --- a/app/routes/_oppgaver._index.tsx +++ b/app/routes/_index.tsx @@ -10,25 +10,25 @@ import { OppgaveListe } from "~/components/oppgave-liste/OppgaveListe"; import tabStyles from "~/components/oppgave-liste-meny/OppgaveListeMeny.module.css"; import { OppgaveListePaginering } from "~/components/oppgave-liste-paginering/OppgaveListePaginering"; import { useHandleAlertMessages } from "~/hooks/useHandleAlertMessages"; -import { useTypedRouteLoaderData } from "~/hooks/useTypedRouteLoaderData"; +import { hentOppgaver } from "~/models/oppgave.server"; import styles from "~/route-styles/index.module.css"; import { commitSession, getSession } from "~/sessions"; import { appendSearchParamIfNotExists } from "~/utils/url.utils"; +export const oppgaverTilBehandlingDefaultParams = [ + { key: "tilstand", value: "KLAR_TIL_KONTROLL" }, + { key: "tilstand", value: "KLAR_TIL_BEHANDLING" }, + { key: "emneknagg", value: "Avslag minsteinntekt" }, + { key: "side", value: "1" }, + { key: "antallOppgaver", value: "100" }, +]; + export async function loader({ request }: LoaderFunctionArgs) { const url = new URL(request.url); if (!url.search) { - const paramsToAppend = [ - { key: "tilstand", value: "KLAR_TIL_KONTROLL" }, - { key: "tilstand", value: "KLAR_TIL_BEHANDLING" }, - { key: "emneknagg", value: "Avslag minsteinntekt" }, - { key: "side", value: "1" }, - { key: "antallOppgaver", value: "100" }, - ]; - let appended = false; - for (const { key, value } of paramsToAppend) { + for (const { key, value } of oppgaverTilBehandlingDefaultParams) { appended = appendSearchParamIfNotExists(url.searchParams, key, value) || appended; } @@ -37,28 +37,28 @@ export async function loader({ request }: LoaderFunctionArgs) { } } + const oppgaverResponse = await hentOppgaver(request, url.search); const session = await getSession(request.headers.get("Cookie")); const alert = session.get("alert"); - if (alert) { - return json( - { alert }, - { - headers: { - "Set-Cookie": await commitSession(session), - }, + return json( + { + alert, + oppgaver: oppgaverResponse.oppgaver, + totaltAntallOppgaver: oppgaverResponse.totaltAntallOppgaver, + }, + { + headers: { + "Set-Cookie": await commitSession(session), }, - ); - } - - return null; + }, + ); } export default function Saksbehandling() { const { state } = useNavigation(); - const loaderData = useLoaderData(); - const { oppgaver, totaltAntallOppgaver } = useTypedRouteLoaderData("routes/_oppgaver"); - useHandleAlertMessages(loaderData?.alert); + const { alert, oppgaver, totaltAntallOppgaver } = useLoaderData(); + useHandleAlertMessages(alert); return (
diff --git a/app/routes/_oppgaver.tsx b/app/routes/_oppgaver.tsx deleted file mode 100644 index 49d8ae4b..00000000 --- a/app/routes/_oppgaver.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import type { LoaderFunctionArgs } from "@remix-run/node"; -import { json } from "@remix-run/node"; -import { Outlet } from "@remix-run/react"; - -import { hentOppgaver } from "~/models/oppgave.server"; - -export async function loader({ request }: LoaderFunctionArgs) { - const url = new URL(request.url); - const oppgaverResponse = await hentOppgaver(request, url.search); - - return json({ - oppgaver: oppgaverResponse.oppgaver, - totaltAntallOppgaver: oppgaverResponse.totaltAntallOppgaver, - }); -} - -export function Oppgaver() { - return ; -} diff --git a/app/routes/_oppgaver.alle-oppgaver.tsx b/app/routes/alle-oppgaver.tsx similarity index 77% rename from app/routes/_oppgaver.alle-oppgaver.tsx rename to app/routes/alle-oppgaver.tsx index b2f85910..b561fcae 100644 --- a/app/routes/_oppgaver.alle-oppgaver.tsx +++ b/app/routes/alle-oppgaver.tsx @@ -1,7 +1,7 @@ import { BarChartIcon, FunnelIcon } from "@navikt/aksel-icons"; import { Tabs } from "@navikt/ds-react"; import { json, LoaderFunctionArgs, redirect } from "@remix-run/node"; -import { useNavigation } from "@remix-run/react"; +import { useLoaderData, useNavigation } from "@remix-run/react"; import { OppgaveFilterDato } from "~/components/oppgave-filter-dato/OppgaveFilterDato"; import { OppgaveFilterEmneknagger } from "~/components/oppgave-filter-emneknagger/OppgaveFilterEmneknagger"; @@ -10,22 +10,23 @@ import { OppgaveFilterStatus } from "~/components/oppgave-filter-status/OppgaveF import { OppgaveListe } from "~/components/oppgave-liste/OppgaveListe"; import tabStyles from "~/components/oppgave-liste-meny/OppgaveListeMeny.module.css"; import { OppgaveListePaginering } from "~/components/oppgave-liste-paginering/OppgaveListePaginering"; -import { useTypedRouteLoaderData } from "~/hooks/useTypedRouteLoaderData"; +import { useHandleAlertMessages } from "~/hooks/useHandleAlertMessages"; +import { hentOppgaver } from "~/models/oppgave.server"; import styles from "~/route-styles/index.module.css"; import { commitSession, getSession } from "~/sessions"; import { appendSearchParamIfNotExists } from "~/utils/url.utils"; +export const alleOppgaverDefaultParams = [ + { key: "side", value: "1" }, + { key: "antallOppgaver", value: "100" }, +]; + export async function loader({ request }: LoaderFunctionArgs) { const url = new URL(request.url); if (!url.search) { - const paramsToAppend = [ - { key: "side", value: "1" }, - { key: "antallOppgaver", value: "100" }, - ]; - let appended = false; - for (const { key, value } of paramsToAppend) { + for (const { key, value } of alleOppgaverDefaultParams) { appended = appendSearchParamIfNotExists(url.searchParams, key, value) || appended; } @@ -34,26 +35,29 @@ export async function loader({ request }: LoaderFunctionArgs) { } } + const oppgaverResponse = await hentOppgaver(request, url.search); const session = await getSession(request.headers.get("Cookie")); const alert = session.get("alert"); - if (alert) { - return json( - { alert }, - { - headers: { - "Set-Cookie": await commitSession(session), - }, + return json( + { + alert, + oppgaver: oppgaverResponse.oppgaver, + totaltAntallOppgaver: oppgaverResponse.totaltAntallOppgaver, + }, + { + headers: { + "Set-Cookie": await commitSession(session), }, - ); - } - - return null; + }, + ); } export default function Saksbehandling() { const { state } = useNavigation(); - const { oppgaver, totaltAntallOppgaver } = useTypedRouteLoaderData("routes/_oppgaver"); + const { alert, oppgaver, totaltAntallOppgaver } = useLoaderData(); + useHandleAlertMessages(alert); + return (