|
| 1 | +import React, { useRef } from "react"; |
| 2 | +import { MagnifyingGlassIcon } from "@navikt/aksel-icons"; |
| 3 | +import { |
| 4 | + Alert, |
| 5 | + BodyLong, |
| 6 | + Button, |
| 7 | + GuidePanel, |
| 8 | + HStack, |
| 9 | + Modal, |
| 10 | + Textarea, |
| 11 | +} from "@navikt/ds-react"; |
| 12 | +import { TakkForTilbakemeldingen } from "./TakkForTilbakemeldingen"; |
| 13 | +import { SubmitHandler, useForm } from "react-hook-form"; |
| 14 | +import { useOpprettFlexjarFeedback } from "./queryhooks/useOpprettFlexjarFeedback"; |
| 15 | +import { OpprettFeedbackData } from "../../pages/api/flexjar"; |
| 16 | +import { EmoQuestion } from "./emoji/EmoQuestion"; |
| 17 | + |
| 18 | +export type FlexjarFormValues = { |
| 19 | + endretFraDagensOppfolgingsplan: string; |
| 20 | + hvordanFolgeOppSykmeldte: string; |
| 21 | +}; |
| 22 | + |
| 23 | +export const FlexJarModal = () => { |
| 24 | + const ref = useRef<HTMLDialogElement>(null); |
| 25 | + const { |
| 26 | + register, |
| 27 | + handleSubmit, |
| 28 | + formState: { errors, isSubmitSuccessful }, |
| 29 | + } = useForm<FlexjarFormValues>(); |
| 30 | + const [activeRating, setActiveRating] = React.useState<number | null>(null); |
| 31 | + const sendFeedbackMutation = useOpprettFlexjarFeedback(); |
| 32 | + |
| 33 | + const onSubmit: SubmitHandler<FlexjarFormValues> = (data) => { |
| 34 | + const feedbackData: OpprettFeedbackData = { |
| 35 | + feedback: data.endretFraDagensOppfolgingsplan, |
| 36 | + svar: activeRating!, |
| 37 | + hvordanFolgeOppSykmeldte: data.hvordanFolgeOppSykmeldte, |
| 38 | + feedbackId: "oppfolgingsplan-arbeidsgiver", |
| 39 | + }; |
| 40 | + sendFeedbackMutation.mutate(feedbackData); |
| 41 | + }; |
| 42 | + |
| 43 | + return ( |
| 44 | + <> |
| 45 | + <GuidePanel className="mb-8"> |
| 46 | + <HStack gap="4"> |
| 47 | + <BodyLong> |
| 48 | + Hei! Vi jobber med en ny og forbedret oppfølgingsplan i 2025. Vi |
| 49 | + ønsker å lære av deg, for å forstå hva dine behov er. Har du to |
| 50 | + minutter? |
| 51 | + </BodyLong> |
| 52 | + <Button onClick={() => ref.current?.showModal()}> |
| 53 | + Åpne spørreskjema |
| 54 | + </Button> |
| 55 | + </HStack> |
| 56 | + </GuidePanel> |
| 57 | + |
| 58 | + <Modal |
| 59 | + ref={ref} |
| 60 | + header={{ |
| 61 | + icon: <MagnifyingGlassIcon aria-hidden={true} />, |
| 62 | + heading: "Innspill til utvikling av ny oppfølgingsplan", |
| 63 | + }} |
| 64 | + > |
| 65 | + <Modal.Body> |
| 66 | + <section> |
| 67 | + {!isSubmitSuccessful && ( |
| 68 | + <form |
| 69 | + id="flexjar-skjema" |
| 70 | + onSubmit={handleSubmit(onSubmit)} |
| 71 | + className="w-full" |
| 72 | + > |
| 73 | + <div> |
| 74 | + <BodyLong> |
| 75 | + Svarene du sender inn er anonyme, og blir sendt til |
| 76 | + utviklingsteamet i Nav som har ansvaret for |
| 77 | + oppfølgingsplanen. |
| 78 | + </BodyLong> |
| 79 | + |
| 80 | + <div className="py-4"> |
| 81 | + <div className="mt-6 w-full space-y-6"> |
| 82 | + <EmoQuestion |
| 83 | + question="Hvordan opplever du dagens oppfølgingsplan?" |
| 84 | + activeState={activeRating} |
| 85 | + setActiveState={setActiveRating} |
| 86 | + /> |
| 87 | + |
| 88 | + {activeRating != null && ( |
| 89 | + <> |
| 90 | + <Textarea |
| 91 | + {...register("endretFraDagensOppfolgingsplan", { |
| 92 | + required: |
| 93 | + "Tilbakemeldingen kan ikke være tom. Legg til tekst i feltet.", |
| 94 | + })} |
| 95 | + label="Hvis du kunne endre på noe i dagens oppfølgingsplan, hva ville det vært?" |
| 96 | + error={ |
| 97 | + errors.endretFraDagensOppfolgingsplan?.message |
| 98 | + } |
| 99 | + maxLength={1000} |
| 100 | + minRows={2} |
| 101 | + /> |
| 102 | + |
| 103 | + <Textarea |
| 104 | + {...register("hvordanFolgeOppSykmeldte", { |
| 105 | + required: |
| 106 | + "Tilbakemeldingen kan ikke være tom. Legg til tekst i feltet.", |
| 107 | + })} |
| 108 | + label="Hva trenger du for at oppfølgingsplanen skal være til hjelp med å følge opp dine sykmeldte?" |
| 109 | + error={errors.hvordanFolgeOppSykmeldte?.message} |
| 110 | + maxLength={1000} |
| 111 | + minRows={2} |
| 112 | + /> |
| 113 | + |
| 114 | + <Alert variant="warning" className="mt-4"> |
| 115 | + Ikke skriv inn navn eller andre personopplysninger. |
| 116 | + Dette blir kun brukt til å lage en best mulig ny |
| 117 | + oppfølgingsplan. |
| 118 | + </Alert> |
| 119 | + </> |
| 120 | + )} |
| 121 | + </div> |
| 122 | + </div> |
| 123 | + </div> |
| 124 | + </form> |
| 125 | + )} |
| 126 | + {isSubmitSuccessful && <TakkForTilbakemeldingen />} |
| 127 | + </section> |
| 128 | + </Modal.Body> |
| 129 | + |
| 130 | + <Modal.Footer> |
| 131 | + {!isSubmitSuccessful && ( |
| 132 | + <Button disabled={activeRating == null} form="flexjar-skjema"> |
| 133 | + Send tilbakemelding |
| 134 | + </Button> |
| 135 | + )} |
| 136 | + <Button |
| 137 | + type="button" |
| 138 | + variant="secondary" |
| 139 | + onClick={() => ref.current?.close()} |
| 140 | + > |
| 141 | + Lukk |
| 142 | + </Button> |
| 143 | + </Modal.Footer> |
| 144 | + </Modal> |
| 145 | + </> |
| 146 | + ); |
| 147 | +}; |
0 commit comments