@@ -9,13 +9,18 @@ import { httpsCallable, getFunctions } from "firebase/functions";
99import { toast } from "utils/Toast" ;
1010import { trackCheckoutFailedEvent , trackCheckoutInitiated } from "modules/analytics/events/misc/business/checkout" ;
1111import STORAGE from "config/constants/sub/storage" ;
12+ import { CONSTANTS as GLOBAL_CONSTANTS } from "@requestly/requestly-core" ;
13+ import { getAppMode } from "store/selectors" ;
14+ import { setRedirectMetadata } from "features/onboarding/utils" ;
15+ import { SOURCE } from "modules/analytics/events/common/constants" ;
1216
1317export const useBannerAction = (
1418 actions : BANNER_ACTIONS [ ] ,
1519 setIsRequestAccessModalOpen ?: ( value : boolean ) => void
1620) : BannerActionConfig [ ] => {
1721 const dispatch = useDispatch ( ) ;
1822 const user = useSelector ( getUserAuthDetails ) ;
23+ const appMode = useSelector ( getAppMode ) ;
1924 const firebaseFunction = getFunctions ( ) ;
2025
2126 const actionMap : Record < BANNER_ACTIONS , BannerActionConfig > = useMemo (
@@ -69,6 +74,30 @@ export const useBannerAction = (
6974 redirectToUrl ( LINKS . NOTION_PAGE_FOR_PROMOTION , true ) ;
7075 } ,
7176 } ,
77+ [ BANNER_ACTIONS . MERGE_BSTACK_ACCOUNT ] : {
78+ label : "Sign in" ,
79+ type : "primary" ,
80+ onClick : ( ) => {
81+ // Brings a web user back to the page they started from. LoginHandler reads and clears
82+ // this after the token exchange. Harmless on desktop, where the OAuth flow runs in a
83+ // different browser and nothing reads it back.
84+ setRedirectMetadata ( {
85+ source : SOURCE . AUTH_MIGRATION_BANNER ,
86+ redirectURL : window . location . href ,
87+ } ) ;
88+
89+ if ( appMode === GLOBAL_CONSTANTS . APP_MODES . DESKTOP ) {
90+ // redirectToUrl is window.open(url, "_self"), which would navigate the whole Electron
91+ // window away from the app. Hand the URL to the system browser instead.
92+ window . RQ ?. DESKTOP ?. SERVICES ?. IPC ?. invokeEventInBG ( "open-external-link" , {
93+ link : LINKS . OAUTH_REDIRECT_URL ,
94+ } ) ;
95+ return ;
96+ }
97+
98+ redirectToUrl ( LINKS . OAUTH_REDIRECT_URL ) ;
99+ } ,
100+ } ,
72101 [ BANNER_ACTIONS . REDIRECT_TO_LINKEDIN_FORM ] : {
73102 label : "Share Now" ,
74103 type : "primary" ,
@@ -120,7 +149,7 @@ export const useBannerAction = (
120149 } ,
121150 } ,
122151 } ) ,
123- [ dispatch , firebaseFunction , user ?. details ?. planDetails , setIsRequestAccessModalOpen ]
152+ [ dispatch , firebaseFunction , user ?. details ?. planDetails , setIsRequestAccessModalOpen , appMode ]
124153 ) ;
125154
126155 return actions . map ( ( action ) => actionMap [ action ] ) . filter ( Boolean ) ;
0 commit comments