Skip to content

Commit 2871212

Browse files
authored
Merge pull request #1962 from navikt/splitt-alternative-audience
Splitt alternative audience
2 parents ae3d567 + f044f16 commit 2871212

File tree

5 files changed

+64
-52
lines changed

5 files changed

+64
-52
lines changed

src/components/_common/alternativeAudience/AlternativeAudience.tsx

+1-43
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { BodyLong } from '@navikt/ds-react';
33
import {
44
AlternativeAudience as AlternativeAudienceType,
55
Audience,
6-
AudienceOptions,
7-
getAudience,
86
} from 'types/component-props/_mixins';
97
import { usePageContentProps } from 'store/pageContext';
108
import { Language, translator } from 'translations';
@@ -71,50 +69,11 @@ export const AlternativeAudience = () => {
7169
const { showProductName } = config;
7270
const { alternativeAudience } = data;
7371

74-
const getAudienceLabel = translator('audience', language);
75-
const getProviderAudienceLabel = translator('providerAudience', language);
7672
const getStringPart = translator('stringParts', language);
7773
const getRelatedString = translator('related', language);
7874

79-
const getProviderTypes = (audience: AudienceOptions) => {
80-
if (audience._selected !== Audience.PROVIDER) {
81-
return [];
82-
}
83-
return audience[audience._selected].provider_audience;
84-
};
85-
86-
const buildAudienceAffirmation = (addPeriod: boolean) => {
87-
const { audience: currentAudience } = data;
88-
const currentAudienceKey = getAudience(currentAudience);
89-
90-
if (!currentAudience || !currentAudienceKey || currentAudienceKey === 'person') {
91-
return '';
92-
}
93-
94-
const currentAudienceLabel = getAudienceLabel(currentAudienceKey);
95-
const providerTypes = getProviderTypes(currentAudience) || [];
96-
const providerTypesString = joinWithConjunction(
97-
providerTypes.map((type) => getProviderAudienceLabel(type)),
98-
language
99-
);
100-
101-
const forString = `${getStringPart('for').charAt(0).toUpperCase()}${getStringPart(
102-
'for'
103-
).slice(1)}`;
104-
105-
return `${forString} ${providerTypesString || currentAudienceLabel}${
106-
addPeriod ? '.' : ''
107-
} `;
108-
};
109-
11075
if (!alternativeAudience) {
111-
return (
112-
<div className={style.alternativeAudience}>
113-
<BodyLong size="small" className={style.text}>
114-
{buildAudienceAffirmation(false)}
115-
</BodyLong>
116-
</div>
117-
);
76+
return null;
11877
}
11978

12079
const productName =
@@ -124,7 +83,6 @@ export const AlternativeAudience = () => {
12483
return (
12584
<div className={style.alternativeAudience}>
12685
<BodyLong size="small" className={style.text}>
127-
{buildAudienceAffirmation(true)}
12886
{getRelatedString('relatedAudience').replace('{name}', productName)}{' '}
12987
{audienceLinks.map((link, index) => (
13088
<Fragment key={index}>

src/components/_common/headers/general-page-header/GeneralPageHeader.module.scss

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
margin-top: var(--a-spacing-3);
4242
font-variant: all-small-caps;
4343
color: var(--a-text-subtle);
44+
white-space: pre-wrap;
4445
}
4546

4647
.ingress:global(.navds-body-long) {

src/components/_common/headers/general-page-header/GeneralPageHeader.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { BodyLong, BodyShort, Heading } from '@navikt/ds-react';
1+
import { BodyLong, Heading } from '@navikt/ds-react';
22
import {
33
PagePropsForPageHeader,
44
getContentTagline,
55
} from 'components/_common/headers/sharedHeaderUtils';
66
import { Illustration } from 'components/_common/illustration/Illustration';
77
import { ContentProps, ContentType } from 'types/content-props/_content-common';
88
import { classNames } from 'utils/classnames';
9+
import { GeneralPageHeaderTagLine } from './GeneralPageHeaderTagLine';
910

1011
import style from './GeneralPageHeader.module.scss';
1112

@@ -26,11 +27,7 @@ export const GeneralPageHeader = (props: Props) => {
2627
return (
2728
<div className={style.generalPageHeader}>
2829
<Illustration illustration={illustration} className={style.illustration} />
29-
{tagLine && (
30-
<BodyShort className={style.tagline} size="small">
31-
{tagLine}
32-
</BodyShort>
33-
)}
30+
{tagLine && <GeneralPageHeaderTagLine tagLine={tagLine} />}
3431
<Heading
3532
level="1"
3633
size="xlarge"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { BodyShort } from '@navikt/ds-react';
2+
import { usePageContentProps } from 'store/pageContext';
3+
import { translator } from 'translations';
4+
import { ProductPageProps } from 'types/content-props/dynamic-page-props';
5+
import { Audience, AudienceOptions, getAudience } from 'types/component-props/_mixins';
6+
import { joinWithConjunction } from 'utils/string';
7+
8+
import style from './GeneralPageHeader.module.scss';
9+
10+
type Props = {
11+
tagLine: string;
12+
};
13+
14+
export const GeneralPageHeaderTagLine = (props: Props) => {
15+
const { data, language } = usePageContentProps<ProductPageProps>();
16+
17+
const getAudienceLabel = translator('audience', language);
18+
const getProviderAudienceLabel = translator('providerAudience', language);
19+
const getStringPart = translator('stringParts', language);
20+
21+
const getProviderTypes = (audience: AudienceOptions) => {
22+
if (audience._selected !== Audience.PROVIDER) {
23+
return [];
24+
}
25+
return audience[audience._selected].provider_audience;
26+
};
27+
28+
const buildAudienceAffirmation = () => {
29+
const { audience: currentAudience } = data;
30+
const currentAudienceKey = getAudience(currentAudience);
31+
32+
if (!currentAudience || !currentAudienceKey || currentAudienceKey === 'person') {
33+
return '';
34+
}
35+
36+
const currentAudienceLabel = getAudienceLabel(currentAudienceKey);
37+
const providerTypes = getProviderTypes(currentAudience) || [];
38+
const providerTypesString = joinWithConjunction(
39+
providerTypes.map((type) => getProviderAudienceLabel(type)),
40+
language
41+
);
42+
43+
const forString = `${getStringPart('for').charAt(0).toUpperCase()}${getStringPart(
44+
'for'
45+
).slice(1)}`;
46+
47+
return ` — ${forString} ${providerTypesString || currentAudienceLabel}`;
48+
};
49+
50+
return (
51+
<BodyShort className={style.tagline} size="small">
52+
{props.tagLine}
53+
{buildAudienceAffirmation()}
54+
</BodyShort>
55+
);
56+
};

src/translations/nn.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ export const translationsBundleNn: PartialTranslations = {
152152
},
153153
situations: {
154154
person: 'Dette kan du ha rett til',
155-
employer: 'For arbeidsgjevarar',
155+
employer: 'Kva arbeidsgjevarar må vita',
156156
provider: 'For samarbeidspartnarar',
157157
},
158158
guides: {
159159
person: 'Slik gjer du det',
160-
employer: 'For arbeidsgjevarar',
161-
provider: 'For samarbeidspartnarar',
160+
employer: 'Slik gjer du det',
161+
provider: 'Slik gjer du det',
162162
},
163163
publishingCalendar: {
164164
event: 'Hending',

0 commit comments

Comments
 (0)