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

Error messages should clearly specify the exact issue encountered during facility cover image uploads #9727

Closed

Conversation

modamaan
Copy link
Contributor

@modamaan modamaan commented Jan 4, 2025

Proposed Changes

loom-video.6.mp4

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features
    • Enhanced cover image upload validation
      • Added file size limit (1MB)
      • Restricted image formats to JPG, JPEG, PNG
      • Enforced square (1:1) aspect ratio
    • Improved user feedback for upload errors
      • Detailed error messages displayed for upload failures using toast notifications
      • Enhanced error handling with structured error reporting for cover image uploads
      • Updated error handling to parse server responses for specific error messages during uploads
      • Full-width button for image upload in the Avatar Edit Modal
      • Improved error handling logic during cover image upload process
      • Added structured error handling for avatar uploads in the User Avatar component

@modamaan modamaan requested a review from a team as a code owner January 4, 2025 05:48
Copy link
Contributor

coderabbitai bot commented Jan 4, 2025

Walkthrough

The pull request enhances the error handling for the cover image upload functionality in the FacilityHome component. It modifies the handleCoverImageUpload function to implement a more detailed error handling mechanism, which parses server responses to extract specific error messages related to the cover_image. These messages are processed through handleStructuredErrors, improving user feedback during upload failures. Additionally, the handleStructuredErrors function's visibility and parameter type have been updated to accommodate a broader range of error types.

Changes

File Change Summary
src/components/Facility/FacilityHome.tsx - Updated handleCoverImageUpload function to improve error handling by parsing server responses for specific error messages.
src/Utils/request/errorHandler.ts - Changed handleStructuredErrors to accept both StructuredError and Error, enhancing its error handling capability.
src/components/Common/AvatarEditModal.tsx - Added className="w-full" to the Button component for styling purposes.
src/components/Users/UserAvatar.tsx - Introduced error handling for avatar uploads, utilizing handleStructuredErrors for improved error management.

Assessment against linked issues

Objective Addressed Explanation
Clear error messages for image upload failures [#9720]
Specify exact upload issues [#9720]

Possibly related PRs

Suggested labels

tested, reviewed

Suggested reviewers

  • rithviknishad

Poem

🐰 A rabbit hops with joy and glee,
Uploads now clear as can be!
Errors once vague, now shine so bright,
With messages that guide, all feels just right!
No more confusion, just pixel delight! 🖼️


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

netlify bot commented Jan 4, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 2b30487
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/678fecc139631500083f337a
😎 Deploy Preview https://deploy-preview-9727--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

🧹 Nitpick comments (7)
src/components/Facility/FacilityHome.tsx (7)

137-139: Consider externalizing constants and using i18n for user-facing text.

The maximum file size and allowed image formats are defined as inline constants, and the text displayed in error messages is currently hard-coded in English. For better maintainability and localization, consider moving these constants to a configuration or environment variables, and placing user-facing error messages in i18n files.


140-144: Localize the file-size error message.

Hard-coded strings like "Max size for image uploaded should be 1MB." are not currently localized. Please consider adding this string to your i18n resources to ensure consistency with the rest of the application’s translation framework.


146-147: Revoke the object URL to free up memory.

After using URL.createObjectURL(file), it’s good practice to call URL.revokeObjectURL(img.src) inside img.onload and img.onerror callbacks. This ensures no lingering references remain in the browser’s memory.

🧰 Tools
🪛 GitHub Check: CodeQL

[warning] 147-147: DOM text reinterpreted as HTML
DOM text is reinterpreted as HTML without escaping meta-characters.


150-153: Localize the format error message.

The message "Allowed formats are jpg, png, jpeg." should be placed under i18n to ensure coverage for non-English locales.


156-162: Localize aspect ratio error.

The aspect ratio warning, "Aspect ratio for the image should be 1:1.", is another user-facing string that would benefit from localization.


164-188: Handle edge cases for more informative server-side errors.

This implementation discards all non-200 responses without displaying the server’s error details (e.g., a 400 response with a specific validation message). Providing more descriptive feedback for failures may help users rectify the problem.


190-193: Add i18n coverage for the invalid image message.

The error message "Invalid image file." would also benefit from being localized in your i18n resources.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68c4c3d and b021ac0.

📒 Files selected for processing (1)
  • src/components/Facility/FacilityHome.tsx (1 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeQL
src/components/Facility/FacilityHome.tsx

[warning] 147-147: DOM text reinterpreted as HTML
DOM text is reinterpreted as HTML without escaping meta-characters.

@bodhish
Copy link
Member

bodhish commented Jan 4, 2025

I really don't want us to replicate the BE validation in FE. The validation should have responded with the actual issue right 🤔

image

We just have to show the errors right 🤔

@modamaan
Copy link
Contributor Author

modamaan commented Jan 4, 2025

@bodhish
Screenshot 2025-01-04 220433

src/components/Facility/FacilityHome.tsx Outdated Show resolved Hide resolved
src/components/Facility/FacilityHome.tsx Outdated Show resolved Hide resolved
@modamaan
Copy link
Contributor Author

modamaan commented Jan 5, 2025

@rithviknishad
Screenshot 2025-01-05 145942

Now Care_FE couldn't open, right?

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 5, 2025
@rithviknishad
Copy link
Member

check now

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f52873d and 9e9fac2.

📒 Files selected for processing (1)
  • src/components/Facility/FacilityHome.tsx (2 hunks)
🔇 Additional comments (2)
src/components/Facility/FacilityHome.tsx (2)

7-7: LGTM! Good choice of toast library

The addition of the sonner toast library is appropriate for improving error message notifications.


149-149: LGTM! Good migration from Notification to toast

The switch to toast.success aligns with the modern notification approach.

src/components/Facility/FacilityHome.tsx Outdated Show resolved Hide resolved
@Jacobjeevan Jacobjeevan added waiting for related PR a co-related detail PR is under construction and removed question Further information is requested needs-triage labels Jan 8, 2025
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Jan 10, 2025
Copy link

👋 Hi, @modamaan,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@modamaan
Copy link
Contributor Author

Screenshot 2025-01-14 195156

@modamaan
Copy link
Contributor Author

modamaan commented Jan 14, 2025

Images taken from camera directly should be allowed to upload the image (currently its not working)
Screenshot 2025-01-15 003217

We need to modify the backend code, update the error handling (e.g., pixel size errors) for mobile devices.
It works fine on desktop size

@modamaan
Copy link
Contributor Author

@nihal467

@nihal467
Copy link
Member

nihal467 commented Jan 21, 2025

image

  • uploading of 5MB file to the cover image, keep the state of the pop-up in a infinite loading state of upload button,

Sample-jpg-image-5mb

  • verify the translate are added properly for image added, remove and modified notifications

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ca79fc and 2b30487.

📒 Files selected for processing (1)
  • src/components/Users/UserAvatar.tsx (2 hunks)
🔇 Additional comments (2)
src/components/Users/UserAvatar.tsx (2)

18-18: LGTM! Import addition is well-placed.

The import for handleStructuredErrors is appropriately grouped with other request-related utilities.


60-66: Verify consistency with facility cover image error handling.

Since this PR primarily focuses on facility cover image uploads, ensure that the error handling implementation is consistent between UserAvatar and FacilityHome components.

✅ Verification successful

Error handling implementation is consistent ✓

The error handling implementation in UserAvatar follows the same pattern as FacilityHome, using identical error parsing and structured error handling approach.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Compare error handling implementation between components

# Find FacilityHome component and check its error handling
echo "Checking FacilityHome component implementation:"
rg -A 10 "handleCoverImageUpload.*=.*async" 

# Check for other image upload handlers
echo "\nChecking other image upload implementations:"
rg -l "handleStructuredErrors.*profile_picture|cover_image"

Length of output: 1527


Script:

#!/bin/bash
# Get complete implementation of FacilityHome error handling
echo "FacilityHome error handling implementation:"
rg -A 20 "handleCoverImageUpload.*=.*async" src/components/Facility/FacilityHome.tsx

# Check handleStructuredErrors usage patterns
echo "\nError handling patterns:"
rg -A 5 "xhr\.responseText.*JSON\.parse|handleStructuredErrors" src/components/Facility/FacilityHome.tsx src/components/Users/UserAvatar.tsx

Length of output: 3041

src/components/Users/UserAvatar.tsx Show resolved Hide resolved
@modamaan
Copy link
Contributor Author

modamaan commented Jan 21, 2025

@nihal467

CARE.-.Google.Chrome.2025-01-22.00-34-11.mp4

@nihal467
Copy link
Member

nihal467 commented Jan 22, 2025

image

@modamaan Bad request error message is not required in the frontend; hide them.

Copy link
Member

@nihal467 nihal467 left a comment

Choose a reason for hiding this comment

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

make necessary changes in the above comment

@rithviknishad
Copy link
Member

Will be done along with #9882

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error handling issue during facility cover image uploads
5 participants