Skip to content

Commit

Permalink
Merge pull request #340 from weni-ai/nexus-1264-redirect-to-intellige…
Browse files Browse the repository at this point in the history
…nce-next-repository

[Nexus-1264] Redirects to the New Intelligence Module
  • Loading branch information
cristiantela authored Jun 3, 2024
2 parents c0dcd37 + 9a25afe commit 797341c
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 161 deletions.
1 change: 1 addition & 0 deletions config.js.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const runtimeVariables = (() => ({
SENTRY_ENVIRONMENT: ('${SENTRY_ENVIRONMENT}' || ''),
NEXUS_API_BASE_URL: '${NEXUS_API_BASE_URL}',
FLOWS_API_BASE_URL: '${FLOWS_API_BASE_URL}',
INTELLIGENCE_NEXT_URL: '${INTELLIGENCE_NEXT_URL}',

get(name){
return this[name];
Expand Down
4 changes: 1 addition & 3 deletions src/components/TutorialModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ export default {
if (target === 'home' || target === 'new') {
if (target === 'home') return;
this.setTutorialActive(name);
this.$router.push({
name: 'home',
});
this.$router.push('/home');
this.closeTutorialMenu();
} else if (
Object.keys(this.finished).includes(previous) ||
Expand Down
4 changes: 1 addition & 3 deletions src/components/payment/PaymentOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ export default {
},
methods: {
goToHome() {
this.$router.push({
name: 'home',
});
this.$router.push('/home');
},
goToPayment() {
this.$router.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,7 @@ export default {
description: this.data.description,
});
this.$router.push({
name: 'intelligence-home',
params: {
intelligenceUuid: data.uuid,
},
});
this.$router.push(`/intelligences/${data.uuid}`);
} else {
const response = await repositoryV2.create({
organization: this.getOrgSelected,
Expand Down
17 changes: 4 additions & 13 deletions src/components/repository/home/HomeRepositoryCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,7 @@ export default {
(this.type === 'repository' &&
this.repositoryDetail?.repository_type === 'content')
) {
this.$router.push({
name: 'intelligence-home',
params: {
intelligenceUuid: this.repositoryDetail.uuid,
},
});
this.$router.push(`/intelligences/${this.repositoryDetail.uuid}`);
} else if (this.type === 'repository') {
let name;
Expand All @@ -685,13 +680,9 @@ export default {
},
});
} else if (this.type === 'base') {
this.$router.push({
name: 'intelligence-content-base-edit',
params: {
intelligenceUuid: this.$route.params.intelligenceUuid,
contentBaseUuid: this.repositoryDetail.uuid,
},
});
this.$router.push(
`/intelligences/${this.$route.params.intelligenceUuid}/bases/${this.repositoryDetail.uuid}/edit`,
);
}
},
async copyIntelligence() {
Expand Down
12 changes: 8 additions & 4 deletions src/components/repository/sidebar/SideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,14 @@ export default {
path !== this.$router.currentRoute.name ||
path === 'repository-settings'
) {
this.$router.push({
name: `${path}`,
...opts,
});
if (path === 'home') {
this.$router.push('/home');
} else {
this.$router.push({
name: `${path}`,
...opts,
});
}
}
},
setInitialSelectedMenu() {
Expand Down
111 changes: 35 additions & 76 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import nexusaiAPI from '../api/nexusaiAPI';

Vue.use(Router);

let nextFromRedirect = '';

const router = new Router({
mode: 'history',
routes: [
Expand Down Expand Up @@ -87,13 +89,18 @@ const router = new Router({
store.state.Auth.connectOrgUuid = to.query?.org_uuid;
store.state.Auth.connectProjectUuid = to.query?.project_uuid;

sessionStorage.setItem('orgUuid', store.state.Auth.connectOrgUuid);

sessionStorage.setItem(
'projectUuid',
store.state.Auth.connectProjectUuid,
);

if (to.query.next) {
next(to.query.next);
const nextPath = to.query.next || to.query.next_from_redirect;

if (nextPath) {
nextFromRedirect = to.query.next_from_redirect;
next(nextPath);
} else {
next('/home');
}
Expand Down Expand Up @@ -123,11 +130,6 @@ const router = new Router({
}
},
},
{
path: '/home',
name: 'home',
component: Home,
},
{
path: '/new/',
name: 'new',
Expand All @@ -149,75 +151,6 @@ const router = new Router({
},
],
},
{
path: '/brain/preview',
name: 'brain-preview-full-page',
component: RouterPreviewFullPage,
beforeEnter: async (to, from, next) => {
store.dispatch('externalLogin', { token: `Bearer ${to.query?.token}` });
store.dispatch('projectSelected', { project: to.query?.project_uuid });

store.state.Auth.connectProjectUuid = to.query?.project_uuid;

sessionStorage.setItem(
'projectUuid',
store.state.Auth.connectProjectUuid,
);

next();
},
},
{
path: '/router',
name: 'router',
component: RepositoryContentBasesForm,
redirect: () => {
return { name: 'router-personalization' };
},
async beforeEnter(_to, _from, next) {
const { data } = await nexusaiAPI.router.read({
projectUuid: store.state.Auth.connectProjectUuid,
});

store.state.router.contentBaseUuid = data.uuid;
store.state.router.intelligenceUuid = data.intelligence;

next();
},
children: [
{
path: 'personalization',
name: 'router-personalization',
},
{
path: 'content',
name: 'router-content',
},
{
path: 'actions',
name: 'router-actions',
},
{
path: 'tunings',
name: 'router-tunings',
},
],
},
{
path: '/intelligences/:intelligenceUuid',
name: 'intelligence-home',
component: RepositoryContentBases,
},
{
path: '/intelligences/:intelligenceUuid/edit',
name: 'intelligence-edit',
component: RepositoryContentAdjustment,
},
{
path: '/intelligences/:intelligenceUuid/bases/:contentBaseUuid/edit',
name: 'intelligence-content-base-edit',
component: RepositoryContentBasesForm,
},
{
path: '/dashboard',
name: 'dashboard',
Expand Down Expand Up @@ -395,6 +328,32 @@ const router = new Router({
path: '*',
name: '404',
component: NotFound,
beforeEnter(to, _from, next) {
if (to.fullPath === nextFromRedirect) {
next();
} else {
const bearerToken = window.localStorage
.getItem('authToken')
.replace(' ', '+');

const intelligenceOrgId = store.state.Auth.org;
const orgUuid = sessionStorage.getItem('orgUuid');
const projectUuid = sessionStorage.getItem('projectUuid');

const path = `/loginexternal/${bearerToken}/${intelligenceOrgId}/${projectUuid}/`;

const redirectUrl = new URL(
path,
runtimeVariables.get('INTELLIGENCE_NEXT_URL'),
);

redirectUrl.searchParams.append('org_uuid', orgUuid);
redirectUrl.searchParams.append('project_uuid', projectUuid);
redirectUrl.searchParams.append('next_from_redirect', to.fullPath);

location.href = redirectUrl.toString();
}
},
},
{
path: '/safariAlert/',
Expand Down
15 changes: 5 additions & 10 deletions src/views/CreateRepository.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="create-repository">
<create-repository-form/>
<CreateRepositoryForm />
</div>
</template>

Expand All @@ -14,22 +14,18 @@ export default {
CreateRepositoryForm,
},
computed: {
...mapGetters([
'authenticated',
]),
...mapGetters(['authenticated']),
},
mounted() {
this.checkIsAuthenticated();
},
methods: {
checkIsAuthenticated() {
if (!this.authenticated) {
this.$router.push({
name: 'home'
});
this.$router.push('/home');
}
}
}
},
},
};
</script>

Expand All @@ -38,5 +34,4 @@ export default {
height: 100vh;
width: 100%;
}
</style>
8 changes: 2 additions & 6 deletions src/views/LandingPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ export default {
},
watch: {
authenticated() {
this.$router.push({
name: 'home',
});
this.$router.push('/home');
},
},
mounted() {
Expand All @@ -141,9 +139,7 @@ export default {
},
methods: {
showAllBots() {
this.$router.push({
name: 'home',
});
this.$router.push('/home');
},
signIn() {
this.$router.push({
Expand Down
4 changes: 1 addition & 3 deletions src/views/auth/RecoverPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export default {
},
methods: {
onAuthenticated() {
this.$router.push({
name: 'home',
});
this.$router.push('/home');
},
},
};
Expand Down
4 changes: 1 addition & 3 deletions src/views/auth/SignIn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export default {
},
methods: {
onAuthenticated() {
this.$router.push({
name: 'home',
});
this.$router.push('/home');
},
goToCreate() {
this.$router.push({
Expand Down
17 changes: 10 additions & 7 deletions src/views/auth/SignUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@ export default {
},
watch: {
authenticated() {
this.$router.push({
name:
this.authenticated &&
runtimeVariables.get('VUE_APP_BOTHUB_WEBAPP_PAYMENT_ENABLED')
? 'payment-options'
: 'home',
});
if (
this.authenticated &&
runtimeVariables.get('VUE_APP_BOTHUB_WEBAPP_PAYMENT_ENABLED')
) {
this.$router.push({
name: 'payment-options',
});
} else {
this.$router.push('/home');
}
},
},
mounted() {
Expand Down
11 changes: 4 additions & 7 deletions src/views/repository/content/Bases.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
type="tertiary"
iconCenter="arrow_left_alt"
scheme="neutral-dark"
@click="$router.push({ name: 'home' })"
@click="$router.push('/home')"
/>

<UnnnicSkeletonLoading
Expand Down Expand Up @@ -193,12 +193,9 @@
@close="isAddContentBaseOpen = false"
@success="
($event) =>
$router.push({
name: 'intelligence-content-base-edit',
params: {
contentBaseUuid: $event.uuid,
},
})
$router.push(
`/intelligences/${$route.params.intelligenceUuid}/bases/${$event.uuid}/edit`,
)
"
></BaseSettingsForm>
</div>
Expand Down
9 changes: 1 addition & 8 deletions src/views/repository/content/BasesForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
:title="contentBase.title"
:dontShowBack="isRouterView"
:brainIsDeactivated="!routerTunings.brainOn"
@back="
$router.push({
name: 'intelligence-home',
params: {
intelligenceUuid: intelligenceUuid,
},
})
"
@back="$router.push(`/intelligences/${intelligenceUuid}`)"
>
<UnnnicButton
v-if="isRouterView"
Expand Down
Loading

0 comments on commit 797341c

Please sign in to comment.