Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(new-primary-school): Implement school meal page #17513

Merged
merged 5 commits into from
Jan 16, 2025

Conversation

veronikasif
Copy link
Member

@veronikasif veronikasif commented Jan 15, 2025

[TS-954] Implement school meal page

What

Specify what you're trying to achieve

Why

Specify why you need to achieve this

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Added a comprehensive section for free school meal options in the primary school application.
    • Introduced new form fields for accepting free school lunch and declaring special needs.
    • Enhanced review screen with detailed free school meal information.
  • Documentation

    • Added localized messages explaining free school meal entitlement and special needs options.
  • Improvements

    • Implemented conditional validation for free school meal and special needs information.
    • Added state management logic to handle free school meal-related answers.

@veronikasif veronikasif requested a review from a team as a code owner January 15, 2025 14:40
Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Walkthrough

This pull request introduces a feature for managing free school meal options in a primary school application. The changes encompass multiple files to implement a new subsection in the application form that captures details about free school lunch acceptance and special needs. This includes the addition of a review component, state management actions, data schema validation, and localized messages to support the new functionality.

Changes

File Change Summary
libs/application/templates/new-primary-school/src/fields/Review/index.tsx Added import and rendering of FreeSchoolMeal component in review screen
libs/application/templates/new-primary-school/src/fields/Review/review-groups/FreeSchoolMeal.tsx New component for displaying free school meal review details
libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/freeSchoolMealSubSection.ts Created subsection for free school meal options with conditional fields
libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts Imported and added freeSchoolMealSubSection to different needs section
libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts Added clearFreeSchoolMeal action for managing application state
libs/application/templates/new-primary-school/src/lib/dataSchema.ts Introduced new freeSchoolMeal schema with validation rules
libs/application/templates/new-primary-school/src/lib/messages.ts Added localized messages for free school meal section
libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts Extended getApplicationAnswers to include free school meal variables

Sequence Diagram

sequenceDiagram
    participant User
    participant Form
    participant FreeSchoolMealSection
    participant StateManager

    User->>Form: Starts application
    Form->>FreeSchoolMealSection: Render free school meal fields
    FreeSchoolMealSection-->>User: Display acceptance and special needs options
    User->>FreeSchoolMealSection: Select options
    FreeSchoolMealSection->>StateManager: Update application state
    StateManager->>Form: Validate input
    Form-->>User: Confirm or request corrections
Loading

Possibly related PRs

Suggested labels

deploy-feature

Suggested reviewers

  • sigruntg
  • HjorturJ

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@veronikasif veronikasif added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Jan 15, 2025
@datadog-island-is
Copy link

datadog-island-is bot commented Jan 15, 2025

Datadog Report

Branch report: feat/new-primary-school-school-meal-page
Commit report: 5edb563
Test service: api

✅ 0 Failed, 4 Passed, 0 Skipped, 3.1s Total Time
➡️ Test Sessions change in coverage: 1 no change

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (6)
libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts (1)

20-20: Consider reordering subsections for better user experience.

The placement of freeSchoolMealSubSection between languageSubSection and allergiesAndIntolerancesSubSection might not provide the most intuitive flow, as food allergies are closely related to school meals. Consider moving it after allergiesAndIntolerancesSubSection for a more logical grouping.

 children: [
   languageSubSection,
-  freeSchoolMealSubSection,
   allergiesAndIntolerancesSubSection,
+  freeSchoolMealSubSection,
   supportSubSection,
 ],
libs/application/templates/new-primary-school/src/fields/Review/review-groups/FreeSchoolMeal.tsx (1)

39-96: Consider adding loading states for all conditional renders.

