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

fix(aod): finishups #15853

Merged
merged 4 commits into from
Sep 2, 2024
Merged

fix(aod): finishups #15853

merged 4 commits into from
Sep 2, 2024

Conversation

albinagu
Copy link
Member

@albinagu albinagu commented Sep 2, 2024

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 required fields for firearm applicant forms to enhance validation.
    • Introduced new fields for displaying firearm applicant information based on updated conditions.
    • Enhanced localization with new message definitions for firearm applicants.
    • Improved SMS notifications with contextual links for better user guidance.
  • Bug Fixes

    • Improved error handling and clarity for validation messages related to firearm applicants.
  • Documentation

    • Updated default messages for better user understanding in the application interface.

@albinagu albinagu requested a review from a team as a code owner September 2, 2024 15:19
Copy link
Contributor

coderabbitai bot commented Sep 2, 2024

Walkthrough

The changes involve enhancements to the FirearmApplicant component, including stricter validation rules for form fields, improved error handling, and modifications to the display logic for firearm applicant information. A new field for indicating whether the applicant has firearms has been added to the data schema, along with updates to message definitions for localization. These adjustments collectively improve the user interface and data handling capabilities of the application.

Changes

Files Change Summary
libs/application/templates/announcement-of-death/src/fields/FirearmApplicant/index.tsx
libs/application/templates/announcement-of-death/src/forms/overviewSections.ts
Enhanced validation and error handling in the FirearmApplicant component; simplified logic for displaying the firearmApplicant section and added new fields.
libs/application/templates/announcement-of-death/src/lib/dataSchema.ts Introduced a new hadFirearms field as an enumeration and refined validation for the nationalId field to ensure it corresponds to a person.
libs/application/templates/announcement-of-death/src/lib/messages.ts Added a new message definition for firearmsApplicant and modified the default message for firearmsApplicantOverviewHeader for localization purposes.
libs/application/template-api-modules/src/lib/modules/templates/announcement-of-death/announcement-of-death.service.ts
libs/application/template-api-modules/src/lib/modules/templates/announcement-of-death/smsGenerators/requestReviewSms.ts
Updated AnnouncementOfDeathService to include configuration handling and modified SMS generation logic to include a link for better context in notifications.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

@albinagu albinagu added the automerge Merge this PR as soon as all checks pass label Sep 2, 2024
Copy link

codecov bot commented Sep 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.91%. Comparing base (47779ce) to head (d643539).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #15853      +/-   ##
==========================================
- Coverage   36.94%   36.91%   -0.03%     
==========================================
  Files        6680     6680              
  Lines      136459   136464       +5     
  Branches    38745    38763      +18     
==========================================
- Hits        50409    50378      -31     
- Misses      86050    86086      +36     
Flag Coverage Δ
api 3.39% <ø> (ø)
application-system-api 41.75% <ø> (ø)
application-template-api-modules 23.66% <ø> (-0.02%) ⬇️
application-ui-shell 21.17% <ø> (ø)

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

see 10 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 47779ce...d643539. 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: 0

Outside diff range, codebase verification and nitpick comments (8)
libs/application/templates/announcement-of-death/src/lib/dataSchema.ts (1)

Line range hint 1-124: Ensure optimal reusability and TypeScript usage.

The changes adhere well to the additional instructions for libs files:

  1. The schema is modular and potentially reusable across different NextJS apps.
  2. TypeScript is used effectively for type definitions.
  3. Specific imports and modular structure support effective tree-shaking.

To further improve TypeScript usage and reusability, consider exporting the FirearmApplicant type:

export type FirearmApplicant = z.TypeOf<typeof dataSchema.shape.firearmApplicant>;

This would allow other parts of the application to import and use this type directly.

libs/application/templates/announcement-of-death/src/fields/FirearmApplicant/index.tsx (4)

110-114: Approve changes with a minor suggestion for error handling

The addition of the required attribute and the use of getErrorViaPath for error handling are good improvements. However, consider simplifying the error path for consistency with other fields.

Consider updating the error path to match the field name structure:

- getErrorViaPath(errors, 'firearmApplicant.nationalId') ||
+ getErrorViaPath(errors, fieldNames.firearmApplicantNationalId) ||

This change would make the error handling consistent across all fields and easier to maintain.


140-143: Approve changes with a minor suggestion for error handling consistency

The addition of the required attribute and the use of getErrorViaPath for error handling are good improvements.

For consistency with the previous suggestion, consider updating the error path:

- getErrorViaPath(errors, 'firearmApplicant.phone') || undefined
+ getErrorViaPath(errors, fieldNames.firearmApplicantPhone) || undefined

