Skip to content

fix(web): org switching now updates sidebar and improve dropdown UX#970

Merged
saddlepaddle merged 1 commit into
mainfrom
satya-patel/pluto
Jan 26, 2026
Merged

fix(web): org switching now updates sidebar and improve dropdown UX#970
saddlepaddle merged 1 commit into
mainfrom
satya-patel/pluto

Conversation

@saddlepaddle
Copy link
Copy Markdown
Collaborator

@saddlepaddle saddlepaddle commented Jan 26, 2026

Summary

  • Fix myOrganization tRPC procedure to filter by activeOrganizationId from session instead of returning first membership found - this was causing the sidebar to not update when switching orgs
  • Update Header dropdown trigger to show org name + avatar (matching desktop app UX) with chevron icon
  • Simplify dropdown to show org switcher submenu and log out button

Test plan

  • Switch between organizations and verify the sidebar org name updates
  • Verify the dropdown trigger shows the current org name and avatar
  • Verify org switcher submenu works correctly
  • Verify log out works

Summary by CodeRabbit

Release Notes

  • New Features
    • Enhanced organization switcher in the header with organization logos and names displayed
    • Improved multi-organization support with a dropdown menu for seamless switching between organizations with visual indicators

✏️ Tip: You can customize this high-level summary in your review settings.

- Fix myOrganization tRPC procedure to filter by activeOrganizationId
  from session instead of returning first membership found
- Update Header dropdown trigger to show org name + avatar (matching
  desktop app UX) with chevron icon
- Simplify dropdown to show org switcher submenu and log out button
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 26, 2026

📝 Walkthrough

Walkthrough

Modified the Header component to use organization-based data for avatar display and added an organization switcher dropdown. Updated the user organization query to filter memberships by both the current user and their active organization from the session.

Changes

Cohort / File(s) Summary
Organization UI Updates
apps/web/src/app/(dashboard)/components/Header/Header.tsx
Replaced user avatar with organization logo; added organization name display and chevron icon. Introduced organization dropdown switcher showing all organizations with logo, name, and active indicator. Updated styling and removed getInitials utility usage.
Organization Query Filtering
packages/trpc/src/router/user/user.ts
Added conditional filtering in myOrganization resolver to require both userId and activeOrganizationId when available; maintains backward compatibility when activeOrganizationId is absent.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A logo where avatars once stood tall,
Organizations switch at the dropdown's call,
The session remembers which org you choose,
No more guessing games—the header's new news! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers key sections (Summary, Test plan) but is missing several template sections: Related Issues, Type of Change, Testing details, Screenshots, and Additional Notes. Add the missing template sections. At minimum, specify the Type of Change (Bug fix/New feature), expand Testing with detailed steps, and include any related issue links if applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: fixing org switching to update the sidebar and improving the dropdown UX, which matches the primary modifications in both files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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

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

Copy link
Copy Markdown
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

🤖 Fix all issues with AI agents
In `@packages/trpc/src/router/user/user.ts`:
- Around line 14-22: The code reads ctx.session.session.activeOrganizationId
without guarding for missing session payload; change to use optional chaining
when extracting activeOrganizationId (e.g., const activeOrganizationId =
ctx.session?.session?.activeOrganizationId) and ensure the conditional passed to
db.query.members.findFirst still only includes the organization filter when
activeOrganizationId is defined so members.userId and members.organizationId
checks remain safe; update the logic around db.query.members.findFirst (and any
use in myOrganization) to handle undefined activeOrganizationId gracefully.

Comment on lines +14 to +22
const activeOrganizationId = ctx.session.session.activeOrganizationId;

const membership = await db.query.members.findFirst({
where: eq(members.userId, ctx.session.user.id),
where: activeOrganizationId
? and(
eq(members.userId, ctx.session.user.id),
eq(members.organizationId, activeOrganizationId),
)
: eq(members.userId, ctx.session.user.id),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Guard against missing session payload before reading activeOrganizationId.

Line 14 assumes ctx.session.session is always defined; if it’s absent (e.g., session variants or partial payloads), this will throw and break myOrganization. The client-side usage already treats it as optional. Consider optional chaining to keep behavior aligned and fail-safe.

✅ Suggested fix
-		const activeOrganizationId = ctx.session.session.activeOrganizationId;
+		const activeOrganizationId = ctx.session.session?.activeOrganizationId;
📝 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
const activeOrganizationId = ctx.session.session.activeOrganizationId;
const membership = await db.query.members.findFirst({
where: eq(members.userId, ctx.session.user.id),
where: activeOrganizationId
? and(
eq(members.userId, ctx.session.user.id),
eq(members.organizationId, activeOrganizationId),
)
: eq(members.userId, ctx.session.user.id),
const activeOrganizationId = ctx.session.session?.activeOrganizationId;
const membership = await db.query.members.findFirst({
where: activeOrganizationId
? and(
eq(members.userId, ctx.session.user.id),
eq(members.organizationId, activeOrganizationId),
)
: eq(members.userId, ctx.session.user.id),
🤖 Prompt for AI Agents
In `@packages/trpc/src/router/user/user.ts` around lines 14 - 22, The code reads
ctx.session.session.activeOrganizationId without guarding for missing session
payload; change to use optional chaining when extracting activeOrganizationId
(e.g., const activeOrganizationId = ctx.session?.session?.activeOrganizationId)
and ensure the conditional passed to db.query.members.findFirst still only
includes the organization filter when activeOrganizationId is defined so
members.userId and members.organizationId checks remain safe; update the logic
around db.query.members.findFirst (and any use in myOrganization) to handle
undefined activeOrganizationId gracefully.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 26, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch
  • ✅ Electric Fly.io app

Thank you for your contribution! 🎉

@saddlepaddle saddlepaddle merged commit 1d0de4e into main Jan 26, 2026
13 checks passed
@Kitenite Kitenite deleted the satya-patel/pluto branch January 26, 2026 22:08
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