From c864358564e276b2bb65558e7d7c137abcee9778 Mon Sep 17 00:00:00 2001
From: leandro <leandroalmada86@gmail.com>
Date: Fri, 8 Oct 2021 15:07:55 +0200
Subject: [PATCH] add events user

---
 src/store/index.js       | 28 +++++++++++++++++++++++++++-
 src/views/My_account.vue | 15 +++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/src/store/index.js b/src/store/index.js
index 329d9b0b..eef57b2b 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -47,7 +47,13 @@ export default new Vuex.Store({
     SSO_SETTED: false,
     USER_LEVEL_PROJECTS: null,
     user_permissions: null,
-    messages: []
+    messages: [],
+    events: null
+    // events: {
+    //   'events': null,
+    //   'features': null,
+    //   'comments': null
+    // }
   },
 
   mutations: {
@@ -90,6 +96,9 @@ export default new Vuex.Store({
     SET_USER_PERMISSIONS(state, userPermissions) {
       state.user_permissions = userPermissions;
     },
+    SET_EVENTS(state, events) {
+      state.events = events;
+    },
     DISPLAY_MESSAGE(state, comment) {
       state.messages = [{ comment }, ...state.messages];
       document.getElementById("messages").scrollIntoView({ block: "start", inline: "nearest" });
@@ -183,6 +192,23 @@ export default new Vuex.Store({
       }
     },
 
+    USER_EVENTS({ commit }) {
+      return new Promise((resolve, reject) => {
+        axios
+          .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}events`)
+          .then((response) => {
+            if (response && response.status === 200) {
+              const events = response.data;
+              commit("SET_EVENTS", events);
+              resolve(response.data);
+            }
+          })
+          .catch(() => {
+            reject("Error");
+          });
+      });
+    },
+
     LOGOUT({ commit, dispatch }) {
       // const pageNoRedirect = ["liste-signalements", "details-type-signalement", "details-signalement", "project_detail", "mentions", "aide", "index"]
       axios
diff --git a/src/views/My_account.vue b/src/views/My_account.vue
index e9f4e924..8967257b 100644
--- a/src/views/My_account.vue
+++ b/src/views/My_account.vue
@@ -309,6 +309,21 @@ export default {
     refreshId() {
       return "?ver=" + Math.random();
     },
+    setEvents(data){
+      this.events = data.events;
+      this.features = data.features;
+      this.comments = data.comments;
+    },
+    getEvents(){
+      this.$store
+        .dispatch("USER_EVENTS")
+        .then((data)=>{
+          this.setEvents(data)
+        })
+    }
   },
+  created(){
+    this.getEvents();
+  }
 };
 </script>
\ No newline at end of file
-- 
GitLab