Skip to content

[FLN-194][Hoang][UI] Fix chat and AI [17.11.2025]#163

Merged
justduck25 merged 1 commit intoFLearningfrom
feature/FLN-194_Fix-chat-and-AI
Nov 18, 2025
Merged

[FLN-194][Hoang][UI] Fix chat and AI [17.11.2025]#163
justduck25 merged 1 commit intoFLearningfrom
feature/FLN-194_Fix-chat-and-AI

Conversation

@hofang42
Copy link
Contributor

@hofang42 hofang42 commented Nov 17, 2025

Overview

  • Fix chat và update logic call api AI

Check list

Checklists

  • Đã test đầy đủ trước khi tạo PR
  • Đã tự review lại code
  • Đảm bảo không commit các file không cần thiết (VD: .env, node_modules, build folder, v.v.)
  • Đã đặt tên branch, commit theo đúng quy định
  • Add Reviewers và Assignees
  • Add Labels

Jira Ticket

https://flearning.atlassian.net/browse/FLN-194


EVD

Uploading image.png…

@hofang42 hofang42 requested a review from justduck25 November 17, 2025 15:40
@hofang42 hofang42 self-assigned this Nov 17, 2025
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on December 7

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

createdAt: conv.createdAt,
// Extract otherParticipant from populated participants
otherParticipant: conv.participants?.find(
(p) => p._id.toString() !== currentUser?._id.toString()
Copy link

Choose a reason for hiding this comment

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

Bug: Improve null safety for _id access.

Calling .toString() on p._id assumes it's always an object with a toString method, but if p._id is already a string or if p is null/undefined, this will throw an error. The optional chaining on conv.participants?.find protects against participants being null, but not against individual participant objects or their _id properties being null/undefined.

Fix in Cursor Fix in Web

createdAt: conv.createdAt,
// Extract otherParticipant from populated participants
otherParticipant: conv.participants?.find(
(p) => p._id.toString() !== currentUser?._id.toString()
Copy link

Choose a reason for hiding this comment

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

Bug: Ensure _id Type Safety for toString Calls

Calling .toString() on p._id assumes it's always an object with a toString method, but if p._id is already a string or if p is null/undefined, this will throw an error. The optional chaining on conv.participants?.find protects against participants being null, but not against individual participant objects or their _id properties being null/undefined.

Fix in Cursor Fix in Web

if (conv.id === newConversationId) {
return {
...conv,
...(conversationData || {}), // Use backend data if available
Copy link

Choose a reason for hiding this comment

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

Bug: Conversation Data Structure Inconsistency

When spreading conversationData from the backend response, the data isn't formatted to match the frontend structure. The backend likely returns _id, last_message, etc., but the frontend expects id, lastMessage. While explicit properties like lastMessage and status override backend properties, _id from the backend will remain, causing the conversation object to have _id instead of or alongside id, breaking comparisons like conv.id === newConversationId throughout the codebase.

Fix in Cursor Fix in Web

lastMessageSenderId: currentUser._id,
},
...prev,
];
Copy link

Choose a reason for hiding this comment

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

Bug: Conversation Data Structure Mismatch Breaks Frontend

When creating a new conversation from conversationData, the backend response is spread directly without formatting to match the frontend structure. The backend returns properties like _id, last_message, and participants with _id fields, but the frontend expects id, lastMessage, and properly formatted participant data. This inconsistency with the socket event handlers (lines 133-144, 162-173) will cause the new conversation to have mismatched property names, breaking functionality that relies on conv.id.

Fix in Cursor Fix in Web

@justduck25 justduck25 merged commit e4b5eea into FLearning Nov 18, 2025
2 checks passed
hofang42 added a commit that referenced this pull request Nov 18, 2025
* [FLN-133][Hoang][UI] Update UI for add course [07.10.2025] (#110)

* [FLN-134][Duc][UI] Apply  API for Adding Course [15.10.2025] (#111)

* [FLN-136][Hoang][UI] Add UI for instructor [15.10.2025] (#112)

* [FLN-143][Duc][UI] Apply Quiz API to WatchCourse [17.10.2025] (#113)

* [FLN-144] instructor registration (#114)

* [Dat] Add UI for Instructor registration #16.10.2025

* [Dat] Add UI for Registration Instructor #17.10.2025

* Delete package-lock.json

* Update GeminiChatBox.jsx

* Update authService.js

* [Fix] Remove biography & bank from instructor profile (#115)

* Remove bio field from instructor registration

Eliminated the 'bio' field from the instructor registration form, validation, and submission payload. This streamlines the registration process by no longer requiring instructors to provide a bio.

* Remove payment information fields from instructor registration

Eliminated bank name, account number, and account holder name fields from the instructor registration form and related validation logic. This streamlines the registration process by no longer requiring payment information at this stage.

* Move auth routes outside main layout in router

Auth routes are now rendered outside the AppLayout component, ensuring they do not inherit the main layout. This change improves route structure and separation between authentication and main application pages.

* Refactor auth routes into with/without layout groups (#116)

Split authentication routes into two groups: routes with layout (login, signup, forgot/reset password) and routes without layout (verification and confirmation pages). Updated the main router to use these new route groups for clearer structure and maintainability, while preserving backward compatibility.

* [FLN-148][Hoang][UI] Add function verify instructor [19.10.2025] (#117)

* [FLN][Duc][UI] Reapply APIs for instructor [18.10.2025] (#118)

* [FLN-130][Thien][UI] Implement PayOs payment code [18.10.2025] (#119)

* Add after payment logic and something else (#120)

* [FLN-130][Thien][UI] Implement PayOs payment code [18.10.2025]

* [FLN-130][Thien][UI] Add logic after payment [19.10.2025]

* [FLN-156][Dat][FE] Instructor Profile Edit Page [19.10.2025] (#122)

* [FLN-157][Dat][FE] Instructor Public Profile Page with Figma Design [19.10.2025] (#123)

* [FLN-158][Dat][FE] Instructor Info Card on Course Details [19.10.2025] (#124)

* [FLN-159][Dat][FE] Routing and Navigation with API Integration [19.10.2025] (#125)

* [FLN-160][Dat][FE] Admin Censor Instructor and UI Polish [19.10.2025] (#126)

* [FLN-162][Thien][UI] Send welcome message when user enrolled an course [19.10.2025] (#127)

* [FLN-163][UI] Update Instructor Rating Display on Course Details Page [19.10.2025] (#128)

* [FLN-161][Hoang][UI] Add censor course for admin [19.10.2025] (#129)

* [FLN-152][UI] Apply Discount API for Instructor (#121)

* [FLN-152][Duc][UI] Apply Discount API for Instructor [19.10.2025]

* [FLN-152][Duc][UI] Apply Discount API to Checkout [19.10.2025]

* [FLN-164][Thien][UI] Fix view top categories [19.10.2025] (#131)

* [FLN-165][Duc][UI] Add Quiz Template, Fix API [19.10.2025] (#132)

* [FLN-166][FLN-167][FE] Instructor Register Button & Active Course Filter [20.10.2025] (#133)

* [FLN-166][FLN-167][FE] Instructor Register Button & Active Course Filter [20.10.2025]

* Enhance course author display and update dashboard stats

Updated BestSellingCourse and RecentlyAddedCourse components to dynamically display the instructor's name and avatar based on course data, defaulting to generic values if missing. Modified InstructorDashboard to show total revenue in VND format. Added route titles for 'Profile' and 'Discounts' in InstructorLayout for improved navigation.

* [FLN-129][Hoang][UI] Add modal for AI explain [25.10.2025] (#135)

* [FLN-129][Hoang][UI] Add modal for AI explain [25.10.2025]

* [FLN-129][Hoang][BE] Cập nhật thêm logic [25.10.2025]

* [FLN-172][Duc][UI] Update Upload Quiz for Instructor [30.10.2025] (#136)

* [FLN-171][Duc][UI] Add AI summaries Video&Article [30.10.2025] (#137)

* [FLN-176][Hoang][UI] Tạo Learning Path cho học viên bằng AI [11.01.2025] (#138)

* [FLN-170][Thien][UI] Auto creating cerficate [01.11.2025] (#139)

* [UI][fix] real-time fetch certificate (#140)

* [FLN-177][Thien][UI] Fix bug real-time receiving certificate [02.11.2025]

* [FLN-177][Thien][UI] Add animation congratulation [02.11.2025]

* [FLN-178][Thien][UI] Fix categories label icon and text size card [02.11.2025] (#141)

* [FLN-179][Thien][UI] Sync data in course detail page [02.11.2025] (#142)

* [FLN-180][Duc][Bug] Fix quiz result saving [02.11.2025] (#143)

* [FLN-181][Hoang][UI] Update instructor dashboard [02.11.2025] (#144)

* [FLN-183][Thien][UI] Hide search bar in some screen avoid duplicate [02.11.2025] (#145)

* [FLN-185][Duc][UI] Sửa bug không fetch đúng data ở nhiều màn [02.11.2025] (#146)

* [FLN-174][UI] ai quiz generation (#148)

* [FLN-174][Dat][UI] Add AI Quiz Generation Feature [30.10.2025]

* feat: Add AI-powered proctoring system with face recognition and progressive punishment

* [FLN-186][Duc][UI] Update Instructor my course chart [03.11.2025] (#150)

* [FLN-175] [FE] Update ban/unban user (#151)

* banned update

* Add AI review status and score to instructor management

Introduces display of AI review status badges and scores in the instructor applications table and details modal. Updates filtering logic to include AI-approved applications and provides visual cues for manual review, approval, and rejection statuses.

* banned update (#152)

* [FLN-188][Duc][UI] Thêm prefix css [03.11.2025] (#153)

* [FLN-189][FE] Fix quiz proctoring system violations and face detection (#154)

- Fixed premature quiz locking (was locking after 1-2 violations instead of 3)
- Removed duplicate violation counting logic in QuizContent
- Added identity verification on "Start Quiz" button click instead of intro page
- Relaxed face detection: users can look away without getting locked
- Added 3-second threshold warning when user looks away from camera
- Fixed warning modal z-index to prevent header overlap
- Added throttling (5 seconds) for face mismatch warnings to prevent spam
- Removed "no face detected" warning banner from camera preview

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>

* [FLN-190][Thien][API] Format Card detail attribute in Home Screen [03.11.2025] (#155)

* FLN-191][Thien][UI] Enhance logic search bar and add to wishlist requirement [03.11.2025] (#157)

* [FLN-192][Thien][UI] Add Withdraw function for instructor [03.11.2025] (#158)

* [FLN-175] [FE] AI for instructor's application (#159)

* banned update

* Add AI review status and score to instructor management

Introduces display of AI review status badges and scores in the instructor applications table and details modal. Updates filtering logic to include AI-approved applications and provides visual cues for manual review, approval, and rejection statuses.

* feat: Add AI review status badge in CensorInstructor

- Added 'Manual Approval' badge for AI-reviewed applications
- Display indigo badge when approved but no AI review status exists
- Enhanced UI for admin to identify AI-reviewed vs manual-reviewed applications

* feat: Add instructor application verification page and routes

- Create InstructorVerifyApplicationPage for existing users
- Add verifyInstructorEmail and verifyInstructorApplication API functions
- Update InstructorVerifyEmailPage to use correct API endpoint
- Add route for /verify-instructor-application/:token

---------

Co-authored-by: cheeseachocolate <giangnlde180815@fpt.edu.vn>

* [UI] Sửa Face Verification chỉ hiện 1 lần (#160)

* Fix modal handling on quiz completion and isActive logic (#161)

* Fix modal handling on quiz completion and isActive logic

ProctorMonitor now closes the identity modal when the quiz is finished or inactive. Updated QuizContent to improve isActive logic, ensuring the proctoring monitor is only active when appropriate.

* Show AI explanation button for all quiz results

Previously, the AI explanation button was only shown if the quiz was passed. This change makes the button always visible, allowing users to access AI explanations regardless of their quiz result.

* Make quiz lockout user-specific in QuizContent (#162)

Quiz lockout is now tracked per user by including userId in the localStorage key. This prevents lockouts from affecting all users on the same device and ensures proper isolation of quiz access restrictions.

* [FLN-195][Thien][UI] Add UI for Notification function[18.11.2025] (#164)

* [FLN-194][Hoang][UI] Fix chat and AI [17.11.2025] (#163)

* [FLN-196][Duc][UI] Fix Student my course card, allow download summaries [18.11.2025] (#165)

---------

Co-authored-by: Nguyen Doan Trong Duc <89635693+trongducdoan25@users.noreply.github.com>
Co-authored-by: Nekomimi <kthkun@gmail.com>
Co-authored-by: Huynh Dinh Thien <136036261+Nomsociuu@users.noreply.github.com>
Co-authored-by: Nguyen Doan Trong Duc <89635693+justduck25@users.noreply.github.com>
Co-authored-by: Nguyễn Lam Giang <133856538+gianglamnguyen@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: cheeseachocolate <giangnlde180815@fpt.edu.vn>
Nomsociuu added a commit that referenced this pull request Nov 18, 2025
* [FLN-133][Hoang][UI] Update UI for add course [07.10.2025] (#110)

* [FLN-134][Duc][UI] Apply  API for Adding Course [15.10.2025] (#111)

* [FLN-136][Hoang][UI] Add UI for instructor [15.10.2025] (#112)

* [FLN-143][Duc][UI] Apply Quiz API to WatchCourse [17.10.2025] (#113)

* [FLN-144] instructor registration (#114)

* [Dat] Add UI for Instructor registration #16.10.2025

* [Dat] Add UI for Registration Instructor #17.10.2025

* Delete package-lock.json

* Update GeminiChatBox.jsx

* Update authService.js

* [Fix] Remove biography & bank from instructor profile (#115)

* Remove bio field from instructor registration

Eliminated the 'bio' field from the instructor registration form, validation, and submission payload. This streamlines the registration process by no longer requiring instructors to provide a bio.

* Remove payment information fields from instructor registration

Eliminated bank name, account number, and account holder name fields from the instructor registration form and related validation logic. This streamlines the registration process by no longer requiring payment information at this stage.

* Move auth routes outside main layout in router

Auth routes are now rendered outside the AppLayout component, ensuring they do not inherit the main layout. This change improves route structure and separation between authentication and main application pages.

* Refactor auth routes into with/without layout groups (#116)

Split authentication routes into two groups: routes with layout (login, signup, forgot/reset password) and routes without layout (verification and confirmation pages). Updated the main router to use these new route groups for clearer structure and maintainability, while preserving backward compatibility.

* [FLN-148][Hoang][UI] Add function verify instructor [19.10.2025] (#117)

* [FLN][Duc][UI] Reapply APIs for instructor [18.10.2025] (#118)

* [FLN-130][Thien][UI] Implement PayOs payment code [18.10.2025] (#119)

* Add after payment logic and something else (#120)

* [FLN-130][Thien][UI] Implement PayOs payment code [18.10.2025]

* [FLN-130][Thien][UI] Add logic after payment [19.10.2025]

* [FLN-156][Dat][FE] Instructor Profile Edit Page [19.10.2025] (#122)

* [FLN-157][Dat][FE] Instructor Public Profile Page with Figma Design [19.10.2025] (#123)

* [FLN-158][Dat][FE] Instructor Info Card on Course Details [19.10.2025] (#124)

* [FLN-159][Dat][FE] Routing and Navigation with API Integration [19.10.2025] (#125)

* [FLN-160][Dat][FE] Admin Censor Instructor and UI Polish [19.10.2025] (#126)

* [FLN-162][Thien][UI] Send welcome message when user enrolled an course [19.10.2025] (#127)

* [FLN-163][UI] Update Instructor Rating Display on Course Details Page [19.10.2025] (#128)

* [FLN-161][Hoang][UI] Add censor course for admin [19.10.2025] (#129)

* [FLN-152][UI] Apply Discount API for Instructor (#121)

* [FLN-152][Duc][UI] Apply Discount API for Instructor [19.10.2025]

* [FLN-152][Duc][UI] Apply Discount API to Checkout [19.10.2025]

* [FLN-164][Thien][UI] Fix view top categories [19.10.2025] (#131)

* [FLN-165][Duc][UI] Add Quiz Template, Fix API [19.10.2025] (#132)

* [FLN-166][FLN-167][FE] Instructor Register Button & Active Course Filter [20.10.2025] (#133)

* [FLN-166][FLN-167][FE] Instructor Register Button & Active Course Filter [20.10.2025]

* Enhance course author display and update dashboard stats

Updated BestSellingCourse and RecentlyAddedCourse components to dynamically display the instructor's name and avatar based on course data, defaulting to generic values if missing. Modified InstructorDashboard to show total revenue in VND format. Added route titles for 'Profile' and 'Discounts' in InstructorLayout for improved navigation.

* [FLN-129][Hoang][UI] Add modal for AI explain [25.10.2025] (#135)

* [FLN-129][Hoang][UI] Add modal for AI explain [25.10.2025]

* [FLN-129][Hoang][BE] Cập nhật thêm logic [25.10.2025]

* [FLN-172][Duc][UI] Update Upload Quiz for Instructor [30.10.2025] (#136)

* [FLN-171][Duc][UI] Add AI summaries Video&Article [30.10.2025] (#137)

* [FLN-176][Hoang][UI] Tạo Learning Path cho học viên bằng AI [11.01.2025] (#138)

* [FLN-170][Thien][UI] Auto creating cerficate [01.11.2025] (#139)

* [UI][fix] real-time fetch certificate (#140)

* [FLN-177][Thien][UI] Fix bug real-time receiving certificate [02.11.2025]

* [FLN-177][Thien][UI] Add animation congratulation [02.11.2025]

* [FLN-178][Thien][UI] Fix categories label icon and text size card [02.11.2025] (#141)

* [FLN-179][Thien][UI] Sync data in course detail page [02.11.2025] (#142)

* [FLN-180][Duc][Bug] Fix quiz result saving [02.11.2025] (#143)

* [FLN-181][Hoang][UI] Update instructor dashboard [02.11.2025] (#144)

* [FLN-183][Thien][UI] Hide search bar in some screen avoid duplicate [02.11.2025] (#145)

* [FLN-185][Duc][UI] Sửa bug không fetch đúng data ở nhiều màn [02.11.2025] (#146)

* [FLN-174][UI] ai quiz generation (#148)

* [FLN-174][Dat][UI] Add AI Quiz Generation Feature [30.10.2025]

* feat: Add AI-powered proctoring system with face recognition and progressive punishment

* [FLN-186][Duc][UI] Update Instructor my course chart [03.11.2025] (#150)

* [FLN-175] [FE] Update ban/unban user (#151)

* banned update

* Add AI review status and score to instructor management

Introduces display of AI review status badges and scores in the instructor applications table and details modal. Updates filtering logic to include AI-approved applications and provides visual cues for manual review, approval, and rejection statuses.

* banned update (#152)

* [FLN-188][Duc][UI] Thêm prefix css [03.11.2025] (#153)

* [FLN-189][FE] Fix quiz proctoring system violations and face detection (#154)

- Fixed premature quiz locking (was locking after 1-2 violations instead of 3)
- Removed duplicate violation counting logic in QuizContent
- Added identity verification on "Start Quiz" button click instead of intro page
- Relaxed face detection: users can look away without getting locked
- Added 3-second threshold warning when user looks away from camera
- Fixed warning modal z-index to prevent header overlap
- Added throttling (5 seconds) for face mismatch warnings to prevent spam
- Removed "no face detected" warning banner from camera preview

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>

* [FLN-190][Thien][API] Format Card detail attribute in Home Screen [03.11.2025] (#155)

* FLN-191][Thien][UI] Enhance logic search bar and add to wishlist requirement [03.11.2025] (#157)

* [FLN-192][Thien][UI] Add Withdraw function for instructor [03.11.2025] (#158)

* [FLN-175] [FE] AI for instructor's application (#159)

* banned update

* Add AI review status and score to instructor management

Introduces display of AI review status badges and scores in the instructor applications table and details modal. Updates filtering logic to include AI-approved applications and provides visual cues for manual review, approval, and rejection statuses.

* feat: Add AI review status badge in CensorInstructor

- Added 'Manual Approval' badge for AI-reviewed applications
- Display indigo badge when approved but no AI review status exists
- Enhanced UI for admin to identify AI-reviewed vs manual-reviewed applications

* feat: Add instructor application verification page and routes

- Create InstructorVerifyApplicationPage for existing users
- Add verifyInstructorEmail and verifyInstructorApplication API functions
- Update InstructorVerifyEmailPage to use correct API endpoint
- Add route for /verify-instructor-application/:token

---------

Co-authored-by: cheeseachocolate <giangnlde180815@fpt.edu.vn>

* [UI] Sửa Face Verification chỉ hiện 1 lần (#160)

* Fix modal handling on quiz completion and isActive logic (#161)

* Fix modal handling on quiz completion and isActive logic

ProctorMonitor now closes the identity modal when the quiz is finished or inactive. Updated QuizContent to improve isActive logic, ensuring the proctoring monitor is only active when appropriate.

* Show AI explanation button for all quiz results

Previously, the AI explanation button was only shown if the quiz was passed. This change makes the button always visible, allowing users to access AI explanations regardless of their quiz result.

* Make quiz lockout user-specific in QuizContent (#162)

Quiz lockout is now tracked per user by including userId in the localStorage key. This prevents lockouts from affecting all users on the same device and ensures proper isolation of quiz access restrictions.

* [FLN-195][Thien][UI] Add UI for Notification function[18.11.2025] (#164)

* [FLN-194][Hoang][UI] Fix chat and AI [17.11.2025] (#163)

* [FLN-196][Duc][UI] Fix Student my course card, allow download summaries [18.11.2025] (#165)

* [FLN-197][Thien][UI] AI check comment UI [18.11.2025] (#166)

---------

Co-authored-by: Thanh Hoang <126055913+hofang42@users.noreply.github.com>
Co-authored-by: Nguyen Doan Trong Duc <89635693+trongducdoan25@users.noreply.github.com>
Co-authored-by: Nekomimi <kthkun@gmail.com>
Co-authored-by: Nguyen Doan Trong Duc <89635693+justduck25@users.noreply.github.com>
Co-authored-by: Nguyễn Lam Giang <133856538+gianglamnguyen@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: cheeseachocolate <giangnlde180815@fpt.edu.vn>
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.

2 participants