@@ -101,13 +101,14 @@ interface DashboardState {
101
101
}
102
102
103
103
class Dashboard extends Component < DashboardWithStylesProps , DashboardState > {
104
+ isThreadConverted = false ;
104
105
unsubscribe : Function
105
106
componentDidMount ( ) {
106
107
const that = this
107
108
const orgId = this . props . orgId
108
109
const onlyProjects = this . props . onlyProjects
109
110
110
- this . unsubscribe = ( Store . listen as RefluxTypes [ 'listen' ] ) ( async function ( ) {
111
+ this . unsubscribe = ( Store . listen as RefluxTypes [ 'listen' ] ) ( function ( ) {
111
112
that . setState ( { data : this . data } )
112
113
113
114
const auth : DashboardState [ 'data' ] [ 'auth' ] =
@@ -118,20 +119,25 @@ class Dashboard extends Component<DashboardWithStylesProps, DashboardState> {
118
119
const cookieName = "pgai_tmp_thread_id=" ;
119
120
const cookies = document . cookie . split ( ';' ) . map ( cookie => cookie . trim ( ) ) ;
120
121
const pgaiTmpThreadId = cookies . find ( cookie => cookie . startsWith ( cookieName ) ) ?. substring ( cookieName . length ) || null ;
121
- if ( pgaiTmpThreadId ) {
122
+ if ( pgaiTmpThreadId && ! that . isThreadConverted ) {
123
+ that . isThreadConverted = true ;
122
124
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
+ }
129
134
}
130
- }
131
- }
135
+ } )
132
136
} catch ( error ) {
133
137
console . error ( 'Error converting thread:' , error ) ;
134
138
}
139
+ } else {
140
+ document . cookie = `${ cookieName } =; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=.${ window . location . hostname . split ( '.' ) . slice ( - 2 ) . join ( '.' ) } ` ;
135
141
}
136
142
137
143
if ( onlyProjects ) {
0 commit comments