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(native-app): Multiple license fixes #16744

Merged
merged 9 commits into from
Nov 13, 2024
Merged

fix(native-app): Multiple license fixes #16744

merged 9 commits into from
Nov 13, 2024

Conversation

thoreyjona
Copy link
Contributor

@thoreyjona thoreyjona commented Nov 6, 2024

What

Multiple license fixes:

  • Make sure add to wallet buttons are always visible at the bottom of the screen when barcodes are visible - tested in ios simulator and android device.
  • Fix bugs in fire arm licenses: make sure we have margin between fields and remove empty header for listing firearms. Máni at Hugsmiðjan will fix a bug I found from the backend as well (I was getting each firearm twice, but luckily only supporting one of the types in the app so only the header was shown twice.)
  • Adding offline placeholder for barcodes
  • Add license errors to translate files

Additional fixes:

  • Don't show bottom tab bar on vehicle details screen
  • Make sure that svgs and images in html documents are not bigger than 100% in width.

Screenshots / Gifs

Removed most of the information since these are production screenshots.

Image fix for html documents:
Before vs after:

Fixing of margin of firearm fields:
Before and after:

Offline placeholder for barcodes:
Screenshot 2024-11-06 at 10 03 16

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

Release Notes

  • New Features

    • Enhanced error messages for wallet functionality, providing clearer user feedback when adding passes fails.
    • Offline messages added to the LicenseCard component to inform users about barcode accessibility based on connectivity.
  • Bug Fixes

    • Improved error handling in the WalletPassScreen for better localization support.
  • Improvements

    • Document viewer updated for better HTML and image rendering.
    • Vehicle detail screen navigation options adjusted for improved layout.
    • Conditional rendering logic in FieldCard refined for clarity.
  • Styling

    • Adjustments made to various components for improved layout and responsiveness.

@thoreyjona thoreyjona requested a review from a team as a code owner November 6, 2024 13:22
Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces several modifications across various files, primarily focusing on enhancing error handling and user feedback related to wallet functionality and document rendering. New localized error messages are added for wallet pass operations, while improvements are made to the rendering logic in document detail and wallet pass screens. Additionally, updates to styling and conditional rendering logic are included to improve user experience and responsiveness of components.

Changes

File Path Change Summary
apps/native/app/src/messages/en.ts Added new error messages for wallet functionality: errorCannotAddPasses, errorAddingOrFetching, errorNotPossibleOnThisDevice, errorNotConnectedNoBarcode.
apps/native/app/src/messages/is.ts Added corresponding error messages for wallet functionality in Greek localization.
apps/native/app/src/screens/document-detail/document-detail.tsx Enhanced HTML/image rendering and error handling in PdfViewer. Updated logic for document fetching based on isUrgent prop.
apps/native/app/src/screens/vehicles/vehicles-detail.tsx Added bottom tab configuration to VehicleDetailScreen.
apps/native/app/src/screens/wallet-pass/wallet-pass.tsx Updated WalletPassScreen to include useOfflineStore. Enhanced error handling with localized messages.
apps/native/app/src/ui/lib/card/license-card.tsx Updated LicenseCard to include showBarcodeOfflineMessage prop for conditional rendering.
apps/native/app/src/ui/lib/field/field-card.tsx Modified conditional rendering logic for Header component in FieldCard.
apps/native/app/src/ui/lib/field/field.tsx Added margin-right style to Value styled component.

Possibly related PRs

  • fix(native-app): Multiple license fixes #16744: This PR adds new error messages related to wallet functionality in the en.ts and is.ts files, which directly relates to the changes made in the main PR that also enhances error messages for wallet pass functionality.

Suggested reviewers

  • snaerseljan

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 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.54%. Comparing base (94a84fb) to head (1c2ea6d).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16744   +/-   ##
=======================================
  Coverage   36.54%   36.54%           
=======================================
  Files        6890     6890           
  Lines      143640   143640           
  Branches    40926    40926           
=======================================
  Hits        52488    52488           
  Misses      91152    91152           
Flag Coverage Δ
api 3.37% <ø> (ø)
application-system-api 41.11% <ø> (ø)
application-template-api-modules 27.68% <ø> (-0.01%) ⬇️
application-ui-shell 20.86% <ø> (ø)

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


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 94a84fb...1c2ea6d. Read the comment docs.

@datadog-island-is
Copy link

Datadog Report

