Skip to content

Commit

Permalink
IS-27IS-2792-measure-apne-enkeltperson (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
ingring authored Nov 7, 2024
1 parent 93f3981 commit 05c2450
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/components/LinkSyfomodiaperson.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { ReactElement } from 'react';
import Lenke from 'nav-frontend-lenker';
import { PersonData } from '@/api/types/personregisterTypes';
import { linkToNewHostAndPath, Subdomain } from '@/utils/miljoUtil';
import { Labels } from '@/components/Labels';
import { useAktivBruker } from '@/data/modiacontext/useAktivBruker';
import { Link } from '@navikt/ds-react';
import * as Amplitude from '@/utils/amplitude';
import { EventType } from '@/utils/amplitude';

export const lenkeTilModia = (personData: PersonData) => {
export function lenkeTilModia(personData: PersonData): string {
let path = `/sykefravaer`;
const isGoingToMoteoversikt =
personData.harMotebehovUbehandlet ||
Expand Down Expand Up @@ -42,7 +44,18 @@ export const lenkeTilModia = (personData: PersonData) => {
}

return linkToNewHostAndPath(Subdomain.SYFOMODIAPERSON, path);
};
}

function logNavigation(destinasjon: string) {
Amplitude.logEvent({
type: EventType.Navigation,
data: {
fromUrl: window.location.href,
lenketekst: 'personnavn',
destinasjon: destinasjon,
},
});
}

interface Props {
personData: PersonData;
Expand All @@ -59,22 +72,24 @@ export function LinkSyfomodiaperson({
const onPersonClick = () => {
aktivBruker.mutate(personident, {
onSuccess: () => {
window.location.href = lenkeTilModia(personData);
const destinasjon = lenkeTilModia(personData);
logNavigation(destinasjon);
window.location.href = destinasjon;
},
});
};

return (
<div className="flex items-center gap-2">
<Lenke
<Link
onClick={(event) => {
event.preventDefault();
onPersonClick();
}}
href={lenkeTilModia(personData)}
>
{linkText}
</Lenke>
</Link>
<Labels personData={personData} />
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/utils/amplitude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type EventPageView = {
type Navigation = {
type: EventType.Navigation;
data: {
fromUrl: string;
lenketekst: string;
destinasjon: string;
};
Expand Down

0 comments on commit 05c2450

Please sign in to comment.