-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOfficePageHeader.tsx
66 lines (57 loc) · 2.29 KB
/
OfficePageHeader.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React from 'react';
import { BodyShort, Heading } from '@navikt/ds-react';
import { AudienceReception } from '@navikt/nav-office-reception-info';
import { classNames } from 'utils/classnames';
import { usePageContentProps } from 'store/pageContext';
import { joinWithConjunction } from 'utils/string';
import { translator } from 'translations';
import { OfficeDetailsData } from 'types/content-props/office-details-props';
import style from './OfficePageHeader.module.scss';
type Props = {
showTimeStamp?: boolean;
officeDetails: OfficeDetailsData;
};
export const OfficePageHeader = ({ officeDetails }: Props) => {
const { navn, brukerkontakt } = officeDetails;
const { language } = usePageContentProps();
const officeTranslations = translator('office', language);
const getSubtitle = (publikumsmottak: AudienceReception[]) => {
if (!Array.isArray(publikumsmottak) || publikumsmottak.length < 2) {
return '';
}
const allPlaces = publikumsmottak.reduce<string[]>((acc, place) => {
const { stedsbeskrivelse } = place;
if (stedsbeskrivelse) {
acc.push(stedsbeskrivelse);
}
return acc;
}, []);
return `Lokalkontor for ${joinWithConjunction(allPlaces, language)}`;
};
const subTitle = getSubtitle(brukerkontakt?.publikumsmottak);
const tagline =
officeDetails.type === 'HMS'
? officeTranslations('taglineHMS')
: officeTranslations('taglineOffice');
return (
<div className={classNames(style.officePageHeader)}>
<div className={style.content}>
<Heading level="1" size="xlarge" className={style.heading}>
{navn}
</Heading>
<div className={style.taglineWrapper}>
<BodyShort size="small" className={style.taglineLabel}>
{tagline}
</BodyShort>
{subTitle && (
<>
<BodyShort size="small" className={style.branchNamesLabel}>
{subTitle}
</BodyShort>
</>
)}
</div>
</div>
</div>
);
};