diff --git a/app/components/regulering/regulering-fortsett-avhengige.tsx b/app/components/regulering/regulering-fortsett-avhengige.tsx new file mode 100644 index 0000000..9bcc7cd --- /dev/null +++ b/app/components/regulering/regulering-fortsett-avhengige.tsx @@ -0,0 +1,63 @@ +import React, { useState } from 'react' +import { Form, useSubmit } from '@remix-run/react' + +export default function FortsettAvhengigeReguleringBehandlinger() { + + const [isClicked, setIsClicked] = useState(false); + const submit = useSubmit(); + const handleSubmit = (e: any) => { + submit(e.target.form) + setIsClicked(true) + } + + return ( +
+

Fortsett Avhengige behandlinger

+
+

+ BehandlingId for Uttreksbehandling + +

+

+ Antall avhengige behandlinger + +

+

+ Fortsett til prosesserings-aktivitet Axxx + +

+

+ +

+
+
+ ) +} \ No newline at end of file diff --git a/app/routes/batch.regulering.tsx b/app/routes/batch.regulering.tsx index 84706b2..91a11bb 100644 --- a/app/routes/batch.regulering.tsx +++ b/app/routes/batch.regulering.tsx @@ -1,9 +1,10 @@ import type { ActionFunctionArgs} from '@remix-run/node'; import { redirect } from '@remix-run/node' import { requireAccessToken } from '~/services/auth.server' -import { fortsettBehandling, startRegulering } from '~/services/batch.bpen068.server' +import { fortsettAvhengigeBehandling, fortsettBehandling, startRegulering } from '~/services/batch.bpen068.server' import ReguleringBatch from '~/components/regulering/regulering-batch' import FortsettFamilieReguleringBehandling from '~/components/regulering/regulering-fortsettbehandling' +import FortsettAvhengigeReguleringBehandlinger from '~/components/regulering/regulering-fortsett-avhengige' export const action = async ({ request }: ActionFunctionArgs) => { const formData = await request.formData() @@ -11,6 +12,7 @@ export const action = async ({ request }: ActionFunctionArgs) => { const accessToken = await requireAccessToken(request) const behandlingIfFamilie = updates.behandlingIdFamilie as string + const behandlingIdFortsettAvhengige = updates.behandlingIdRegulering as string if(behandlingIfFamilie !== undefined && behandlingIfFamilie !== ''){ let response = await fortsettBehandling( @@ -20,7 +22,7 @@ export const action = async ({ request }: ActionFunctionArgs) => { ) return redirect(`/behandling/${response.behandlingId}`) - } else { + } else if((behandlingIfFamilie === undefined || behandlingIfFamilie === '') && (behandlingIdFortsettAvhengige !== undefined && behandlingIdFortsettAvhengige !== '')){ let response = await startRegulering( accessToken, updates.satsDato as string, @@ -29,6 +31,15 @@ export const action = async ({ request }: ActionFunctionArgs) => { updates.maxFamiliebehandlinger as string ) + return redirect(`/behandling/${response.behandlingId}`) + } else { + let response = await fortsettAvhengigeBehandling( + accessToken, + updates.behandlingIdRegulering as string, + updates.antallFamiliebehandlinger as string, + updates.fortsettTilAktivitet as string + ) + return redirect(`/behandling/${response.behandlingId}`) } @@ -39,6 +50,7 @@ export default function OpprettReguleringBatchRoute() {
+
) } \ No newline at end of file diff --git a/app/services/batch.bpen068.server.ts b/app/services/batch.bpen068.server.ts index 24ca5d1..6408a95 100644 --- a/app/services/batch.bpen068.server.ts +++ b/app/services/batch.bpen068.server.ts @@ -1,5 +1,5 @@ import { env } from '~/services/env.server' -import type { StartBatchResponse } from '~/types' +import { FortsettBatchResponse, StartBatchResponse } from '~/types' export async function startRegulering( accessToken: string, @@ -71,3 +71,36 @@ export async function fortsettBehandling( throw new Error() } } + +export async function fortsettAvhengigeBehandling( + accessToken: string, + behandlingIdRegulering: string, + antallFamiliebehandlinger: string, + fortsettTilAktivitet: string, +): Promise { + + const body: any = { + behandlingId: behandlingIdRegulering, + fortsettTilAktivitet: fortsettTilAktivitet, + antallBehandlinger: antallFamiliebehandlinger, + } + + const response = await fetch( + `${env.penUrl}/api/vedtak/regulering/fortsett/avhengige`, + { + method: 'POST', + headers: { + Authorization: `Bearer ${accessToken}`, + 'Content-Type': 'application/json', + 'X-Request-ID': crypto.randomUUID(), + }, + body: JSON.stringify(body), + }, + ) + + if (response.ok) { + return (await response.json()) as FortsettBatchResponse + } else { + throw new Error() + } +} diff --git a/app/types.ts b/app/types.ts index aaee7f3..a8182b1 100644 --- a/app/types.ts +++ b/app/types.ts @@ -144,3 +144,6 @@ export interface HalLinks { export type StartBatchResponse = { behandlingId: number } +export type FortsettBatchResponse = { + behandlingId: number[] +} \ No newline at end of file