-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redirection to dashboard user application on /intro route (#908)
- Loading branch information
Showing
3 changed files
with
42 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,56 @@ | ||
import Route from '@ember/routing/route'; | ||
import fetch from 'fetch'; | ||
import { inject as service } from '@ember/service'; | ||
import { APPLICATION_URL } from '../constants/apis'; | ||
import { APPLICATION_ID_LINK, APPLICATION_URL } from '../constants/apis'; | ||
import { APPS } from '../constants/urls'; | ||
|
||
export default class IntroRoute extends Route { | ||
queryParams = { | ||
id: { refreshModel: true }, | ||
status: { refreshModel: true }, | ||
}; | ||
|
||
@service fastboot; | ||
@service router; | ||
|
||
async model(params) { | ||
if (this.fastboot.isFastBoot) { | ||
return; | ||
} | ||
const userId = params.id; | ||
const response = await fetch(APPLICATION_URL(userId), { | ||
credentials: 'include', | ||
}); | ||
const status = params.status; | ||
|
||
try { | ||
let userResponse; | ||
let userData; | ||
|
||
if (status === 'submitted') { | ||
userResponse = await fetch(`${APPS.API_BACKEND}/users/self`, { | ||
credentials: 'include', | ||
}); | ||
userData = await userResponse.json(); | ||
} | ||
|
||
const response = await fetch(APPLICATION_URL(userId), { | ||
credentials: 'include', | ||
}); | ||
|
||
if (response.status === 404) { | ||
if (response.status === 404) { | ||
this.router.transitionTo('/page-not-found'); | ||
return; | ||
} | ||
|
||
const applicationData = await response.json(); | ||
const applicationId = applicationData.data[0].id; | ||
|
||
if (userData?.roles?.super_user) { | ||
window.location.replace(APPLICATION_ID_LINK(applicationId)); | ||
} | ||
|
||
return applicationData.data; | ||
} catch (error) { | ||
console.error('Error fetching application details:', error); | ||
this.router.transitionTo('/page-not-found'); | ||
} | ||
|
||
const data = await response.json(); | ||
return data.data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters