Skip to content

Implement backend connection for the profile page#178

Merged
SameerIssa merged 7 commits intomainfrom
profile-page
Apr 28, 2025
Merged

Implement backend connection for the profile page#178
SameerIssa merged 7 commits intomainfrom
profile-page

Conversation

@SameerIssa
Copy link
Contributor

@SameerIssa SameerIssa commented Apr 27, 2025

Overview

What does this PR do?

This PR connects the Profile Page and Edit Profile Page to the backend API, enabling real-time retrieval and updates of user data on LessonConnect. It replaces placeholder profile data with live data integration for a production-ready profile management experience.


Key Features & Changes

What has been added or changed?

  • Backend Integration:

    • Fetched user profile details from the backend API on page load.
    • Updated the profile edit form to send PATCH/PUT requests to the backend upon saving changes.
  • Error Handling:

    • Added loading states, success messages, and basic error messages for API interactions.
  • State Management Enhancements:

    • Introduced useEffect and useContext hooks for fetching and updating live profile data.
    • Centralized user profile state for better management across Profile and Edit Profile pages.
  • API Utility Functions:

    • Created profileData.js and auth.js for clean, reusable API call functions (e.g., getProfile, updateProfile).
  • UI/UX Improvements:

    • Loading spinner while profile data is being fetched.
    • "Saved successfully" alert upon editing profile information.

New/Updated Components and Files:

  • ProfilePage.jsx: Now fetches live profile data instead of static imports.
  • EditProfile.jsx: Sends updated profile data to the backend and handles API responses.
  • profileData.js and auth.js : New utility files for handling API requests.
  • ProfilePage.css and EditProfile.css: Minor updates for loading/error display states.

Why This Is Needed

What problem does this solve?

With backend integration, user profiles are now dynamically managed rather than relying on static placeholder data, supporting a scalable, production-level platform. This is critical for user personalization, security, and long-term app functionality.


Related Issue

This PR addresses ##177


Implementation Details

How was this feature developed?

  • API Communication: Axios used for HTTP requests (GET, PATCH).
  • Authentication Handling: Included Authorization headers using bearer tokens from user context.
  • State Synchronization: Live updates reflect across profile view and edit components without requiring a full page reload.
  • Fallback Handling: Default placeholders display when data is missing or fails to load.

How to Test This PR

Step-by-step testing guide

  1. Log into the application.
  2. Navigate to /profile and verify that real user data loads.
  3. From django backend, modify any fields (e.g., name, bio, status).
  4. Confirm changes reflect immediately on the Profile Page.
  5. Test failure scenarios by disabling backend and verifying fallback states.
  6. Test on different devices to ensure responsiveness remains intact.

Files Added/Modified

File Name Description
profileData.js Utility functions for profile-related API calls
auth.js Authentication functions for profile-related API calls
ProfilePage.jsx Now fetches and renders real user data
EditProfile.jsx Sends edited data back to backend
ProfilePage.css / EditProfile.css Styling updates for loading/error messages

AI Code Usage

Was AI-generated code used in this PR?

  • Yes (Some API scaffolding and error message handling were accelerated with AI assistance.)
  • No

Checklist for Reviewers

  • Does the Profile Page load dynamic user data successfully?
  • Is the error handling user-friendly and non-intrusive?
  • Is API communication secure (e.g., using tokens properly)?
  • Is the code clean, modular, and well-documented?

Next Steps & Future Enhancements

  • Refine form validation and add more robust error feedback.
  • Integrate profile picture uploads via backend storage.
  • Implement notification toasts for better user experience.
  • Expand user settings (e.g., privacy controls, theme preferences).

UML diagram:
profileuml

Final Notes

Thanks again for reviewing! Your feedback is crucial to perfecting the user profile management flow as we move toward full production readiness.
– Sameer

@SameerIssa SameerIssa self-assigned this Apr 27, 2025
@codecov
Copy link

codecov bot commented Apr 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.16%. Comparing base (2b7a50c) to head (b7a3e5c).
Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #178   +/-   ##
=======================================
  Coverage   81.16%   81.16%           
=======================================
  Files          17       17           
  Lines         775      775           
  Branches       51       51           
=======================================
  Hits          629      629           
  Misses        123      123           
  Partials       23       23           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@FrankFurter123 FrankFurter123 removed their request for review April 27, 2025 23:11
Copy link
Contributor

@Jose-Alarcon1 Jose-Alarcon1 left a comment

Choose a reason for hiding this comment

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

🔍 Peer Review: Great Job on This PR!

Hey Sameer, I just finished reviewing your PR titled "Implement backend connection for the profile page". Here’s my feedback:


✅ What Looks Great

  • The backend integration is solid — API-related logic is well separated into profileData.js and auth.js, keeping things modular and maintainable.
  • I appreciate the focus on error handling and fallback states — even when the backend fails, the UI remains stable and user-friendly.
  • The loading and success feedback really improves the user experience, making user actions feel responsive and smooth.
  • Your separation of concerns between UI components and API/data logic is very clean — future updates will be much easier to handle.
  • The PR write-up is clear and professional — it walks the reviewer through exactly what changed and how to test everything thoroughly.

💡 Suggestions for Improvement (if any)

These are ideas for future improvements or things to address in the next iteration.

  • Minor Issue: In the "Edit Profile" tab, there’s an occasional problem saving information. (Possibly backend-related, and understandable given the short timeline.)
  • Minor Issue: In "Share Profile", the current behavior shows only a temporary confirmation message. (Possibly backend-related — worth revisiting for a smoother UX.)
  • Consider adding retry logic for API calls (for example, allow a user to retry fetching the profile if the initial load fails).
  • Small optimization idea: you could clean up the useEffect hook slightly in case of component unmount while an async fetch is still pending.
  • Maybe for the next phase, explore optimistic UI updates — reflect edits immediately on the page while awaiting backend confirmation.
  • Over the long term, adding PropTypes or migrating toward TypeScript could help catch unexpected API response changes early.

🧪 Tested This Feature

  • ✅ Logged in and navigated to /profile — verified real-time profile data loads correctly.
  • ✅ Edited several fields (bio, status) — confirmed the data updated and reflected instantly after save.
  • ✅ Simulated backend failures and slow responses — fallback behavior worked smoothly with appropriate user feedback.
  • ✅ Checked layout responsiveness across desktop, tablet, and mobile — no layout breakage detected.

Everything worked exactly as intended! 🎯


🔄 Next Steps

  • Maybe refine edit validation by highlighting specific form fields that fail instead of using only a general error message.
  • Would be great to see profile picture upload and a user settings/preferences section added in a future PR.

🚀 Final Thoughts

Fantastic job integrating backend functionality cleanly into the user-facing pages!
The strong separation into profileData.js and auth.js really shows good planning for scale and maintainability.

You're helping set a strong foundation for future personalization features — can't wait to see where you take this next!

Author: Jose Alarcon

Copy link
Contributor

@omgdory omgdory left a comment

Choose a reason for hiding this comment

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

🔍 Peer Review: Great Job on This PR!

Hey Sameer 👋 — just finished reviewing your PR titled "Connect Profile and Edit Profile Pages to Backend API". Here’s my feedback:


✅ What Looks Great

  • The backend integration aligns perfectly with the related issue.
  • The GET request is functioning as expected, displaying everything on the profile page appropriately.
  • Good call profileData.js and auth.js for clean code responsibility separation.

💡 Suggestions for Improvement (if any)

  • In future iterations, a UML or sequence diagram showing the frontend-backend communication flow could help newer reviewers or developers understand the API lifecycle at a glance.
  • Implementing the PATCH request would help with allowing users to save changes to their profile.

🧪 Tested This Feature

I ran the following test steps:

  • Does the Profile Page load dynamic user data successfully?
  • Is the error handling user-friendly and non-intrusive?
  • Is API communication secure (e.g., using tokens properly)?
  • Is the code clean, modular, and well-documented?

🔄 Next Steps

  • Implement the PATCH request for dynamic changing of data

🚀 Final Thoughts

Incredible work connecting the backend!
You're helping push LessonConnect closer to full production quality with features like this.
If you want help brainstorming backend validation strategies or improving form handling even further, let’s collaborate!

Excited to see this rolled out live soon! 🚀

@SameerIssa SameerIssa marked this pull request as ready for review April 28, 2025 20:26
@SameerIssa SameerIssa merged commit c1f6064 into main Apr 28, 2025
5 checks passed
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.

3 participants