Skip to content

Commit ae6170b

Browse files
committed
Viser en advarsel dersom en side tidligere hadde en annen content-type
1 parent 9558785 commit ae6170b

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

src/components/_top-container/TopContainer.tsx

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import React from 'react';
2-
import { classNames } from '../../utils/classnames';
3-
import {
4-
ContentProps,
5-
ContentType,
6-
} from '../../types/content-props/_content-common';
7-
import { getContentLanguages } from '../../utils/languages';
2+
import { classNames } from 'utils/classnames';
3+
import { ContentProps, ContentType } from 'types/content-props/_content-common';
4+
import { getContentLanguages } from 'utils/languages';
85
import { VersionHistory } from './version-history/VersionHistory';
96
import { PageWarning } from './page-warning/PageWarning';
7+
import { translator } from 'translations';
108

119
import style from './TopContainer.module.scss';
1210

@@ -25,27 +23,41 @@ type Props = {
2523
};
2624

2725
export const TopContainer = ({ content }: Props) => {
28-
const { __typename, breadcrumbs, isFailover, isPagePreview } = content;
26+
const {
27+
__typename,
28+
breadcrumbs,
29+
isFailover,
30+
isPagePreview,
31+
originalType,
32+
language,
33+
} = content;
2934
const hasDecoratorWidgets =
3035
breadcrumbs?.length > 0 || getContentLanguages(content)?.length > 0;
3136
const hasWhiteHeader = contentTypesWithWhiteHeader[__typename];
3237
// Should be shown in Content Studio only (except the edit view)
3338
const showVersionPicker =
3439
!!content.editorView && content.editorView !== 'edit';
3540

41+
const warningLabels = translator('pageWarnings', language);
42+
3643
return (
3744
<>
3845
{isPagePreview && (
39-
<PageWarning
40-
labelKey={'draftWarning'}
41-
whiteBg={hasWhiteHeader}
42-
/>
46+
<PageWarning whiteBg={hasWhiteHeader}>
47+
{warningLabels('draftWarning')}
48+
</PageWarning>
4349
)}
4450
{isFailover && (
45-
<PageWarning
46-
labelKey={'failoverWarning'}
47-
whiteBg={hasWhiteHeader}
48-
/>
51+
<PageWarning whiteBg={hasWhiteHeader}>
52+
{warningLabels('failoverWarning')}
53+
</PageWarning>
54+
)}
55+
{originalType && content.editorView && (
56+
<PageWarning whiteBg={hasWhiteHeader}>{`${warningLabels(
57+
'contentTypeChangedWarningPre'
58+
)}"${originalType}"${warningLabels(
59+
'contentTypeChangedWarningPost'
60+
)}`}</PageWarning>
4961
)}
5062
<div
5163
className={classNames(

src/components/_top-container/page-warning/PageWarning.tsx

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
import React from 'react';
2-
import { usePageConfig } from 'store/hooks/usePageConfig';
3-
import { translator } from 'translations';
4-
import { Translations } from '../../../translations/default';
52
import { AlertBox } from '../../_common/alert-box/AlertBox';
6-
import { classNames } from '../../../utils/classnames';
3+
import { classNames } from 'utils/classnames';
74

85
import style from './PageWarning.module.scss';
96

107
type Props = {
11-
labelKey: keyof Translations['pageWarnings'];
128
whiteBg?: boolean;
9+
children: React.ReactNode;
1310
};
1411

15-
export const PageWarning = ({ labelKey, whiteBg }: Props) => {
16-
const { language } = usePageConfig();
17-
const getDraftLabels = translator('pageWarnings', language);
18-
12+
export const PageWarning = ({ whiteBg, children }: Props) => {
1913
return (
2014
<div className={classNames(style.container, whiteBg && style.whiteBg)}>
2115
<AlertBox
2216
variant={'warning'}
2317
size={'small'}
2418
className={style.warning}
2519
>
26-
{getDraftLabels(labelKey)}
20+
{children}
2721
</AlertBox>
2822
</div>
2923
);

src/translations/default.ts

+4
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ export const translationsBundleNb = {
203203
draftWarning: 'Utkast - siden er under arbeid',
204204
failoverWarning:
205205
'Vi har for tiden tekniske problemer på nav.no. Du kan oppleve noe treghet eller at innhold mangler. Du kan prøve å laste inn siden på nytt.',
206+
contentTypeChangedWarningPre:
207+
'Obs! Denne siden var tidligere av typen ',
208+
contentTypeChangedWarningPost:
209+
' - Sjekk om versjonshistorikken har innhold som må arkiveres før eventuell sletting.',
206210
},
207211
caseTimeUnit: {
208212
single: {

src/types/content-props/_content-common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ type ContentCommonData = Partial<{
107107

108108
export type ContentCommonProps = {
109109
__typename: ContentType;
110+
originalType?: string;
110111
children?: ContentCommonProps[];
111112
parent?: ContentCommonProps;
112113
data?: ContentCommonData;

0 commit comments

Comments
 (0)