This change would make the error handling consistent across all fields and easier to maintain.


151-154: Approve changes with a minor suggestion for error handling consistency

The addition of the required attribute and the use of getErrorViaPath for error handling are good improvements.

For consistency with the previous suggestions, consider updating the error path:

- getErrorViaPath(errors, 'firearmApplicant.email') || undefined
+ getErrorViaPath(errors, fieldNames.firearmApplicantEmail) || undefined

This change would make the error handling consistent across all fields and easier to maintain.


Line range hint 1-160: Enhance TypeScript usage for better type safety

The component generally adheres to the guidelines for library files, including reusability and TypeScript usage. However, there's room for improvement in type definitions.

Consider the following enhancements:

  1. Define a type for the application prop in FirearmApplicantBaseProps:
interface FirearmApplicantBaseProps extends FieldBaseProps {
  errors: FieldErrors<FieldValues>;
  application: Application; // Define the Application type
}
  1. Use more specific types for the watch function results:
const nationalId = watch(fieldNames.firearmApplicantNationalId) as string;
const name = watch(fieldNames.firearmApplicantName) as string;
  1. Consider creating a union type for field names:
type FieldName = keyof typeof fieldNames;

These changes will improve type safety and make the component more robust.

libs/application/templates/announcement-of-death/src/forms/overviewSections.ts (2)

339-345: New field added to display firearm possession status.

A new buildKeyValueField has been added to explicitly show whether the applicant had firearms. This enhances the user interface and provides clear information.

Consider adding a comment explaining the purpose of this new field for better code maintainability. For example:

+  // Explicitly display whether the applicant had firearms
   buildKeyValueField({
     label: m.firearmsHadFirearms,
     width: 'full',
     value: ({ answers }) =>
       answers.hadFirearms === YES ? m.firearmsYes : m.firearmsNo,
     condition: (answers) => showInDone(answers.viewOverview),
   }),

346-352: Repositioned and updated firearmApplicantInfo field.

The firearmApplicantInfo description field has been moved after the new key-value field, maintaining a logical flow of information. The condition remains unchanged, ensuring that detailed applicant info is only shown when necessary. The added space property likely improves the visual layout.

For consistency with the previous fields, consider updating the condition to use the showInDone function:

   condition: (answers) =>
-    showInDone(answers.viewOverview) && answers.hadFirearms === YES,
+    showInDone(answers.viewOverview) && showInDone(answers.hadFirearms === YES),

This change would make the condition consistent with the pattern used in other fields and potentially more flexible if the showInDone function's behavior is modified in the future.

libs/application/templates/announcement-of-death/src/lib/messages.ts (1)

235-242: Lack of TypeScript Type Definitions or Interfaces

The file libs/application/templates/announcement-of-death/src/lib/messages.ts does not contain any TypeScript type definitions or interfaces. This may not align with the requirement to use TypeScript for defining props and exporting types where applicable. Please review and ensure that TypeScript is used appropriately for type safety.

  • No export type or export interface statements were found.
Analysis chain

Verify TypeScript usage and export.

To ensure compliance with the additional instructions for libs/**/* files, please confirm that these message definitions are properly exported and that TypeScript is used for defining props and exporting types where applicable.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the messages are properly exported and if TypeScript is used for types
grep -n "export const m = defineMessages" libs/application/templates/announcement-of-death/src/lib/messages.ts
grep -n "import.*from 'react-intl'" libs/application/templates/announcement-of-death/src/lib/messages.ts

Length of output: 307


Script:

#!/bin/bash
# Check for TypeScript type definitions and exports in the file
grep -n "export type" libs/application/templates/announcement-of-death/src/lib/messages.ts
grep -n "export interface" libs/application/templates/announcement-of-death/src/lib/messages.ts

Length of output: 190

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a8fee4b and 47c5b1c.

Files selected for processing (4)
  • libs/application/templates/announcement-of-death/src/fields/FirearmApplicant/index.tsx (3 hunks)
  • libs/application/templates/announcement-of-death/src/forms/overviewSections.ts (2 hunks)
  • libs/application/templates/announcement-of-death/src/lib/dataSchema.ts (2 hunks)
  • libs/application/templates/announcement-of-death/src/lib/messages.ts (1 hunks)
Additional context used
Path-based instructions (4)
libs/application/templates/announcement-of-death/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/announcement-of-death/src/fields/FirearmApplicant/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/announcement-of-death/src/forms/overviewSections.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/announcement-of-death/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 not posted (7)
libs/application/templates/announcement-of-death/src/lib/dataSchema.ts (3)

