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(old-age-pension): Show conclusion page based on income plan status #17087

Merged
merged 10 commits into from
Dec 5, 2024

Conversation

ylfahfa
Copy link
Member

@ylfahfa ylfahfa commented Nov 29, 2024

...

Attach a link to issue if relevant

What

Specify what you're trying to achieve

Why

Specify why you need to achieve this

Screenshots / Gifs

Hs no income plan:

Screenshot 2024-11-29 at 11 25 44

Has income plan:

Screenshot 2024-11-29 at 11 26 52

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

    • Introduced a new API for fetching the latest income plan in the Social Insurance Administration module.
    • Added a new Conclusion component that dynamically displays messages based on income plan status.
    • Integrated a new data provider for the latest income plan into the prerequisites form.
    • Enhanced user messaging regarding application status in the old-age pension form.
  • Bug Fixes

    • Streamlined the conclusion section of the old-age pension form for clarity and functionality.

@ylfahfa ylfahfa requested a review from a team as a code owner November 29, 2024 11:22
Copy link
Contributor

coderabbitai bot commented Nov 29, 2024

Walkthrough

The changes in this pull request introduce a new API export for the Social Insurance Administration module, specifically the SocialInsuranceAdministrationLatestIncomePlan constant. Additionally, a new React component named Conclusion is added, which dynamically renders UI elements based on the hasIncomePlanStatus property. Various files are updated to incorporate this new data provider and component, including modifications to forms and message definitions to enhance user feedback and application status updates.

Changes

File Change Summary
libs/application/templates/social-insurance-administration/old-age-pension/src/dataProviders/index.ts Added new API export: SocialInsuranceAdministrationLatestIncomePlan.
libs/application/templates/social-insurance-administration/old-age-pension/src/fields/Conclusion/index.tsx Introduced new React component Conclusion that renders UI based on hasIncomePlanStatus.
libs/application/templates/social-insurance-administration/old-age-pension/src/fields/index.ts Added export for the new Conclusion component.
libs/application/templates/social-insurance-administration/old-age-pension/src/forms/OldAgePensionForm.ts Refactored conclusion handling by replacing buildFormConclusionSection with buildSection for the conclusion part of the form.
libs/application/templates/social-insurance-administration/old-age-pension/src/forms/Prerequisites.ts Added new data provider SocialInsuranceAdministrationLatestIncomePlan to the PrerequisitesForm.
libs/application/templates/social-insurance-administration/old-age-pension/src/lib/OldAgePensionTemplate.ts Integrated new import for SocialInsuranceAdministrationLatestIncomePlan into the OldAgePensionTemplate configuration.
libs/application/templates/social-insurance-administration/old-age-pension/src/lib/messages.ts Added new messages title and alertMessage under conclusionScreen in oldAgePensionFormMessage.
libs/application/templates/social-insurance-administration/old-age-pension/src/lib/oldAgePensionUtils.ts Introduced new variable hasIncomePlanStatus in getApplicationExternalData function.

Possibly related PRs

Suggested labels

automerge, deploy-feature

Suggested reviewers

  • Toti91
  • birkirkristmunds

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 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.

Copy link

codecov bot commented Nov 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 35.82%. Comparing base (69c02b2) to head (7f06f35).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17087      +/-   ##
==========================================
+ Coverage   35.74%   35.82%   +0.08%     
==========================================
  Files        6925     6936      +11     
  Lines      147559   147519      -40     
  Branches    42010    42262     +252     
==========================================
+ Hits        52745    52854     +109     
+ Misses      94814    94665     -149     
Flag Coverage Δ
api 3.33% <ø> (ø)
application-system-api 38.77% <50.00%> (+<0.01%) ⬆️
application-template-api-modules 27.80% <100.00%> (+<0.01%) ⬆️
application-ui-shell 22.48% <ø> (ø)

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