All test runs a96c100 🔗

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.32s 1 no change Link
application-system-api 0 0 0 120 2 3m 15.7s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 3.36s 1 no change Link
application-ui-shell 0 0 0 74 0 31.86s 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 and nitpick comments (11)
apps/native/app/src/ui/lib/field/field.tsx (2)

Line range hint 26-31: Consider making the margin size configurable.

While the current implementation works, consider making the margin size configurable through props for better component reusability across different contexts.

-const Value = styled.Text<{ size?: 'large' | 'small' }>`
-  margin-right: ${({ theme }) => theme.spacing[2]}px;
+const Value = styled.Text<{ size?: 'large' | 'small'; marginSize?: keyof Theme['spacing'] }>`
+  margin-right: ${({ theme, marginSize = 2 }) => theme.spacing[marginSize]}px;

Line range hint 31-58: Enhance type safety for value prop.

The component could benefit from stronger typing for the value prop to prevent potential runtime issues.

 interface FieldProps {
   label?: string | null
-  value?: string | null
+  value?: string | number | null
   loading?: boolean
   compact?: boolean
   size?: 'large' | 'small'
   style?: ViewStyle | null
 }
apps/native/app/src/ui/lib/field/field-card.tsx (1)

154-156: Consider simplifying the conditional logic.

The current condition is complex and contains redundant checks. Consider this simpler alternative that maintains the same behavior:

