diff --git a/app/constants/urls.js b/app/constants/urls.js index 6cbc989a..b231990d 100644 --- a/app/constants/urls.js +++ b/app/constants/urls.js @@ -38,7 +38,7 @@ const APP_URLS = { TASKS: `${SCHEME}staging-my.${DOMAIN}/tasks`, IDENTITY: `${SCHEME}staging-my.${DOMAIN}/identity`, MY_STATUS: `${SCHEME}staging-my.${DOMAIN}`, - API_BACKEND: `${SCHEME}staging-api.${DOMAIN}`, + API_BACKEND: `http://localhost:3000`, }, test: { HOME: `${SCHEME}${DOMAIN}`, diff --git a/app/controllers/goto.js b/app/controllers/goto.js new file mode 100644 index 00000000..fffb071d --- /dev/null +++ b/app/controllers/goto.js @@ -0,0 +1,66 @@ +import Controller from '@ember/controller'; +import { inject as service } from '@ember/service'; +import { APPS, AUTH } from '../constants/urls'; +import { tracked } from '@glimmer/tracking'; +import fetch from 'fetch'; + +export default class GotoController extends Controller { + queryParams = ['dev']; + @service router; + @service store; + @service fastboot; + @tracked user; + + WELCOME_URL = APPS.WELCOME; + SIGN_UP_URL = AUTH.SIGN_UP; + HOME_URL = 'index'; + + constructor() { + super(...arguments); + + if (!this.fastboot.isFastBoot) { + const queryParams = new URLSearchParams(window.location.search); + const isDev = Boolean(queryParams.get('dev')); + + (async () => { + await this.getSelfUser(); + this.redirectionHandler(isDev, this.user); + })(); + } + } + + redirectionHandler(isDev, user) { + if (user.incompleteUserDetails) { + this.redirectUserToPage(this.SIGN_UP_URL); + } else if (isDev) { + if (user.roles?.developer && !user.roles?.in_discord) { + this.redirectUserToPage(this.WELCOME_URL); + } else { + this.router.transitionTo(this.HOME_URL); + } + } else { + if (!user.roles?.in_discord) { + this.redirectUserToPage(this.WELCOME_URL); + } else { + this.router.transitionTo(this.HOME_URL); + } + } + } + + redirectUserToPage(url) { + window.location.replace(url); + } + + async getSelfUser() { + const response = await fetch(`${APPS.API_BACKEND}/users/self`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + credentials: 'include', + }); + + const userData = await response.json(); + this.user = userData; + } +} diff --git a/app/router.js b/app/router.js index e4e9a0df..d8ee69c2 100644 --- a/app/router.js +++ b/app/router.js @@ -12,4 +12,5 @@ Router.map(function () { this.route('live'); this.route('page-not-found', { path: '/*' }); this.route('intro'); + this.route('goto'); }); diff --git a/app/routes/application.js b/app/routes/application.js index accaec92..473ef158 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -1,3 +1,2 @@ import Route from '@ember/routing/route'; - -export default class IndexRoute extends Route {} +export default class ApplicationRoute extends Route {} diff --git a/app/routes/goto.js b/app/routes/goto.js new file mode 100644 index 00000000..b6e3bbfb --- /dev/null +++ b/app/routes/goto.js @@ -0,0 +1,2 @@ +import Route from '@ember/routing/route'; +export default class GotoRoute extends Route {} diff --git a/app/styles/app.css b/app/styles/app.css index e373fdcf..2c84c66a 100644 --- a/app/styles/app.css +++ b/app/styles/app.css @@ -30,6 +30,7 @@ @import url("events.module.css"); @import url("identity-card.module.css"); @import url("wheel-animations.css"); +@import url("goto.module.css"); * { margin: 0; diff --git a/app/styles/goto.module.css b/app/styles/goto.module.css new file mode 100644 index 00000000..eaf4a4dc --- /dev/null +++ b/app/styles/goto.module.css @@ -0,0 +1,33 @@ +.redirection-wrapper { + height: 90vh; + width: 100vw; + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; + box-sizing: border-box; +} + +.logo-img { + width: 18rem; + height: 18rem; + display: block; + margin: 0 auto; +} + +.redirection { + font-size: 1.6rem; + text-align: center; +} + +@media (width >= 425px) { + .logo-img { + width: 25rem; + height: 25rem; + } + + .redirection { + font-size: 2rem; + text-align: center; + } +} diff --git a/app/templates/goto.hbs b/app/templates/goto.hbs new file mode 100644 index 00000000..1d860d12 --- /dev/null +++ b/app/templates/goto.hbs @@ -0,0 +1,10 @@ +{{page-title 'Please wait'}} + +
+ Real Dev Squad +

Redirecting to your correct location...

+
\ No newline at end of file