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/profile photo upload issues #11093

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

Conversation

Rustix69
Copy link
Contributor

@Rustix69 Rustix69 commented Mar 6, 2025

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Screenshots :

Image 01 :

image

Image 02 :

image

Image 03 :

image

Summary by CodeRabbit

  • New Features

    • Enhanced image editing by integrating a cropping tool that allows users to adjust and preview their image selections before finalizing.
    • Introduced a new library to streamline image cropping functionality.
  • Documentation

    • Updated user interface messages with clearer error alerts for input length, numerical values, age limits, and image dimension requirements.

@Rustix69 Rustix69 requested a review from a team as a code owner March 6, 2025 21:06
Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

Walkthrough

This pull request performs cosmetic and functional updates. It removes extra blank lines from the configuration file, adds a new dependency (react-easy-crop) to the project, and updates the localization strings. In addition, a new utility function for image cropping is introduced and integrated into the AvatarEditModal component, which now includes a cropping UI, state management, and error handling for enhanced image editing.

Changes

File(s) Change Summary
care.config.ts Removed three blank lines at the end of the careConfig object declaration.
package.json Added new dependency "react-easy-crop": "^5.4.1".
public/locale/en.json Removed "preview_form" key; added keys "min_length_error", "min_value_error", "minimum_age_should_be", "minimum_image_dimensions"; updated "resend_otp_timer" string.
src/Utils/getCroppedImg.tsx, src/components/Common/…/AvatarEditModal.tsx Introduced image cropping functionality by adding the getCroppedImg utility function and integrating the Cropper component with state variables, methods (handleCropImage, onCropComplete), and error handling in the AvatarEditModal component.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant M as AvatarEditModal
    participant C as Cropper (react-easy-crop)
    participant G as getCroppedImg
    participant A as Canvas

    U->>M: Upload/select image
    M->>M: Set cropping state and render Cropper
    M->>C: Display image for cropping
    C-->>M: Return cropped area pixels via onCropComplete
    M->>G: Invoke handleCropImage(imageSrc, croppedAreaPixels)
    G->>A: Configure canvas and draw cropped section
    A-->>G: Return Blob URL of the cropped image
    G-->>M: Pass cropped image URL back
    M->>U: Update UI with cropped image preview
Loading

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • Jacobjeevan
  • rithviknishad

Poem

Oh, I’m a rabbit with coding delight,
Hopping through lines both day and night.
I prance past blank spaces trimmed so neat,
Crop and slice images—a visual treat!
With bytes and bugs leaping out of sight,
I celebrate changes with a joyful tweet!
🐇💻 Happy coding!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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 Mar 6, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 69516bf
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67ca0e58b34e700008a03825
😎 Deploy Preview https://deploy-preview-11093.preview.ohc.network
📱 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.

image.addEventListener("load", () => resolve(image));
image.addEventListener("error", (error) => reject(error));
image.setAttribute("crossOrigin", "anonymous"); // needed to avoid cross-origin issues on some browsers
image.src = url;

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
/>
) : (
<img
src={preview || imageUrl}

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
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

🧹 Nitpick comments (4)
src/Utils/getCroppedImg.tsx (1)

1-8: Check for potential large image handling.

The createImage function correctly loads an image and manages load/error events, but for large image URLs, memory usage could be high. Consider adding checks or constraints for image dimensions if this utility is used in memory-intensive contexts.

🧰 Tools
🪛 GitHub Check: CodeQL

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

src/components/Common/AvatarEditModal.tsx (3)

134-151: Add more specific error feedback for cropping.

While the try...catch includes a generic error toast, consider logging the actual error for debugging.


153-166: Cropped image fetch logic.

Fetching the Blob for conversion works well. Optionally wrap in a try-catch to handle fetch exceptions or typed array errors if the file is large.


188-200: Enable cropping on file selection.

Automatically setting isCropping to true on file import fosters a cohesive workflow. You might also integrate additional file size checks if needed (enforced limit is only documented, not programmatically validated).

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1fdd91f and 69516bf.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • care.config.ts (0 hunks)
  • package.json (1 hunks)
  • public/locale/en.json (3 hunks)
  • src/Utils/getCroppedImg.tsx (1 hunks)
  • src/components/Common/AvatarEditModal.tsx (14 hunks)
💤 Files with no reviewable changes (1)
  • care.config.ts
🧰 Additional context used
🪛 GitHub Check: CodeQL
src/components/Common/AvatarEditModal.tsx

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

src/Utils/getCroppedImg.tsx

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

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test
  • GitHub Check: OSSAR-Scan
  • GitHub Check: cypress-run (1)
🔇 Additional comments (17)
package.json (1)

110-110: Add a note to verify the new dependency version.

Adding "react-easy-crop": "^5.4.1" looks valid, but it's good to verify the library’s version for security patches and feature stability.

public/locale/en.json (6)

1500-1500: Translation key addition confirmed.

"min_length_error": "Minimum length of {{min}} characters required" is well-structured with placeholders.


1503-1503: Translation key addition confirmed.

"min_value_error": "Value should be greater than or equal to {{min}}" is consistent and clear for user messages.


1505-1505: Translation key addition confirmed.

"minimum_age_should_be": "Minimum age should be {{age}} years" is meaningful for validations.


1506-1506: Translation key addition confirmed.

"minimum_image_dimensions": "Minimum image dimensions required: {{width}} × {{height}}" properly indicates dimension constraints.


1893-1893: Key removal or update check.

"preview_form": "Preview form" is marked as changed. Ensure this removal (or modification) is intentional and does not affect references in the codebase.


2022-2022: Translation key addition confirmed.

"resend_otp_timer": "Resend OTP in {{time}} seconds" handles dynamic text well.

src/components/Common/AvatarEditModal.tsx (10)

8-8: New import for the Cropper component.

The import statement is correct. Confirm that 'react-easy-crop' is installed and properly peer-dependent.


26-26: Ensure the getCroppedImg utility matches expected usage.

import { getCroppedImg } is consistent with the new utility. Verify that the function’s signature aligns with the new states set in this component.


44-50: Reduced video resolution from 1280 to 720.

This change improves performance but may lower image quality. Confirm if 720×720 meets project needs, especially on large screens or high-resolution devices.


82-92: Comprehensive state management for cropping.

Introducing crop, zoom, croppedAreaPixels, croppedImage, isCropping, and errorMessage effectively centralizes the cropping logic. Ensure that multiple re-renders do not cause performance bottlenecks.


100-115: Crop callback setup.

handleSwitchCamera toggles constraints, and onCropComplete updates croppedAreaPixels. The approach is straightforward and maintainable.


168-177: Clear resets upon modal closing.

The closeModal function properly resets the new cropping states, preventing stale data on re-open.


248-254: Drag and drop triggers cropping workflow.

Setting isCropping = true on drop is consistent with line 188. Same note about optional file size checks.


302-345: Conditional rendering of Cropper for normal preview.

Utilizing a dedicated Cropper section ensures a smooth user experience. The absolute-positioned bottom controls are a nice touch for confirm/cancel. Consider verifying mobile styling.

🧰 Tools
🪛 GitHub Check: CodeQL

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


438-445: Inline “Crop” button.

Toggling the cropping state is straightforward. Code is concise.


492-616: Camera capture and cropping integration for webcam mode.

The logic to retake or confirm the photo is user-friendly. Remember to manage camera permission errors gracefully. The fallback to environment mode is stable.

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

Successfully merging this pull request may close these issues.

Profile Photo Upload Issues: Missing 1:1 Crop and Unclear Pixel Requirements
1 participant