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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

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

@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 replace Notification.Success with toast.success for success notifications. Additionally, the error handling logic now includes parsing server responses to provide specific error messages related to the cover_image, which are displayed using toast.error, improving user feedback during upload failures.

Changes

File Change Summary
src/components/Facility/FacilityHome.tsx - Updated handleCoverImageUpload function to use toast.success and toast.error for notifications.
- Enhanced error handling by parsing server responses to extract specific error messages.

Assessment against linked issues

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

Possibly related PRs

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 9e9fac2
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/677a8f05bc1cb30008704dc9
😎 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 Show resolved Hide resolved
Comment on lines +154 to +158
if (error?.msg?.cover_image) {
error.msg.cover_image.forEach((errorMsg: string) => {
toast.error(errorMsg);
});
}
Copy link
Member

Choose a reason for hiding this comment

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

i'd recommend creating a handler function for this in errorHandler.tsx similar to this:

function handlePydanticErrors(errors: PydanticError[]) {
errors.map(({ type, loc, msg }) => {
const title = type
.replace("_", " ")
.replace(/\b\w/g, (char) => char.toUpperCase());
toast.error(`${title}: '${loc.join(".")}'`, {
description: msg,
duration: 8000,
});
});
}

so that it can be re-used whenever needed.

Copy link
Member

Choose a reason for hiding this comment

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

Already implemented in #9708; export and re-use that once it's merged instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes required needs-triage question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error handling issue during facility cover image uploads
3 participants