Skip to content

Commit e611af9

Browse files
authored
IS-3017: log error message søk (#585)
1 parent e3343f8 commit e611af9

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

src/sider/sokperson/SokPerson.tsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,71 @@ function logSokPersonResults(amount: number, requestDTO: SokDTO) {
9595
});
9696
}
9797

98+
interface LogSokPersonErrorProps {
99+
birthdate: string;
100+
isValidBirthdate: boolean;
101+
isInvalidBirthdate: boolean;
102+
initials: string;
103+
isValidInitials: boolean;
104+
isInvalidInitials: boolean;
105+
isError: boolean;
106+
}
107+
108+
function logSokPersonError({
109+
birthdate,
110+
isValidBirthdate,
111+
isInvalidBirthdate,
112+
initials,
113+
isValidInitials,
114+
isInvalidInitials,
115+
isError,
116+
}: LogSokPersonErrorProps) {
117+
Amplitude.logEvent({
118+
type: Amplitude.EventType.ErrorMessageShowed,
119+
data: {
120+
url: window.location.href,
121+
handling: 'Søk etter sykmeldt - feilmeldinger',
122+
feilmelding:
123+
'Fødselsdato: ' +
124+
getValidationMessage({
125+
value: birthdate,
126+
isValid: isValidBirthdate,
127+
isInvalid: isInvalidBirthdate,
128+
}) +
129+
' - Initialer: ' +
130+
getValidationMessage({
131+
value: initials,
132+
isValid: isValidInitials,
133+
isInvalid: isInvalidInitials,
134+
}) +
135+
(isError ? ' - Feil ved søk' : ''),
136+
},
137+
});
138+
}
139+
140+
interface ValidationArgs {
141+
value: string;
142+
isValid: boolean;
143+
isInvalid: boolean;
144+
}
145+
146+
function getValidationMessage({
147+
value,
148+
isValid,
149+
isInvalid,
150+
}: ValidationArgs): string {
151+
if (value === '') {
152+
return 'ingen innhold';
153+
}
154+
if (isValid) {
155+
return 'gyldig innhold';
156+
}
157+
if (isInvalid) {
158+
return 'ugyldig innhold';
159+
}
160+
return '';
161+
}
162+
98163
function InitialerLabel() {
99164
return (
100165
<div className="flex gap-2">
@@ -165,6 +230,15 @@ export default function SokPerson() {
165230
});
166231
} else {
167232
setIsFormError(true);
233+
logSokPersonError({
234+
birthdate: birthdate,
235+
isValidBirthdate: !!parsedBirthdate,
236+
isInvalidBirthdate: isInvalidBirthdate,
237+
initials: initials,
238+
isValidInitials: isValidInitials(initials),
239+
isInvalidInitials: isInvalidInitials,
240+
isError: isError,
241+
});
168242
}
169243
};
170244

src/utils/amplitude.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export enum EventType {
1212
ButtonClick = 'knapp trykket',
1313
SortingColumn = 'kolonne sortert på',
1414
AmountDisplayed = 'antall vist',
15+
ErrorMessageShowed = 'feilmelding vist',
1516
}
1617

1718
type EventPageView = {
@@ -66,13 +67,23 @@ type EventAmountDisplayed = {
6667
};
6768
};
6869

70+
type ErrorMessageShowed = {
71+
type: EventType.ErrorMessageShowed;
72+
data: {
73+
url: string;
74+
handling: string;
75+
feilmelding: string;
76+
};
77+
};
78+
6979
type Event =
7080
| EventPageView
7181
| Navigation
7282
| OptionSelected
7383
| EventButtonClick
7484
| EventSortingColumn
75-
| EventAmountDisplayed;
85+
| EventAmountDisplayed
86+
| ErrorMessageShowed;
7687

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

0 commit comments

Comments
 (0)