Skip to content

Commit dfc591c

Browse files
bchapuisclaude
andcommitted
Always redirect to dashboard when switching organizations
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e1d4ebe commit dfc591c

1 file changed

Lines changed: 3 additions & 14 deletions

File tree

apps/app/src/components/organization-switcher.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import Check from "lucide-react/icons/check";
44
import ChevronsUpDown from "lucide-react/icons/chevrons-up-down";
5-
import { useLocation, useNavigate, useParams } from "react-router";
5+
import { useNavigate, useParams } from "react-router";
66

77
import { useAuth } from "@/components/auth-context";
88
import { Button } from "@/components/ui/button";
@@ -19,14 +19,13 @@ export function OrganizationSwitcher() {
1919
const { organizations: orgList } = useOrganizations();
2020

2121
const navigate = useNavigate();
22-
const location = useLocation();
2322
const params = useParams<{ organizationId?: string }>();
2423
const currentOrgId = params.organizationId || organization?.id;
2524
const currentOrg =
2625
orgList?.find((org) => org.id === currentOrgId) || organization;
2726
const currentOrgName = currentOrg?.name || "Personal";
2827
const orgs = orgList || [];
29-
const isOrgScope = location.pathname.startsWith("/org/");
28+
const isOrgScope = !!params.organizationId;
3029

3130
return (
3231
<DropdownMenu>
@@ -48,17 +47,7 @@ export function OrganizationSwitcher() {
4847
{orgs.map((org) => {
4948
const handleSwitch = () => {
5049
if (org.id === currentOrgId) return;
51-
let newPath = location.pathname;
52-
if (params.organizationId) {
53-
newPath = newPath.replace(
54-
`/org/${params.organizationId}`,
55-
`/org/${org.id}`
56-
);
57-
} else {
58-
// No current :organizationId in URL (e.g., /settings/organizations): go to dashboard
59-
newPath = `/org/${org.id}/dashboard`;
60-
}
61-
navigate(newPath, { replace: true });
50+
navigate(`/org/${org.id}/dashboard`, { replace: true });
6251
};
6352
return (
6453
<DropdownMenuItem key={org.id} onClick={handleSwitch}>

0 commit comments

Comments
 (0)