22
33import Check from "lucide-react/icons/check" ;
44import ChevronsUpDown from "lucide-react/icons/chevrons-up-down" ;
5- import { useLocation , useNavigate , useParams } from "react-router" ;
5+ import { useNavigate , useParams } from "react-router" ;
66
77import { useAuth } from "@/components/auth-context" ;
88import { 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