Files with missing lines Coverage Δ
...nce-administration/income-plan/src/lib/messages.ts 100.00% <ø> (ø)
...tration/old-age-pension/src/dataProviders/index.ts 100.00% <100.00%> (ø)
...n/old-age-pension/src/lib/OldAgePensionTemplate.ts 15.15% <ø> (ø)
...administration/old-age-pension/src/lib/messages.ts 100.00% <ø> (ø)
...tion/old-age-pension/src/lib/oldAgePensionUtils.ts 34.54% <100.00%> (+0.29%) ⬆️

... and 336 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 69c02b2...7f06f35. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 29, 2024

Datadog Report

All test runs 814cb4b 🔗

4 Total Test Services: 0 Failed, 4 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.07%), 8 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.89s 1 no change Link
application-system-api 0 0 0 46 0 2m 27.72s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 41.46s 1 no change Link
application-ui-shell 0 0 0 74 0 38.06s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • application-templates-social-insurance-administration-old-age-pension - jest 32.78% (-0.07%) - Details

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: 2

🧹 Outside diff range and nitpick comments (7)
libs/application/templates/social-insurance-administration/old-age-pension/src/dataProviders/index.ts (1)

38-42: Add JSDoc documentation for the new API export.

Consider adding JSDoc documentation to describe the purpose and return type of this API, which will improve maintainability and help other developers understand its usage.

+/**
+ * Retrieves the latest income plan for the applicant from the Social Insurance Administration.
+ * Used to determine the conclusion page display in the old-age pension application.
+ */
export const SocialInsuranceAdministrationLatestIncomePlan = defineTemplateApi({
  action: 'getLatestIncomePlan',
  externalDataId: 'socialInsuranceAdministrationLatestIncomePlan',
  namespace: 'SocialInsuranceAdministration',
})
libs/application/templates/social-insurance-administration/old-age-pension/src/fields/Conclusion/index.tsx (2)

21-30: Add error handling for external data fetching.

While the code works, it would be more robust to handle potential errors when fetching external data. Consider adding error boundaries or fallback UI for cases where application.externalData might be undefined.

- const { hasIncomePlanStatus } = getApplicationExternalData(
-   application.externalData,
- )
+ const { hasIncomePlanStatus } = getApplicationExternalData(
+   application.externalData ?? {}
+ )

48-87: Reduce code duplication in conditional rendering.

The AccordionCard and its contents are largely duplicated between the two conditions. Consider extracting the common UI elements into a separate component.

const ConclusionCard: FC<{ title: string }> = ({ title }) => (
  <AccordionCard
    id="conclusion-card"
    label={title}
    startExpanded={true}
  >
    <Box marginBottom={4}>
      <Markdown>
        {formatMessage(
          oldAgePensionFormMessage.conclusionScreen.nextStepsText,
        )}
      </Markdown>
    </Box>
    <BulletList space="gutter" type="ul">
      <Markdown>
        {formatMessage(
          oldAgePensionFormMessage.conclusionScreen.bulletList,
        )}
      </Markdown>
    </BulletList>
  </AccordionCard>
)

Also applies to: 103-138

libs/application/templates/social-insurance-administration/old-age-pension/src/forms/Prerequisites.ts (1)

167-170: Consider adding configuration options for better reusability.

The data provider is added correctly, but unlike some other providers (e.g., UserProfileApi), it lacks configuration options that might be useful for reuse in different contexts.

Consider adding relevant configuration options like:

 buildDataProviderItem({
   provider: SocialInsuranceAdministrationLatestIncomePlan,
   title: '',
+  subTitle: oldAgePensionFormMessage.pre.incomePlanDataDescription,
+  loadingMessage: oldAgePensionFormMessage.pre.loadingIncomePlan,
+  failureMessage: oldAgePensionFormMessage.pre.failedToLoadIncomePlan,
 }),
libs/application/templates/social-insurance-administration/old-age-pension/src/lib/oldAgePensionUtils.ts (2)

257-260: Consider adding JSDoc documentation for the new field.

