From 58593433fa3bb31d793b0b803bebb42228bacceb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr>
Date: Mon, 16 Aug 2021 11:12:52 +0200
Subject: [PATCH] fix circular route if opening app on login & started add
 duplicate type feature route

---
 src/router/index.js                          | 13 ++++++++++---
 src/store/index.js                           |  4 +++-
 src/views/feature_type/Feature_type_edit.vue | 16 ++++++++++++----
 src/views/project/Project_detail.vue         | 10 ++++++----
 4 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/src/router/index.js b/src/router/index.js
index 40a6e946..c94cd258 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -69,13 +69,20 @@ const routes = [
     component: () => import('../views/project/Project_members.vue')
   },
   // * FEATURE TYPE 
-    {
+  {
     path: '/projet/:slug/type-signalement/ajouter/',
     name: 'ajouter-type-signalement',
     props: true,
     hasProject: true,
     component: () => import('../views/feature_type/Feature_type_edit.vue')
   },
+  {
+    path: '/projet/:slug/type-signalement/ajouter/?create_from=:slug_type_signal',
+    name: 'dupliquer-type-signalement',
+    props: true,
+    hasProject: true,
+    component: () => import('../views/feature_type/Feature_type_edit.vue')
+  },
   {
     path: '/projet/:slug/type-signalement/:feature_type_slug/',
     name: 'details-type-signalement',
@@ -83,7 +90,7 @@ const routes = [
     hasProject: true,
     component: () => import('../views/feature_type/Feature_type_detail.vue')
   },
-  { // todo : adapter le template
+  {
     path: '/projet/:slug/type-signalement/:slug_type_signal/editer/',
     name: 'editer-type-signalement',
     props: true,
@@ -119,7 +126,7 @@ const routes = [
     hasProject: true,
     component: () => import('../views/feature/Feature_edit.vue')
   },
-  
+
   { path: '/:pathMatch(.*)*', name: 'NotFound', component: () => import('../views/NotFound.vue') },
 ]
 //let routerHistory = [];
diff --git a/src/store/index.js b/src/store/index.js
index 3c4b4856..da6ffd7f 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -110,7 +110,9 @@ export default new Vuex.Store({
             password: payload.password,
           })
           .then((response) => {
-            const routerHistory = router.options.routerHistory // * use store previous route to go back after login
+            console.log(router.options.routerHistory)
+            // * use stored previous route to go back after login if page not open on login at first
+            const routerHistory = router.options.routerHistory[0].name !== "login" ? router.options.routerHistory : "/"
             commit("SET_USER", response.data.user);
             router.push(routerHistory[routerHistory.length - 1] || "/")
             dispatch("GET_USER_LEVEL_PROJECTS");
diff --git a/src/views/feature_type/Feature_type_edit.vue b/src/views/feature_type/Feature_type_edit.vue
index 3602fa40..58f9c100 100644
--- a/src/views/feature_type/Feature_type_edit.vue
+++ b/src/views/feature_type/Feature_type_edit.vue
@@ -185,10 +185,7 @@ export default {
 
   data() {
     return {
-      action:
-        this.$router.history.current.name === "ajouter-type-signalement"
-          ? "create"
-          : "edit",
+      action: "create",
       dataKey: 0,
       form: {
         colors_style: {
@@ -277,6 +274,17 @@ export default {
       "feature_type/SET_CURRENT_FEATURE_TYPE_SLUG",
       this.slug_type_signal
     );
+    if (this.$router.history.current.name === "ajouter-type-signalement") {
+      this.action = "create";
+    } else if (
+      this.$router.history.current.name === "editer-type-signalement"
+    ) {
+      this.action = "edit";
+    } else if (
+      this.$router.history.current.name === "dupliquer-type-signalement"
+    ) {
+      this.action = "duplicate";
+    }
   },
   mounted() {
     if (this.action === "edit") {
diff --git a/src/views/project/Project_detail.vue b/src/views/project/Project_detail.vue
index c9cb3d14..b86ab611 100644
--- a/src/views/project/Project_detail.vue
+++ b/src/views/project/Project_detail.vue
@@ -127,7 +127,11 @@
                   ><!-- // todo : adapt -->
                   <i class="ui plus icon"></i>
                 </router-link>
-                <a
+                <router-link
+                  :to="{
+                    name: 'dupliquer-type-signalement',
+                    params: { slug_type_signal: type.title },
+                  }"
                   v-if="project && permissions.can_create_feature"
                   class="
                     ui
@@ -141,10 +145,9 @@
                   data-tooltip="Dupliquer un type de signalement"
                   data-position="left center"
                   data-variation="mini"
-                  href="{% url 'geocontrib:feature_type_create' slug=project.slug %}?create_from=type.slug"
                   ><!-- // todo : adapt -->
                   <i class="inverted grey copy alternate icon"></i>
-                </a>
+                </router-link>
                 <router-link
                   :to="{
                     name: 'editer-type-signalement',
@@ -163,7 +166,6 @@
                   data-tooltip="Éditer le type de signalement"
                   data-position="left center"
                   data-variation="mini"
-                  href="{% url 'geocontrib:feature_type_update' slug=project.slug feature_type_slug=type.slug %}"
                 >
                   <i class="inverted grey pencil alternate icon"></i>
                 </router-link>
-- 
GitLab