@@ -4,6 +4,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, SelectSe
44import { type CloudUserInfo , type CloudOrganizationMembership } from "@roo-code/types"
55import { useAppTranslation } from "@src/i18n/TranslationContext"
66import { vscode } from "@src/utils/vscode"
7+ import { type ExtensionMessage } from "@roo/ExtensionMessage"
78
89type OrganizationSwitcherProps = {
910 userInfo : CloudUserInfo
@@ -21,6 +22,28 @@ export const OrganizationSwitcher = ({ userInfo, organizations, onOrganizationCh
2122 setSelectedOrgId ( userInfo . organizationId || null )
2223 } , [ userInfo . organizationId ] )
2324
25+ // Listen for organization switch results
26+ useEffect ( ( ) => {
27+ const handleMessage = ( event : MessageEvent ) => {
28+ const message = event . data as ExtensionMessage
29+ if ( message . type === "organizationSwitchResult" ) {
30+ // Reset loading state when we receive the result
31+ setIsLoading ( false )
32+
33+ if ( message . success ) {
34+ // Update selected org based on the result
35+ setSelectedOrgId ( message . organizationId ?? null )
36+ } else {
37+ // Revert to the previous organization on error
38+ setSelectedOrgId ( userInfo . organizationId || null )
39+ }
40+ }
41+ }
42+
43+ window . addEventListener ( "message" , handleMessage )
44+ return ( ) => window . removeEventListener ( "message" , handleMessage )
45+ } , [ userInfo . organizationId ] )
46+
2447 const handleOrganizationChange = async ( value : string ) => {
2548 const newOrgId = value === "personal" ? null : value
2649
@@ -44,11 +67,6 @@ export const OrganizationSwitcher = ({ userInfo, organizations, onOrganizationCh
4467 if ( onOrganizationChange ) {
4568 onOrganizationChange ( newOrgId )
4669 }
47-
48- // Reset loading state after a delay
49- setTimeout ( ( ) => {
50- setIsLoading ( false )
51- } , 1000 )
5270 }
5371
5472 // If user has no organizations, don't show the switcher
0 commit comments