Skip to content

Commit 9db93ba

Browse files
authored
Merge pull request #2124 from navikt/skjemanummer-validering
Validering for skjemanummer i redaktørvarsel
2 parents 43b3089 + 8f0f866 commit 9db93ba

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

next-env.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/basic-features/typescript for more information.
5+
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.

src/components/_editor-only/global-warnings/EditorGlobalWarnings.tsx

+17-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { createPortal } from 'react-dom';
33
import { Alert } from '@navikt/ds-react';
44
import { ContentProps } from 'types/content-props/_content-common';
55
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';
77
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';
810

911
const EDITOR_GLOBAL_WARNINGS_CONTAINER_ID = 'global-warnings';
1012

@@ -28,17 +30,29 @@ export const RenderToEditorGlobalWarnings = ({ children }: { children: React.Rea
2830
};
2931

3032
export const EditorGlobalWarnings = ({ content }: { content: ContentProps }) => {
33+
//Kort-URL
3134
const maalgruppe = content.data?.audience?._selected;
3235
const path = content.data?.customPath;
3336
const feilKortUrl =
3437
(maalgruppe === 'employer' && path && !path?.includes('/arbeidsgiver')) ||
3538
(maalgruppe === 'provider' && path && !path?.includes('/samarbeidspartner'));
3639

40+
//Duplikat ID
3741
const [elementsWithDupeIds, setElementsWithDupeIds] = useState<HTMLElement[]>([]);
3842
const uniqueDupeIds = removeDuplicates(elementsWithDupeIds, (a, b) => a.id === b.id).map(
3943
(element) => element.id
4044
);
4145

46+
//Skjemanummer
47+
const formNumberRegex: RegExp = /^NAV\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+
4256
useEffect(() => {
4357
// Delay the check slightly to avoid certain false positives.
4458
// Typically mobile/desktop exclusive elements which may have duplicate
@@ -60,7 +74,7 @@ export const EditorGlobalWarnings = ({ content }: { content: ContentProps }) =>
6074
}, 1000);
6175
}, []);
6276

63-
const harFeil = uniqueDupeIds.length > 0 || feilKortUrl;
77+
const harFeil = uniqueDupeIds.length > 0 || feilKortUrl || formNumbersAreWrong;
6478

6579
return (
6680
<>
@@ -77,6 +91,7 @@ export const EditorGlobalWarnings = ({ content }: { content: ContentProps }) =>
7791
elementsWithDupeIds={elementsWithDupeIds}
7892
/>
7993
)}
94+
{formNumbersAreWrong && <FormNumbersWarning />}
8095
</ul>
8196
</Alert>
8297
)}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
export const FormNumbersWarning = () => {
4+
return <li>Skjemanummer må være på formatet {'NAV XX-XX.XX'}</li>;
5+
};

0 commit comments

Comments
 (0)