The implementation looks good and follows the existing pattern. Consider adding JSDoc documentation to describe the purpose and possible values of hasIncomePlanStatus.

+/** Status of the latest income plan for the applicant */
 const hasIncomePlanStatus = getValueViaPath(
   externalData,
   'socialInsuranceAdministrationLatestIncomePlan.data.status',
 ) as string

257-260: Consider using a more specific type for income plan status.

Instead of using a generic string type, consider defining an enum or union type for the possible status values. This would provide better type safety and self-documentation.

type IncomePlanStatus = 'PENDING' | 'APPROVED' | 'REJECTED' | 'NOT_FOUND';

const hasIncomePlanStatus = getValueViaPath(
  externalData,
  'socialInsuranceAdministrationLatestIncomePlan.data.status',
) as IncomePlanStatus

Also applies to: 276-276

libs/application/templates/social-insurance-administration/old-age-pension/src/lib/messages.ts (1)

264-275: LGTM! Consider enhancing the message descriptions.

The new messages are well-structured and properly internationalized. However, the descriptions could be more detailed to provide better context for translators.

Consider updating the descriptions to be more specific:

     title: {
       id: 'oap.application:conclusionScreen.expandableDescriptionField.title',
       defaultMessage: 'Hvað gerist næst?',
-      description: 'What happens next',
+      description: 'Title for the section explaining next steps after submitting the pension application',
     },
     alertMessage: {
       id: 'oap.application:conclusionScreen.alertMessage',
       defaultMessage:
         'Umsókn um ellilífeyri hefur verið send til Tryggingastofnunar',
-      description:
-        'An application for old age pension has been sent to the Social Insurance Administration',
+      description:
+        'Confirmation message shown to users after successfully submitting their old age pension application',
     },
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 467e050 and 1f7c74c.

📒 Files selected for processing (8)
  • libs/application/templates/social-insurance-administration/old-age-pension/src/dataProviders/index.ts (1 hunks)
  • libs/application/templates/social-insurance-administration/old-age-pension/src/fields/Conclusion/index.tsx (1 hunks)
  • libs/application/templates/social-insurance-administration/old-age-pension/src/fields/index.ts (1 hunks)
  • libs/application/templates/social-insurance-administration/old-age-pension/src/forms/OldAgePensionForm.ts (1 hunks)
  • libs/application/templates/social-insurance-administration/old-age-pension/src/forms/Prerequisites.ts (2 hunks)
  • libs/application/templates/social-insurance-administration/old-age-pension/src/lib/OldAgePensionTemplate.ts (2 hunks)
  • libs/application/templates/social-insurance-administration/old-age-pension/src/lib/messages.ts (1 hunks)
  • libs/application/templates/social-insurance-administration/old-age-pension/src/lib/oldAgePensionUtils.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
libs/application/templates/social-insurance-administration/old-age-pension/src/dataProviders/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/social-insurance-administration/old-age-pension/src/fields/Conclusion/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/social-insurance-administration/old-age-pension/src/fields/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/social-insurance-administration/old-age-pension/src/forms/OldAgePensionForm.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/social-insurance-administration/old-age-pension/src/forms/Prerequisites.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/social-insurance-administration/old-age-pension/src/lib/OldAgePensionTemplate.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/social-insurance-administration/old-age-pension/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."
libs/application/templates/social-insurance-administration/old-age-pension/src/lib/oldAgePensionUtils.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 (8)
libs/application/templates/social-insurance-administration/old-age-pension/src/fields/index.ts (2)

5-5: LGTM! Export follows the established pattern.

The new export for Conclusion uses named export syntax, which is consistent with most other exports in this file.


Line range hint 1-5: Consider standardizing export patterns for better tree-shaking.

Two components use default exports while others use named exports. Consider converting EmployersOverview and EmployersRatioMonthly to named exports for consistency and better tree-shaking support.

