1
1
import { Alert , Checkbox , CheckboxGroup , Heading } from '@navikt/ds-react' ;
2
2
import { ConfirmationModal , i18nUtils , makeStyles } from '@navikt/skjemadigitalisering-shared-components' ;
3
- import { Form , I18nTranslations } from '@navikt/skjemadigitalisering-shared-domain' ;
3
+ import { Form , FormsApiFormTranslation , I18nTranslations } from '@navikt/skjemadigitalisering-shared-domain' ;
4
4
import { useEffect , useState } from 'react' ;
5
5
import { useFormTranslations } from '../../context/translations/FormTranslationsContext' ;
6
+ import { useGlobalTranslations } from '../../context/translations/GlobalTranslationsContext' ;
6
7
import { getFormTextsWithoutCountryNames } from '../../translations/utils/formTextsUtils' ;
7
8
import FormStatus from '../status/FormStatus' ;
8
9
import { allLanguagesInNorwegian } from '../status/PublishedLanguages' ;
@@ -29,6 +30,7 @@ interface Props {
29
30
open : boolean ;
30
31
onClose : ( ) => void ;
31
32
onConfirm : ( languageCodes : string [ ] ) => void ;
33
+ unsavedGlobalTranslations : FormsApiFormTranslation [ ] ;
32
34
}
33
35
34
36
export const getCompleteTranslationLanguageCodeList = (
@@ -52,8 +54,9 @@ export const getCompleteTranslationLanguageCodeList = (
52
54
return completeTranslationList ;
53
55
} ;
54
56
55
- const PublishSettingsModal = ( { open, onClose, onConfirm, form } : Props ) => {
56
- const { translations } = useFormTranslations ( ) ;
57
+ const PublishSettingsModal = ( { open, onClose, onConfirm, form, unsavedGlobalTranslations } : Props ) => {
58
+ const { translations : formTranslations } = useFormTranslations ( ) ;
59
+ const { translations : globalTranslations } = useGlobalTranslations ( ) ;
57
60
const [ allFormOriginalTexts , setAllFormOriginalTexts ] = useState < string [ ] > ( [ ] ) ;
58
61
const [ completeTranslationLanguageCodeList , setCompleteTranslationLanguageCodeList ] = useState < string [ ] > ( [ ] ) ;
59
62
const [ checkedLanguages , setCheckedLanguages ] = useState < string [ ] > ( [ ] ) ;
@@ -67,14 +70,23 @@ const PublishSettingsModal = ({ open, onClose, onConfirm, form }: Props) => {
67
70
} , [ form ] ) ;
68
71
69
72
useEffect ( ( ) => {
70
- const i18n = i18nUtils . mapFormsApiTranslationsToI18n ( translations ) ;
71
- const completeTranslations = getCompleteTranslationLanguageCodeList ( allFormOriginalTexts , i18n ) ;
73
+ const i18n = i18nUtils . mapFormsApiTranslationsToI18n ( [ ...formTranslations ] ) ;
74
+ const skipWhenCheckingForCompleteTranslations = unsavedGlobalTranslations . map ( ( translation ) => translation . key ) ;
75
+ const originalTextsExcludingUnsavedGlobalTranslations = allFormOriginalTexts . filter (
76
+ ( text ) => ! skipWhenCheckingForCompleteTranslations . includes ( text ) ,
77
+ ) ;
78
+
79
+ const completeTranslations = getCompleteTranslationLanguageCodeList (
80
+ originalTextsExcludingUnsavedGlobalTranslations ,
81
+ i18n ,
82
+ ) ;
83
+
72
84
const sanitizedCompleteTranslations = completeTranslations
73
85
. map ( ( langCode ) => ( langCode . length > 2 ? langCode . substring ( 0 , 2 ) : langCode ) )
74
86
. filter ( skipBokmal ) ;
75
87
setCompleteTranslationLanguageCodeList ( [ ...sanitizedCompleteTranslations , 'nb' ] ) ;
76
88
setCheckedLanguages ( [ ...sanitizedCompleteTranslations , 'nb' ] ) ;
77
- } , [ allFormOriginalTexts , translations ] ) ;
89
+ } , [ allFormOriginalTexts , formTranslations , globalTranslations , unsavedGlobalTranslations ] ) ;
78
90
79
91
const PublishStatusPanel = ( { form } : { form : Form } ) => {
80
92
const statusPanelStyles = useStatusPanelStyles ( ) ;
0 commit comments