-
Notifications
You must be signed in to change notification settings - Fork 514
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
base: develop
Are you sure you want to change the base?
Error messages should clearly specify the exact issue encountered during facility cover image uploads #9727
Conversation
WalkthroughThe pull request enhances the error handling for the cover image upload functionality in the Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
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
CodeRabbit Configuration File (
|
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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
🧹 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 callURL.revokeObjectURL(img.src)
insideimg.onload
andimg.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
📒 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.
Now Care_FE couldn't open, right? |
check now |
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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 libraryThe addition of the
sonner
toast library is appropriate for improving error message notifications.
149-149
: LGTM! Good migration from Notification to toastThe switch to
toast.success
aligns with the modern notification approach.
if (error?.msg?.cover_image) { | ||
error.msg.cover_image.forEach((errorMsg: string) => { | ||
toast.error(errorMsg); | ||
}); | ||
} |
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.
i'd recommend creating a handler function for this in errorHandler.tsx similar to this:
care_fe/src/Utils/request/errorHandler.ts
Lines 88 to 99 in a6f4ab6
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.
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.
Already implemented in #9708; export and re-use that once it's merged instead.
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.
ok👍
Proposed Changes
loom-video.6.mp4
@ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit