Skip to content

Commit

Permalink
Merge pull request #4557 from navikt/bedriftsmeny
Browse files Browse the repository at this point in the history
bedriftsmeny
  • Loading branch information
sndrem authored Oct 30, 2024
2 parents b3396b5 + 5cf1a41 commit bc2f7ac
Show file tree
Hide file tree
Showing 22 changed files with 270 additions and 154 deletions.
5 changes: 5 additions & 0 deletions frontend/arrangor-flate/app/auth/arrangortilgang.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ArrangorflateService } from "@mr/api-client";

export async function hentArrangortilgangerForBruker() {
return ArrangorflateService.getArrangorerInnloggetBrukerHarTilgangTil();
}
19 changes: 14 additions & 5 deletions frontend/arrangor-flate/app/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { Link } from "@remix-run/react";
import css from "../root.module.css";
import { Arrangorvelger } from "./arrangorvelger/Arrangorvelger";
import { Arrangor } from "@mr/api-client";

export function Header() {
interface Props {
arrangorer: Arrangor[];
}

export function Header({ arrangorer }: Props) {
return (
<header className="bg-blue-100 h-28">
<header className="bg-blue-100">
<div className={css.side + " h-full mt-0 flex flex-row content-center items-center"}>
<Link className="text-gray-900 font-bold text-4xl no-underline" to="/">
Refusjonskrav
</Link>
<div className="flex flex-row items-center justify-between w-full ">
<Link className="text-gray-900 font-bold text-4xl no-underline" to="/">
Refusjonskrav
</Link>
<Arrangorvelger arrangorer={arrangorer} />
</div>
</div>
</header>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Select } from "@navikt/ds-react";
import { useNavigate } from "@remix-run/react";
import { useOrgnrFromUrl } from "../../utils";
import { Arrangor } from "@mr/api-client";

interface Props {
arrangorer: Arrangor[];
}

export function Arrangorvelger({ arrangorer }: Props) {
const navigate = useNavigate();
const currentOrgnr = useOrgnrFromUrl();

const alfabetisk = (a: Arrangor, b: Arrangor) => a.navn.localeCompare(b.navn);

return (
<Select
defaultValue={currentOrgnr}
label="Velg arrangør du vil representere"
hideLabel
name="orgnr"
onChange={(e) => {
navigate(`${e.target.value}/refusjonskrav`);
}}
>
{arrangorer.sort(alfabetisk).map((arrangor) => (
<option key={arrangor.organisasjonsnummer} value={arrangor.organisasjonsnummer}>
{arrangor.navn} - {arrangor.organisasjonsnummer}
</option>
))}
</Select>
);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { RefusjonKravKompakt, RefusjonskravStatus } from "@mr/api-client";
import { formaterNOK } from "@mr/frontend-common/utils/utils";
import { Alert, Table, Tag } from "@navikt/ds-react";
import { Link } from "@remix-run/react";
import React, { ReactNode } from "react";
import { formaterDato } from "~/utils";
import { formaterNOK } from "@mr/frontend-common/utils/utils";
import { formaterDato, useOrgnrFromUrl } from "~/utils";
import { internalNavigation } from "../../internal-navigation";

interface Props {
krav: RefusjonKravKompakt[];
}

export function RefusjonskravTable({ krav }: Props) {
const orgnr = useOrgnrFromUrl();
if (krav.length === 0) {
return (
<Alert className="my-10" variant="info">
Expand Down Expand Up @@ -40,24 +42,21 @@ export function RefusjonskravTable({ krav }: Props) {
({ id, status, fristForGodkjenning, beregning, gjennomforing, tiltakstype }) => {
return (
<React.Fragment key={id}>
<Table.Row
className={
getRowStyle(status) +
" pb-10 border-border-divider border-b-2 border-x-2 border-t-0"
}
>
<Table.Row className={getRowStyle(status)}>
<Table.DataCell>{tiltakstype.navn}</Table.DataCell>
<Table.DataCell>{gjennomforing.navn}</Table.DataCell>
<Table.DataCell colSpan={3}>
<Table.DataCell colSpan={3} className="w-80">
{`${formaterDato(beregning.periodeStart)} - ${formaterDato(beregning.periodeSlutt)}`}
</Table.DataCell>
<Table.DataCell>{formaterNOK(beregning.belop)}</Table.DataCell>
<Table.DataCell className="min-w-44">
{formaterNOK(beregning.belop)}
</Table.DataCell>
<Table.DataCell>{formaterDato(fristForGodkjenning)}</Table.DataCell>
<Table.DataCell>{statusTilTag(status)}</Table.DataCell>
<Table.DataCell>
<Link
className="hover:underline font-bold no-underline"
to={`/refusjonskrav/${id}/for-du-begynner`}
to={internalNavigation(orgnr).forDuBegynner(id)}
>
Detaljer
</Link>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { ArrangorflateTilsagn } from "@mr/api-client";
import { Table } from "@navikt/ds-react";
import { Link } from "@remix-run/react";
import { formaterDato } from "~/utils";
import { formaterDato, useOrgnrFromUrl } from "~/utils";
import { internalNavigation } from "../../internal-navigation";

interface Props {
tilsagn: ArrangorflateTilsagn[];
}

export function TilsagnTable({ tilsagn }: Props) {
const orgnr = useOrgnrFromUrl();
return (
<>
<div className="border-spacing-y-6 border-collapsed mt-4">
Expand All @@ -24,7 +26,7 @@ export function TilsagnTable({ tilsagn }: Props) {
<Table.DataCell>
<Link
className="hover:underline font-bold no-underline"
to={`tilsagn/${tilsagn.id}`}
to={internalNavigation(orgnr).tilsagn(tilsagn.id)}
>
Detaljer
</Link>
Expand Down
11 changes: 11 additions & 0 deletions frontend/arrangor-flate/app/internal-navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const internalNavigation = (orgnr: string) => {
return {
root: "/",
refusjonskravliste: `/${orgnr}/refusjonskrav`,
forDuBegynner: (id: string) => `/${orgnr}/refusjonskrav/${id}/for-du-begynner`,
beregning: (id: string) => `/${orgnr}/refusjonskrav/${id}/beregning`,
bekreft: (id: string) => `/${orgnr}/refusjonskrav/${id}/bekreft`,
kvittering: (id: string) => `/${orgnr}/refusjonskrav/${id}/kvittering`,
tilsagn: (id: string) => `/${orgnr}/tilsagn/${id}`,
};
};
29 changes: 15 additions & 14 deletions frontend/arrangor-flate/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Alert, BodyShort, Box, Heading } from "@navikt/ds-react";
import { Arrangor } from "@mr/api-client";
import { BodyShort, Box, Heading } from "@navikt/ds-react";
import { LoaderFunction } from "@remix-run/node";
import {
isRouteErrorResponse,
Expand All @@ -14,7 +15,8 @@ import {
} from "@remix-run/react";
import parse from "html-react-parser";
import { ReactNode, useEffect } from "react";
import { checkValidToken } from "./auth/auth.server";
import { hentArrangortilgangerForBruker } from "./auth/arrangortilgang.server";
import { checkValidToken, setupOpenApi } from "./auth/auth.server";
import { Header } from "./components/Header";
import css from "./root.module.css";
import { Dekoratørfragmenter, hentSsrDekoratør } from "./services/dekoratør/dekorator.server";
Expand All @@ -24,22 +26,26 @@ import "./tailwind.css";
export const meta: MetaFunction = () => [{ title: "Refusjoner" }];

export const loader: LoaderFunction = async ({ request }) => {
await setupOpenApi(request);
await checkValidToken(request);
const arrangortilganger = await hentArrangortilgangerForBruker();

return json({
dekorator: await hentSsrDekoratør(),
arrangortilganger,
});
};

export type LoaderData = {
dekorator: Dekoratørfragmenter | null;
arrangortilganger: Arrangor[];
};

function App() {
const { dekorator } = useLoaderData<LoaderData>();
const { dekorator, arrangortilganger } = useLoaderData<LoaderData>();

return (
<Dokument dekorator={dekorator || undefined}>
<Dokument dekorator={dekorator || undefined} arrangorer={arrangortilganger}>
<Outlet />
</Dokument>
);
Expand All @@ -48,9 +54,11 @@ function App() {
function Dokument({
dekorator,
children,
arrangorer,
}: {
dekorator?: Dekoratørfragmenter;
children: ReactNode;
arrangorer: Arrangor[];
}) {
useInjectDecoratorScript(dekorator?.scripts);
return (
Expand All @@ -64,14 +72,7 @@ function Dokument({
</head>
<body>
{dekorator && parse(dekorator.header)}
<Header />
<Alert variant="warning">
Dette er en tjeneste under utvikling - Kontakt{" "}
<a href="https://teamkatalog.nav.no/team/aa730c95-b437-497b-b1ae-0ccf69a10997">
Team Valp
</a>{" "}
ved spørsmål
</Alert>
<Header arrangorer={arrangorer} />
<main className={css.side}>{children}</main>
<ScrollRestoration />
<Scripts />
Expand All @@ -92,7 +93,7 @@ export const ErrorBoundary = () => {

if (isRouteErrorResponse(error)) {
return (
<Dokument>
<Dokument arrangorer={[]}>
<Heading spacing size="large" level="2">
{error.status}
</Heading>
Expand All @@ -104,7 +105,7 @@ export const ErrorBoundary = () => {
);
} else {
return (
<Dokument>
<Dokument arrangorer={[]}>
<Heading spacing size="large" level="2">
Ojsann!
</Heading>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { checkValidToken } from "~/auth/auth.server";
import { loadRefusjonskrav } from "~/loaders/loadRefusjonskrav";
import { ArrangorflateService, ArrangorflateTilsagn } from "@mr/api-client";
import { RefusjonskravDetaljer } from "~/components/refusjonskrav/RefusjonskravDetaljer";
import { useOrgnrFromUrl } from "../utils";
import { internalNavigation } from "../internal-navigation";
import invariant from "tiny-invariant";
import React from "react";
import { Definisjon } from "~/components/Definisjon";

Expand Down Expand Up @@ -36,9 +39,10 @@ export const loader: LoaderFunction = async ({
export const action: ActionFunction = async ({ request }) => {
const formdata = await request.formData();
const bekreftelse = formdata.get("bekreftelse");
const refusjonskravId = formdata.get("refusjonskravId");
const refusjonskravId = formdata.get("refusjonskravId")?.toString();
const kontonummer = formdata.get("kontonummer");
const kid = formdata.get("kid");
const orgnr = formdata.get("orgnr")?.toString();

if (!bekreftelse) {
return json({ error: "Du må bekrefte at opplysningene er korrekte" }, { status: 400 });
Expand All @@ -52,6 +56,8 @@ export const action: ActionFunction = async ({ request }) => {
return json({ error: "Mangler kontonummer" }, { status: 400 });
}

invariant(orgnr, "Mangler orgnr");

await ArrangorflateService.godkjennRefusjonskrav({
id: refusjonskravId as string,
requestBody: {
Expand All @@ -60,20 +66,21 @@ export const action: ActionFunction = async ({ request }) => {
},
});

return redirect(`/refusjonskrav/${refusjonskravId}/kvittering`);
return redirect(internalNavigation(orgnr).kvittering(refusjonskravId));
};

export default function BekreftRefusjonskrav() {
const { krav, tilsagn } = useLoaderData<BekreftRefusjonskravData>();
const data = useActionData<typeof action>();
const orgnr = useOrgnrFromUrl();

return (
<>
<PageHeader
title="Detaljer for refusjonskrav"
tilbakeLenke={{
navn: "Tilbake til deltakerliste",
url: `/refusjonskrav/${krav.id}`,
url: `/refusjonskrav/${orgnr}/${krav.id}`,
}}
/>
<VStack className="max-w-[50%]" gap="5">
Expand Down Expand Up @@ -106,6 +113,7 @@ export default function BekreftRefusjonskrav() {
Det erklæres herved at alle opplysninger er gitt i henhold til de faktiske forhold
</Checkbox>
<input type="hidden" name="refusjonskravId" value={krav.id} />
<input type="hidden" name="orgnr" value={orgnr} />
{data?.error && <Alert variant="error">{data.error}</Alert>}
<Button type="submit">Bekreft og send refusjonskrav</Button>
</VStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { checkValidToken } from "~/auth/auth.server";
import { useState } from "react";
import { Definisjonsliste } from "~/components/Definisjonsliste";
import { loadRefusjonskrav } from "~/loaders/loadRefusjonskrav";
import { formaterDato } from "~/utils";
import { formaterDato, useOrgnrFromUrl } from "~/utils";
import { formaterNOK } from "@mr/frontend-common/utils/utils";
import { GenerelleDetaljer } from "~/components/refusjonskrav/GenerelleDetaljer";
import { sortBy, SortBySelector, SortOrder } from "~/utils/sort-by";
import { RefusjonKravDeltakelsePerson } from "@mr/api-client";
import { internalNavigation } from "../internal-navigation";

export const meta: MetaFunction = () => {
return [{ title: "Refusjon" }, { name: "description", content: "Refusjonsdetaljer" }];
Expand Down Expand Up @@ -43,6 +44,7 @@ enum DeltakerSortKey {
}

export default function RefusjonskravBeregning() {
const orgnr = useOrgnrFromUrl();
const { krav } = useLoaderData<LoaderData>();
const [sort, setSort] = useState<DeltakerSortState | undefined>();

Expand Down Expand Up @@ -131,7 +133,11 @@ export default function RefusjonskravBeregning() {
},
]}
/>
<Button as={Link} className="justify-self-end" to={`/refusjonskrav/${krav.id}/bekreft`}>
<Button
as={Link}
className="justify-self-end"
to={internalNavigation(orgnr).bekreft(krav.id)}
>
Neste
</Button>
</HGrid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Button, GuidePanel, Heading, HGrid, List } from "@navikt/ds-react";
import { LoaderFunction } from "@remix-run/node";
import { json, Link, MetaFunction, useParams } from "@remix-run/react";
import { PageHeader } from "../components/PageHeader";
import { checkValidToken } from "../auth/auth.server";
import { LoaderFunction } from "@remix-run/node";
import { PageHeader } from "../components/PageHeader";
import { internalNavigation } from "../internal-navigation";
import { useOrgnrFromUrl } from "../utils";
import invariant from "tiny-invariant";

export const meta: MetaFunction = () => {
return [
Expand All @@ -18,7 +21,9 @@ export const loader: LoaderFunction = async ({ request, params }): Promise<objec
};

export default function ForDuBegynner() {
const { id } = useParams();
const { id } = useParams<{ id: string }>();
invariant(id, "Mangler id");
const orgnr = useOrgnrFromUrl();
return (
<>
<PageHeader
Expand All @@ -36,7 +41,7 @@ export default function ForDuBegynner() {
<List.Item>Og for øvrig kan man gjøre som man vil</List.Item>
</List>
</GuidePanel>
<Button as={Link} className="justify-self-end" to={`/refusjonskrav/${id}/beregning`}>
<Button as={Link} className="justify-self-end" to={internalNavigation(orgnr).beregning(id)}>
Neste
</Button>
</HGrid>
Expand Down
Loading

0 comments on commit bc2f7ac

Please sign in to comment.