From 3b1f9f8061f6cb1c3aa2f99093cebceca5b1a06c Mon Sep 17 00:00:00 2001
From: ingrid <ingrimeg@stud.ntnu.no>
Date: Tue, 25 Apr 2023 11:05:50 +0200
Subject: [PATCH] gjemmer matpreferanseinnstillinger

---
 src/views/ProfileSettings.vue | 58 ++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/src/views/ProfileSettings.vue b/src/views/ProfileSettings.vue
index 5561b05..be44856 100644
--- a/src/views/ProfileSettings.vue
+++ b/src/views/ProfileSettings.vue
@@ -3,14 +3,14 @@
         <h1><br><br>Profilinnstillinger <br></h1>
 
         <div v-if="hasProfileImage" id = "profilepicture-container">
-            <img width="100" src="../components/images/w66XcIlw.jpeg" alt="profile picture">
+            <img width="100" :src="this.currentProfile.image" alt="profile picture">
         </div>
         <div v-else id = "profilepicture-container">
             <Icon icon="material-symbols:person" :color=iconColor :style="{ fontSize: '500px'}" />
         </div>
 
-        <h2>{{this.currentProfile.name}}</h2>
-        <button id="changeUserBtn" >Bytt bruker</button>
+        <h2>{{profile.name}}</h2>
+        <button  @click="changeProfile" id="changeUserBtn" >Bytt bruker</button>
 
         <form @submit.prevent="submit">
             <label for="brukernavn">Profilnavn</label><br>
@@ -27,12 +27,12 @@
             <h3>Profilbilde</h3>
             <div id="changeUserImage">
                 <div v-if="hasProfileImage" id = "profilepicture-container">
-                    <img width="50" src="../components/images/w66XcIlw.jpeg" alt="profile picture">
+                    <img width="50" :src="this.currentProfile.image" alt="profile picture">
                 </div>
                 <div v-else id = "profilepicture-container">
                     <Icon icon="material-symbols:person" :color=iconColor :style="{ fontSize: '30px'}" />
                 </div>
-                <button>Endre bilde</button>
+                <button @click="chooseProfilePicture">Endre bilde</button>
             </div>
 
             <div id = "submitbuttonBox">
@@ -75,12 +75,12 @@
 
             <p class="infoText">OBS: Kontakt admin dersom du ønsker å oppdatere epost</p><br>
 
-            <p>Epost:</p>
+            <p>Epost: {{user.email}}</p><br>
 
             <label for="password">Endre passord</label><br>
-            <input type="password" id="password" >
+            <input type="password" id="password" v-model="this.currentUser.newPassword">
 
-            <button class="saveBtn" @click="saveAccountSettings">Lagre kontoinnstillinger</button>
+            <button class="saveBtn" @click="saveAccountSettings">Lagre nytt passord</button>
 
           </form>
           <br>
@@ -110,8 +110,8 @@
 import {mapStores} from "pinia";
 import {Icon} from "@iconify/vue";
 import {API} from "@/util/API";
-//import {useAuthStore} from "../stores/authStore";
 import { useAuthStore } from "@/stores/authStore";
+import router from "../router";
 export default {
     name: "ProfileSettings",
     components: {Icon},
@@ -121,6 +121,7 @@ export default {
             const store = useAuthStore();
             this.currentProfile.name = store.profile.name;
             this.currentProfile.isRestricted = store.profile.restricted;
+            this.currentProfile.image = store.profile.profileImageUrl;
             return store.profile
         },
         user() {
@@ -131,36 +132,27 @@ export default {
             return "#000000"
         },
         hasProfileImage() {
-            return false;
-            //return this.profile.image.length > 0;
+            return this.currentProfile.image.length > 0;
         }
     },
     data() {
         return {
             currentUser: {
-                username: "petter@hello.no",
-                password: "",
-
+                newPassword: "",
             },
             currentProfile: {
                 name: "",
                 isRestricted: true,
-                image: "../components/images/w66XcIlw.jpeg",
+                image: "",
             },
             foodPreferences: [],
             allergens: [],
             deletionConfirmation: false,
         }
     },
-    beforeMount(){
-        //...mapStores(useAuthStore),
-
-        //TODO: Hent bruker
-        //todo hent profil
-    },
     methods: {
-      saveUserSettings(){
-          console.log(this.currentProfile.isRestricted)
+      saveUserSettings(){ //profilnavn, profilbilde, profilrestriksjoner
+          console.log(this.currentProfile.image)
         alert("(Denne knappen gjør ingen ting) brukerinnstillinger lagret!")
           API.updateProfile(
               this.user.id,
@@ -169,8 +161,17 @@ export default {
               this.profile.image,
           );
       },
-      saveAccountSettings(){
-        alert("(Denne knappen gjør ingen ting) konto oppdatert")
+        chooseProfilePicture(){
+            alert("velgBilde")
+        },
+      saveAccountSettings(){ //passord
+          if(this.currentUser.newPassword.length===0){
+              alert("Det er ikke gjort endringer, og passordet vil ikke bli oppdatert")
+          } else {
+
+              alert("(Denne knappen gjør ingen ting) konto oppdatert")
+          }
+
           /*API.updateAccount(
               this.user.id,
               this.user.password,
@@ -188,10 +189,11 @@ export default {
       },
       deleteUser(){
         alert("(Denne knappen gjør ingen ting)  bruker slettet")
+          //API.deleteAccount(this.user.id, token).then
       },
-      saveFoodPreference() {
-        alert("(Denne knappen gjør ingen ting) matpreferanser lagret")
-      }
+        changeProfile(){
+            router.push("/selectProfile");
+        }
     }
 }
 </script>
-- 
GitLab