diff --git a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.utils.ts b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.utils.ts index e427330fbbed..b76b4007b4aa 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.utils.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.utils.ts @@ -22,10 +22,14 @@ export const transformApplicationToNewPrimarySchoolDTO = ( reasonForApplicationStreetAddress, reasonForApplicationPostalCode, selectedSchool, - nativeLanguage, - otherLanguagesSpokenDaily, - otherLanguages, - icelandicNotSpokenAroundChild, + language1, + language2, + language3, + language4, + childLanguage, + languageEnvironment, + signLanguage, + interpreter, developmentalAssessment, specialSupport, startDate, @@ -77,17 +81,6 @@ export const transformApplicationToNewPrimarySchoolDTO = ( : []), ] - let noIcelandic: boolean - if (otherLanguagesSpokenDaily === YES) { - if (nativeLanguage === 'is' || otherLanguages?.includes('is')) { - noIcelandic = false - } else { - noIcelandic = icelandicNotSpokenAroundChild?.includes(YES) - } - } else { - noIcelandic = nativeLanguage !== 'is' - } - const newPrimarySchoolDTO: FormDto = { type: FormDtoTypeEnum.Registration, user: { @@ -133,12 +126,11 @@ export const transformApplicationToNewPrimarySchoolDTO = ( social: { hasHadSupport: specialSupport === YES, hasDiagnoses: developmentalAssessment === YES, - }, + }, // Languages needs to be updated when Juni is ready with the data struccture language: { - nativeLanguage: nativeLanguage, - noIcelandic, - otherLanguages: - otherLanguagesSpokenDaily === YES ? otherLanguages : undefined, + nativeLanguage: '', + noIcelandic: false, + otherLanguages: undefined, }, } diff --git a/libs/application/templates/new-primary-school/src/fields/LanguageSelection/index.tsx b/libs/application/templates/new-primary-school/src/fields/LanguageSelection/index.tsx new file mode 100644 index 000000000000..105d2a4e4d0c --- /dev/null +++ b/libs/application/templates/new-primary-school/src/fields/LanguageSelection/index.tsx @@ -0,0 +1,157 @@ +import { FieldBaseProps } from '@island.is/application/types' +import React, { FC, useEffect, useState } from 'react' + +import { getErrorViaPath } from '@island.is/application/core' +import { Box, Button, Stack, Text } from '@island.is/island-ui/core' +import { useLocale } from '@island.is/localization' +import { SelectController } from '@island.is/shared/form-fields' +import { getAllLanguageCodes } from '@island.is/shared/utils' +import { useFormContext } from 'react-hook-form' +import { LanguageEnvironmentOptions } from '../../lib/constants' +import { newPrimarySchoolMessages } from '../../lib/messages' +import { getApplicationAnswers } from '../../lib/newPrimarySchoolUtils' + +export type LanguageSelectionProps = {} + +const languagesIds = { + language1: 'languages.language1', + language2: 'languages.language2', + language3: 'languages.language3', + language4: 'languages.language4', + childLanguage: 'languages.childLanguage', +} + +const LanguageSelection: FC> = ({ + application, + errors, +}) => { + const { formatMessage } = useLocale() + const { getValues } = useFormContext() + + const [visibleLanguagesCount, setVisibleLanguagesCount] = useState(1) + const [selectedLanguages, setSelectedLanguages] = useState([ + '', + '', + '', + '', + ]) + + const allLanguages = getAllLanguageCodes() + const allLanguageOptions = allLanguages + .filter((language) => { + if ( + language.code === 'is' && + getValues().languages.languageEnvironment === + LanguageEnvironmentOptions.ONLY_FOREIGN + ) { + return false + } + return true + }) + .map((language) => ({ + label: language.name, + value: language.code, + })) + + const languageIdsArray = [ + languagesIds.language1, + languagesIds.language2, + languagesIds.language3, + languagesIds.language4, + ] + + const addLanguage = () => { + setVisibleLanguagesCount((prev) => Math.min(prev + 1, 4)) + } + + useEffect(() => { + const { language1, language2, language3, language4 } = + getApplicationAnswers(application.answers) + + const selected = [language1, language2, language3, language4].filter( + Boolean, + ) + + // Ensure the visible count is at least 1 + const visibleCount = Math.max(1, selected.length) + + setSelectedLanguages(selected) + setVisibleLanguagesCount(visibleCount) + }, [application]) + + return ( + + {languageIdsArray.slice(0, visibleLanguagesCount).map((id, index) => ( + { + setSelectedLanguages((prevLanguages) => { + const newLanguages = [...prevLanguages] + newLanguages[index] = value + return newLanguages + }) + }} + /> + ))} + + + + + + ) +} +export default LanguageSelection diff --git a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Languages.tsx b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Languages.tsx index 184f2c44bdfb..0dd028d68329 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Languages.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Languages.tsx @@ -1,4 +1,3 @@ -import { YES } from '@island.is/application/types' import { DataValue, RadioValue, @@ -7,8 +6,12 @@ import { import { GridColumn, GridRow, Stack } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' import { getLanguageByCode } from '@island.is/shared/utils' +import { LanguageEnvironmentOptions } from '../../../lib/constants' import { newPrimarySchoolMessages } from '../../../lib/messages' -import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' +import { + getApplicationAnswers, + getLanguageEnvironments, +} from '../../../lib/newPrimarySchoolUtils' import { ReviewGroupProps } from './props' export const Languages = ({ @@ -18,14 +21,19 @@ export const Languages = ({ }: ReviewGroupProps) => { const { formatMessage } = useLocale() const { - nativeLanguage, - otherLanguagesSpokenDaily, - otherLanguages, - icelandicNotSpokenAroundChild, + interpreter, + languageEnvironment, + language1, + language2, + language3, + language4, + childLanguage, + signLanguage, } = getApplicationAnswers(application.answers) - const icelandicSelected = - nativeLanguage === 'is' || otherLanguages?.includes('is') + const selectedLanguageEnvironment = getLanguageEnvironments().find( + (env) => env.value === languageEnvironment, + ) return ( - - - - - - {otherLanguagesSpokenDaily === YES && ( + + {languageEnvironment === LanguageEnvironmentOptions.ONLY_ICELANDIC ? ( + + + + + + ) : ( <> - + { - return getLanguageByCode(language)?.name - }) - .join(', ')} + value={getLanguageByCode(language1)?.name} /> + {language2 && ( + + + + )} - {!icelandicSelected && - icelandicNotSpokenAroundChild?.includes(YES) && ( - - - - - + + {language3 && ( + + + + )} + {language4 && ( + + + )} + + {childLanguage && ( + + + + + + )} + + + + + + + + + )} diff --git a/libs/application/templates/new-primary-school/src/fields/index.ts b/libs/application/templates/new-primary-school/src/fields/index.ts index 8e1b50610fa5..630bcc206bca 100644 --- a/libs/application/templates/new-primary-school/src/fields/index.ts +++ b/libs/application/templates/new-primary-school/src/fields/index.ts @@ -2,3 +2,4 @@ export { default as FriggOptionsAsyncSelectField } from './FriggOptionsAsyncSele export { default as DynamicDisabledText } from './DynamicDisabledText' export { default as ContactsTableRepeater } from './ContactsTableRepeater' export { Review } from './Review' +export { default as LanguageSelection } from './LanguageSelection' diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/languageSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/languageSubSection.ts index 90ae44ff6518..f1efeb31969b 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/languageSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/languageSubSection.ts @@ -1,16 +1,19 @@ import { - buildCheckboxField, + buildCustomField, buildDescriptionField, - buildHiddenInput, buildMultiField, buildRadioField, buildSelectField, buildSubSection, } from '@island.is/application/core' import { NO, YES } from '@island.is/application/types' -import { getAllLanguageCodes } from '@island.is/shared/utils' import { newPrimarySchoolMessages } from '../../../lib/messages' -import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' +import { + getApplicationAnswers, + getLanguageEnvironments, + hasForeignLanguages, +} from '../../../lib/newPrimarySchoolUtils' +import { LanguageSelectionProps } from '../../../fields/LanguageSelection' export const languageSubSection = buildSubSection({ id: 'languageSubSection', @@ -22,104 +25,88 @@ export const languageSubSection = buildSubSection({ description: newPrimarySchoolMessages.differentNeeds.languageDescription, children: [ buildDescriptionField({ - id: 'languages.nativeLanguage.title', - title: newPrimarySchoolMessages.differentNeeds.childNativeLanguage, + id: 'languages.sub.title', + title: newPrimarySchoolMessages.differentNeeds.languageSubTitle, titleVariant: 'h4', }), buildSelectField({ - id: 'languages.nativeLanguage', - dataTestId: 'languages-native-language', + id: 'languages.languageEnvironment', + dataTestId: 'languages-language-environment', title: - newPrimarySchoolMessages.differentNeeds.languageSubSectionTitle, + newPrimarySchoolMessages.differentNeeds.languageEnvironmentTitle, placeholder: - newPrimarySchoolMessages.differentNeeds.languagePlaceholder, + newPrimarySchoolMessages.differentNeeds + .languageEnvironmentPlaceholder, options: () => { - const languages = getAllLanguageCodes() - return languages.map((language) => { - return { - label: language.name, - value: language.code, - } - }) + return getLanguageEnvironments() }, }), - buildRadioField({ - id: 'languages.otherLanguagesSpokenDaily', + buildDescriptionField({ + id: 'languages.languages.title', title: - newPrimarySchoolMessages.differentNeeds.otherLanguagesSpokenDaily, + newPrimarySchoolMessages.differentNeeds.languageSubSectionTitle, + description: + newPrimarySchoolMessages.differentNeeds.languagesDescription, + titleVariant: 'h4', + condition: (answers) => { + return hasForeignLanguages(answers) + }, + marginBottom: 'gutter', + }), + buildCustomField( + { + id: 'languages', + title: '', + component: 'LanguageSelection', + condition: (answers) => { + return hasForeignLanguages(answers) + }, + }, + {} as LanguageSelectionProps, + ), + buildRadioField({ + id: 'languages.signLanguage', + title: newPrimarySchoolMessages.differentNeeds.signLanguage, width: 'half', required: true, space: 4, options: [ { label: newPrimarySchoolMessages.shared.yes, - dataTestId: 'other-languages', + dataTestId: 'sign-language', value: YES, }, { label: newPrimarySchoolMessages.shared.no, - dataTestId: 'no-other-languages', + dataTestId: 'no-sign-language', value: NO, }, ], - }), - buildSelectField({ - id: 'languages.otherLanguages', - dataTestId: 'languages-other-languages', - title: - newPrimarySchoolMessages.differentNeeds.languageSubSectionTitle, - placeholder: - newPrimarySchoolMessages.differentNeeds.languagePlaceholder, - options: () => { - const languages = getAllLanguageCodes() - return languages.map((language) => { - return { - label: language.name, - value: language.code, - } - }) - }, - isMulti: true, condition: (answers) => { - const { otherLanguagesSpokenDaily } = getApplicationAnswers(answers) - - return otherLanguagesSpokenDaily === YES + const { languageEnvironment } = getApplicationAnswers(answers) + return !!languageEnvironment }, }), - buildCheckboxField({ - id: 'languages.icelandicNotSpokenAroundChild', - title: '', - options: (application) => { - const { nativeLanguage, otherLanguages } = getApplicationAnswers( - application.answers, - ) - const icelandicSelected = - nativeLanguage === 'is' || otherLanguages?.includes('is') - - return [ - { - label: - newPrimarySchoolMessages.differentNeeds - .icelandicNotSpokenAroundChild, - value: icelandicSelected ? NO : YES, - disabled: icelandicSelected, - }, - ] - }, - condition: (answers) => { - const { otherLanguagesSpokenDaily } = getApplicationAnswers(answers) - - return otherLanguagesSpokenDaily === YES - }, - }), - buildHiddenInput({ - // Needed to trigger an update on options in the checkbox above - id: 'languages.icelandicSelectedHiddenInput', + buildRadioField({ + id: 'languages.interpreter', + title: newPrimarySchoolMessages.differentNeeds.interpreter, + width: 'half', + required: true, + space: 4, + options: [ + { + label: newPrimarySchoolMessages.shared.yes, + dataTestId: 'interpreter', + value: YES, + }, + { + label: newPrimarySchoolMessages.shared.no, + dataTestId: 'no-interpreter', + value: NO, + }, + ], condition: (answers) => { - const { nativeLanguage, otherLanguages } = - getApplicationAnswers(answers) - - return nativeLanguage === 'is' || otherLanguages?.includes('is') + return hasForeignLanguages(answers) }, }), ], diff --git a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts index 2365fec89ab4..0473349546c4 100644 --- a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts +++ b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts @@ -34,6 +34,7 @@ import { newPrimarySchoolMessages, statesMessages } from './messages' import { determineNameFromApplicationAnswers, getApplicationAnswers, + hasForeignLanguages, } from './newPrimarySchoolUtils' const NewPrimarySchoolTemplate: ApplicationTemplate< @@ -205,12 +206,14 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< }), clearLanguages: assign((context) => { const { application } = context - const { otherLanguagesSpokenDaily } = getApplicationAnswers( - application.answers, - ) - if (otherLanguagesSpokenDaily === NO) { - unset(application.answers, 'languages.otherLanguages') - unset(application.answers, 'languages.icelandicNotSpokenAroundChild') + + if (hasForeignLanguages(application.answers)) { + unset(application.answers, 'languages.language1') + unset(application.answers, 'languages.language2') + unset(application.answers, 'languages.language3') + unset(application.answers, 'languages.language4') + unset(application.answers, 'languages.childLanguage') + unset(application.answers, 'languages.interpreter') } return context }), diff --git a/libs/application/templates/new-primary-school/src/lib/constants.ts b/libs/application/templates/new-primary-school/src/lib/constants.ts index bc5a092a8438..45e8644c0057 100644 --- a/libs/application/templates/new-primary-school/src/lib/constants.ts +++ b/libs/application/templates/new-primary-school/src/lib/constants.ts @@ -55,6 +55,12 @@ export enum MembershipOrganizationType { School = 'school', } +export enum LanguageEnvironmentOptions { + ONLY_ICELANDIC = 'onlyIcelandic', + ICELANDIC_AND_FOREIGN = 'icelandicAndForeign', + ONLY_FOREIGN = 'onlyForeign', +} + export enum ApplicationType { NEW_PRIMARY_SCHOOL = 'newPrimarySchool', ENROLLMENT_IN_PRIMARY_SCHOOL = 'enrollmentInPrimarySchool', diff --git a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts index 391ad2b4ba71..6f2eb7440c65 100644 --- a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts +++ b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts @@ -2,7 +2,12 @@ import { NO, YES } from '@island.is/application/types' import * as kennitala from 'kennitala' import { parsePhoneNumberFromString } from 'libphonenumber-js' import { z } from 'zod' -import { ApplicationType, ReasonForApplicationOptions } from './constants' +import { + ApplicationType, + ReasonForApplicationOptions, + LanguageEnvironmentOptions, +} from './constants' + import { errorMessages } from './messages' const validatePhoneNumber = (value: string) => { @@ -126,19 +131,47 @@ export const dataSchema = z.object({ startDate: z.string(), languages: z .object({ - nativeLanguage: z.string(), - otherLanguagesSpokenDaily: z.enum([YES, NO]), - otherLanguages: z.array(z.string()).optional(), + languageEnvironment: z.string(), + signLanguage: z.enum([YES, NO]), + interpreter: z.string().optional(), + language1: z.string().optional().nullable(), + language2: z.string().optional().nullable(), + childLanguage: z.string().optional().nullable(), }) .refine( - ({ otherLanguagesSpokenDaily, otherLanguages }) => - otherLanguagesSpokenDaily === YES - ? !!otherLanguages && otherLanguages.length > 0 - : true, + ({ languageEnvironment, language1 }) => { + return languageEnvironment !== LanguageEnvironmentOptions.ONLY_ICELANDIC + ? !!language1 + : true + }, { - path: ['otherLanguages'], + path: ['language1'], params: errorMessages.languagesRequired, }, + ) + .refine( + ({ languageEnvironment, language1, language2, childLanguage }) => { + return languageEnvironment !== + LanguageEnvironmentOptions.ONLY_ICELANDIC && + !!language1 && + !!language2 + ? !!childLanguage + : true + }, + { + path: ['childLanguage'], + params: errorMessages.languageRequired, + }, + ) + .refine( + ({ languageEnvironment, interpreter }) => { + return languageEnvironment !== LanguageEnvironmentOptions.ONLY_ICELANDIC + ? !!interpreter + : true + }, + { + path: ['interpreter'], + }, ), freeSchoolMeal: z .object({ diff --git a/libs/application/templates/new-primary-school/src/lib/messages.ts b/libs/application/templates/new-primary-school/src/lib/messages.ts index 81cbba099394..a131b75f4f82 100644 --- a/libs/application/templates/new-primary-school/src/lib/messages.ts +++ b/libs/application/templates/new-primary-school/src/lib/messages.ts @@ -1,4 +1,5 @@ import { defineMessages, MessageDescriptor } from 'react-intl' +import { LanguageEnvironmentOptions } from './constants' type MessageDir = Record> @@ -495,30 +496,78 @@ export const newPrimarySchoolMessages: MessageDir = { defaultMessage: 'Til að hægt sé að koma til móts við þarfir barnsins þarf skólinn að vita hvaða tungumál eru töluð í nærumhverfi þess. Veldu þau tungumál, eitt eða fleiri sem töluð eru dagsdaglega á heimilinu í samskiptum við eða í kringum barn.', description: - "In order to meet the child's needs, the school needs to know which languages ​​are spoken in their immediate environment. Choose the languages, one or more, that are spoken daily at home in communication with or around a child.", + "In order to meet the child's needs, the school needs to know which languages are used in communication with the child in the family's daily life.", }, - childNativeLanguage: { - id: 'nps.application:different.needs.child.native.language', - defaultMessage: 'Hvert er móðurmál barnsins?', - description: "What is the child's native language?", + languageSubTitle: { + id: 'nps.application:different.needs.language.sub.title', + defaultMessage: + 'Hvað á best við í tilfelli barnsins og tungumála sem notuð eru í daglegu lífi fjölskyldunnar?', + description: + 'What is best for the child and the languages used in the familys daily life?', + }, + languageEnvironmentTitle: { + id: 'nps.application:different.needs.language.environment.title', + defaultMessage: 'Tungumálaumhverfi', + description: 'Language environment', + }, + languageEnvironmentPlaceeholder: { + id: 'nps.application:different.needs.language.environment.placeholder', + defaultMessage: 'Veldu það sem best á við', + description: 'Choose what best applies', + }, + onlyIcelandicOption: { + id: 'nps.application:different.needs.language.only.icelandic.option', + defaultMessage: 'Aðeins töluð íslenska', + description: 'Only Icelandic spoken', + }, + icelandicAndForeignOption: { + id: 'nps.application:different.needs.language.icelandic.and.foreign.option', + defaultMessage: 'Töluð íslenska og annað/önnur tungumál', + description: 'Icelandic and other language(s) spoken', + }, + onlyForeignOption: { + id: 'nps.application:different.needs.language.only.foreign.option', + defaultMessage: 'Aðeins töluð önnur tungumál en íslenska', + description: 'Only other languages spoken, not Icelandic', }, - otherLanguagesSpokenDaily: { - id: 'nps.application:different.needs.other.languages.spoken.daily', + languagesDescription: { + id: 'nps.application:different.needs.languages.description', defaultMessage: - 'Eru önnur tungumál en móðurmál töluð daglega á heimili barnsins?', + 'Raðaðu tungumálunum eftir því hvaða tungumál er mest er notað. Það sem er mest notað er nr. 1 og svo koll af kolli.', description: - "Are languages ​​other than the native language spoken daily in the child's home?", + 'Rank the languages according to which language is used the most. The most used language is number 1, and so on.', }, - languagePlaceholder: { - id: 'nps.application:different.needs.language.placeholder', + languageSelectionTitle: { + id: 'nps.application:different.needs.language.selection.title', + defaultMessage: 'Tungumál {no}', + description: 'Language {no}', + }, + addLanguageButton: { + id: 'nps.application:different.needs.language.add.button', + defaultMessage: 'Bæta við tungumáli', + description: 'Add language', + }, + languageSelectionPlaceholder: { + id: 'nps.application:different.needs.language.selection.placeholder', defaultMessage: 'Veldu tungumál', - description: 'Choose a language', + description: 'Choose language', }, - icelandicNotSpokenAroundChild: { - id: 'nps.application:different.needs.icelandic.not.spoken.around.child', - defaultMessage: 'Það er ekki töluð íslenska í nærumhverfi barnsins', + childLanguageTitle: { + id: 'nps.application:different.needs.child.language.title', + defaultMessage: + 'Á hvaða tungumáli sem þú hefur valið, finnst barninu sjálfu best að tjá sig á?', description: - "Icelandic is not spoken in the child's immediate environment", + 'In which of these languages that you have chosen does the child feel most comfortable expressing themselves?', + }, + signLanguage: { + id: 'nps.application:different.needs.sign.language', + defaultMessage: 'Notar barnið táknmál?', + description: 'Does the child use sign language?', + }, + interpreter: { + id: 'nps.application:different.needs.interpreter', + defaultMessage: 'Þurfa foreldrar túlk?', + description: 'Do the parents need an interpreter?', }, // Free school meal @@ -722,17 +771,17 @@ export const newPrimarySchoolMessages: MessageDir = { parents: { id: 'nps.application:overview.parents', defaultMessage: 'Foreldri/forsjáraðili', - description: 'Parent/guardian', + description: 'Parent / guardian', }, - nativeLanguage: { - id: 'nps.application:overview.native.language', - defaultMessage: 'Móðurmál barnsins', - description: "The child's native language", + languageEnvironment: { + id: 'nps.application:overview.language.environment', + defaultMessage: 'Tungumálaumhverfi', + description: 'Language environment', }, - icelandicSpokenAroundChild: { - id: 'nps.application:overview.icelandic.spoken.around.child', - defaultMessage: 'Íslenska er töluð í nærumhverfi barnsins', - description: "Icelandic is spoken in the child's immediate environment", + childLanguage: { + id: 'nps.application:overview.child.language', + defaultMessage: 'Tungumálið sem barninu finnst best að tjá sig á', + description: 'The language the child prefers to express themselves in', }, schoolTitle: { id: 'nps.application:overview.school.title', @@ -829,6 +878,11 @@ export const errorMessages = defineMessages({ defaultMessage: 'Það þarf að velja a.m.k eitt tungumál', description: 'At least one language must be selected', }, + languageRequired: { + id: 'nps.application:error.language.required', + defaultMessage: 'Það þarf að velja tungumál', + description: 'Language must be selected', + }, noChildrenFoundTitle: { id: 'nps.application:error.no.children.found.title', defaultMessage: 'Því miður ert þú ekki með skráð barn á grunnskólaaldri', diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts index 253d8e040091..49e7ef4cbbb2 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -18,7 +18,12 @@ import { SelectOption, SiblingsRow, } from '../types' -import { ApplicationType, ReasonForApplicationOptions } from './constants' +import { + ApplicationType, + ReasonForApplicationOptions, + LanguageEnvironmentOptions, +} from './constants' + import { newPrimarySchoolMessages } from './messages' export const getApplicationAnswers = (answers: Application['answers']) => { @@ -54,25 +59,33 @@ export const getApplicationAnswers = (answers: Application['answers']) => { const siblings = getValueViaPath(answers, 'siblings') as SiblingsRow[] - const nativeLanguage = getValueViaPath( + const languageEnvironment = getValueViaPath( answers, - 'languages.nativeLanguage', + 'languages.languageEnvironment', ) as string - const otherLanguagesSpokenDaily = getValueViaPath( + const signLanguage = getValueViaPath( answers, - 'languages.otherLanguagesSpokenDaily', + 'languages.signLanguage', ) as YesOrNo - const otherLanguages = getValueViaPath( + const language1 = getValueViaPath(answers, 'languages.language1') as string + + const language2 = getValueViaPath(answers, 'languages.language2') as string + + const language3 = getValueViaPath(answers, 'languages.language3') as string + + const language4 = getValueViaPath(answers, 'languages.language4') as string + + const childLanguage = getValueViaPath( answers, - 'languages.otherLanguages', - ) as string[] + 'languages.childLanguage', + ) as string - const icelandicNotSpokenAroundChild = getValueViaPath( + const interpreter = getValueViaPath( answers, - 'languages.icelandicNotSpokenAroundChild', - ) as string[] + 'languages.interpreter', + ) as YesOrNo const acceptFreeSchoolLunch = getValueViaPath( answers, @@ -167,10 +180,14 @@ export const getApplicationAnswers = (answers: Application['answers']) => { reasonForApplicationStreetAddress, reasonForApplicationPostalCode, siblings, - nativeLanguage, - otherLanguagesSpokenDaily, - otherLanguages, - icelandicNotSpokenAroundChild, + languageEnvironment, + language1, + language2, + language3, + language4, + childLanguage, + signLanguage, + interpreter, acceptFreeSchoolLunch, hasSpecialNeeds, specialNeedsType, @@ -337,6 +354,33 @@ export const getCurrentSchoolName = (application: Application) => { .find((organization) => organization?.id === primaryOrgId)?.name } +export const getLanguageEnvironments = () => { + return [ + { + value: LanguageEnvironmentOptions.ONLY_ICELANDIC, + label: newPrimarySchoolMessages.differentNeeds.onlyIcelandicOption, + }, + { + value: LanguageEnvironmentOptions.ICELANDIC_AND_FOREIGN, + label: newPrimarySchoolMessages.differentNeeds.icelandicAndForeignOption, + }, + { + value: LanguageEnvironmentOptions.ONLY_FOREIGN, + label: newPrimarySchoolMessages.differentNeeds.onlyForeignOption, + }, + ] +} + +export const hasForeignLanguages = (answers: FormValue) => { + const { languageEnvironment } = getApplicationAnswers(answers) + + if (!languageEnvironment) { + return false + } + + return languageEnvironment !== LanguageEnvironmentOptions.ONLY_ICELANDIC +} + export const determineNameFromApplicationAnswers = ( application: Application, ) => {