1
+ import { useState } from 'react' ;
1
2
import { ExpansionCard , BodyShort , Heading } from '@navikt/ds-react' ;
2
3
import { usePageContentProps } from 'store/pageContext' ;
3
4
import { translator } from 'translations' ;
5
+ import { AnalyticsEvents , logAmplitudeEvent } from 'utils/amplitude' ;
4
6
import { OfficeDetailsData } from 'types/content-props/office-details-props' ;
5
7
import { officeDetailsFormatAddress } from 'components/pages/office-page/office-details/utils' ;
6
8
@@ -11,17 +13,31 @@ export interface OfficeInformationProps {
11
13
}
12
14
13
15
export const OfficeInformation = ( { officeData } : OfficeInformationProps ) => {
16
+ const [ isOpen , setIsOpen ] = useState ( false ) ;
14
17
const { language } = usePageContentProps ( ) ;
15
18
const getOfficeTranslations = translator ( 'office' , language ) ;
16
-
17
19
const title = getOfficeTranslations ( 'officeInformation' ) ;
18
20
const { postadresse, beliggenhet, organisasjonsnummer, enhetNr } = officeData ;
19
-
20
21
const visitingAddress = officeDetailsFormatAddress ( beliggenhet , true ) ;
21
22
const postalAddress = officeDetailsFormatAddress ( postadresse , true ) ;
22
23
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
+
23
33
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
+ >
25
41
< ExpansionCard . Header className = { styles . expansionCardHeader } >
26
42
< ExpansionCard . Title as = "h2" size = "small" >
27
43
{ title }
0 commit comments