-
Notifications
You must be signed in to change notification settings - Fork 61
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
chore(driving-license): add delivery price if pickup = post selected #16194
Conversation
WalkthroughThe changes involve modifications to two files related to the driving license application forms. The Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 (1)
libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts (1)
162-162
: Add TypeScript type annotation to theapplication
parameterFor better type safety and code clarity, consider adding a type annotation to the
application
parameter in thevalue
function.You can modify the function signature as:
-value: (application) => { +value: (application: Application) => {Ensure that
Application
is imported from@island.is/application/types
if it's not already imported.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (3)
- libs/application/templates/driving-license/src/forms/draft/subSectionDelivery.ts (0 hunks)
- libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts (1 hunks)
- libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts (2 hunks)
💤 Files not reviewed due to no reviewable changes (1)
- libs/application/templates/driving-license/src/forms/draft/subSectionDelivery.ts
🧰 Additional context used
📓 Path-based instructions (2)
libs/application/templates/driving-license/src/forms/draft/subSectionSummary.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/driving-license/src/lib/drivingLicenseTemplate.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 (3)
libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts (3)
36-36
: LGTM: Import statement correctly updatedThe addition of the
Pickup
import is consistent with the changes in thegetCodes
function and follows the TypeScript usage guideline for importing types.
55-76
: LGTM: Delivery price logic correctly implementedThe changes in the
getCodes
function successfully implement the new functionality for adding a delivery price when the pickup option is set to post. The code is well-structured, maintains error handling, and adheres to TypeScript usage guidelines. It also preserves the reusability of the component across different NextJS apps.A few observations:
- The
pickup
variable is correctly retrieved usinggetValueViaPath
.- The
codes
array is used to collect charge item codes, allowing for multiple codes.- The conditional check for
Pickup.POST
is correctly implemented.- The return statement is properly updated to return the
codes
array.
Line range hint
1-76
: Summary: Changes align with PR objectives and maintain code qualityThe modifications to the
drivingLicenseTemplate.ts
file are focused and effective in implementing the delivery price functionality when the pickup option is set to post. The changes are minimal, affecting only thegetCodes
function and its related import, without disrupting the overall structure or functionality of the template.The implementation adheres to the project's coding guidelines, maintaining:
- Reusability of components across different NextJS apps
- Proper TypeScript usage for defining types
- Consistency with existing code style and structure
The changes successfully fulfill the PR objectives while preserving the quality and integrity of the codebase.
libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts
Outdated
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16194 +/- ##
==========================================
- Coverage 36.92% 36.92% -0.01%
==========================================
Files 6781 6781
Lines 140014 140030 +16
Branches 39811 39815 +4
==========================================
+ Hits 51703 51705 +2
- Misses 88311 88325 +14
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
|
Datadog ReportAll test runs ✅ 7 Total Test Services: 0 Failed, 6 Passed Test Services
🔻 Code Coverage Decreases vs Default Branch (1)
|
libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts
Outdated
Show resolved
Hide resolved
fe09c7c
to
14ddd61
Compare
There was a problem hiding this 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/driving-license/src/lib/constants.ts (1)
19-25
: LGTM: CHARGE_ITEM_CODES constant added with a minor suggestionThe new
CHARGE_ITEM_CODES
constant is well-structured and includes all necessary mappings, including the newDELIVERY_FEE
. The use ofRecord<string, string>
is a good TypeScript practice.Consider using a more specific type for better type safety:
export const CHARGE_ITEM_CODES: Record<typeof B_TEMP | typeof B_FULL | typeof B_FULL_RENEWAL_65 | typeof BE | typeof DELIVERY_FEE, string> = { // ... (rest of the code remains the same) }This change would ensure that only valid keys can be used when accessing
CHARGE_ITEM_CODES
.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (5)
- libs/application/templates/driving-license/src/fields/HealthDeclaration.tsx (1 hunks)
- libs/application/templates/driving-license/src/forms/draft/subSectionDelivery.ts (0 hunks)
- libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts (2 hunks)
- libs/application/templates/driving-license/src/lib/constants.ts (1 hunks)
- libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts (2 hunks)
💤 Files with no reviewable changes (1)
- libs/application/templates/driving-license/src/forms/draft/subSectionDelivery.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts
🧰 Additional context used
📓 Path-based instructions (3)
libs/application/templates/driving-license/src/fields/HealthDeclaration.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/driving-license/src/forms/draft/subSectionSummary.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/driving-license/src/lib/constants.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 (10)
libs/application/templates/driving-license/src/lib/constants.ts (2)
12-12
: LGTM: DELIVERY_FEE constant addedThe new
DELIVERY_FEE
constant is well-defined and consistent with the existing coding style. It's appropriately exported for use in other modules.
12-25
: Compliance with coding guidelines confirmedThe changes in this file adhere to the specified coding guidelines for
libs/**/*
:
- The new constants (
DELIVERY_FEE
andCHARGE_ITEM_CODES
) are reusable across different NextJS apps.- TypeScript is used appropriately for defining types (e.g.,
Record<string, string>
).- The constants are exported, allowing for effective tree-shaking and bundling.
libs/application/templates/driving-license/src/fields/HealthDeclaration.tsx (4)
14-14
: Approved: Component declaration updated to arrow functionThe change from a function declaration to an arrow function is a good modernization of the code. This approach:
- Aligns with current React best practices.
- Potentially improves tree-shaking, which is important as per the coding guidelines for files in the
libs
directory.- Maintains correct TypeScript typing for props and return value.
Line range hint
9-12
: Approved: Proper TypeScript usage for props and componentThe TypeScript implementation in this file is excellent:
- The
PropTypes
interface is well-defined, extendingFieldBaseProps
and including the customfield
prop.- The component's props are correctly typed using the
PropTypes
interface.- The return type of the component is explicitly set to
JSX.Element
.This adheres to the coding guidelines for TypeScript usage in the
libs
directory.Also applies to: 14-14
Line range hint
1-7
: Approved: Component demonstrates good reusability potentialThe
HealthDeclaration
component shows excellent reusability characteristics:
- It uses shared UI components from
@island.is/island-ui/core
, promoting consistent design across applications.- Utility functions from
@island.is/application/core
are used, enabling shared functionality.- The component's logic is not tightly coupled to a specific application, allowing for use in various contexts.
- Use of
react-hook-form
and custom hooks (useLocale
) provides flexibility for integration in different NextJS apps.These aspects align well with the coding guideline for reusability of components across different NextJS apps in the
libs
directory.Also applies to: 14-89
Line range hint
18-89
: Suggestions for improving component logicWhile the overall logic of the
HealthDeclaration
component is sound, there are a few areas that could be improved:
Consider extracting the
checkForGlassesMismatch
function outside the component for better testability and potential reuse.The BE license-specific logic in the
onSelect
callback could be moved to a separate function for improved readability and maintainability.There's a TODO comment regarding health certificate support for BE license. It would be beneficial to create a ticket to track this item for future implementation.
Would you like assistance in implementing these suggestions?
Regarding the TODO comment, let's check if there's an existing issue for this:
libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts (4)
16-25
: Improved code organization with centralized constantsThe addition of these imports from a centralized constants file is a positive change. It enhances code maintainability and reusability across different NextJS apps, aligning well with our coding guidelines.
171-172
: Simplified function signature improves flexibilityThe change from destructuring
externalData
andanswers
to using a singleapplication
parameter is a good improvement. It simplifies the function signature and allows for more flexible access to the application data, enhancing code readability without affecting functionality.
178-181
: Improved charge code lookup with centralized mappingGreat job implementing the suggestion from the past review comment. The use of
CHARGE_ITEM_CODES
mapping improves maintainability and readability. The default fallback toCHARGE_ITEM_CODES[B_FULL]
ensures robustness. This change aligns well with our TypeScript usage guidelines and enhances code maintainability.
182-200
: Enhanced price calculation with improved robustnessExcellent improvements in the price calculation logic:
- The introduction of
pickupItem
correctly handles thePickup.POST
scenario.- The total price calculation now includes both the main item price and the delivery price when applicable.
- The use of optional chaining and nullish coalescing operators (
??
) improves code robustness by handling potential undefined values.These changes successfully address the PR objective of adding delivery price for post pickup and enhance the overall functionality of the pricing logic.
There was a problem hiding this 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/driving-license/src/forms/draft/subSectionSummary.ts (1)
171-204
: Improved payment charge calculation logicThe changes in this section significantly enhance the clarity and robustness of the payment charge calculation. The use of
CHARGE_ITEM_CODES
mapping and the addition of the delivery fee calculation for postal pickup are particularly noteworthy improvements.However, the
targetCode
determination could be simplified further:const targetCode = CHARGE_ITEM_CODES[application.answers.applicationFor as keyof typeof CHARGE_ITEM_CODES] || DEFAULT_ITEM_CODE;This approach eliminates the nested ternary operators, making the code more readable and maintainable.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
- libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts (2 hunks)
- libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts
🧰 Additional context used
📓 Path-based instructions (1)
libs/application/templates/driving-license/src/forms/draft/subSectionSummary.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/driving-license/src/forms/draft/subSectionSummary.ts (2)
16-25
: Improved code organization with centralized constantsThe addition of these imports from a centralized constants file is a positive change. It enhances code maintainability and aligns with best practices for effective tree-shaking and bundling. This approach makes it easier to manage and update constants across the application.
Line range hint
1-214
: Overall improvement in code quality and functionalityThe changes in this file significantly enhance the payment charge calculation logic for the driving license application process. The use of centralized constants and improved type safety aligns well with the coding guidelines for reusability and TypeScript usage. These modifications make the code more maintainable and robust, particularly in handling different license types and pickup options.
The refactoring maintains the overall structure of the
subSectionSummary
, ensuring that the changes integrate seamlessly with the existing code. This approach demonstrates a good balance between improving functionality and maintaining code stability.
Summary by CodeRabbit
New Features
DELIVERY_FEE
.Bug Fixes
Refactor