Skip to content

Commit

Permalink
Merge pull request #38 from navikt/regulering-fortsettavhengige
Browse files Browse the repository at this point in the history
Fortsett avhengige reguleringsbehandlinger
  • Loading branch information
arefsahl authored Nov 26, 2024
2 parents ae02878 + c80b05b commit 184c624
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 3 deletions.
63 changes: 63 additions & 0 deletions app/components/regulering/regulering-fortsett-avhengige.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<h1>Fortsett Avhengige behandlinger</h1>
<Form method="POST">
<p>
BehandlingId for Uttreksbehandling
<input
defaultValue=""
aria-label="BehandlingIdRegulering"
name="behandlingIdRegulering"
type="text"
placeholder="BehandlingId for Uttreksbehandling"
/>
</p>
<p>
Antall avhengige behandlinger
<select
aria-label="AntallFamiliebehandlinger"
name="antallFamiliebehandlinger"
defaultValue="0"
>
<option value="1">1</option>
<option value="10">10</option>
<option value="100">100</option>
<option value="500">500</option>
<option value="500">500</option>
</select>
</p>
<p>
Fortsett til prosesserings-aktivitet Axxx
<input
defaultValue="A202"
aria-label="FortsettTilAktivitet"
name="fortsettTilAktivitet"
type="text"
placeholder="Fortsett Til Aktivitet"
/>
</p>
<p>
<button
type="submit"
disabled={isClicked}
onClick={handleSubmit}
>
Fortsett
</button>
</p>
</Form>
</div>
)
}
16 changes: 14 additions & 2 deletions app/routes/batch.regulering.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
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()
const updates = Object.fromEntries(formData)
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(
Expand All @@ -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,
Expand All @@ -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}`)
}

Expand All @@ -39,6 +50,7 @@ export default function OpprettReguleringBatchRoute() {
<div>
<ReguleringBatch />
<FortsettFamilieReguleringBehandling />
<FortsettAvhengigeReguleringBehandlinger />
</div>
)
}
35 changes: 34 additions & 1 deletion app/services/batch.bpen068.server.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -71,3 +71,36 @@ export async function fortsettBehandling(
throw new Error()
}
}

export async function fortsettAvhengigeBehandling(
accessToken: string,
behandlingIdRegulering: string,
antallFamiliebehandlinger: string,
fortsettTilAktivitet: string,
): Promise<FortsettBatchResponse> {

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()
}
}
3 changes: 3 additions & 0 deletions app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,6 @@ export interface HalLinks {
export type StartBatchResponse = {
behandlingId: number
}
export type FortsettBatchResponse = {
behandlingId: number[]
}

0 comments on commit 184c624

Please sign in to comment.