Skip to content

Commit 86a0fba

Browse files
author
Bogdan Tsechoev
committed
Merge branch 'guest_mode_fix' into 'master'
Bot UI: Check user orgs before redirect to /demo/bot after registration See merge request postgres-ai/database-lab!889
2 parents 16e1bc8 + 2a460f7 commit 86a0fba

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

ui/packages/platform/src/components/Dashboard/Dashboard.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,33 @@ class Dashboard extends Component<DashboardWithStylesProps, DashboardState> {
107107
const orgId = this.props.orgId
108108
const onlyProjects = this.props.onlyProjects
109109

110-
this.unsubscribe = (Store.listen as RefluxTypes['listen'])(function () {
110+
this.unsubscribe = (Store.listen as RefluxTypes['listen'])(async function () {
111111
that.setState({ data: this.data })
112+
112113
const auth: DashboardState['data']['auth'] =
113114
this.data && this.data.auth ? this.data.auth : null
114115
const userProfile: DashboardState['data']['userProfile'] =
115116
this.data && this.data.userProfile ? this.data.userProfile : null
116117

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+
117137
if (onlyProjects) {
118138
const projects: DashboardState['data']['projects'] =
119139
this.data && this.data.projects ? this.data.projects : null
@@ -164,8 +184,6 @@ class Dashboard extends Component<DashboardWithStylesProps, DashboardState> {
164184
})
165185

166186
Actions.refresh()
167-
168-
this.convertThreadAndRedirectToBot()
169187
}
170188

171189
componentWillUnmount() {
@@ -215,24 +233,6 @@ class Dashboard extends Component<DashboardWithStylesProps, DashboardState> {
215233
this.setState({ filterValue: event.target.value })
216234
}
217235

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-
236236
render() {
237237
const renderProjects = this.props.onlyProjects
238238

0 commit comments

Comments
 (0)