Skip to content

Commit

Permalink
Cdn upload (#136)
Browse files Browse the repository at this point in the history
* Legg til cdn for statiske filer

* Legg aktivt oppgavesøk som context istedet for session cookie

* Alle kan legge tilbake oppgaver som ikke er ferdigstilt. Man skal kun se oppgaver som er ferdig
  • Loading branch information
ssaegrov authored Dec 12, 2024
1 parent c0d8576 commit 26120a0
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 37 deletions.
12 changes: 10 additions & 2 deletions app/components/oppgave-liste-valg/OppgaveListeValg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ export function OppgaveListeValg({ oppgave }: { oppgave: IListeOppgave }) {
oppgave.tilstand === "KLAR_TIL_KONTROLL" ||
(oppgave.tilstand === "UNDER_KONTROLL" && minBeslutterOppgaver);

const kanLeggeTilbakeOppgave =
oppgave.behandlerIdent &&
oppgave.tilstand !== "FERDIG_BEHANDLET" &&
oppgave.tilstand !== "BEHANDLES_I_ARENA";

const kanSeOppgave =
oppgave.tilstand === "FERDIG_BEHANDLET" || oppgave.tilstand === "BEHANDLES_I_ARENA";

return (
<>
<Button
Expand Down Expand Up @@ -67,7 +75,7 @@ export function OppgaveListeValg({ oppgave }: { oppgave: IListeOppgave }) {
</Form>
)}

{!kanTildeleOgBehandleOppgave && (
{kanSeOppgave && (
<RemixLink
to={`/oppgave/${oppgave.oppgaveId}/se`}
asButtonVariant="tertiary-neutral"
Expand All @@ -77,7 +85,7 @@ export function OppgaveListeValg({ oppgave }: { oppgave: IListeOppgave }) {
</RemixLink>
)}

{minSaksbehandlerOppgave && oppgave.tilstand !== "FERDIG_BEHANDLET" && (
{kanLeggeTilbakeOppgave && (
<Form method="post">
<input name="_action" value="legg-tilbake-oppgave" hidden={true} readOnly={true} />
<input name="oppgaveId" value={oppgave.oppgaveId} hidden={true} readOnly={true} />
Expand Down
9 changes: 8 additions & 1 deletion app/components/oppgave-liste/OppgaveListe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classnames from "classnames";
import { differenceInCalendarDays } from "date-fns";

import { OppgaveListeValg } from "~/components/oppgave-liste-valg/OppgaveListeValg";
import { useSaksbehandler } from "~/hooks/useSaksbehandler";
import { useTableSort } from "~/hooks/useTableSort";
import type { IListeOppgave, IOppgaveTilstand } from "~/models/oppgave.server";
import { formaterNorskDato } from "~/utils/dato.utils";
Expand All @@ -29,7 +30,7 @@ export function OppgaveListe({
}: IProps) {
const { state } = useNavigation();
const location = useLocation();

const { aktivtOppgaveSok } = useSaksbehandler();
const { sortedData, handleSort, sortState } = useTableSort<IListeOppgave>(oppgaver, {
orderBy: "tidspunktOpprettet",
direction: "ascending",
Expand All @@ -42,6 +43,12 @@ export function OppgaveListe({
{visNesteOppgaveKnapp && (
<Form method="post" className={styles.nesteKnapp}>
<input hidden={true} readOnly={true} name="_action" value="hent-neste-oppgave" />
<input
name="aktivtOppgaveSok"
value={aktivtOppgaveSok}
hidden={true}
readOnly={true}
/>
<Button
variant="primary"
size="small"
Expand Down
19 changes: 19 additions & 0 deletions app/context/saksbehandler-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { PropsWithChildren } from "react";
import { createContext, useState } from "react";

interface ISaksbehandlerContext {
aktivtOppgaveSok: string;
setAktivtOppgaveSok: (sok: string) => void;
}

export const SaksbehandlerContext = createContext<ISaksbehandlerContext | undefined>(undefined);

export function SaksbehandlerProvider(props: PropsWithChildren<{ aktivtSok: string }>) {
const [aktivtOppgaveSok, setAktivtOppgaveSok] = useState<string>("");

return (
<SaksbehandlerContext.Provider value={{ aktivtOppgaveSok, setAktivtOppgaveSok }}>
{props.children}
</SaksbehandlerContext.Provider>
);
}
11 changes: 11 additions & 0 deletions app/hooks/useSaksbehandler.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useContext } from "react";

import { SaksbehandlerContext } from "~/context/saksbehandler-context";

export function useSaksbehandler() {
const context = useContext(SaksbehandlerContext);
if (!context) {
throw new Error("useSaksbehandler must be used within an SaksbehandlerProvider");
}
return context;
}
10 changes: 5 additions & 5 deletions app/models/oppgave.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getSession } from "~/sessions";
import { getSaksbehandlingOboToken } from "~/utils/auth.utils.server";
import { getEnv } from "~/utils/env.utils";
import { handleErrorResponse } from "~/utils/error-response.server";
Expand Down Expand Up @@ -133,16 +132,17 @@ export async function hentOppgave(request: Request, oppgaveId: string): Promise<
return await response.json();
}

export async function hentNesteOppgave(request: Request): Promise<Response> {
export async function hentNesteOppgave(
request: Request,
aktivtOppgaveSok: string,
): Promise<Response> {
const onBehalfOfToken = await getSaksbehandlingOboToken(request);
const session = await getSession(request.headers.get("Cookie"));
const aktivtOppgaveFilter = session.get("aktivtOppgaveFilter");

const url = `${getEnv("DP_SAKSBEHANDLING_URL")}/oppgave/neste`;
return await fetch(url, {
method: "PUT",
headers: getHeaders(onBehalfOfToken),
body: JSON.stringify({ queryParams: aktivtOppgaveFilter }),
body: JSON.stringify({ queryParams: aktivtOppgaveSok }),
});
}

Expand Down
51 changes: 27 additions & 24 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { PumpkinSvg } from "~/components/halloween/PumpkinSvg";
import { HeaderMeny } from "~/components/header-meny/HeaderMeny";
import { MistelteinSvg } from "~/components/jul/MistelteinSvg";
import { AlertProvider } from "~/context/alert-context";
import { SaksbehandlerProvider } from "~/context/saksbehandler-context";
import globalCss from "~/global.css?url";
import meldingOmVedtakCss from "~/melding-om-vedtak.css?url";
import { hentOppgaver } from "~/models/oppgave.server";
Expand Down Expand Up @@ -136,33 +137,35 @@ export default function App() {
<Links />
</head>
<body>
<InternalHeader className={styles.header}>
<Link to={"/"} className={styles.headerLogo}>
<InternalHeader.Title as="h1" className={styles.pageHeader}>
{featureFlags.halloween && <PumpkinSvg />}
{featureFlags.jul && <MistelteinSvg />}
Dagpenger
</InternalHeader.Title>
</Link>
<SaksbehandlerProvider aktivtSok="">
<InternalHeader className={styles.header}>
<Link to={"/"} className={styles.headerLogo}>
<InternalHeader.Title as="h1" className={styles.pageHeader}>
{featureFlags.halloween && <PumpkinSvg />}
{featureFlags.jul && <MistelteinSvg />}
Dagpenger
</InternalHeader.Title>
</Link>

<HeaderMeny
saksbehandler={saksbehandler}
antallOppgaverJegHarTilBehandling={antallOppgaverJegHarTilBehandling}
/>
</InternalHeader>
<HeaderMeny
saksbehandler={saksbehandler}
antallOppgaverJegHarTilBehandling={antallOppgaverJegHarTilBehandling}
/>
</InternalHeader>

<AlertProvider>
<GlobalAlerts />
<Outlet />
</AlertProvider>
<AlertProvider>
<GlobalAlerts />
<Outlet />
</AlertProvider>

<ScrollRestoration />
<Scripts />
<script
dangerouslySetInnerHTML={{
__html: `window.env = ${JSON.stringify(env)}`,
}}
/>
<ScrollRestoration />
<Scripts />
<script
dangerouslySetInnerHTML={{
__html: `window.env = ${JSON.stringify(env)}`,
}}
/>
</SaksbehandlerProvider>
</body>
</html>
);
Expand Down
7 changes: 5 additions & 2 deletions app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { BarChartIcon, FunnelIcon } from "@navikt/aksel-icons";
import { Tabs } from "@navikt/ds-react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { useActionData, useLoaderData, useNavigation } from "@remix-run/react";
import { useActionData, useLoaderData, useNavigation, useSearchParams } from "@remix-run/react";

import { OppgaveFilterDato } from "~/components/oppgave-filter-dato/OppgaveFilterDato";
import { OppgaveFilterEmneknagger } from "~/components/oppgave-filter-emneknagger/OppgaveFilterEmneknagger";
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 { useSaksbehandler } from "~/hooks/useSaksbehandler";
import { hentOppgaver } from "~/models/oppgave.server";
import styles from "~/route-styles/index.module.css";
import { handleActions } from "~/server-side-actions/handle-actions";
Expand Down Expand Up @@ -46,7 +47,6 @@ 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");
session.set("aktivtOppgaveFilter", url.search);

return json(
{
Expand All @@ -64,10 +64,13 @@ export async function loader({ request }: LoaderFunctionArgs) {

export default function Saksbehandling() {
const { state } = useNavigation();
const [searchParams] = useSearchParams();
const actionData = useActionData<typeof action>();
const { alert, oppgaver, totaltAntallOppgaver } = useLoaderData<typeof loader>();
const { setAktivtOppgaveSok } = useSaksbehandler();
useHandleAlertMessages(alert);
useHandleAlertMessages(isAlert(actionData) ? actionData : undefined);
setAktivtOppgaveSok(searchParams.toString());

return (
<div className={styles.container}>
Expand Down
8 changes: 8 additions & 0 deletions app/routes/oppgave.$oppgaveId.se.fullfort-oppgave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useRef, useState } from "react";
import { KonfettiKanon } from "~/components/konfetti-kanon/KonfettiKanon";
import { RemixLink } from "~/components/RemixLink";
import { useHandleAlertMessages } from "~/hooks/useHandleAlertMessages";
import { useSaksbehandler } from "~/hooks/useSaksbehandler";
import styles from "~/route-styles/oppgave.module.css";
import { oppgaverTilBehandlingDefaultParams } from "~/routes/_index";
import { handleActions } from "~/server-side-actions/handle-actions";
Expand Down Expand Up @@ -39,6 +40,7 @@ export default function NesteOppgave() {
const ref = useRef<HTMLDialogElement>(null);
const [kaffepuase, setKaffepause] = useState(false);
const actionData = useActionData<typeof action>();
const { aktivtOppgaveSok } = useSaksbehandler();
useHandleAlertMessages(isAlert(actionData) ? actionData : undefined);

return (
Expand Down Expand Up @@ -77,6 +79,12 @@ export default function NesteOppgave() {

<Form method="post">
<input name="_action" value="hent-neste-oppgave" hidden={true} readOnly={true} />
<input
name="aktivtOppgaveSok"
value={aktivtOppgaveSok}
hidden={true}
readOnly={true}
/>
<Button
variant="primary"
size="small"
Expand Down
3 changes: 3 additions & 0 deletions app/routes/oppgave.$oppgaveId.se.neste-oppgave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Form, useLoaderData, useNavigation } from "@remix-run/react";
import { useRef } from "react";

import { RemixLink } from "~/components/RemixLink";
import { useSaksbehandler } from "~/hooks/useSaksbehandler";
import { oppgaverTilBehandlingDefaultParams } from "~/routes/_index";
import { handleActions } from "~/server-side-actions/handle-actions";
import { commitSession, getSession } from "~/sessions";
Expand All @@ -31,6 +32,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
export default function NesteOppgave() {
const { state } = useNavigation();
const { alert } = useLoaderData<typeof loader>();
const { aktivtOppgaveSok } = useSaksbehandler();
const ref = useRef<HTMLDialogElement>(null);

return (
Expand Down Expand Up @@ -58,6 +60,7 @@ export default function NesteOppgave() {

<Form method="post">
<input name="_action" value="hent-neste-oppgave" hidden={true} readOnly={true} />
<input name="aktivtOppgaveSok" value={aktivtOppgaveSok} hidden={true} readOnly={true} />
<Button
variant="primary"
size="small"
Expand Down
2 changes: 1 addition & 1 deletion app/server-side-actions/handle-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function handleActions(request: Request, params: ActionFunctionArgs
return await lagreNotatAction(request, formData);

case "hent-neste-oppgave":
return await hentNesteOppgaveAction(request);
return await hentNesteOppgaveAction(request, formData);

case "returner-oppgave-til-saksbehandler":
return await returnerOppgaveTilSaksbehandlerAction(request, params, formData);
Expand Down
9 changes: 7 additions & 2 deletions app/server-side-actions/hent-neste-oppgave-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import { commitSession, getSession } from "~/sessions";
import { getAlertMessage } from "~/utils/alert-message.utils";
import { logger } from "~/utils/logger.utils";

export async function hentNesteOppgaveAction(request: Request) {
const response = await hentNesteOppgave(request);
export async function hentNesteOppgaveAction(request: Request, formData: FormData) {
const aktivtOppgaveSok = formData.get("aktivtOppgaveSok") as string;

if (aktivtOppgaveSok == null) {
throw new Error("Mangler aktivt oppgave søk");
}

const response = await hentNesteOppgave(request, aktivtOppgaveSok);
if (response.ok) {
const oppgave = (await response.json()) as IOppgave;
if (oppgave.tilstand === "UNDER_KONTROLL") {
Expand Down

0 comments on commit 26120a0

Please sign in to comment.