@@ -107,13 +107,33 @@ class Dashboard extends Component<DashboardWithStylesProps, DashboardState> {
107
107
const orgId = this . props . orgId
108
108
const onlyProjects = this . props . onlyProjects
109
109
110
- this . unsubscribe = ( Store . listen as RefluxTypes [ 'listen' ] ) ( function ( ) {
110
+ this . unsubscribe = ( Store . listen as RefluxTypes [ 'listen' ] ) ( async function ( ) {
111
111
that . setState ( { data : this . data } )
112
+
112
113
const auth : DashboardState [ 'data' ] [ 'auth' ] =
113
114
this . data && this . data . auth ? this . data . auth : null
114
115
const userProfile : DashboardState [ 'data' ] [ 'userProfile' ] =
115
116
this . data && this . data . userProfile ? this . data . userProfile : null
116
117
118
+ const cookieName = "pgai_tmp_thread_id=" ;
119
+ const cookies = document . cookie . split ( ';' ) . map ( cookie => cookie . trim ( ) ) ;
120
+ const pgaiTmpThreadId = cookies . find ( cookie => cookie . startsWith ( cookieName ) ) ?. substring ( cookieName . length ) || null ;
121
+ if ( pgaiTmpThreadId ) {
122
+ 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 } ` ) ;
129
+ }
130
+ }
131
+ }
132
+ } catch ( error ) {
133
+ console . error ( 'Error converting thread:' , error ) ;
134
+ }
135
+ }
136
+
117
137
if ( onlyProjects ) {
118
138
const projects : DashboardState [ 'data' ] [ 'projects' ] =
119
139
this . data && this . data . projects ? this . data . projects : null
@@ -164,8 +184,6 @@ class Dashboard extends Component<DashboardWithStylesProps, DashboardState> {
164
184
} )
165
185
166
186
Actions . refresh ( )
167
-
168
- this . convertThreadAndRedirectToBot ( )
169
187
}
170
188
171
189
componentWillUnmount ( ) {
@@ -215,24 +233,6 @@ class Dashboard extends Component<DashboardWithStylesProps, DashboardState> {
215
233
this . setState ( { filterValue : event . target . value } )
216
234
}
217
235
218
- convertThreadAndRedirectToBot = async ( ) => {
219
- const cookieName = "pgai_tmp_thread_id=" ;
220
- const cookies = document . cookie . split ( ';' ) . map ( cookie => cookie . trim ( ) ) ;
221
- const pgaiTmpThreadId = cookies . find ( cookie => cookie . startsWith ( cookieName ) ) ?. substring ( cookieName . length ) || null ;
222
-
223
- if ( pgaiTmpThreadId ) {
224
- try {
225
- const data = await convertThread ( pgaiTmpThreadId ) ;
226
- if ( data ?. response ?. final_thread_id ) {
227
- document . cookie = `${ cookieName } =; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=.${ window . location . hostname . split ( '.' ) . slice ( - 2 ) . join ( '.' ) } ` ;
228
- this . props . history . push ( `demo/bot/${ data . response . final_thread_id } ` ) ;
229
- }
230
- } catch ( error ) {
231
- console . error ( 'Error converting thread:' , error ) ;
232
- }
233
- }
234
- }
235
-
236
236
render ( ) {
237
237
const renderProjects = this . props . onlyProjects
238
238
0 commit comments