Przeglądaj źródła

Update profile to only show current user logged in

master
Lene Scholtz 5 lat temu
rodzic
commit
41f1d9fd22

+ 44
- 16
src/components/user/updateProfileInfo.vue Wyświetl plik

@@ -20,19 +20,18 @@
20 20
             <th>Telephone Number</th>
21 21
             <th>Email</th>
22 22
             <th>Role</th>
23
-            <th></th>
23
+            <th>Modify</th>
24 24
           </tr>
25 25
         </thead>
26 26
         <tbody>
27
-          <tr v-for="(item, i) in individuals" :key="i">
28
-            <td>{{ item.id }}</td>
29
-            <td>{{ item.name }}</td>
30
-            <td>{{ item.surname }}</td>
31
-            <td>{{ item.cellNumber }}</td>
32
-            <td>{{ item.telephone }}</td>
33
-            <td>{{ item.email }}</td>
34
-            <td v-if="item.user">{{ item.user.role }}</td>
35
-            <td v-else></td>
27
+          <tr>
28
+            <td>{{ user.id }}</td>
29
+            <td>{{ indiv.name }}</td>
30
+            <td>{{ indiv.surname }}</td>
31
+            <td>{{ indiv.cellNumber }}</td>
32
+            <td>{{ indiv.landlineNumber }}</td>
33
+            <td>{{ indiv.emailAddress }}</td>
34
+            <td>{{ user.role }}</td>
36 35
             <td>
37 36
               <button
38 37
                 type="button"
@@ -63,7 +62,7 @@
63 62
 </template>
64 63
 
65 64
 <script>
66
-import { mapState, mapActions } from 'vuex';
65
+import { mapState, mapActions, mapGetters } from 'vuex';
67 66
 import Individual from './registerPage.vue';
68 67
 
69 68
 export default {
@@ -71,19 +70,48 @@ export default {
71 70
   components: {
72 71
     Individual,
73 72
   },
73
+  props: {
74
+    currentUser: {
75
+      name: undefined,
76
+      surname: undefined,
77
+      idNumber: undefined,
78
+      companyRegNumber: undefined,
79
+      emailAddress: undefined,
80
+      cellNumber: undefined,
81
+      landlineNumer: undefined,
82
+      bankingDetails: {},
83
+      address: {},
84
+    },
85
+    showChangeCurrentUser: {
86
+      default: false,
87
+    },
88
+    showBank: {
89
+      default: false,
90
+    },
91
+    showAddress: {
92
+      default: false,
93
+    },
94
+  },
74 95
   data() {
75 96
     return {
76 97
       item: {},
77 98
     };
78 99
   },
79
-  methods: {
80
-    ...mapActions('register', ['getIndividuals']),
81
-  },
82 100
   mounted() {
83
-    this.getIndividuals();
101
+    if (!this.currentUser) {
102
+      if (this.user) {
103
+        this.getIndividual(this.user.id);
104
+      }
105
+    }
84 106
   },
85 107
   computed: {
86
-    ...mapState('register', ['individuals']),
108
+    ...mapState('individual', ['indiv']),
109
+    ...mapGetters({
110
+      user: 'authentication/getUser',
111
+    }),
112
+  },
113
+  methods: {
114
+    ...mapActions('individual', ['getIndividual']),
87 115
   },
88 116
 };
89 117
 </script>

+ 5
- 12
src/store/modules/user/authentication.js Wyświetl plik

@@ -7,8 +7,8 @@ Vue.use(Vuex);
7 7
 export default {
8 8
   namespaced: true,
9 9
   state: {
10
-    username: 'kobusb',
11
-    password: '123123',
10
+    username: 'UniVate2018',
11
+    password: 'UniVate2018',
12 12
     isLoggedIn: log.isLoggedIn(),
13 13
     flag: false,
14 14
     status: undefined,
@@ -55,9 +55,7 @@ export default {
55 55
     getUser: () => log.getUser(),
56 56
   },
57 57
   actions: {
58
-    init({
59
-      commit,
60
-    }) {
58
+    init({ commit }) {
61 59
       if (!log.isLoggedIn() && log.tokenExpired) {
62 60
         log.clearValues();
63 61
       } else log.updateTokenExpiry();
@@ -68,10 +66,7 @@ export default {
68 66
         agency: log.getJSONObject('agency'),
69 67
       });
70 68
     },
71
-    login({
72
-      commit,
73
-      state,
74
-    }) {
69
+    login({ commit, state }) {
75 70
       axios({
76 71
         url: '/api/register/authenticate',
77 72
         data: {
@@ -92,9 +87,7 @@ export default {
92 87
           commit('auth_error', err.data);
93 88
         });
94 89
     },
95
-    logout({
96
-      commit,
97
-    }) {
90
+    logout({ commit }) {
98 91
       return new Promise(() => {
99 92
         commit('logout');
100 93
         log.clearValues();

+ 5
- 6
src/store/modules/user/individual.js Wyświetl plik

@@ -18,15 +18,14 @@ export default {
18 18
   },
19 19
   getters: {},
20 20
   actions: {
21
-    getIndividual({
22
-      commit,
23
-    }, userId) {
21
+    getIndividual({ commit }, userId) {
24 22
       axios
25 23
         .get(`/api/individual/getIndividual/${userId}`)
26 24
         .then(r => commit('setItem', {
27
-          name: 'item',
28
-          value: r.data,
29
-        })).catch(console.error);
25
+            name: 'indiv',
26
+            value: r.data,
27
+          }),)
28
+        .catch(console.error);
30 29
     },
31 30
   },
32 31
 };

Ładowanie…
Anuluj
Zapisz