Also, verify that any TypeScript types/interfaces from the Conclusion component that might be needed by consumers are being exported.

libs/application/templates/social-insurance-administration/old-age-pension/src/fields/Conclusion/index.tsx (2)

1-20: LGTM! Well-organized imports following best practices.

The imports are properly structured and support effective tree-shaking. The TypeScript types are correctly imported from their respective modules.


89-139: LGTM! Success state implementation is correct.

The implementation correctly handles the case when an income plan exists, showing appropriate success messages and linking to the service portal.

libs/application/templates/social-insurance-administration/old-age-pension/src/forms/Prerequisites.ts (1)

38-38: Verify the reusability of the imported data provider.

Since this is in the libs directory, let's ensure the data provider is properly exported and reusable across different NextJS apps.

✅ Verification successful

The data provider is properly exported and reused across templates

The verification shows that SocialInsuranceAdministrationLatestIncomePlan is:

  • Properly exported from data providers in both old-age-pension and income-plan templates
  • Follows the same implementation pattern using defineTemplateApi
  • Consistently used across multiple components within both templates
  • Maintains consistent naming and configuration across usages
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the data provider is properly exported and potentially reused
ast-grep --pattern 'export const SocialInsuranceAdministrationLatestIncomePlan'

# Check for other potential usages
rg "SocialInsuranceAdministrationLatestIncomePlan" --type ts

Length of output: 3280

libs/application/templates/social-insurance-administration/old-age-pension/src/lib/OldAgePensionTemplate.ts (2)

101-101: LGTM! API integration follows established patterns

The SocialInsuranceAdministrationLatestIncomePlan API is correctly integrated into the PREREQUISITES state configuration, following the same pattern as other Social Insurance Administration APIs. This addition aligns with the PR objective to show the conclusion page based on income plan status.


41-41: Verify the reusability of the imported API

The import follows TypeScript conventions and maintains proper organization. Let's verify its reusability across different NextJS apps.

✅ Verification successful

Let me gather more information about the API definition to ensure it's properly implemented.


The imported API is properly defined and reused across templates

The verification shows that SocialInsuranceAdministrationLatestIncomePlan is:

  • Correctly defined as a reusable template API with proper namespace and action
  • Used consistently in both old-age pension and income plan templates
  • Follows the same pattern as other social insurance administration APIs
  • Properly imported and integrated in the Prerequisites forms
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the API is defined as a reusable module
# and verify its usage across the codebase

# Check API definition
ast-grep --pattern 'defineTemplateApi({
  action: "getLatestIncomePlan",
  $$$
})'

# Check for other potential usages
rg "SocialInsuranceAdministrationLatestIncomePlan" --type ts

Length of output: 1793


Script:

#!/bin/bash
# Check the API definition in both locations
fd "index.ts" --type f --exec cat {} \; | rg -A 10 "SocialInsuranceAdministrationLatestIncomePlan = defineTemplateApi"

Length of output: 1085

libs/application/templates/social-insurance-administration/old-age-pension/src/forms/OldAgePensionForm.ts (1)

790-815: Implementation of the conclusionSection is appropriate and aligns with coding guidelines

The addition of the conclusionSection with dynamic title handling based on hasIncomePlanStatus enhances the user experience. The use of buildSection and buildMultiField is consistent with the application's structure.

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!

@ylfahfa ylfahfa added the automerge Merge this PR as soon as all checks pass label Dec 5, 2024
@kodiakhq kodiakhq bot merged commit 55aacf7 into main Dec 5, 2024
42 checks passed
@kodiakhq kodiakhq bot deleted the feat/dynamic-overview-page branch December 5, 2024 11:39
thorhildurt pushed a commit that referenced this pull request Dec 11, 2024
…us (#17087)

* start changes to conclusion page

* add component for dynamic conclusion page

* format

* amendments after review plus small text change

* remove unused import

* chore: nx format:write update dirty files

---------

Co-authored-by: andes-it <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants