@@ -3,8 +3,10 @@ import { createPortal } from 'react-dom';
3
3
import { Alert } from '@navikt/ds-react' ;
4
4
import { ContentProps } from 'types/content-props/_content-common' ;
5
5
import { DuplicateIdsWarning } from 'components/_editor-only/warnings/duplicate-ids-warning/DuplicateIdsWarning' ;
6
- import { KortUrlWarning } from 'components/_editor-only/warnings/kort-id -warning/KortUrlWarning' ;
6
+ import { KortUrlWarning } from 'components/_editor-only/warnings/kort-url -warning/KortUrlWarning' ;
7
7
import { removeDuplicates } from 'utils/arrays' ;
8
+ import { FormNumbersWarning } from 'components/_editor-only/warnings/form-numbers-warning/FormNumbersWarning' ;
9
+ import { FormDetailsData } from 'types/content-props/form-details' ;
8
10
9
11
const EDITOR_GLOBAL_WARNINGS_CONTAINER_ID = 'global-warnings' ;
10
12
@@ -28,17 +30,29 @@ export const RenderToEditorGlobalWarnings = ({ children }: { children: React.Rea
28
30
} ;
29
31
30
32
export const EditorGlobalWarnings = ( { content } : { content : ContentProps } ) => {
33
+ //Kort-URL
31
34
const maalgruppe = content . data ?. audience ?. _selected ;
32
35
const path = content . data ?. customPath ;
33
36
const feilKortUrl =
34
37
( maalgruppe === 'employer' && path && ! path ?. includes ( '/arbeidsgiver' ) ) ||
35
38
( maalgruppe === 'provider' && path && ! path ?. includes ( '/samarbeidspartner' ) ) ;
36
39
40
+ //Duplikat ID
37
41
const [ elementsWithDupeIds , setElementsWithDupeIds ] = useState < HTMLElement [ ] > ( [ ] ) ;
38
42
const uniqueDupeIds = removeDuplicates ( elementsWithDupeIds , ( a , b ) => a . id === b . id ) . map (
39
43
( element ) => element . id
40
44
) ;
41
45
46
+ //Skjemanummer
47
+ const formNumberRegex : RegExp = / ^ N A V \s \d { 2 } - \d { 2 } \. \d { 2 } $ / as RegExp ;
48
+ let formNumbersAreWrong = false ;
49
+
50
+ if ( content . type === 'no.nav.navno:form-details' ) {
51
+ content . data ?. formNumbers ?. some (
52
+ ( formNumber : string ) => ( formNumbersAreWrong = ! formNumberRegex . test ( formNumber ) )
53
+ ) ;
54
+ }
55
+
42
56
useEffect ( ( ) => {
43
57
// Delay the check slightly to avoid certain false positives.
44
58
// Typically mobile/desktop exclusive elements which may have duplicate
@@ -60,7 +74,7 @@ export const EditorGlobalWarnings = ({ content }: { content: ContentProps }) =>
60
74
} , 1000 ) ;
61
75
} , [ ] ) ;
62
76
63
- const harFeil = uniqueDupeIds . length > 0 || feilKortUrl ;
77
+ const harFeil = uniqueDupeIds . length > 0 || feilKortUrl || formNumbersAreWrong ;
64
78
65
79
return (
66
80
< >
@@ -77,6 +91,7 @@ export const EditorGlobalWarnings = ({ content }: { content: ContentProps }) =>
77
91
elementsWithDupeIds = { elementsWithDupeIds }
78
92
/>
79
93
) }
94
+ { formNumbersAreWrong && < FormNumbersWarning /> }
80
95
</ ul >
81
96
</ Alert >
82
97
) }
0 commit comments