The loading state is only shown when both acceptFreeSchoolLunch and hasSpecialNeeds are YES. Consider showing loading states for each conditional block to improve user experience during data fetching.

 return (
   <ReviewGroup
     isEditable={editable}
     editAction={() => goToScreen?.('freeSchoolMeal')}
   >
     <Stack space={2}>
-      {acceptFreeSchoolLunch === YES && hasSpecialNeeds === YES && loading ? (
+      {loading ? (
         <SkeletonLoader height={40} width="80%" borderRadius="large" />
       ) : (
         <>
           <GridRow>
libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/freeSchoolMealSubSection.ts (1)

82-94: Consider moving the alert message before the special needs type field.

The alert message about food allergies should appear before asking for the special needs type to better inform the user's selection.

       children: [
         buildRadioField({...}),
         buildRadioField({...}),
+        buildAlertMessageField({
+          id: 'freeSchoolMeal.foodAlergiesAlertMessage',
+          title: newPrimarySchoolMessages.shared.alertTitle,
+          message:
+            newPrimarySchoolMessages.differentNeeds.foodAlergiesAlertMessage,
+          doesNotRequireAnswer: true,
+          alertType: 'info',
+          condition: (answers) => {
+            const { acceptFreeSchoolLunch, hasSpecialNeeds } =
+              getApplicationAnswers(answers)
+
+            return acceptFreeSchoolLunch === YES && hasSpecialNeeds === YES
+          },
+        }),
         buildCustomField({...}),
-        buildAlertMessageField({...}),
       ],
libs/application/templates/new-primary-school/src/fields/Review/index.tsx (1)

170-170: Consider grouping related review sections.

The FreeSchoolMeal component should be placed after AllergiesAndIntolerances for a more logical flow, as they are related concerns.

         <School {...childProps} />
         <Languages {...childProps} />
-        <FreeSchoolMeal {...childProps} />
         <AllergiesAndIntolerances {...childProps} />
+        <FreeSchoolMeal {...childProps} />
         <Support {...childProps} />
libs/application/templates/new-primary-school/src/lib/dataSchema.ts (1)

157-180: Add error messages to refinement rules and simplify the second refinement.

The schema structure is well-defined, but the refinement rules could be improved:

  1. Add error messages to help users understand validation failures
  2. Simplify the second refinement by combining conditions
   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'],
+        params: errorMessages.hasSpecialNeedsRequired,
       },
     )
     .refine(
-      ({ acceptFreeSchoolLunch, hasSpecialNeeds, specialNeedsType }) =>
-        acceptFreeSchoolLunch === YES && hasSpecialNeeds === YES
-          ? !!specialNeedsType && specialNeedsType.length > 0
-          : true,
+      ({ hasSpecialNeeds, specialNeedsType }) =>
+        hasSpecialNeeds === YES
+          ? !!specialNeedsType && specialNeedsType.length > 0
+          : true,
       {
         path: ['specialNeedsType'],
+        params: errorMessages.specialNeedsTypeRequired,
       },
     ),
libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts (1)

251-264: Add a descriptive comment for the clearFreeSchoolMeal action.

The implementation is correct, but adding a comment would improve code maintainability by explaining the purpose and conditions of the field clearing logic.

+      // Clear special needs fields if free school lunch is not accepted
+      // Clear special needs type if special needs is not indicated
       clearFreeSchoolMeal: assign((context) => {
         const { application } = context
         const { acceptFreeSchoolLunch, hasSpecialNeeds } =
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90eb567 and fdb54a9.

📒 Files selected for processing (8)
  • libs/application/templates/new-primary-school/src/fields/Review/index.tsx (2 hunks)
  • libs/application/templates/new-primary-school/src/fields/Review/review-groups/FreeSchoolMeal.tsx (1 hunks)
  • libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/freeSchoolMealSubSection.ts (1 hunks)
  • libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts (2 hunks)
  • libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts (2 hunks)
  • libs/application/templates/new-primary-school/src/lib/dataSchema.ts (1 hunks)
  • libs/application/templates/new-primary-school/src/lib/messages.ts (1 hunks)
  • libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/new-primary-school/src/fields/Review/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/new-primary-school/src/lib/dataSchema.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/new-primary-school/src/fields/Review/review-groups/FreeSchoolMeal.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/freeSchoolMealSubSection.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/new-primary-school/src/lib/messages.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
📓 Learnings (1)
libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts (1)
Learnt from: veronikasif
PR: island-is/island.is#17477
File: libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts:82-115
Timestamp: 2025-01-13T14:20:07.540Z
Learning: In the new-primary-school application template, the user prefers to keep the type casting approach for extracting allergies data from application answers, rather than introducing additional type safety measures.
🔇 Additional comments (9)
libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts (1)

6-6: LGTM!

The import statement follows the established pattern and maintains consistency with other imports.

libs/application/templates/new-primary-school/src/fields/Review/review-groups/FreeSchoolMeal.tsx (2)

1-22: LGTM!

The imports are well-organized and follow the project's conventions. Props are properly typed using the shared ReviewGroupProps interface.


33-37: Update the options type for special needs.

The TODO comment indicates that the wrong options type is being used (ALLERGY). This should be updated when the correct key-options are available.

✅ Verification successful

Temporary usage of ALLERGY options type is already tracked

The review comment is correct in identifying the issue. However, this is already being tracked by TODO comments, indicating that the team is aware and waiting for proper key-options to be added by Júní. No immediate action is needed until the new options are available.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are other components using ALLERGY options type
rg "OptionsType\.ALLERGY" -A 2 -B 2

Length of output: 3088


Script:

#!/bin/bash
# Check for all available OptionsType values
rg "OptionsType\." -g "!*.test.*" -g "!*.spec.*" -g "!*.d.ts" -A 0 -B 0 | sort -u

# Check for recent changes in options-related files
fd "options?" --type f --exec ls -l {} \;

Length of output: 6749

libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/freeSchoolMealSubSection.ts (2)

1-12: LGTM!

The imports are well-organized and follow the project's conventions.


75-75: Update the options type for special needs.

The TODO comment indicates that the wrong options type is being used (ALLERGY). This should be updated when the correct key-options are available.

libs/application/templates/new-primary-school/src/fields/Review/index.tsx (1)

21-21: LGTM!

The import statement follows the established pattern and maintains consistency with other review group imports.

libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts (1)

97-97: LGTM!

The clearFreeSchoolMeal action is correctly added to the exit array, following the established pattern of other clear actions.

libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts (2)

82-96: LGTM!

The implementation follows the established pattern and correctly uses type casting as preferred in this codebase.


180-182: LGTM!

The new variables are correctly added to the return object, maintaining alphabetical order and consistent structure.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 15, 2025
Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 27.27273% with 32 lines in your changes missing coverage. Please review.

Project coverage is 35.63%. Comparing base (374bc28) to head (56d5559).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...src/fields/Review/review-groups/FreeSchoolMeal.tsx 0.00% 16 Missing ⚠️
.../differentNeedsSection/freeSchoolMealSubSection.ts 0.00% 10 Missing ⚠️
...templates/new-primary-school/src/lib/dataSchema.ts 0.00% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17513      +/-   ##
==========================================
+ Coverage   35.60%   35.63%   +0.03%     
==========================================
  Files        7016     7017       +1     
  Lines      150332   150191     -141     
  Branches    42947    42921      -26     
==========================================
- Hits        53533    53528       -5     
+ Misses      96799    96663     -136     
Flag Coverage Δ
api 3.33% <ø> (ø)
application-system-api 38.70% <0.00%> (-0.02%) ⬇️
application-template-api-modules 27.56% <ø> (ø)
application-templates-new-primary-school 21.21% <27.27%> (+0.19%) ⬆️
application-ui-shell 22.04% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...tes/new-primary-school/src/fields/Review/index.tsx 0.00% <ø> (ø)
...ewPrimarySchoolForm/differentNeedsSection/index.ts 0.00% <ø> (ø)
...primary-school/src/lib/NewPrimarySchoolTemplate.ts 75.00% <100.00%> (+3.57%) ⬆️
...n/templates/new-primary-school/src/lib/messages.ts 100.00% <ø> (ø)
...ew-primary-school/src/lib/newPrimarySchoolUtils.ts 72.72% <100.00%> (+0.96%) ⬆️
...templates/new-primary-school/src/lib/dataSchema.ts 16.66% <0.00%> (-2.09%) ⬇️
.../differentNeedsSection/freeSchoolMealSubSection.ts 0.00% <0.00%> (ø)
...src/fields/Review/review-groups/FreeSchoolMeal.tsx 0.00% <0.00%> (ø)

... and 16 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 374bc28...56d5559. Read the comment docs.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
libs/application/templates/new-primary-school/src/lib/dataSchema.ts (1)

159-176: Add error messages to refinement rules.

The validation rules are logically correct, but they lack error messages to guide users when validation fails.

Add error messages to both refinement rules:

     .refine(
       ({ acceptFreeSchoolLunch, hasSpecialNeeds }) =>
         acceptFreeSchoolLunch === YES
           ? !!hasSpecialNeeds && hasSpecialNeeds.length > 0
           : true,
       {
         path: ['hasSpecialNeeds'],
+        params: errorMessages.specialNeedsRequired,
       },
     )
     .refine(
       ({ acceptFreeSchoolLunch, hasSpecialNeeds, specialNeedsType }) =>
         acceptFreeSchoolLunch === YES && hasSpecialNeeds === YES
           ? !!specialNeedsType && specialNeedsType.length > 0
           : true,
       {
         path: ['specialNeedsType'],
+        params: errorMessages.specialNeedsTypeRequired,
       },
     ),
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fdb54a9 and fe851f4.

📒 Files selected for processing (4)
  • libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/freeSchoolMealSubSection.ts (1 hunks)
  • libs/application/templates/new-primary-school/src/lib/dataSchema.ts (1 hunks)
  • libs/application/templates/new-primary-school/src/lib/messages.ts (1 hunks)
  • libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts
  • libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/freeSchoolMealSubSection.ts
🧰 Additional context used
📓 Path-based instructions (2)
libs/application/templates/new-primary-school/src/lib/dataSchema.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/new-primary-school/src/lib/messages.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (1)
libs/application/templates/new-primary-school/src/lib/messages.ts (1)

452-494: LGTM! The message definitions are well-structured.

The new messages for the free school meal section are properly defined with:

  • Consistent ID naming pattern
  • Clear descriptions in English
  • Appropriate translations in Icelandic

Copy link
Member

@helgifr helgifr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants