11import { ReduxActionTypes } from "ee/constants/ReduxActionConstants" ;
22import { requiresAuth } from "pages/UserAuth/requiresAuthHOC" ;
33import React from "react" ;
4- import { useCallback } from "react" ;
4+ import { useCallback , useState } from "react" ;
55import { useEffect } from "react" ;
66import { useDispatch , useSelector } from "react-redux" ;
77import { getCurrentUser } from "selectors/usersSelectors" ;
@@ -16,6 +16,7 @@ import { redirectUserAfterSignup } from "ee/utils/signupHelpers";
1616import { setUserSignedUpFlag } from "utils/storage" ;
1717import AnalyticsUtil from "ee/utils/AnalyticsUtil" ;
1818import { getIsAiAgentInstanceEnabled } from "ee/selectors/aiAgentSelectors" ;
19+ import { useIsCloudBillingEnabled } from "hooks/useIsCloudBillingEnabled" ;
1920
2021export function SignupSuccess ( ) {
2122 const dispatch = useDispatch ( ) ;
@@ -25,50 +26,78 @@ export function SignupSuccess() {
2526 "enableFirstTimeUserExperience" ,
2627 ) ;
2728 const isAiAgentInstanceEnabled = useSelector ( getIsAiAgentInstanceEnabled ) ;
29+ const isMultiOrgEnabled = useIsCloudBillingEnabled ( ) ;
2830 const validLicense = useSelector ( isValidLicense ) ;
2931 const user = useSelector ( getCurrentUser ) ;
3032 const isOnLoginPage = ! useSelector ( isWithinAnOrganization ) ;
3133
34+ const [ isRedirecting , setIsRedirecting ] = useState ( false ) ;
35+
3236 useEffect ( ( ) => {
3337 user ?. email && setUserSignedUpFlag ( user ?. email ) ;
3438 } , [ ] ) ;
3539
3640 const isNonInvitedUser = shouldEnableFirstTimeUserOnboarding === "true" ;
3741
38- const redirectUsingQueryParam = useCallback (
39- ( ) =>
40- redirectUserAfterSignup ( {
42+ const redirectUsingQueryParam = useCallback ( async ( ) => {
43+ if ( isRedirecting ) return ;
44+
45+ setIsRedirecting ( true ) ;
46+
47+ try {
48+ await redirectUserAfterSignup ( {
4149 redirectUrl,
4250 shouldEnableFirstTimeUserOnboarding,
4351 validLicense,
4452 dispatch,
4553 isAiAgentInstanceEnabled,
54+ isMultiOrgEnabled,
4655 isOnLoginPage,
47- } ) ,
48- [
49- dispatch ,
50- isNonInvitedUser ,
51- isOnLoginPage ,
52- redirectUrl ,
53- shouldEnableFirstTimeUserOnboarding ,
54- validLicense ,
55- ] ,
56- ) ;
56+ } ) ;
57+ } catch ( err ) {
58+ setIsRedirecting ( false ) ;
59+ }
60+ } , [
61+ dispatch ,
62+ isNonInvitedUser ,
63+ isOnLoginPage ,
64+ redirectUrl ,
65+ shouldEnableFirstTimeUserOnboarding ,
66+ validLicense ,
67+ isAiAgentInstanceEnabled ,
68+ isMultiOrgEnabled ,
69+ ] ) ;
5770
58- const onGetStarted = useCallback ( ( proficiency ?: string , useCase ?: string ) => {
59- dispatch ( {
60- type : ReduxActionTypes . UPDATE_USER_DETAILS_INIT ,
61- payload : {
71+ const onGetStarted = useCallback (
72+ async ( proficiency ?: string , useCase ?: string ) => {
73+ dispatch ( {
74+ type : ReduxActionTypes . UPDATE_USER_DETAILS_INIT ,
75+ payload : {
76+ proficiency,
77+ useCase,
78+ } ,
79+ } ) ;
80+ AnalyticsUtil . logEvent ( "GET_STARTED_CLICKED" , {
6281 proficiency,
63- useCase,
64- } ,
65- } ) ;
66- AnalyticsUtil . logEvent ( "GET_STARTED_CLICKED" , {
67- proficiency,
68- goal : useCase ,
69- } ) ;
70- redirectUsingQueryParam ( ) ;
71- } , [ ] ) ;
82+ goal : useCase ,
83+ } ) ;
84+ await redirectUsingQueryParam ( ) ;
85+ } ,
86+ [ redirectUsingQueryParam ] ,
87+ ) ;
88+
89+ const shouldAutoRedirect =
90+ user ?. isSuperUser ||
91+ ( ( user ?. role || user ?. proficiency ) && user ?. useCase ) ||
92+ shouldEnableFirstTimeUserOnboarding !== "true" ||
93+ isAiAgentInstanceEnabled ||
94+ isMultiOrgEnabled ;
95+
96+ useEffect ( ( ) => {
97+ if ( shouldAutoRedirect && ! isRedirecting ) {
98+ redirectUsingQueryParam ( ) ;
99+ }
100+ } , [ shouldAutoRedirect , redirectUsingQueryParam , isRedirecting ] ) ;
72101
73102 /*
74103 * Proceed with redirection,
@@ -78,15 +107,7 @@ export function SignupSuccess() {
78107 * We identify an invited user based on `enableFirstTimeUserExperience` flag in url.
79108 */
80109 //TODO(Balaji): Factor in case, where user had closed the tab, while filling the form.And logs back in again.
81- if (
82- user ?. isSuperUser ||
83- ( ( user ?. role || user ?. proficiency ) && user ?. useCase ) ||
84- shouldEnableFirstTimeUserOnboarding !== "true" ||
85- isAiAgentInstanceEnabled
86- ) {
87- redirectUsingQueryParam ( ) ;
88-
89- // Showing a loader until the redirect
110+ if ( shouldAutoRedirect ) {
90111 return (
91112 < Center >
92113 < Spinner size = "lg" />
0 commit comments