Skip to content
Snippets Groups Projects
Commit 7b4d0274 authored by Ingrid Martinsheimen Egge's avatar Ingrid Martinsheimen Egge :cow2:
Browse files

oppdatere profilnavn

parent 9ccb508d
No related branches found
No related tags found
1 merge request!21Merge profilinnstillinger into main
...@@ -2,31 +2,31 @@ ...@@ -2,31 +2,31 @@
<h1><br><br>Profilinnstillinger <br></h1> <h1><br><br>Profilinnstillinger <br></h1>
<div v-if="hasProfileImage" id = "profilepicture-container"> <div v-if="hasProfileImage" id = "profilepicture-container">
<img width="100" :src="this.currentProfile.image" alt="profile picture"> <img width="100" :src="this.updatedProfile.upImage" alt="profile picture">
</div> </div>
<div v-else id = "profilepicture-container"> <div v-else id = "profilepicture-container">
<Icon icon="material-symbols:person" :color=iconColor :style="{ fontSize: '500px'}" /> <Icon icon="material-symbols:person" :color=iconColor :style="{ fontSize: '500px'}" />
</div> </div>
<h2>{{profile.name}}</h2> <h2>{{this.profile.name}}</h2>
<button @click="changeProfile" id="changeUserBtn" >Bytt bruker</button> <button @click="changeProfile" id="changeUserBtn" >Bytt bruker</button>
<form @submit.prevent="submit"> <form @submit.prevent="submit">
<label for="brukernavn">Profilnavn</label><br> <label for="brukernavn">Profilnavn</label><br>
<input type="text" required v-model="profileName"><br> <input type="text" required v-model="this.updatedProfile.upName"><br>
<br> <br>
<h4>Brukertype</h4> <h4>Brukertype</h4>
<input type="radio" id="normal" value="false" v-model="isRestricted"> <input type="radio" id="normal" value="false" v-model="this.updatedProfile.upRestricted">
<label for="normal"> Standard</label><br> <label for="normal"> Standard</label><br>
<input type="radio" id="restricted" value="true" v-model="isRestricted"> <input type="radio" id="restricted" value="true" v-model="this.updatedProfile.upRestricted">
<label for="restricted"> Begrenset - Kan ikke redigere ukeplan eller handleliste</label><br> <label for="restricted"> Begrenset - Kan ikke redigere ukeplan eller handleliste</label><br>
<br> <br>
<h3>Profilbilde</h3> <h3>Profilbilde</h3>
<div id="changeUserImage"> <div id="changeUserImage">
<div v-if="hasProfileImage" id = "profilepicture-container"> <div v-if="hasProfileImage" id = "profilepicture-container">
<img width="50" :src="profileImage" alt="profile picture"> <img width="50" :src="this.updatedProfile.upImage" alt="profile picture">
</div> </div>
<div v-else id = "profilepicture-container"> <div v-else id = "profilepicture-container">
<Icon icon="material-symbols:person" :color=iconColor :style="{ fontSize: '30px'}" /> <Icon icon="material-symbols:person" :color=iconColor :style="{ fontSize: '30px'}" />
...@@ -44,75 +44,54 @@ ...@@ -44,75 +44,54 @@
</template> </template>
<script> <script>
import {mapStores} from "pinia"; import {mapState, mapStores} from "pinia";
import {Icon} from "@iconify/vue"; import {Icon} from "@iconify/vue";
import {API} from "@/util/API"; import {API} from "@/util/API";
import { useAuthStore } from "@/stores/authStore"; import { useAuthStore } from "@/stores/authStore";
import router from "../router"; import router from "../router";
export default { export default {
setup() {
const authStore = useAuthStore();
const profileName = authStore.profile.name;
const profileImage = authStore.profile.profileImageUrl;
const isRestricted = authStore.profile.restricted;
},
name: "EditProfile", name: "EditProfile",
components: {Icon}, components: {Icon},
computed: { computed: {
...mapStores(useAuthStore),
profile() {
let store = useAuthStore();
this.currentProfile.name = store.profile.name; ...mapState(useAuthStore, ['profile']),
this.currentProfile.isRestricted = store.profile.restricted; ...mapStores(useAuthStore),
this.currentProfile.image = store.profile.profileImageUrl; updatedProfile() {
return store.profile return {
}, upName: this.profile.name,
user() { upRestricted: this.profile.restricted,
const store = useAuthStore(); upImage: this.profile.profileImageUrl,
return store.user }
}, },
iconColor() { iconColor() {
return "#000000" return "#000000"
}, },
hasProfileImage() { hasProfileImage() {
return this.currentProfile.image.length > 0; return this.updatedProfile.upImage.length > 0;
} }
}, },
data() { data() {
return { return {
currentUser: {
newPassword: "",
},
currentProfile: {
name: "",
isRestricted: true,
image: "",
},
foodPreferences: [],
allergens: [],
deletionConfirmation: false, deletionConfirmation: false,
} }
}, },
methods: { methods: {
saveUserSettings(){ //profilnavn, profilbilde, profilrestriksjoner saveUserSettings(){
const namee = this.currentProfile.name; const id = this.profile.id;
const isRestrictede = this.currentProfile.isRestricted;
const profileImageUrle = this.currentProfile.image;
API.updateProfile( API.updateProfile(
this.profile.id,{ id,{
name:namee, name:this.updatedProfile.upName,
profileImageUrl: profileImageUrle, profileImageUrl:this.updatedProfile.upImage,
restricted: isRestrictede, restricted:this.updatedProfile.upRestricted,
} }
).then((savedProfile)=>{ ).then((savedProfile)=>{
console.log(this.updatedProfile.upName)
useAuthStore().setProfile(savedProfile); useAuthStore().setProfile(savedProfile);
alert("profil oppdatert.")
}).catch((error)=> { }).catch((error)=> {
console.log(error) console.log(error)
}) })
}, },
chooseProfilePicture(){ chooseProfilePicture(){
alert("velgBilde") alert("velgBilde")
...@@ -121,7 +100,6 @@ export default { ...@@ -121,7 +100,6 @@ export default {
if(this.currentUser.newPassword.length===0){ if(this.currentUser.newPassword.length===0){
alert("Det er ikke gjort endringer, og passordet vil ikke bli oppdatert") alert("Det er ikke gjort endringer, og passordet vil ikke bli oppdatert")
} else { } else {
alert("(Denne knappen gjør ingen ting) konto oppdatert") alert("(Denne knappen gjør ingen ting) konto oppdatert")
} }
}, },
...@@ -145,8 +123,6 @@ export default { ...@@ -145,8 +123,6 @@ export default {
} }
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
...@@ -245,6 +221,4 @@ button:hover{ ...@@ -245,6 +221,4 @@ button:hover{
color: darkred; color: darkred;
} }
</style> </style>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment