diff --git a/libs/application/templates/new-primary-school/src/fields/Review/index.tsx b/libs/application/templates/new-primary-school/src/fields/Review/index.tsx index ae7abe8c98c0..32e0cb3be0cf 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/index.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/index.tsx @@ -18,6 +18,7 @@ import { getApplicationAnswers } from '../../lib/newPrimarySchoolUtils' import { AllergiesAndIntolerances } from './review-groups/AllergiesAndIntolerances' import { Child } from './review-groups/Child' +import { FreeSchoolMeal } from './review-groups/FreeSchoolMeal' import { Languages } from './review-groups/Languages' import { Parents } from './review-groups/Parents' import { ReasonForApplication } from './review-groups/ReasonForApplication' @@ -166,6 +167,7 @@ export const Review: FC = ({ )} + diff --git a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/FreeSchoolMeal.tsx b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/FreeSchoolMeal.tsx new file mode 100644 index 000000000000..d6e6ce676ffe --- /dev/null +++ b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/FreeSchoolMeal.tsx @@ -0,0 +1,97 @@ +import { coreErrorMessages } from '@island.is/application/core' +import { YES } from '@island.is/application/types' +import { + DataValue, + RadioValue, + ReviewGroup, +} from '@island.is/application/ui-components' +import { + GridColumn, + GridRow, + SkeletonLoader, + Stack, +} from '@island.is/island-ui/core' +import { useLocale } from '@island.is/localization' +import { useFriggOptions } from '../../../hooks/useFriggOptions' +import { OptionsType } from '../../../lib/constants' +import { newPrimarySchoolMessages } from '../../../lib/messages' +import { + getApplicationAnswers, + getSelectedOptionLabel, +} from '../../../lib/newPrimarySchoolUtils' +import { ReviewGroupProps } from './props' + +export const FreeSchoolMeal = ({ + application, + editable, + goToScreen, +}: ReviewGroupProps) => { + const { formatMessage } = useLocale() + const { acceptFreeSchoolLunch, hasSpecialNeeds, specialNeedsType } = + getApplicationAnswers(application.answers) + + const { + options: specialNeedsTypeOptions, + loading, + error, + } = useFriggOptions(OptionsType.ALLERGY) // TODO: Update when Júní has updated key-options + + return ( + goToScreen?.('freeSchoolMeal')} + > + + {acceptFreeSchoolLunch === YES && hasSpecialNeeds === YES && loading ? ( + + ) : ( + <> + + + + + + {acceptFreeSchoolLunch === YES && ( + + + + + + )} + {acceptFreeSchoolLunch === YES && hasSpecialNeeds === YES && ( + + + + + + )} + + )} + + + ) +} diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/freeSchoolMealSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/freeSchoolMealSubSection.ts new file mode 100644 index 000000000000..4eb978679266 --- /dev/null +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/freeSchoolMealSubSection.ts @@ -0,0 +1,98 @@ +import { + buildAlertMessageField, + buildCustomField, + buildMultiField, + buildRadioField, + buildSubSection, +} from '@island.is/application/core' +import { NO, YES } from '@island.is/application/types' +import { OptionsType } from '../../../lib/constants' +import { newPrimarySchoolMessages } from '../../../lib/messages' +import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' + +export const freeSchoolMealSubSection = buildSubSection({ + id: 'freeSchoolMealSubSection', + title: newPrimarySchoolMessages.differentNeeds.freeSchoolMealSubSectionTitle, + children: [ + buildMultiField({ + id: 'freeSchoolMeal', + title: + newPrimarySchoolMessages.differentNeeds.freeSchoolMealSubSectionTitle, + description: + newPrimarySchoolMessages.differentNeeds.freeSchoolMealDescription, + children: [ + buildRadioField({ + id: 'freeSchoolMeal.acceptFreeSchoolLunch', + title: newPrimarySchoolMessages.differentNeeds.acceptFreeSchoolLunch, + width: 'half', + required: true, + options: [ + { + label: newPrimarySchoolMessages.shared.yes, + value: YES, + }, + { + label: newPrimarySchoolMessages.shared.no, + value: NO, + }, + ], + }), + buildRadioField({ + id: 'freeSchoolMeal.hasSpecialNeeds', + title: newPrimarySchoolMessages.differentNeeds.hasSpecialNeeds, + width: 'half', + required: true, + space: 4, + options: [ + { + label: newPrimarySchoolMessages.shared.yes, + value: YES, + }, + { + label: newPrimarySchoolMessages.shared.no, + value: NO, + }, + ], + condition: (answers) => { + const { acceptFreeSchoolLunch } = getApplicationAnswers(answers) + + return acceptFreeSchoolLunch === YES + }, + }), + buildCustomField( + { + id: 'freeSchoolMeal.specialNeedsType', + title: newPrimarySchoolMessages.differentNeeds.specialNeedsType, + component: 'FriggOptionsAsyncSelectField', + condition: (answers) => { + const { acceptFreeSchoolLunch, hasSpecialNeeds } = + getApplicationAnswers(answers) + + return acceptFreeSchoolLunch === YES && hasSpecialNeeds === YES + }, + }, + { + optionsType: OptionsType.ALLERGY, // TODO: Update when Júní has updated key-options + placeholder: + newPrimarySchoolMessages.differentNeeds + .specialNeedsTypePlaceholder, + }, + ), + buildAlertMessageField({ + id: 'freeSchoolMeal.foodAllergiesAlertMessage', + title: newPrimarySchoolMessages.shared.alertTitle, + message: + newPrimarySchoolMessages.differentNeeds.foodAllergiesAlertMessage, + doesNotRequireAnswer: true, + alertType: 'info', + condition: (answers) => { + const { acceptFreeSchoolLunch, hasSpecialNeeds } = + getApplicationAnswers(answers) + + return acceptFreeSchoolLunch === YES && hasSpecialNeeds === YES + }, + }), + ], + }), + ], +}) diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts index 0e60db343854..848467a98ae8 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts @@ -3,6 +3,7 @@ import { ReasonForApplicationOptions } from '../../../lib/constants' import { newPrimarySchoolMessages } from '../../../lib/messages' import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' import { allergiesAndIntolerancesSubSection } from './allergiesAndIntolerancesSubSection' +import { freeSchoolMealSubSection } from './freeSchoolMealSubSection' import { languageSubSection } from './languageSubSection' import { supportSubSection } from './supportSubSection' @@ -16,6 +17,7 @@ export const differentNeedsSection = buildSection({ }, children: [ languageSubSection, + freeSchoolMealSubSection, allergiesAndIntolerancesSubSection, supportSubSection, ], 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 a29b0a7ce246..e08562377831 100644 --- a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts +++ b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts @@ -94,6 +94,7 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< 'clearPlaceOfResidence', 'clearLanguages', 'clearAllergiesAndIntolerances', + 'clearFreeSchoolMeal', ], meta: { name: States.DRAFT, @@ -247,6 +248,20 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< } return context }), + clearFreeSchoolMeal: assign((context) => { + const { application } = context + const { acceptFreeSchoolLunch, hasSpecialNeeds } = + getApplicationAnswers(application.answers) + + if (acceptFreeSchoolLunch !== YES) { + unset(application.answers, 'freeSchoolMeal.hasSpecialNeeds') + unset(application.answers, 'freeSchoolMeal.specialNeedsType') + } + if (hasSpecialNeeds !== YES) { + unset(application.answers, 'freeSchoolMeal.specialNeedsType') + } + return context + }), }, }, 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 9132bca3e2ee..923e3c523ada 100644 --- a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts +++ b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts @@ -150,6 +150,30 @@ export const dataSchema = z.object({ params: errorMessages.languagesRequired, }, ), + freeSchoolMeal: z + .object({ + acceptFreeSchoolLunch: z.enum([YES, NO]), + hasSpecialNeeds: z.string().optional(), + specialNeedsType: z.string().optional(), + }) + .refine( + ({ acceptFreeSchoolLunch, hasSpecialNeeds }) => + acceptFreeSchoolLunch === YES + ? !!hasSpecialNeeds && hasSpecialNeeds.length > 0 + : true, + { + path: ['hasSpecialNeeds'], + }, + ) + .refine( + ({ acceptFreeSchoolLunch, hasSpecialNeeds, specialNeedsType }) => + acceptFreeSchoolLunch === YES && hasSpecialNeeds === YES + ? !!specialNeedsType && specialNeedsType.length > 0 + : true, + { + path: ['specialNeedsType'], + }, + ), allergiesAndIntolerances: z .object({ hasFoodAllergiesOrIntolerances: z.array(z.string()), 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 133c0a41cad3..efe862ac1bf8 100644 --- a/libs/application/templates/new-primary-school/src/lib/messages.ts +++ b/libs/application/templates/new-primary-school/src/lib/messages.ts @@ -449,6 +449,50 @@ export const newPrimarySchoolMessages: MessageDir = { "Icelandic is not spoken in the child's immediate environment", }, + // Free school meal + freeSchoolMealSubSectionTitle: { + id: 'nps.application:different.needs.free.school.meal.sub.section.title', + defaultMessage: 'Gjaldfrjáls skólamáltíð', + description: 'Free school meal ', + }, + freeSchoolMealDescription: { + id: 'nps.application:different.needs.free.school.meal.description', + defaultMessage: + 'Barninu stendur til boða gjaldfrjáls skólamáltíð. Til þess að skólinn geti mætt fæðuþörfum barnsins á sama tíma og spornað er við matarsóun þurfum við upplýsingar er varða matarumhverfi barnsins.', + description: + "The child is entitled to a free school meal. In order for the school to be able to meet the child's nutritional needs while at the same time preventing food waste, we need information about the child's food environment.", + }, + acceptFreeSchoolLunch: { + id: 'nps.application:different.needs.free.school.meal.accept.free.school.lunch', + defaultMessage: + 'Viltu þiggja gjaldfrjálsa máltíð í hádeginu fyrir barnið þitt?', + description: + 'Would you like to accept a free school lunch for your child?', + }, + hasSpecialNeeds: { + id: 'nps.application:different.needs.free.school.meal.has.special.needs', + defaultMessage: + 'Er barnið með sérþarfir sem óskað er eftir að tekið sé tillit til?', + description: + 'Does the child have special needs that you wish to be taken into account?', + }, + specialNeedsType: { + id: 'nps.application:different.needs.free.school.meal.special.needs.type', + defaultMessage: 'Tegund', + description: 'Type', + }, + specialNeedsTypePlaceholder: { + id: 'nps.application:different.needs.free.school.meal.special.needs.type.placeholder', + defaultMessage: 'Veldu tegund', + description: 'Select type', + }, + foodAllergiesAlertMessage: { + id: 'nps.application:different.needs.free.school.meal.food.allergies.alert.message', + defaultMessage: 'Spurt er um matarofnæmi undir ofnæmi og óþól', + description: + 'Food allergies are addressed in the allergies and intolerances section', + }, + // Allergies and intolerances allergiesAndIntolerancesSubSectionTitle: { id: 'nps.application:different.needs.allergies.and.intolerances.sub.section.title', 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 df8a63e4a642..b2f2c3613852 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -75,6 +75,21 @@ export const getApplicationAnswers = (answers: Application['answers']) => { 'languages.icelandicNotSpokenAroundChild', ) as string[] + const acceptFreeSchoolLunch = getValueViaPath( + answers, + 'freeSchoolMeal.acceptFreeSchoolLunch', + ) as YesOrNo + + const hasSpecialNeeds = getValueViaPath( + answers, + 'freeSchoolMeal.hasSpecialNeeds', + ) as YesOrNo + + const specialNeedsType = getValueViaPath( + answers, + 'freeSchoolMeal.specialNeedsType', + ) as string + const hasFoodAllergiesOrIntolerances = getValueViaPath( answers, 'allergiesAndIntolerances.hasFoodAllergiesOrIntolerances', @@ -158,6 +173,9 @@ export const getApplicationAnswers = (answers: Application['answers']) => { otherLanguagesSpokenDaily, otherLanguages, icelandicNotSpokenAroundChild, + acceptFreeSchoolLunch, + hasSpecialNeeds, + specialNeedsType, hasFoodAllergiesOrIntolerances, foodAllergiesOrIntolerances, hasOtherAllergies,