8-8: LGTM: Importing specific constants.

The import of YES and NO constants from '@island.is/application/core' is appropriate and follows good practices for tree-shaking.


80-80: LGTM: New field added as per requirements.

The addition of the hadFirearms field using z.enum([YES, NO]) is correct and aligns with the PR objectives. It enhances the schema to capture whether the applicant has firearms.


83-83: LGTM: Improved validation for nationalId.

The update to the nationalId field in the firearmApplicant object enhances validation by ensuring the ID corresponds to a person. This is a good use of Zod's refine method for custom validation.

libs/application/templates/announcement-of-death/src/fields/FirearmApplicant/index.tsx (1)

126-126: Approve the addition of readOnly attribute

The addition of the readOnly attribute to the name input is appropriate. This ensures that the automatically populated name from the national ID lookup cannot be manually edited by the user, maintaining data integrity.

libs/application/templates/announcement-of-death/src/forms/overviewSections.ts (1)

331-338: Simplified condition for firearm applicant section.

The condition for displaying the divider and description fields has been simplified to only check showInDone(answers.viewOverview). This change broadens the circumstances under which these fields are displayed.

To ensure this change doesn't have unintended consequences, please run the following script:

Verification successful

Simplified condition for firearm applicant section verified.

The search confirmed that there are no other occurrences of hadFirearms in conditions for firearmApplicant. This indicates that the condition simplification is isolated and does not introduce unintended side effects.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other occurrences of hadFirearms in conditions
# Expected: No other occurrences of hadFirearms in conditions for firearmApplicant

rg --type typescript 'condition.*hadFirearms.*firearmApplicant' libs/application/templates/announcement-of-death/src/

Length of output: 154


Script:

#!/bin/bash
# Description: Check for other occurrences of hadFirearms in conditions
# Expected: No other occurrences of hadFirearms in conditions for firearmApplicant

rg 'condition.*hadFirearms.*firearmApplicant' libs/application/templates/announcement-of-death/src/

Length of output: 101

libs/application/templates/announcement-of-death/src/lib/messages.ts (2)

235-239: New message definition looks good.

The new firearmsApplicant message has been added correctly with a unique ID and an appropriate default message in Icelandic.


242-242: Simplified message for firearms applicant overview header.

The defaultMessage for firearmsApplicantOverviewHeader has been simplified from 'Skotvopn - vörsluaðili' to 'Skotvopn', which appears to be an intentional improvement in the user interface text.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 2, 2024

Datadog Report

All test runs eb2589b 🔗

4 Total Test Services: 0 Failed, 4 Passed
➡️ Test Sessions change in coverage: 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.76s 1 no change Link
application-system-api 0 0 0 111 2 3m 4.46s 1 no change Link
application-template-api-modules 0 0 0 109 0 1m 45.31s 1 no change Link
application-ui-shell 0 0 0 74 0 33.06s 1 no change Link

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

Outside diff range, codebase verification and nitpick comments (1)
libs/application/template-api-modules/src/lib/modules/templates/announcement-of-death/smsGenerators/requestReviewSms.ts (1)

5-8: Verify and Update Usages of generateRequestReviewSms

The RequestReviewSms type and generateRequestReviewSms function have been updated to include a link parameter. While this change is correctly implemented in the announcement-of-death.service.ts file, other usages in different services might not have been updated. Please verify and update these usages to ensure they pass the required link parameter:

  • libs/application/template-api-modules/src/lib/modules/templates/transport-authority/transfer-of-vehicle-ownership/transfer-of-vehicle-ownership.service.ts
  • libs/application/template-api-modules/src/lib/modules/templates/transport-authority/change-co-owner-of-vehicle/change-co-owner-of-vehicle.service.ts
  • libs/application/template-api-modules/src/lib/modules/templates/transport-authority/change-operator-of-vehicle/change-operator-of-vehicle.service.ts
  • libs/application/template-api-modules/src/lib/modules/templates/aosh/transfer-of-machine-ownership/transfer-of-machine-ownership.service.ts
Analysis chain

Update to RequestReviewSms type signature

The RequestReviewSms type has been updated to include a new link parameter of type string. This change is consistent with the modifications in the function implementation.

To ensure this change doesn't break existing code, let's verify its usage:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of RequestReviewSms type
rg --type typescript "RequestReviewSms" -C 5

Length of output: 79


Script:

#!/bin/bash
# Correct the file type and search for usages of RequestReviewSms type
rg --type ts "RequestReviewSms" -C 5

Length of output: 37423

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 47c5b1c and fb2ccc5.

