Skip to content

Conversation

@SandeepChauhan00
Copy link

@SandeepChauhan00 SandeepChauhan00 commented Nov 17, 2025

###Fixes
#132 – Search result “View Profile” is hidden behind collaboration Dialog .

###Description

This PR fixes the issue where the "View Profile" modal was appearing behind the Collaboration modal and also allowed click-through, causing unexpected behaviour.

###This PR ensures

  1. Parent modal closes before opening View Profile modal

  2. Prevents click-through and focus leakage

  3. Provides consistent modal behaviour across collaboration flow

Summary by CodeRabbit

  • Bug Fixes

    • Fixed modal closure sequencing when viewing creator profiles—modal now properly closes before opening the profile view.
    • Improved connection flow to automatically select the first search result when connecting to a creator.
  • Refactor

    • Adjusted UI element spacing and structure for consistency.
    • Optimized modal interaction behavior for improved user experience.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 17, 2025

Walkthrough

This change fixes a modal stacking issue where the View Profile modal appeared behind the New Collaboration modal. The fix explicitly closes the collaboration modal before opening the profile view, preventing overlapping modals and unintended redirects. Minor formatting adjustments and structural improvements are also applied.

Changes

Cohort / File(s) Summary
Modal stacking fix
Frontend/src/components/collaboration-hub/NewCollaborationModal.tsx
Adds explicit onClose() call before opening View Profile modal to prevent z-index layering issues; adjusts onConnect to select first search result; minor formatting and spacing refinements

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Modal as NewCollaborationModal
    participant Profile as ViewProfileModal
    
    User->>Modal: Click "View Profile"
    
    rect rgb(200, 220, 240)
    Note over Modal: Fix: Close collaboration modal first
    Modal->>Modal: onClose()
    end
    
    Modal->>Profile: Open with creator data
    User->>Profile: View creator information
    Profile-->>User: Profile displayed in front
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Focus areas:
    • Verify onClose() is called at the correct point in the View Profile click handler
    • Confirm ViewProfileModal's onConnect logic correctly selects the first search result
    • Validate no regression in modal lifecycle management or state transitions
    • Check that formatting changes don't introduce unintended behavior shifts

Poem

🐰 Two modals danced with confused sight,
One hid the other, out of light.
With onClose() whispered between,
They learned to queue—a clean, ordered scene.
Now profiles bloom in their rightful frame,
No more z-index games!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main changes: fixing modal order and preventing click-through on View Profile, which directly addresses the core issues in the changeset.
Linked Issues check ✅ Passed The code changes directly address all primary objectives from issue #132: closing the parent modal before opening View Profile [#132], preventing click-through behavior [#132], and preventing unintended redirects [#132].
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue #132; formatting adjustments and state flow modifications are necessary implementation details for fixing the modal behavior and click-through issues.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3be437 and fcab300.

📒 Files selected for processing (1)
  • Frontend/src/components/collaboration-hub/NewCollaborationModal.tsx (12 hunks)
🔇 Additional comments (2)
Frontend/src/components/collaboration-hub/NewCollaborationModal.tsx (2)

101-106: Good practice to reset state on close.

The onOpenChange handler properly cleans up modal state when the Dialog is dismissed, which is good for ensuring a fresh start on the next open. However, this aggressive reset may cause issues with the View Profile flow (see comment on lines 177-179).


402-409: Verify focus management for accessibility.

The PR objectives mention preventing "focus leakage," but there's no explicit focus management when transitioning between the collaboration modal and profile modal. While the Dialog component may handle focus internally, ensure that:

  1. Focus moves correctly to the ViewProfileModal when it opens
  2. Focus returns appropriately when the profile modal closes
  3. Keyboard navigation (Tab, Escape) works as expected
  4. Screen readers announce modal transitions properly

Test the modal transitions with keyboard-only navigation and screen readers to confirm accessibility requirements are met, especially since the fix changes the modal flow from overlapping to sequential.