-      {(props.title !== null &&
-        !(props.title === undefined && props.code === undefined)) ||
-      (props.title !== undefined && props.code) ? (
+      {(props.title != null || props.code != null) ? (

This simplified version:

  • Uses != null to check for both null and undefined
  • Maintains the requirement that at least one of title or code must be defined
  • Preserves the existing behavior for all license types
  • Is more readable and maintainable
apps/native/app/src/screens/vehicles/vehicles-detail.tsx (1)

Line range hint 23-27: Enhance type safety with explicit type annotations

While the TypeScript implementation is generally good, we could improve type safety by:

  1. Adding explicit return type for the component
  2. Adding type annotations for destructured query results

Consider applying these changes:

-export const VehicleDetailScreen: NavigationFunctionComponent<{
+export const VehicleDetailScreen: NavigationFunctionComponent<{
   title?: string
   id: string
-}> = ({ componentId, title, id }) => {
+}> = ({ componentId, title, id }): JSX.Element => {

And for query results:

  const {
    mainInfo,
    basicInfo,
    registrationInfo,
    inspectionInfo,
    technicalInfo,
-  } = data?.vehiclesDetail || {}
+  } = data?.vehiclesDetail || {} as {
+    mainInfo: typeof data.vehiclesDetail.mainInfo
+    basicInfo: typeof data.vehiclesDetail.basicInfo
+    registrationInfo: typeof data.vehiclesDetail.registrationInfo
+    inspectionInfo: typeof data.vehiclesDetail.inspectionInfo
+    technicalInfo: typeof data.vehiclesDetail.technicalInfo
+  }
apps/native/app/src/ui/lib/card/license-card.tsx (2)

312-314: Consider extracting barcode dimensions logic.

While the calculations are correct, consider extracting them into a utility function for better reusability and testability.

+const calculateBarcodeDimensions = (screenWidth: number, spacing: Theme['spacing']) => {
+  const width = screenWidth - spacing[4] * 2 - spacing.smallGutter * 2
+  const height = width / 3
+  return { width, height }
+}

 export function LicenseCard({...}) {
-  const barcodeWidth = screenWidth - theme.spacing[4] * 2 - theme.spacing.smallGutter * 2
-  const barcodeHeight = barcodeWidth / 3
+  const { width: barcodeWidth, height: barcodeHeight } = calculateBarcodeDimensions(screenWidth, theme.spacing)

400-412: LGTM: Clean implementation of offline message.

The offline message implementation is well-structured and consistent with the design system. However, consider extracting the background opacity value to a constant or theme variable for better maintainability.

+const OFFLINE_MESSAGE_BG_OPACITY = 0.4

 {showBarcodeOfflineMessage && !showBarcodeView && (
   <BarcodeWrapper minHeight={barcodeHeight}>
     <BarcodeContainer
-      style={{ backgroundColor: 'rgba(255,255,255,0.4)' }}
+      style={{ backgroundColor: `rgba(255,255,255,${OFFLINE_MESSAGE_BG_OPACITY})` }}
     >
apps/native/app/src/screens/wallet-pass/wallet-pass.tsx (2)

177-181: Consider simplifying the spacing calculation logic

The complex conditional for informationTopSpacing could be more readable by breaking it down into smaller, named conditions.

-  const informationTopSpacing =
-    (allowLicenseBarcode && ((loading && !data?.barcode) || data?.barcode)) ||
-    (!isConnected && isBarcodeEnabled)
-      ? barcodeHeight + LICENSE_CARD_ROW_GAP
-      : 0
+  const shouldShowBarcode = allowLicenseBarcode && ((loading && !data?.barcode) || data?.barcode)
+  const isOfflineWithBarcodeEnabled = !isConnected && isBarcodeEnabled
+  const informationTopSpacing = 
+    (shouldShowBarcode || isOfflineWithBarcodeEnabled)
+      ? barcodeHeight + LICENSE_CARD_ROW_GAP
+      : 0

249-264: Consider consolidating duplicate alert logic

The error alert logic is duplicated between the Android and iOS code paths. Consider extracting this into a reusable function.

+ const showErrorAlert = (canAddPass: boolean, licenseType?: string) => {
+   Alert.alert(
+     intl.formatMessage({ id: 'walletPass.errorTitle' }),
+     !canAddPass
+       ? intl.formatMessage({ id: 'walletPass.errorCannotAddPasses' })
+       : licenseType === 'DriversLicense'
+       ? intl.formatMessage({ id: 'walletPass.errorNotPossibleToAddDriverLicense' })
+       : intl.formatMessage({ id: 'walletPass.errorAddingOrFetching' }),
+     licenseType === 'DriversLicense'
+       ? [
+           {
+             text: intl.formatMessage({ id: 'walletPass.moreInfo' }),
+             onPress: () => Linking.openURL('https://island.is/okuskirteini'),
+           },
+           {
+             text: intl.formatMessage({ id: 'walletPass.alertClose' }),
+             style: 'cancel',
+           },
+         ]
+       : []
+   )
+ }

Also applies to: 292-310

apps/native/app/src/screens/document-detail/document-detail.tsx (1)

105-112: LGTM! Consider adding aspect-ratio preservation.

The CSS changes correctly prevent SVG and image overflow by setting max-width to 100%. While this is a good fix, consider adding height: auto to preserve aspect ratio and prevent distortion.

 svg {
   max-width: 100%;
   display: block;
+  height: auto;
 }
 img {
   max-width: 100%;
   display: block;
+  height: auto;
 }
apps/native/app/src/messages/en.ts (1)

262-264: Consider making error messages more specific and actionable.

The error messages could be more helpful by:

  1. Specifying where to install Smartwallet from (e.g., App Store/Play Store)
  2. Providing more context about why the fetch/add operation failed
-  'walletPass.errorCannotAddPasses':
-    'You cannot add passes. Please make sure you have Smartwallet installed on your device.',
-  'walletPass.errorAddingOrFetching': 'Failed to fetch or add pass.',
+  'walletPass.errorCannotAddPasses':
+    'You cannot add passes. Please install Smartwallet from the App Store/Play Store to continue.',
+  'walletPass.errorAddingOrFetching': 'Failed to fetch or add pass. Please check your connection and try again.',
apps/native/app/src/messages/is.ts (1)

398-405: LGTM! Consider adding periods for message consistency.

The new wallet pass error messages are well-structured and provide clear user guidance. They align with the PR objectives and follow the established patterns.

For consistency with other error messages in the file, consider adding periods at the end of each message:

  'walletPass.errorCannotAddPasses':
-    'Þú getur ekki bætt við skírteini. Vinsamlegast vertu viss um að þú sért með Smartwallet appið sett upp á tækinu.',
+    'Þú getur ekki bætt við skírteini. Vinsamlegast vertu viss um að þú sért með Smartwallet appið sett upp á tækinu..',
  'walletPass.errorAddingOrFetching':
-    'Tókst ekki að sækja eða bæta við skírteini.',
+    'Tókst ekki að sækja eða bæta við skírteini..',
  'walletPass.errorNotPossibleOnThisDevice':
-    'Þú getur ekki bætt við skírteinum á þetta tæki.',
+    'Þú getur ekki bætt við skírteinum á þetta tæki..',
  'walletPass.errorNotConnectedNoBarcode':
-    'Ekki er hægt að skanna skírteini nema að tækið sé nettengt.',
+    'Ekki er hægt að skanna skírteini nema að tækið sé nettengt..',
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 94a84fb and 1c2ea6d.

📒 Files selected for processing (8)
  • apps/native/app/src/messages/en.ts (1 hunks)
  • apps/native/app/src/messages/is.ts (1 hunks)
  • apps/native/app/src/screens/document-detail/document-detail.tsx (1 hunks)
  • apps/native/app/src/screens/vehicles/vehicles-detail.tsx (1 hunks)
  • apps/native/app/src/screens/wallet-pass/wallet-pass.tsx (10 hunks)
  • apps/native/app/src/ui/lib/card/license-card.tsx (6 hunks)
  • apps/native/app/src/ui/lib/field/field-card.tsx (1 hunks)
  • apps/native/app/src/ui/lib/field/field.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
apps/native/app/src/messages/en.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/native/app/src/messages/is.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/native/app/src/screens/document-detail/document-detail.tsx (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/native/app/src/screens/vehicles/vehicles-detail.tsx (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/native/app/src/screens/wallet-pass/wallet-pass.tsx (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/native/app/src/ui/lib/card/license-card.tsx (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/native/app/src/ui/lib/field/field-card.tsx (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/native/app/src/ui/lib/field/field.tsx (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (10)
apps/native/app/src/ui/lib/field/field.tsx (1)

26-26: LGTM: Margin addition aligns with PR objectives.

The added margin-right improves the spacing between fields, which directly addresses the PR objective of adding margins between firearm fields.

apps/native/app/src/ui/lib/field/field-card.tsx (1)

154-156: LGTM! The changes successfully prevent empty headers.

The updated condition correctly handles the case where both title and code are undefined, preventing the rendering of empty headers for firearms while maintaining existing behavior for other license types.

apps/native/app/src/screens/vehicles/vehicles-detail.tsx (1)

17-20: LGTM: Bottom tab configuration properly implemented

The navigation options correctly implement the requirement to hide the bottom tab bar on the vehicle details screen. The drawBehind: true setting ensures proper layout handling.

apps/native/app/src/ui/lib/card/license-card.tsx (3)

36-37: LGTM: Clean implementation of Typography and screen dimensions.

The new imports and styled component follow the project's patterns and maintain consistency with the design system.

Also applies to: 116-120


275-275: LGTM: Well-defined prop interface.

The new optional prop follows TypeScript best practices and boolean naming conventions.


293-293: LGTM: Clean props destructuring.

The new prop is correctly destructured following the existing pattern.

apps/native/app/src/screens/wallet-pass/wallet-pass.tsx (3)

39-39: LGTM: Clean offline state management implementation

The addition of offline state management through useOfflineStore is well-integrated and follows React best practices.

Also applies to: 150-150


414-414: LGTM: Improved layout handling

The updates to layout handling, including:

  • Offline message display
  • Dynamic content inset calculations
  • Proper margin handling with SafeAreaView

These changes effectively address the PR objectives for improving the display of wallet passes and offline states.

Also applies to: 418-424, 427-435


183-188: 🛠️ Refactor suggestion

Review the necessity of key-based re-render

While the current implementation works, forcing re-renders using a key is a temporary solution. Consider refactoring to use proper state management or component lifecycle methods.

apps/native/app/src/messages/en.ts (1)

265-268: LGTM! Clear and informative error messages.

The error messages for device compatibility and offline mode are clear, concise, and provide good user feedback. They align well with the PR objectives, particularly the addition of an offline placeholder for barcodes.

Copy link
Contributor

@snaerseljan snaerseljan left a comment

Choose a reason for hiding this comment

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

Awesome. Nice job. I know this must have been frustrating 🙃

apps/native/app/src/ui/lib/field/field-card.tsx Outdated Show resolved Hide resolved
@snaerseljan
Copy link
Contributor

@thoreyjona maybe add max width on text so the second line won't only have one word
image

@thoreyjona thoreyjona added the automerge Merge this PR as soon as all checks pass label Nov 12, 2024
@kodiakhq kodiakhq bot merged commit 378ee5f into main Nov 13, 2024
23 checks passed
@kodiakhq kodiakhq bot deleted the fix/license-fixes branch November 13, 2024 04:07
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
* fix: don't show bottom tabs on vehicle details screen

* feat: fix padding issues for licenses and add errors to translation files

* feat: add offline placeholder for barcodes

* fix: fire arm license fixes

* fix: make sure images and svgs in html documents are not super big

* fix: remove contentContainer style

* fix: better condition for field-card

* fix: make sure there is not one word in line 2 for offline message

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2024
6 tasks
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