Skip to content

Commit

Permalink
IS-3017: log error message søk
Browse files Browse the repository at this point in the history
  • Loading branch information
ingring committed Jan 29, 2025
1 parent 05cdbf2 commit 854a7d9
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
74 changes: 74 additions & 0 deletions src/sider/sokperson/SokPerson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,71 @@ function logSokPersonResults(amount: number, requestDTO: SokDTO) {
});
}

interface LogSokPersonErrorProps {
birthdate: string;
isValidBirthdate: boolean;
isInvalidBirthdate: boolean;
initials: string;
isValidInitials: boolean;
isInvalidInitials: boolean;
isError: boolean;
}

function logSokPersonError({
birthdate,
isValidBirthdate,
isInvalidBirthdate,
initials,
isValidInitials,
isInvalidInitials,
isError,
}: LogSokPersonErrorProps) {
Amplitude.logEvent({
type: Amplitude.EventType.ErrorMessageShowed,
data: {
url: window.location.href,
handling: 'Søk etter sykmeldt - feilmeldinger',
feilmelding:
'Fødselsdato: ' +
getValidationMessage({
isEmpty: !!birthdate,
isValid: isValidBirthdate,
isInvalid: isInvalidBirthdate,
}) +
'Initialer: ' +
getValidationMessage({
isEmpty: !!initials,
isValid: isValidInitials,
isInvalid: isInvalidInitials,
}) +
(isError ? 'Feil ved søk' : ''),
},
});
}

interface ValidationArgs {
isEmpty: boolean;
isValid: boolean;
isInvalid: boolean;
}

function getValidationMessage({
isEmpty,
isValid,
isInvalid,
}: ValidationArgs): string {
if (isEmpty) {
return 'ingen innhold';
}
if (isValid) {
return 'gyldig innhold';
}
if (isInvalid) {
return 'ugyldig innhold';
}
return '';
}

function InitialerLabel() {
return (
<div className="flex gap-2">
Expand Down Expand Up @@ -148,6 +213,15 @@ export default function SokPerson() {
});
} else {
setIsFormError(true);
logSokPersonError({
birthdate: birthdate,
isValidBirthdate: !!parsedBirthdate,
isInvalidBirthdate: isInvalidBirthdate,
initials: initials,
isValidInitials: isValidInitials(initials),
isInvalidInitials: isInvalidInitials,
isError: isError,
});
}
};

Expand Down
13 changes: 12 additions & 1 deletion src/utils/amplitude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum EventType {
ButtonClick = 'knapp trykket',
SortingColumn = 'kolonne sortert på',
AmountDisplayed = 'antall vist',
ErrorMessageShowed = 'feilmelding vist',
}

type EventPageView = {
Expand Down Expand Up @@ -66,13 +67,23 @@ type EventAmountDisplayed = {
};
};

type ErrorMessageShowed = {
type: EventType.ErrorMessageShowed;
data: {
url: string;
handling: string;
feilmelding: string;
};
};

type Event =
| EventPageView
| Navigation
| OptionSelected
| EventButtonClick
| EventSortingColumn
| EventAmountDisplayed;
| EventAmountDisplayed
| ErrorMessageShowed;

export const logEvent = (event: Event) =>
amplitude.track(event.type, { ...event.data });
Expand Down

0 comments on commit 854a7d9

Please sign in to comment.