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

meldinger ved feil

parent 29c5f03e
No related branches found
No related tags found
1 merge request!21Merge profilinnstillinger into main
Pipeline #223684 failed
<template> <template>
<h1>Konto-innstillinger</h1> <h1>Konto-innstillinger</h1>
<form @submit.prevent="submit"> <form @submit.prevent="submit">
<p class="infoText">OBS: Kontakt admin dersom du ønsker å oppdatere epost</p><br> <p class="infoText">OBS: Kontakt admin dersom du ønsker å oppdatere epost</p><br>
<p>Epost: {{this.account.email}}</p><br> <p>Epost: {{this.account.email}}</p><br>
...@@ -13,8 +12,9 @@ ...@@ -13,8 +12,9 @@
<input type="password" id="password" v-model="updatedAccount.upPassword"> <input type="password" id="password" v-model="updatedAccount.upPassword">
<button class="saveBtn" @click="saveAccountSettings">Lagre profilendringer</button> <button class="saveBtn" @click="saveAccountSettings">Lagre profilendringer</button>
<p :style={color:alertMsgColor} id="alert">{{alertMsg}}</p>
</form> </form>
<br> <br>
<br> <br>
<hr> <hr>
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<input type="checkbox" id="deletionCheckbox" v-model="deletionConfirmation"> <input type="checkbox" id="deletionCheckbox" v-model="deletionConfirmation">
<label for="deletionCheckbox"> Jeg bekrefter jeg skjønner dette, og ønsker å slette kontoen min SmartMat-konto for alltid.</label><br> <label for="deletionCheckbox"> Jeg bekrefter jeg skjønner dette, og ønsker å slette kontoen min SmartMat-konto for alltid.</label><br>
<button class="delBtn" @click="deleteAccount">SLETT KONTO</button> <button class="delBtn" @click="deleteAccount">SLETT KONTO</button>
<p :style={color:alertMsgColor} id="alert">{{delAlertMsg}}</p>
</form> </form>
</template> </template>
...@@ -53,6 +54,9 @@ export default { ...@@ -53,6 +54,9 @@ export default {
data() { data() {
return { return {
deletionConfirmation: false, deletionConfirmation: false,
alertMsg:'',
alertMsgColor:'black',
delAlertMsg:'',
} }
}, },
methods: { methods: {
...@@ -67,8 +71,9 @@ export default { ...@@ -67,8 +71,9 @@ export default {
} }
).then((savedAccount)=>{ ).then((savedAccount)=>{
useAuthStore().setAccount(savedAccount); useAuthStore().setAccount(savedAccount);
alert("Bruker oppdatert.") this.setAlertText("Melding: Bruker oppdatert.",'light-green');
}).catch((error)=> { }).catch((error)=> {
this.setAlertText("Melding: Det oppsto en feil. ",'red');
console.log(error) console.log(error)
}) })
} else { } else {
...@@ -81,15 +86,16 @@ export default { ...@@ -81,15 +86,16 @@ export default {
} }
).then((savedAccount)=>{ ).then((savedAccount)=>{
useAuthStore().setAccount(savedAccount); useAuthStore().setAccount(savedAccount);
alert("Konto oppdatert.") this.setAlertText("Melding: Konto oppdatert.",'light-green')
}).catch((error)=> { }).catch((error)=> {
this.setAlertText("Melding: Det oppsto en feil. ",'red');
console.log(error) console.log(error)
}) })
} }
}, },
deleteAccount(){ deleteAccount(){
if(this.deletionConfirmation===false){ if(this.deletionConfirmation===false){
alert("Du må bekrefte at du vil slette konto ved å huke av boksen") this.setDeleationAlertText("Du må bekrefte at du vil slette konto ved å huke av boksen", 'red')
} }
else { else {
const id = this.account.id; const id = this.account.id;
...@@ -98,11 +104,43 @@ export default { ...@@ -98,11 +104,43 @@ export default {
).then(()=>{ ).then(()=>{
router.push('/login') router.push('/login')
}).catch((error)=> { }).catch((error)=> {
alert("Det oppsto en feil ved sletting av bruker") this.setDeleationAlertText("Melding: Det oppsto en feil ved sletting av bruker", 'red')
console.log(error)
}) })
} }
}, },
setAlertText(text, color){
switch (color) {
case 'red':
this.alertMsgColor ='#EE6D6D';
this.alertMsg = text;
break;
case 'light-green':
this.alertMsgColor ='hsla(160, 100%, 37%, 1);';
this.alertMsg = text;
break;
default:
this.alertMsgColor ='black';
this.alertMsg = text;
break;
}
},
setDeleationAlertText(text,color){
switch (color) {
case 'red':
this.alertMsgColor ='#EE6D6D';
this.delAlertMsg = text;
break;
case 'light-green':
this.alertMsgColor ='hsla(160, 100%, 37%, 1);';
this.delAlertMsg = text;
break;
default:
this.alertMsgColor ='black';
this.delAlertMsg = text;
break;
}
}
} }
} }
</script> </script>
...@@ -142,6 +180,7 @@ input[type="password"]{ ...@@ -142,6 +180,7 @@ input[type="password"]{
button { button {
background-color: base.$red; background-color: base.$red;
color: black; color: black;
border: 1px solid black; border: 1px solid black;
...@@ -168,4 +207,12 @@ button:hover{ ...@@ -168,4 +207,12 @@ button:hover{
color: darkred; color: darkred;
} }
#alert {
display: flex;
width:100%;
justify-content: center;
color: base.$light-green;
font-weight: bold;
}
</style> </style>
\ No newline at end of file
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
<button class="delBtn" @click="deleteProfile">Slett brukerprofil</button> <button class="delBtn" @click="deleteProfile">Slett brukerprofil</button>
</div> </div>
<p :style={color:alertMsgColor} id="alert">{{alertMsg}}</p>
</form> </form>
</template> </template>
...@@ -55,6 +57,12 @@ import router from "../router"; ...@@ -55,6 +57,12 @@ import router from "../router";
export default { export default {
name: "EditProfile", name: "EditProfile",
components: {Icon}, components: {Icon},
data() {
return {
alertMsg:'',
alertMsgColor:'black',
}
},
computed: { computed: {
...mapState(useAuthStore, ['profile']), ...mapState(useAuthStore, ['profile']),
...@@ -79,7 +87,7 @@ export default { ...@@ -79,7 +87,7 @@ export default {
const numOfProfiles = API.getProfiles().length const numOfProfiles = API.getProfiles().length
if(numOfProfiles===1 && this.updatedProfile.upRestricted===true){ if(numOfProfiles===1 && this.updatedProfile.upRestricted===true){
alert("Du må ha minst en standardprofil per konto. (ingen endringer er gjort)") this.setAlertText("Du må ha minst en standardprofil per konto. (ingen endringer er gjort)",'red')
} }
else { else {
API.updateProfile( API.updateProfile(
...@@ -90,14 +98,15 @@ export default { ...@@ -90,14 +98,15 @@ export default {
} }
).then((savedProfile)=>{ ).then((savedProfile)=>{
useAuthStore().setProfile(savedProfile); useAuthStore().setProfile(savedProfile);
alert("profil oppdatert.") this.setAlertText("profil oppdatert.",'light-green')
}).catch((error)=> { }).catch((error)=> {
this.setAlertText("Det oppsto en feil",'red')
console.log(error) console.log(error)
}) })
} }
}, },
chooseProfilePicture(){ chooseProfilePicture(){
alert("skriv inn bildelenke i feltet, og oppdater innstillinger") this.setAlertText("skriv inn bildelenke i feltet, og oppdater innstillinger",'black')
}, },
changeProfile(){ changeProfile(){
router.push("/selectProfile"); router.push("/selectProfile");
...@@ -105,16 +114,32 @@ export default { ...@@ -105,16 +114,32 @@ export default {
deleteProfile(){ deleteProfile(){
const numOfProfiles = API.getProfiles().length const numOfProfiles = API.getProfiles().length
if(numOfProfiles===1){ if(numOfProfiles===1){
alert("Du kan ikke slette profilen. Hver Konto må ha minst en profil") this.setAlertText("Du kan ikke slette profilen. Hver Konto må ha minst en profil",'red')
}else { }else {
const id = this.profile.id; const id = this.profile.id;
API.deleteProfile(id).then(()=>{ API.deleteProfile(id).then(()=>{
router.push('/selectProfile') router.push('/selectProfile')
}).catch((error)=> { }).catch((error)=> {
alert("Det oppsto en feil ved sletting profil: " + error) this.setAlertText("Det oppsto en feil ved sletting profil", 'red')
}) })
} }
} },
setAlertText(text, color){
switch (color) {
case 'red':
this.alertMsgColor ='#EE6D6D';
this.alertMsg = text;
break;
case 'light-green':
this.alertMsgColor ='hsla(160, 100%, 37%, 1);';
this.alertMsg = text;
break;
default:
this.alertMsgColor ='black';
this.alertMsg = text;
break;
}
},
} }
} }
...@@ -215,5 +240,13 @@ button:hover{ ...@@ -215,5 +240,13 @@ button:hover{
#dangerZone { #dangerZone {
color: darkred; color: darkred;
} }
#alert {
display: flex;
width:100%;
justify-content: center;
color: base.$light-green;
font-weight: bold;
}
</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