diff --git a/frontend/mulighetsrommet-veileder-flate/src/apps/modia/ModiaArbeidsmarkedstiltak.tsx b/frontend/mulighetsrommet-veileder-flate/src/apps/modia/ModiaArbeidsmarkedstiltak.tsx index b202595339..2d8be7dd30 100644 --- a/frontend/mulighetsrommet-veileder-flate/src/apps/modia/ModiaArbeidsmarkedstiltak.tsx +++ b/frontend/mulighetsrommet-veileder-flate/src/apps/modia/ModiaArbeidsmarkedstiltak.tsx @@ -11,7 +11,7 @@ import { DemoImageHeader } from "@/components/DemoImageHeader"; import { Landingsside } from "./views/Landingsside"; import { ModiaArbeidsmarkedstiltakOversikt } from "./views/ModiaArbeidsmarkedstiltakOversikt"; import { ModiaArbeidsmarkedstiltakDetaljer } from "./views/ModiaArbeidsmarkedstiltakDetaljer"; -import { DeltakerRegistrering } from "@/microfrontends/team_komet/DeltakerRegistrering"; +import { DeltakerRegistrering } from "@/microfrontends/deltaker-registrering/DeltakerRegistrering"; export function ModiaArbeidsmarkedstiltak() { return ( @@ -24,7 +24,7 @@ export function ModiaArbeidsmarkedstiltak() { function ModiaArbeidsmarkedstiltakRoutes() { useHentVeilederdata(); // Pre-fetch veilederdata så slipper vi å vente på data når vi trenger det i appen senere - const { fnr, enhet } = useInitializeAppContext(); + useInitializeAppContext(); useInitializeArbeidsmarkedstiltakFilterForBruker(); @@ -48,10 +48,7 @@ function ModiaArbeidsmarkedstiltakRoutes() { } /> } /> {visDeltakerregistrering ? ( - } - /> + } /> ) : null} { - if (isProduction) { - return "production"; - } - - if (isDevelopment) { - return "development"; - } - - return "local"; -}; diff --git a/frontend/mulighetsrommet-veileder-flate/src/core/api/useLoadDeltakerRegistreringApp.ts b/frontend/mulighetsrommet-veileder-flate/src/core/api/useLoadDeltakerRegistreringApp.ts deleted file mode 100644 index e17fe1df7e..0000000000 --- a/frontend/mulighetsrommet-veileder-flate/src/core/api/useLoadDeltakerRegistreringApp.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { useSuspenseQuery } from "@tanstack/react-query"; -import { - DELTAKERREGISTRERING_ENTRY, - DELTAKERREGISTRERING_MODULE, -} from "../../microfrontends/entrypoints"; -import { DELTAKERREGISTRERING_KOMET } from "../../urls"; -import { getEnvironment } from "./getEnvironment"; - -export function useLoadDeltakerRegistreringApp(manifestUrl: string) { - return useSuspenseQuery({ - queryKey: ["manifest"], - queryFn: async () => { - const response = await fetch(manifestUrl); - if (!response.ok) { - throw new Error("Could not fetch"); - } - - const manifest = await response.json(); - return import( - /* @vite-ignore */ - `${DELTAKERREGISTRERING_KOMET[getEnvironment()]}/${ - manifest[DELTAKERREGISTRERING_ENTRY][DELTAKERREGISTRERING_MODULE] - }` - ); - }, - }); -} diff --git a/frontend/mulighetsrommet-veileder-flate/src/environment.ts b/frontend/mulighetsrommet-veileder-flate/src/environment.ts new file mode 100644 index 0000000000..aee0d3d21b --- /dev/null +++ b/frontend/mulighetsrommet-veileder-flate/src/environment.ts @@ -0,0 +1,23 @@ +export enum Environment { + PROD = "PROD", + DEV = "DEV", + LOCAL = "LOCAL", +} + +export const environment: Environment = getEnvironment(); + +export const isProduction = window.location.origin.endsWith(".intern.nav.no"); + +export const isDevelopment = window.location.origin.endsWith(".intern.dev.nav.no"); + +function getEnvironment() { + if (isProduction) { + return Environment.PROD; + } + + if (isDevelopment) { + return Environment.DEV; + } + + return Environment.LOCAL; +} diff --git a/frontend/mulighetsrommet-veileder-flate/src/hooks/useInitializeAppContext.ts b/frontend/mulighetsrommet-veileder-flate/src/hooks/useInitializeAppContext.ts index 13656de3bb..4886b1057f 100644 --- a/frontend/mulighetsrommet-veileder-flate/src/hooks/useInitializeAppContext.ts +++ b/frontend/mulighetsrommet-veileder-flate/src/hooks/useInitializeAppContext.ts @@ -1,10 +1,10 @@ import { useSetAtom } from "jotai"; import { useOverordnetEnhet } from "../core/api/queries/useOverordnetEnhet"; -import { appContextAtom, AppContextData, useAppContext } from "./useAppContext"; +import { appContextAtom, useAppContext } from "./useAppContext"; import { useEffect } from "react"; import { useLogEvent } from "../logging/amplitude"; -export function useInitializeAppContext(): AppContextData { +export function useInitializeAppContext() { const appContext = useAppContext(); const setAppContext = useSetAtom(appContextAtom); const { data: overordnetEnhet } = useOverordnetEnhet(appContext.enhet); @@ -21,6 +21,4 @@ export function useInitializeAppContext(): AppContextData { logEvent({ name: "arbeidsmarkedstiltak.unike-brukere" }); } }, [appContext.overordnetEnhet]); - - return appContext; } diff --git a/frontend/mulighetsrommet-veileder-flate/src/microfrontends/deltaker-registrering/DeltakerRegistrering.tsx b/frontend/mulighetsrommet-veileder-flate/src/microfrontends/deltaker-registrering/DeltakerRegistrering.tsx new file mode 100644 index 0000000000..4c80c44fb1 --- /dev/null +++ b/frontend/mulighetsrommet-veileder-flate/src/microfrontends/deltaker-registrering/DeltakerRegistrering.tsx @@ -0,0 +1,45 @@ +import { Alert, Button } from "@navikt/ds-react"; +import React from "react"; +import { ErrorBoundary } from "react-error-boundary"; +import { useLoadDeltakerRegistreringApp } from "@/microfrontends/deltaker-registrering/useLoadDeltakerRegistreringApp"; +import { useGetTiltaksgjennomforingIdFraUrl } from "@/core/api/queries/useGetTiltaksgjennomforingIdFraUrl"; +import { useAppContext } from "@/hooks/useAppContext"; + +export function DeltakerRegistrering() { + return ( + + { + return ( +
+ Klarte ikke laste deltakerregistrering + +
+ ); + }} + > + +
+
+ ); +} + +function DeltakerRegistreringApp() { + useLoadDeltakerRegistreringApp(); + + const tiltaksgjennomforingId = useGetTiltaksgjennomforingIdFraUrl(); + + const { fnr, enhet } = useAppContext(); + + return React.createElement("arbeidsmarkedstiltak-deltaker", { + "data-personident": fnr, + "data-deltakerlisteId": tiltaksgjennomforingId, + "data-enhetId": enhet, + }); +} diff --git a/frontend/mulighetsrommet-veileder-flate/src/microfrontends/deltaker-registrering/useLoadDeltakerRegistreringApp.ts b/frontend/mulighetsrommet-veileder-flate/src/microfrontends/deltaker-registrering/useLoadDeltakerRegistreringApp.ts new file mode 100644 index 0000000000..0fa0aef7dd --- /dev/null +++ b/frontend/mulighetsrommet-veileder-flate/src/microfrontends/deltaker-registrering/useLoadDeltakerRegistreringApp.ts @@ -0,0 +1,40 @@ +import { useSuspenseQuery } from "@tanstack/react-query"; +import { environment } from "@/environment"; +import { headers } from "@/core/api/headers"; + +export const DELTAKERREGISTRERING_ENTRY = "src/webComponentWrapper.tsx"; + +const DELTAKERREGISTRERING_KOMET = { + LOCAL: "http://localhost:4173", + DEV: "https://amt-deltaker-flate.intern.dev.nav.no", // URL til bundle som blir hostet et sted i dev + PROD: "", // URL til bundle som blir hostet et sted i prod +}; + +const deltakerRegistreringOrigin = DELTAKERREGISTRERING_KOMET[environment]; + +const deltakerregistreringKometManifestUrl = `${deltakerRegistreringOrigin}/asset-manifest.json`; + +interface DeltakerRegistreringAssetManifest { + "src/webComponentWrapper.tsx": { + file: string; + }; +} + +export function useLoadDeltakerRegistreringApp() { + return useSuspenseQuery({ + queryKey: ["deltaker-registrering-asset-manifest"], + queryFn: async () => { + const response = await fetch(deltakerregistreringKometManifestUrl, { + headers, + }); + + if (!response.ok) { + throw new Error("Failed to load DeltakerRegistrering"); + } + + const manifest: DeltakerRegistreringAssetManifest = await response.json(); + const entry = manifest[DELTAKERREGISTRERING_ENTRY].file; + return import(/* @vite-ignore */ `${deltakerRegistreringOrigin}/${entry}`); + }, + }); +} diff --git a/frontend/mulighetsrommet-veileder-flate/src/microfrontends/entrypoints.ts b/frontend/mulighetsrommet-veileder-flate/src/microfrontends/entrypoints.ts deleted file mode 100644 index 3ccee00a2a..0000000000 --- a/frontend/mulighetsrommet-veileder-flate/src/microfrontends/entrypoints.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const DELTAKERREGISTRERING_ENTRY = "src/webComponentWrapper.tsx"; -export const DELTAKERREGISTRERING_MODULE = "file"; diff --git a/frontend/mulighetsrommet-veileder-flate/src/microfrontends/team_komet/DeltakerRegistrering.tsx b/frontend/mulighetsrommet-veileder-flate/src/microfrontends/team_komet/DeltakerRegistrering.tsx deleted file mode 100644 index 34958f7f9f..0000000000 --- a/frontend/mulighetsrommet-veileder-flate/src/microfrontends/team_komet/DeltakerRegistrering.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { Alert, Button } from "@navikt/ds-react"; -import React from "react"; -import { ErrorBoundary } from "react-error-boundary"; -import { useLoadDeltakerRegistreringApp } from "../../core/api/useLoadDeltakerRegistreringApp"; -import { deltakerregistreringKometManifestUrl } from "../../urls"; -import { useGetTiltaksgjennomforingIdFraUrl } from "../../core/api/queries/useGetTiltaksgjennomforingIdFraUrl"; - -interface Props { - fnr: string; - enhetId: String; -} - -export function DeltakerRegistrering(props: Props) { - return ( - - { - return ( - <> -
- Klarte ikke laste deltakerregistrering - -
- - ); - }} - > - -
-
- ); -} - -function DeltakerRegistreringKomponent({ fnr, enhetId }: Props) { - const tiltaksgjennomforingId = useGetTiltaksgjennomforingIdFraUrl(); - useLoadDeltakerRegistreringApp(deltakerregistreringKometManifestUrl); - - return React.createElement("arbeidsmarkedstiltak-deltaker", { - "data-personident": fnr, - "data-deltakerlisteId": tiltaksgjennomforingId, - "data-enhetId": enhetId, - }); -} diff --git a/frontend/mulighetsrommet-veileder-flate/src/urls.ts b/frontend/mulighetsrommet-veileder-flate/src/urls.ts deleted file mode 100644 index 16c746d217..0000000000 --- a/frontend/mulighetsrommet-veileder-flate/src/urls.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getEnvironment } from "./core/api/getEnvironment"; - -export const DELTAKERREGISTRERING_KOMET = { - local: "http://localhost:4173", - development: "https://amt-deltaker-flate.intern.dev.nav.no", // URL til bundle som blir hostet et sted i dev - production: "", // URL til bundle som blir hostet et sted i prod -}; - -export const deltakerregistreringKometManifestUrl = `${ - DELTAKERREGISTRERING_KOMET[getEnvironment()] -}/asset-manifest.json`; diff --git a/frontend/mulighetsrommet-veileder-flate/src/utils/Utils.ts b/frontend/mulighetsrommet-veileder-flate/src/utils/Utils.ts index 705dd4f673..d28a34899b 100644 --- a/frontend/mulighetsrommet-veileder-flate/src/utils/Utils.ts +++ b/frontend/mulighetsrommet-veileder-flate/src/utils/Utils.ts @@ -4,14 +4,6 @@ import { valgteEnhetsnumre, } from "../hooks/useArbeidsmarkedstiltakFilter"; -export function isDev() { - return !isProd(); -} - -export function isProd() { - return window.location.origin.endsWith(".intern.nav.no"); -} - export const inneholderUrl = (string: string) => { return window.location.href.indexOf(string) > -1; };