Skip to content

Commit 2767f86

Browse files
committed
Amplitude: Rettet og refaktorert logging for alle Accordion-typer
1 parent 4603575 commit 2767f86

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/components/_common/productPanelExpandable/ProductPanelExpandable.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const ProductPanelExpandable = ({
6363
// eslint-disable-next-line react-hooks/exhaustive-deps
6464
}, []);
6565

66-
const handleClick = (isOpening: boolean, tittel: string) => {
66+
const toggleExpandCollapse = (isOpening: boolean, tittel: string) => {
6767
setIsOpen(isOpening);
6868
contentLoaderCallback?.();
6969
logAmplitudeEvent(isOpening ? AnalyticsEvents.ACC_EXPAND : AnalyticsEvents.ACC_COLLAPSE, {
@@ -79,7 +79,7 @@ export const ProductPanelExpandable = ({
7979
className={style.expandable}
8080
id={anchorId}
8181
open={isOpen}
82-
onToggle={(isOpen) => handleClick(isOpen, header)}
82+
onToggle={(isOpen) => toggleExpandCollapse(isOpen, header)}
8383
aria-label={header}
8484
>
8585
<ExpansionCard.Header

src/components/pages/office-page/office-details/officeInformation/OfficeInformation.tsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { useState } from 'react';
12
import { ExpansionCard, BodyShort, Heading } from '@navikt/ds-react';
23
import { usePageContentProps } from 'store/pageContext';
34
import { translator } from 'translations';
5+
import { AnalyticsEvents, logAmplitudeEvent } from 'utils/amplitude';
46
import { OfficeDetailsData } from 'types/content-props/office-details-props';
57
import { officeDetailsFormatAddress } from 'components/pages/office-page/office-details/utils';
68

@@ -11,17 +13,31 @@ export interface OfficeInformationProps {
1113
}
1214

1315
export const OfficeInformation = ({ officeData }: OfficeInformationProps) => {
16+
const [isOpen, setIsOpen] = useState(false);
1417
const { language } = usePageContentProps();
1518
const getOfficeTranslations = translator('office', language);
16-
1719
const title = getOfficeTranslations('officeInformation');
1820
const { postadresse, beliggenhet, organisasjonsnummer, enhetNr } = officeData;
19-
2021
const visitingAddress = officeDetailsFormatAddress(beliggenhet, true);
2122
const postalAddress = officeDetailsFormatAddress(postadresse, true);
2223

24+
const toggleExpandCollapse = (isOpening: boolean, tittel: string) => {
25+
setIsOpen(isOpening);
26+
logAmplitudeEvent(isOpening ? AnalyticsEvents.ACC_EXPAND : AnalyticsEvents.ACC_COLLAPSE, {
27+
tittel,
28+
opprinnelse: 'kontorinformasjon',
29+
komponent: 'OfficeInformation',
30+
});
31+
};
32+
2333
return (
24-
<ExpansionCard aria-label={title} className={styles.officeInformation} size="small">
34+
<ExpansionCard
35+
size="small"
36+
aria-label={title}
37+
className={styles.officeInformation}
38+
onToggle={(isOpen) => toggleExpandCollapse(isOpen, title)}
39+
open={isOpen}
40+
>
2541
<ExpansionCard.Header className={styles.expansionCardHeader}>
2642
<ExpansionCard.Title as="h2" size="small">
2743
{title}

0 commit comments

Comments
 (0)