11import { type FormEvent } from "react" ;
2- import { Controller , useFormContext } from "react-hook-form" ;
2+ import { Controller , useFormContext , useWatch } from "react-hook-form" ;
33import { ArrowLeftIcon , ArrowRightIcon } from "@navikt/aksel-icons" ;
4- import { Button , HGrid , Heading , TextField , VStack , Fieldset } from "@navikt/ds-react" ;
4+ import {
5+ BodyShort ,
6+ Button ,
7+ ErrorMessage ,
8+ Fieldset ,
9+ HGrid ,
10+ Heading ,
11+ Label ,
12+ Loader ,
13+ TextField ,
14+ VStack ,
15+ } from "@navikt/ds-react" ;
516import DecoratedPage from "../components/DecoratedPage" ;
617import { FORM_COLUMN_STYLE } from "../styles/forms" ;
718import type { SoknadInputs } from "../features/soknad/schema" ;
@@ -17,6 +28,7 @@ import { SkjemaFormProgress } from "../components/SkjemaFormProgress";
1728import { useSkjemaNavigation } from "../hooks/useSkjemaNavigation" ;
1829import { SOKNADER_PATH } from "../utils/constants" ;
1930import { SistLagretInfo } from "../components/SistLagretInfo.tsx" ;
31+ import { useVirksomhetAdresse } from "../hooks/useVirksomhetAdresse" ;
2032
2133export default function SkjemaSteg1Page ( ) {
2234 const form = useFormContext < SoknadInputs > ( ) ;
@@ -26,6 +38,13 @@ export default function SkjemaSteg1Page() {
2638
2739 const { clearDraft, lastPersistedAt } = useSoknadDraft ( ) ;
2840 const { goToSoknader, goToStep2, goToSummary, createLinkHandler } = useSkjemaNavigation ( ) ;
41+ const virksomhetsnummer = useWatch ( { control, name : "virksomhet.virksomhetsnummer" } ) ;
42+ const {
43+ adresse,
44+ isLoading : adresseLoading ,
45+ error : adresseError ,
46+ } = useVirksomhetAdresse ( virksomhetsnummer ) ;
47+ const hasVirksomhet = Boolean ( virksomhetsnummer ?. trim ( ) ) ;
2948
3049 useAttemptedSubmitRedirect ( form , { fields : STEP1_FIELDS , onValidationFailed : bumpFocusKey } ) ;
3150
@@ -86,6 +105,25 @@ export default function SkjemaSteg1Page() {
86105 />
87106 ) }
88107 />
108+ { hasVirksomhet ? (
109+ < VStack gap = "1" style = { { marginTop : "1rem" } } >
110+ < Label > Beliggenhetsadresse (hentet fra brreg.no)</ Label >
111+ { adresseLoading ? (
112+ < BodyShort size = "small" >
113+ < Loader size = "small" title = "Laster beliggenhetsadresse" aria-live = "polite" /> { " " }
114+ Laster beliggenhetsadresse ...
115+ </ BodyShort >
116+ ) : null }
117+ { ! adresseLoading && ! adresseError ? (
118+ < BodyShort size = "small" >
119+ { adresse ?? "Fant ikke beliggenhetsadresse." }
120+ </ BodyShort >
121+ ) : null }
122+ { adresseError ? (
123+ < ErrorMessage > Kunne ikke hente beliggenhetsadresse.</ ErrorMessage >
124+ ) : null }
125+ </ VStack >
126+ ) : null }
89127 </ div >
90128 < input type = "hidden" { ...register ( "virksomhet.navn" ) } />
91129
0 commit comments