Files selected for processing (2)
  • libs/application/template-api-modules/src/lib/modules/templates/announcement-of-death/announcement-of-death.service.ts (3 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/announcement-of-death/smsGenerators/requestReviewSms.ts (2 hunks)
Additional context used
Path-based instructions (2)
libs/application/template-api-modules/src/lib/modules/templates/announcement-of-death/smsGenerators/requestReviewSms.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/template-api-modules/src/lib/modules/templates/announcement-of-death/announcement-of-death.service.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 not posted (6)
libs/application/template-api-modules/src/lib/modules/templates/announcement-of-death/smsGenerators/requestReviewSms.ts (2)

10-13: Update to generateRequestReviewSms function signature

The function signature has been updated to match the new RequestReviewSms type, adding the link parameter. This change is consistent with the type definition.

Let's verify that all calls to this function have been updated:

Verification successful

All calls to generateRequestReviewSms have been updated

The verification confirms that all instances of the generateRequestReviewSms function call have been updated to include the link parameter, consistent with the updated function signature.

  • transfer-of-vehicle-ownership.service.ts
  • change-operator-of-vehicle.service.ts
  • change-co-owner-of-vehicle.service.ts
  • transfer-of-machine-ownership.service.ts
  • announcement-of-death.service.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for calls to generateRequestReviewSms
rg --type typescript "generateRequestReviewSms\(" -C 5

Length of output: 91


Script:

#!/bin/bash
# Correcting the file type and searching for calls to generateRequestReviewSms
rg --type ts "generateRequestReviewSms\(" -C 5

Length of output: 11859


24-26: Update to SMS message content

The SMS message has been updated to include instructions for using the provided link. This enhances the user experience by providing clear guidance.

However, there are a few points to consider:

  1. The message is quite long and might be split into multiple SMS messages.
  2. The link is appended at the end without any context or call-to-action.

Consider the following improvements:

  1. Shorten the message if possible to fit within SMS character limits.
  2. Add a clear call-to-action before the link, e.g., "Click here to proceed:"

Here's a suggested refactor:

-      `Með undirritun lýsir þú því yfir að þú hafir leyfi til að varsla skotvopnin og samþykkir jafnframt að taka við vörslu þeirra.
-      Ef þú áttir von á þessari beiðni máttu smella á linkinn hér fyrir neðan.
-      ${link}`,
+      `Með undirritun samþykkir þú að taka við vörslu skotvopnanna.
+      Ef þú áttir von á þessari beiðni, smelltu hér til að halda áfram: ${link}`,

Let's check if similar message constructions exist elsewhere in the codebase:

libs/application/template-api-modules/src/lib/modules/templates/announcement-of-death/announcement-of-death.service.ts (4)

4-7: LGTM: New imports are appropriate and follow best practices.

The added imports are necessary for the changes in the file and follow TypeScript best practices. They support effective tree-shaking and bundling.

Also applies to: 29-33, 39-40


48-48: LGTM: Constructor updated with ConfigService parameter.

The addition of the ConfigService parameter with the correct type ConfigService<BaseTemplateAPIModuleConfig> follows dependency injection best practices and ensures type safety.


149-156: Approve changes with a suggestion for improved error handling.

The addition of the dynamic link in the SMS is a good improvement. However, consider adding a check for the clientLocationOrigin value to ensure it's defined before using it.

Consider adding a check for clientLocationOrigin:

const clientLocationOrigin = getConfigValue(
  this.configService,
  'clientLocationOrigin',
) as string | undefined

if (!clientLocationOrigin) {
  throw new Error('clientLocationOrigin is not defined in the configuration');
}

const link = `${clientLocationOrigin}/${ApplicationConfigurations.AnnouncementOfDeath.slug}/${application.id}`

This will prevent potential runtime errors if the configuration is missing.


Line range hint 1-307: Overall changes align with PR objectives and improve functionality.

The modifications to the AnnouncementOfDeathService class, particularly in the SMS notification functionality, are consistent with the PR objectives. The changes improve the service's ability to generate contextually relevant notifications by leveraging configuration data.

The code adheres to TypeScript best practices, supports reusability, and maintains effective tree-shaking and bundling practices. These improvements enhance the overall quality and functionality of the application.

@kodiakhq kodiakhq bot merged commit 0b9d9d8 into main Sep 2, 2024
36 checks passed
@kodiakhq kodiakhq bot deleted the aod_finishups branch September 2, 2024 16:08
jonnigs pushed a commit that referenced this pull request Sep 12, 2024
* fix(aod): finishups

* sms tweak

* Revert "sms tweak"

This reverts commit fb2ccc5.

---------

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.

2 participants