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(application-system): Add phone and email fields to tablerepeater #17219

Merged
merged 15 commits into from
Dec 16, 2024

Conversation

norda-gunni
Copy link
Member

@norda-gunni norda-gunni commented Dec 12, 2024

...

Attach a link to issue if relevant

What

Add possibility of having phone and email fields to nationalIdWithName

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 new property for handling complex data structures in the schema.
    • Enhanced repeater item and table repeater configurations to include optional phone and email fields.
    • Expanded the National ID component to support optional phone and email inputs with improved error handling.
  • Bug Fixes

    • Improved error handling for various fields within the National ID component.

@norda-gunni norda-gunni requested a review from a team as a code owner December 12, 2024 14:29
@norda-gunni norda-gunni marked this pull request as draft December 12, 2024 14:29
Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jest > @jest/core > jest-config > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-runtime > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/transform > babel-plugin-istanbul > test-exclude > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > puppeteer-core > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > puppeteer-core > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > tempy > del > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > jscodeshift > temp > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > jscodeshift > temp > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning react-native > @react-native/codegen > [email protected]: Glob versions prior to v9 are no longer supported
warning react-native > @react-native/community-cli-plugin > [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning react-native > @react-native/community-cli-plugin > @react-native/dev-middleware > @rnx-kit/chromium-edge-launcher > [email protected]: Rimraf versions prior to v4 are no longer supported
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-logical-assignment-operators instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning next-auth > [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning next-auth > [email protected]: this version is no longer supported
warning next-auth > @next-auth/typeorm-legacy-adapter > typeorm > [email protected]: Glob versions prior to v9 are no longer supported
warning @nx/next > @nx/webpack > stylus > [email protected]: Glob versions prior to v9 are no longer supported
warning @nx/next > @nx/webpack > webpack-dev-server > [email protected]: Rimraf versions prior to v4 are no longer supported
warning @nx/next > @nx/webpack > fork-ts-checker-webpack-plugin > [email protected]: this will be v4
warning @nx/next > @nx/webpack > webpack-dev-server > webpack-dev-middleware > [email protected]: this will be v4
warning workspace-aggregator-192d9115-f5f8-40e7-8d3d-98d0f9ebf138 > [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.

Walkthrough

This pull request introduces a new property, tableRepeaterField, to the ExampleSchema in the dataSchema.ts file, which includes complex validation for national ID, phone, and email fields. Additionally, the RepeaterItem and TableRepeaterField types in Fields.ts are enhanced with optional properties for configuring phone and email fields. The NationalIdWithName component is updated to support these new fields, improving error handling and rendering logic. Overall, the changes enhance the data schema, type definitions, and UI components to better manage user contact information.

Changes

File Change Summary
libs/application/templates/reference-template/src/lib/dataSchema.ts Added tableRepeaterField property to ExampleSchema with validation for nationalIdWithName, phone, and email.
libs/application/types/src/lib/Fields.ts Updated RepeaterItem type with new optional properties for phone and email configuration.
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx Extended NationalIdWithNameProps to include phone and email input handling with new props for labels, visibility, and validation.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • RunarVestmann
  • jonnigs
  • Toti91

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request.


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.

@norda-gunni norda-gunni changed the title Sa add person field to tablerepeater feature(application-system): Add person field to tablerepeater Dec 12, 2024
- Renamed 'rentalHousingLandlordInfoTable' to 'tableRepeaterField' in ExampleForm.
- Updated ExampleSchema to include validation for the new 'tableRepeaterField' structure.
- Enhanced NationalIdWithName component to accept phone and email default values.
- Refactored error handling in NationalIdWithName for better validation feedback.
- Cleaned up unused code in TableRepeaterFormField for improved readability.
@norda-gunni norda-gunni force-pushed the sa-add-person-field-to-tablerepeater branch from bccaf47 to e52f68a Compare December 13, 2024 08:25
@norda-gunni norda-gunni changed the title feature(application-system): Add person field to tablerepeater feature(application-system): Add phone and email fields to tablerepeater Dec 13, 2024
@norda-gunni norda-gunni changed the title feature(application-system): Add phone and email fields to tablerepeater feat(application-system): Add phone and email fields to tablerepeater Dec 13, 2024
Copy link

codecov bot commented Dec 13, 2024

Codecov Report

Attention: Patch coverage is 0% with 52 lines in your changes missing coverage. Please review.

Project coverage is 35.72%. Comparing base (8aa0e52) to head (41eed98).

Files with missing lines Patch % Lines
...mponents/NationalIdWithName/NationalIdWithName.tsx 0.00% 51 Missing ⚠️
...templates/reference-template/src/lib/dataSchema.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17219      +/-   ##
==========================================
- Coverage   35.74%   35.72%   -0.03%     
==========================================
  Files        6937     6937              
  Lines      148284   148334      +50     
  Branches    42311    42404      +93     
==========================================
- Hits        52998    52986      -12     
- Misses      95286    95348      +62     
Flag Coverage Δ
air-discount-scheme-web 0.00% <ø> (ø)
api 3.33% <ø> (ø)
application-api-files 61.87% <ø> (ø)
application-core 75.78% <ø> (ø)
application-system-api 38.75% <0.00%> (+<0.01%) ⬆️
application-template-api-modules 27.83% <ø> (+0.02%) ⬆️
application-templates-accident-notification 28.82% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.77% <ø> (ø)
application-templates-driving-license 18.16% <ø> (ø)
application-templates-estate 13.76% <0.00%> (-0.05%) ⬇️
application-templates-example-payment 24.72% <ø> (ø)
application-templates-general-petition 23.15% <ø> (ø)
application-templates-inheritance-report 6.59% <ø> (ø)
application-templates-marriage-conditions 15.19% <ø> (ø)
application-templates-mortgage-certificate 43.64% <ø> (ø)
application-templates-parental-leave 29.94% <ø> (ø)
application-types 6.51% <ø> (ø)
application-ui-components 1.22% <0.00%> (-0.03%) ⬇️
application-ui-shell 22.45% <0.00%> (-0.06%) ⬇️
clients-charge-fjs-v2 28.35% <ø> (ø)
judicial-system-api 20.20% <ø> (ø)
judicial-system-backend 55.83% <ø> (ø)
judicial-system-formatters 78.33% <ø> (ø)
judicial-system-message 66.48% <ø> (ø)
judicial-system-message-handler 48.16% <ø> (ø)
judicial-system-scheduler 70.92% <ø> (ø)
judicial-system-types 42.09% <ø> (ø)
judicial-system-web 27.93% <ø> (ø)
web 2.41% <ø> (ø)

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

Files with missing lines Coverage Δ
libs/application/types/src/lib/Fields.ts 100.00% <ø> (ø)
...templates/reference-template/src/lib/dataSchema.ts 30.00% <0.00%> (-1.58%) ⬇️
...mponents/NationalIdWithName/NationalIdWithName.tsx 0.88% <0.00%> (-0.22%) ⬇️

... and 7 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 8aa0e52...41eed98. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Dec 13, 2024

Datadog Report

All test runs 416e887 🔗

30 Total Test Services: 0 Failed, 29 Passed
🔻 Test Sessions change in coverage: 3 decreased, 102 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-web 0 0 0 2 0 7.31s 1 no change Link
api 0 0 0 4 0 3.39s 1 no change Link
application-api-files 0 0 0 2 0 5.54s 1 no change Link
application-core 0 0 0 97 0 22.06s 1 no change Link
application-system-api 0 0 0 46 0 2m 31.24s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 48.87s 1 no change Link
application-templates-accident-notification 0 0 0 148 0 18.82s 1 no change Link
application-templates-criminal-record 0 0 0 2 0 10.6s 1 no change Link
application-templates-driving-license 0 0 0 13 0 15.32s 1 no change Link
application-templates-example-payment 0 0 0 2 0 10.91s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (3)

  • application-ui-shell - jest 29.36% (-0.05%) - Details
  • application-templates-estate - jest 20.64% (-0.04%) - Details
  • application-ui-components - jest 1.61% (-0.02%) - Details

@norda-gunni norda-gunni marked this pull request as ready for review December 13, 2024 08:54
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: 4

🧹 Outside diff range and nitpick comments (5)
libs/application/templates/reference-template/src/forms/ExampleForm.ts (1)

27-27: Unused Import: 'applicantInformationMultiField'

The import applicantInformationMultiField is not used in the file. Consider removing it to keep the code clean.

libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (2)

253-263: Simplify Error Handling Logic

The conditional statements for handling errors in the nameField are complex and may affect readability. Consider refactoring the logic to make it more straightforward.


270-300: Conditional Rendering May Cause Layout Shifts

The conditional rendering of phone and email fields within the GridRow could lead to layout shifts if only one of the fields is rendered. To maintain consistent layout, consider always rendering both GridColumn components and conditionally rendering the input controllers inside them.

libs/application/types/src/lib/Fields.ts (2)

Line range hint 92-107: Document New Properties in 'RepeaterItem'

The properties phoneLabel, emailLabel, phone, phoneRequired, email, and emailRequired have been added to RepeaterItem. Ensure these are properly documented to maintain clarity for future developers.


630-631: Redundant 'phone' and 'email' Properties

The phone and email properties in TableRepeaterField may be unnecessary if these configurations are already handled within the fields property. Verify whether these properties are required, and remove them if they serve no additional purpose.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2523e39 and 1f74023.

📒 Files selected for processing (4)
  • libs/application/templates/reference-template/src/forms/ExampleForm.ts (2 hunks)
  • libs/application/templates/reference-template/src/lib/dataSchema.ts (1 hunks)
  • libs/application/types/src/lib/Fields.ts (3 hunks)
  • libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (7 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
libs/application/templates/reference-template/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/reference-template/src/forms/ExampleForm.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/types/src/lib/Fields.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/ui-components/src/components/NationalIdWithName/NationalIdWithName.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."
🔇 Additional comments (2)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (2)

95-102: Verify 'getFieldErrorString' Functionality

Ensure that the getFieldErrorString function correctly retrieves error messages for all field types, especially when dealing with nested fields or arrays.


233-233: Possible Redundant 'error' Prop Usage

The error prop is passed to InputController for nationalIdField. Since getErrorViaPath is already used for error handling, verify that passing the error prop as getFieldErrorString(error, 'nationalId') is necessary and does not cause unexpected behavior.

@norda-gunni norda-gunni force-pushed the sa-add-person-field-to-tablerepeater branch from 694164f to 11c905b Compare December 13, 2024 11:30
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

🧹 Outside diff range and nitpick comments (3)
libs/application/templates/reference-template/src/lib/dataSchema.ts (1)

18-31: Consider enhancing field validations

While the basic validations are in place, consider the following improvements:

  1. Add character set validation for the name field to prevent special characters
  2. Add specific phone number format validation for Icelandic numbers
 tableRepeaterField: z.array(
   z.object({
     nationalIdWithName: z.object({
-      name: z.string().min(1).max(256),
+      name: z.string()
+        .min(1)
+        .max(256)
+        .regex(/^[a-zA-ZÀ-ÿ\s'-]+$/, { message: 'Name contains invalid characters' }),
       nationalId: z.string().refine((n) => n && kennitala.isValid(n), {
         params: m.dataSchemeNationalId,
       }),
       phone: z.string().refine(isValidNumber, {
         params: m.dataSchemePhoneNumber,
       }),
       email: z.string().email(),
     }),
   }),
 ),
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (2)

29-45: Enhance type safety for label props

Consider making the label props required when their corresponding feature flags are enabled.

interface NationalIdWithNameProps {
  // ... other props
  phoneLabel: phone extends true ? StaticText : never;
  emailLabel: email extends true ? StaticText : never;
  // ... other props
}

266-296: Consider adding ARIA attributes for accessibility

While the implementation is correct, consider enhancing accessibility by adding appropriate ARIA attributes to the form fields.

 <PhoneInputController
   id={phoneField}
   label={formatMessage(phoneLabel)}
+  aria-describedby={`${phoneField}-description`}
   // ... other props
 />
 <InputController
   id={emailField}
   label={formatMessage(emailLabel)}
+  aria-describedby={`${emailField}-description`}
   // ... other props
 />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1f74023 and 11c905b.

📒 Files selected for processing (2)
  • libs/application/templates/reference-template/src/lib/dataSchema.ts (1 hunks)
  • libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (7 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/application/templates/reference-template/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/ui-components/src/components/NationalIdWithName/NationalIdWithName.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."
🔇 Additional comments (1)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (1)

125-130: LGTM!

The default value handling for phone and email fields follows the established pattern consistently.

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 and nitpick comments (2)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (2)

57-74: Consider providing meaningful default labels.

Empty string defaults for phoneLabel and emailLabel could result in fields without visible labels. Consider using default messages from your i18n system.

-  phoneLabel = '',
-  emailLabel = '',
+  phoneLabel = coreErrorMessages.phone,
+  emailLabel = coreErrorMessages.email,

270-300: Consider improving responsive layout.

The current layout might stack fields awkwardly on smaller screens when both phone and email are enabled. Consider:

  1. Using a more flexible grid system
  2. Adding spacing between stacked fields
-      {(phone || email) && (
-        <GridRow>
+      {(phone || email) && (
+        <GridRow spacing={[2, 2, 2, 3]}>
           {phone && (
             <GridColumn span={['1/1', '1/1', '1/1', '1/2']} paddingTop={2}>
               <PhoneInputController
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 11c905b and 7d95f67.

📒 Files selected for processing (1)
  • libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.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."
🔇 Additional comments (4)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (4)

12-15: LGTM! Imports follow best practices.

The imports are properly tree-shakeable and promote reusability by using shared form field components.


29-45: LGTM! Interface changes maintain backward compatibility.

The new props are:

  • Properly typed with TypeScript
  • Optional, ensuring backward compatibility
  • Use StaticText type for labels, supporting internationalization

91-102: Improve type safety in error handling.

The implementation uses multiple type assertions which could be unsafe. Consider using type guards instead.


129-134: LGTM! Default value handling is consistent.

The implementation follows the established pattern and properly handles fallback values.

@norda-gunni norda-gunni marked this pull request as draft December 13, 2024 12:39
@norda-gunni norda-gunni marked this pull request as ready for review December 13, 2024 12:50
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 and nitpick comments (1)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (1)

230-231: Use optional chaining for better code safety

Replace the conditional operator with optional chaining for better readability and safety.

-              onNationalIdChange &&
-                onNationalIdChange(v.target.value.replace(/\W/g, ''))
+              onNationalIdChange?.(v.target.value.replace(/\W/g, ''))
🧰 Tools
🪛 Biome (1.9.4)

[error] 230-231: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7d95f67 and a5ce555.

📒 Files selected for processing (1)
  • libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.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."
🪛 Biome (1.9.4)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx

[error] 230-231: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (4)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (4)

13-15: LGTM: Well-structured TypeScript interface extensions

The new props for phone and email fields are properly typed and follow TypeScript best practices with appropriate optional flags.

Also applies to: 29-32, 37-38, 43-45


57-60: LGTM: Props initialization follows consistent patterns

Default values are properly set and field IDs are constructed consistently with the existing pattern.

Also applies to: 66-67, 72-74, 79-80


91-102: Improve type safety in error handling

The current implementation uses multiple type assertions which could be unsafe. Consider using type guards instead.


272-302: LGTM: Clean implementation of conditional phone and email fields

The implementation:

  • Uses clean conditional rendering
  • Maintains consistent error handling
  • Follows responsive design patterns
  • Preserves component reusability

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 and nitpick comments (1)
libs/application/templates/reference-template/src/forms/ExampleForm.ts (1)

27-27: Remove unused import

The applicantInformationMultiField import appears to be unused in this file.

-import { applicantInformationMultiField } from '@island.is/application/ui-forms'
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a5ce555 and b7dcbdd.

📒 Files selected for processing (2)
  • libs/application/templates/reference-template/src/forms/ExampleForm.ts (2 hunks)
  • libs/application/types/src/lib/Fields.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/application/templates/reference-template/src/forms/ExampleForm.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/types/src/lib/Fields.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 (2)
libs/application/templates/reference-template/src/forms/ExampleForm.ts (1)

44-62: 🛠️ Refactor suggestion

Use message descriptors for localization

The field labels are hardcoded in Icelandic. For better internationalization support, use message descriptors for the labels.

 nationalIdWithName: {
   component: 'nationalIdWithName',
   label: 'nationalIdWithName',
-  phoneLabel: 'Símanúmer',
-  emailLabel: 'Netfang',
+  phoneLabel: m.phoneNumber,
+  emailLabel: m.email,
   required: true,
   showPhone: true,
   phoneRequired: true,
   showEmail: true,
   emailRequired: true,
 },
libs/application/types/src/lib/Fields.ts (1)

92-93: LGTM! Well-structured type definitions

The new phone and email field properties are properly typed as optional fields with clear, consistent naming that matches the codebase conventions.

Also applies to: 104-107

@norda-gunni norda-gunni force-pushed the sa-add-person-field-to-tablerepeater branch from b7dcbdd to 61f7f17 Compare December 13, 2024 13:23
Copy link
Member

@jonnigs jonnigs left a comment

Choose a reason for hiding this comment

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

LGTM

…me/NationalIdWithName.tsx


Add suggestion from jonni

Co-authored-by: Jónas G. Sigurðsson <[email protected]>
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

♻️ Duplicate comments (1)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (1)

91-102: 🛠️ Refactor suggestion

Improve type safety in error handling

The current implementation uses multiple type assertions which could be unsafe. Consider using type guards instead.

const getFieldErrorString = (error: unknown, id: string): string | undefined => {
  if (!error || typeof error !== 'object') return undefined;
  
  const errorList = error as Record<string, unknown>[];
  if (!Array.isArray(errorList)) return undefined;
  
  const fieldError = errorList[id as any];
  return typeof fieldError === 'string' ? fieldError : undefined;
};
🧹 Nitpick comments (4)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (4)

57-60: Consider more descriptive boolean prop names

The boolean flags showPhoneField and showEmailField could be more descriptive to better indicate their purpose.

Consider renaming to:

-  showPhoneField?: boolean
-  showEmailField?: boolean
+  includePhoneField?: boolean
+  includeEmailField?: boolean

Also applies to: 72-74


129-134: Optimize default value assignments

The default value assignments could be more concise using nullish coalescing.

-  const defaultPhone = phoneDefaultValue
-    ? phoneDefaultValue
-    : getValueViaPath<string>(application.answers, phoneField, '')
-  const defaultEmail = emailDefaultValue
-    ? emailDefaultValue
-    : getValueViaPath<string>(application.answers, emailField, '')
+  const defaultPhone = phoneDefaultValue ?? getValueViaPath<string>(application.answers, phoneField, '')
+  const defaultEmail = emailDefaultValue ?? getValueViaPath<string>(application.answers, emailField, '')

272-302: Consider extracting contact fields into a separate component

The phone and email fields section could be extracted into a reusable component to improve maintainability and reusability across different forms.

Example implementation:

interface ContactFieldsProps {
  showPhone?: boolean;
  showEmail?: boolean;
  phoneField: string;
  emailField: string;
  phoneLabel: StaticText;
  emailLabel: StaticText;
  defaultPhone?: string;
  defaultEmail?: string;
  phoneRequired?: boolean;
  emailRequired?: boolean;
  disabled?: boolean;
  error?: unknown;
}

const ContactFields: FC<ContactFieldsProps> = ({...props}) => {
  return (
    <GridRow>
      {props.showPhone && (
        <GridColumn span={['1/1', '1/1', '1/1', '1/2']} paddingTop={2}>
          <PhoneInputController {...phoneProps} />
        </GridColumn>
      )}
      {props.showEmail && (
        <GridColumn span={['1/1', '1/1', '1/1', '1/2']} paddingTop={2}>
          <InputController {...emailProps} />
        </GridColumn>
      )}
    </GridRow>
  );
};

230-231: Use optional chaining for callback invocation

Replace the conditional operator with optional chaining for better readability.

-              onNationalIdChange &&
-                onNationalIdChange(v.target.value.replace(/\W/g, ''))
+              onNationalIdChange?.(v.target.value.replace(/\W/g, ''))
🧰 Tools
🪛 Biome (1.9.4)

[error] 230-231: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eb76670 and 81d4d45.

📒 Files selected for processing (1)
  • libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.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."
🪛 Biome (1.9.4)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx

[error] 230-231: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (1)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (1)

4-4: LGTM! Interface and imports are well-structured

The new props and imports are properly typed and organized, following TypeScript best practices.

Also applies to: 12-15, 29-32, 37-38, 43-45

@norda-gunni norda-gunni added deprecated:automerge (Disabled) Merge this PR as soon as all checks pass and removed deprecated:automerge (Disabled) Merge this PR as soon as all checks pass labels Dec 16, 2024
@norda-gunni norda-gunni added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Dec 16, 2024
@kodiakhq kodiakhq bot merged commit 3314c57 into main Dec 16, 2024
103 checks passed
@kodiakhq kodiakhq bot deleted the sa-add-person-field-to-tablerepeater branch December 16, 2024 13:12
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.

3 participants