@@ -101,13 +101,14 @@ interface DashboardState {
101101}
102102
103103class Dashboard extends Component < DashboardWithStylesProps , DashboardState > {
104+ isThreadConverted = false ;
104105 unsubscribe : Function
105106 componentDidMount ( ) {
106107 const that = this
107108 const orgId = this . props . orgId
108109 const onlyProjects = this . props . onlyProjects
109110
110- this . unsubscribe = ( Store . listen as RefluxTypes [ 'listen' ] ) ( async function ( ) {
111+ this . unsubscribe = ( Store . listen as RefluxTypes [ 'listen' ] ) ( function ( ) {
111112 that . setState ( { data : this . data } )
112113
113114 const auth : DashboardState [ 'data' ] [ 'auth' ] =
@@ -118,20 +119,25 @@ class Dashboard extends Component<DashboardWithStylesProps, DashboardState> {
118119 const cookieName = "pgai_tmp_thread_id=" ;
119120 const cookies = document . cookie . split ( ';' ) . map ( cookie => cookie . trim ( ) ) ;
120121 const pgaiTmpThreadId = cookies . find ( cookie => cookie . startsWith ( cookieName ) ) ?. substring ( cookieName . length ) || null ;
121- if ( pgaiTmpThreadId ) {
122+ if ( pgaiTmpThreadId && ! that . isThreadConverted ) {
123+ that . isThreadConverted = true ;
122124 try {
123- const data = await convertThread ( pgaiTmpThreadId ) ;
124- if ( data ?. response ?. final_thread_id ) {
125- document . cookie = `${ cookieName } =; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=.${ window . location . hostname . split ( '.' ) . slice ( - 2 ) . join ( '.' ) } ` ;
126- if ( userProfile && userProfile . data && userProfile . data . orgs ) {
127- if ( userProfile . data . orgs . hasOwnProperty ( 'demo' ) ) {
128- that . props . history . push ( `demo/bot/${ data . response . final_thread_id } ` ) ;
125+ convertThread ( pgaiTmpThreadId )
126+ . then ( ( { response, error} ) => {
127+ if ( response ?. final_thread_id ) {
128+ document . cookie = `${ cookieName } =; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=.${ window . location . hostname . split ( '.' ) . slice ( - 2 ) . join ( '.' ) } ` ;
129+ if ( userProfile && userProfile . data && userProfile . data . orgs ) {
130+ if ( userProfile . data . orgs . hasOwnProperty ( 'demo' ) ) {
131+ that . props . history . push ( `demo/bot/${ response . final_thread_id } ` ) ;
132+ }
133+ }
129134 }
130- }
131- }
135+ } )
132136 } catch ( error ) {
133137 console . error ( 'Error converting thread:' , error ) ;
134138 }
139+ } else {
140+ document . cookie = `${ cookieName } =; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=.${ window . location . hostname . split ( '.' ) . slice ( - 2 ) . join ( '.' ) } ` ;
135141 }
136142
137143 if ( onlyProjects ) {
0 commit comments