Comment on lines +173 to 183
<Button
size="sm"
variant="outline"
onClick={() => {
onClose();
setSelectedCreator(creator);
setShowProfile(true);
}}
>
View Profile
</Button>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: State reset causes data loss and breaks onConnect callback.

Calling onClose() before opening the profile modal triggers handleResetModal() (via onOpenChange on line 103), which resets searchTerm to "" and selectedCreator to null. This creates two critical problems:

  1. Broken onConnect callback: When the user clicks "Connect" in the ViewProfileModal (line 407), searchResults[0] will be undefined because searchResults is empty (since searchTerm was reset). This will cause incorrect behavior.

  2. User data loss: The user loses all search context, collaboration description, and proposal data when viewing a profile, forcing them to start over.

Recommended approach: Instead of closing the parent modal, use one of these solutions:

  • Option 1 (Recommended): Pass the creator object directly to ViewProfileModal as a prop, and handle z-index/stacking with CSS (z-50, z-[60], etc.) or a Portal.
  • Option 2: Store creator in a ref or separate state that persists across modal close/open cycles.
  • Option 3: Only reset state after both modals are fully closed, not during the profile view flow.

Apply this diff for Option 1:

                        <Button
                          size="sm"
                          variant="outline"
                          onClick={() => {
-                           onClose(); 
                            setSelectedCreator(creator);
                            setShowProfile(true);
                          }}
                        >
                          View Profile
                        </Button>

Then update ViewProfileModal to accept a creator prop and adjust its z-index styling to appear above the parent modal.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Button
size="sm"
variant="outline"
onClick={() => {
onClose();
setSelectedCreator(creator);
setShowProfile(true);
}}
>
View Profile
</Button>
<Button
size="sm"
variant="outline"
onClick={() => {
setSelectedCreator(creator);
setShowProfile(true);
}}
>
View Profile
</Button>
🤖 Prompt for AI Agents
In Frontend/src/components/collaboration-hub/NewCollaborationModal.tsx around
lines 173 to 183, calling onClose() before opening the profile modal resets the
parent modal state and clears search/results causing broken onConnect and data
loss; instead, stop closing the parent modal here and pass the clicked creator
object directly into ViewProfileModal as a new prop
(setSelectedCreator(creator); setShowProfile(true) only), update
ViewProfileModal to accept a creator prop and use it for display and connect
actions (do not rely on searchResults[0]), and ensure the profile modal renders
above the parent by adding appropriate z-index classes or rendering it in a
Portal so the parent modal state remains intact while viewing profiles.

Comment on lines +405 to +408
onConnect={() => {
setShowProfile(false);
setSelectedCreator(searchResults[0]);
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: Accessing undefined array element.

After the parent modal closes (triggered by onClose() on line 177), searchTerm is reset to "", which makes searchResults an empty array. This callback accesses searchResults[0], which will be undefined, causing selectedCreator to be set to undefined.

This is a direct consequence of the state reset issue identified in lines 173-183.

Fix: Once the state reset issue is resolved (by not closing the parent modal or preserving the creator data), update this callback to use the preserved creator:

      <ViewProfileModal
        open={showProfile}
        onClose={() => setShowProfile(false)}
        onConnect={() => {
          setShowProfile(false);
-         setSelectedCreator(searchResults[0]);
+         // selectedCreator is already set when opening the profile
+         // or pass creator as prop to ViewProfileModal and use it here
        }}
      />

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In Frontend/src/components/collaboration-hub/NewCollaborationModal.tsx around
lines 405 to 408, the onConnect handler directly reads searchResults[0] which
can be undefined after the parent modal closes and searchResults is cleared;
update the handler to avoid accessing searchResults[0] directly by instead using
the preserved creator data (passed via props or kept in a local preservedCreator
state) and fall back to a guarded check (only use searchResults[0] if
searchResults.length > 0) before calling setSelectedCreator; keep the
setShowProfile(false) call but ensure setSelectedCreator receives a valid
creator object (preservedCreator or guarded searchResults[0]) to prevent setting
undefined.

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.

1 participant