-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IS-1801: Innstilling om stans vurdering aktivitetskrav
- Loading branch information
1 parent
520e9b0
commit 1f68381
Showing
9 changed files
with
113 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 83 additions & 21 deletions
104
src/sider/aktivitetskrav/vurdering/IkkeOppfyltAktivitetskravSkjema.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,116 @@ | ||
import { | ||
AktivitetskravStatus, | ||
CreateAktivitetskravVurderingDTO, | ||
InnstillingOmStansVurderingDTO, | ||
} from "@/data/aktivitetskrav/aktivitetskravTypes"; | ||
import React from "react"; | ||
import { useVurderAktivitetskrav } from "@/data/aktivitetskrav/useVurderAktivitetskrav"; | ||
import { SkjemaHeading } from "@/sider/aktivitetskrav/vurdering/SkjemaHeading"; | ||
import { SkjemaInnsendingFeil } from "@/components/SkjemaInnsendingFeil"; | ||
import { VurderAktivitetskravSkjemaProps } from "@/sider/aktivitetskrav/vurdering/vurderAktivitetskravSkjemaTypes"; | ||
import { Button } from "@navikt/ds-react"; | ||
import { ButtonRow } from "@/components/Layout"; | ||
import { Button, DatePicker, Textarea, useDatepicker } from "@navikt/ds-react"; | ||
import { useAktivitetskravNotificationAlert } from "@/sider/aktivitetskrav/useAktivitetskravNotificationAlert"; | ||
import { useForm } from "react-hook-form"; | ||
|
||
const texts = { | ||
lagre: "Lagre", | ||
avbryt: "Avbryt", | ||
title: "Ikke oppfylt", | ||
form: { | ||
stansDatoLabel: "Stans gjelder fra (obligatorisk)", | ||
missingStansDato: "Vennligst angi stansdato", | ||
begrunnelseLabel: "Begrunnelse (obligatorisk)", | ||
missingBegrunnelse: "Vennligst angi begrunnelse", | ||
}, | ||
subtitle1: | ||
"Innstilling må skrives og sendes til NAY i Gosys. Ved å lagre fjerner du hendelsen fra oversikten.", | ||
}; | ||
|
||
export const IkkeOppfyltAktivitetskravSkjema = ({ | ||
const begrunnelseMaxLength = 5000; | ||
|
||
interface FormValues { | ||
stansFom: Date; | ||
begrunnelse: string; | ||
} | ||
|
||
interface Props { | ||
aktivitetskravUuid: string; | ||
varselSvarfrist: Date; | ||
} | ||
|
||
export default function IkkeOppfyltAktivitetskravSkjema({ | ||
aktivitetskravUuid, | ||
}: VurderAktivitetskravSkjemaProps) => { | ||
varselSvarfrist, | ||
}: Props) { | ||
const formMethods = useForm<FormValues>(); | ||
const { | ||
register, | ||
watch, | ||
formState: { errors }, | ||
handleSubmit, | ||
setValue, | ||
clearErrors, | ||
} = formMethods; | ||
const vurderAktivitetskrav = useVurderAktivitetskrav(aktivitetskravUuid); | ||
const { displayNotification } = useAktivitetskravNotificationAlert(); | ||
|
||
const submit = () => { | ||
const status = AktivitetskravStatus.IKKE_OPPFYLT; | ||
const createAktivitetskravVurderingDTO: CreateAktivitetskravVurderingDTO = { | ||
status, | ||
arsaker: [], | ||
function submit(values: FormValues) { | ||
const createAktivitetskravVurderingDTO: InnstillingOmStansVurderingDTO = { | ||
status: AktivitetskravStatus.STANS, | ||
stansFom: values.stansFom, | ||
beskrivelse: values.begrunnelse, | ||
}; | ||
vurderAktivitetskrav.mutate(createAktivitetskravVurderingDTO, { | ||
onSuccess: () => { | ||
displayNotification(status); | ||
displayNotification(AktivitetskravStatus.STANS); | ||
}, | ||
}); | ||
}; | ||
} | ||
|
||
const { datepickerProps, inputProps } = useDatepicker({ | ||
fromDate: varselSvarfrist, | ||
onDateChange: (date: Date | undefined) => { | ||
if (!!date) { | ||
setValue("stansFom", date); | ||
clearErrors("stansFom"); | ||
} | ||
}, | ||
}); | ||
|
||
return ( | ||
<> | ||
<form onSubmit={handleSubmit(submit)}> | ||
<SkjemaHeading title={texts.title} subtitles={[texts.subtitle1]} /> | ||
{vurderAktivitetskrav.isError && ( | ||
<SkjemaInnsendingFeil error={vurderAktivitetskrav.error} /> | ||
)} | ||
<ButtonRow> | ||
<Button loading={vurderAktivitetskrav.isPending} onClick={submit}> | ||
{texts.lagre} | ||
</Button> | ||
</ButtonRow> | ||
</> | ||
<DatePicker {...datepickerProps} strategy="fixed"> | ||
<DatePicker.Input | ||
{...inputProps} | ||
size="small" | ||
label={texts.form.stansDatoLabel} | ||
{...register("stansFom", { | ||
required: texts.form.missingStansDato, | ||
})} | ||
error={errors.stansFom?.message} | ||
className="mb-4" | ||
/> | ||
</DatePicker> | ||
|
||
<Textarea | ||
{...register("begrunnelse", { | ||
maxLength: begrunnelseMaxLength, | ||
required: texts.form.missingBegrunnelse, | ||
})} | ||
value={watch("begrunnelse")} | ||
label={texts.form.begrunnelseLabel} | ||
error={errors.begrunnelse?.message} | ||
size="small" | ||
minRows={6} | ||
maxLength={begrunnelseMaxLength} | ||
className="mb-4" | ||
/> | ||
|
||
<Button loading={vurderAktivitetskrav.isPending} type="submit"> | ||
{texts.lagre} | ||
</Button> | ||
</form> | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters