ki-frontend/src/views/profile/Edit.vue

213 lines
5.7 KiB
Vue
Raw Normal View History

2021-06-07 17:41:25 +02:00
<template>
<div class="container">
<h1>Profil Ändern</h1>
<form @submit.prevent="submitForm()">
2021-07-12 19:12:51 +02:00
<div class="row">
<div class="col">
<input type="radio" id="false" :value="false" v-model="profile.visible" />
<label for="false">Nicht Öffentlich</label>
</div>
<div class="col">
<input type="radio" id="true" :value="true" v-model="profile.visible" />
<label for="true">Öffentlich</label>
</div>
</div>
<div class="row">
<div class="col-6 col-xs-12">
<label for="nickname" class="form-label">Nickname:</label>
<input
type="text"
class="form-control"
id="nickname"
v-model="profile.nickname"
required
/>
</div>
<div class="col-6 col-xs-12">
<label for="nickname" class="form-label">Pronomen:</label>
<input
type="text"
class="form-control"
id="pronouns"
v-model="profile.pronouns"
/>
2021-06-24 00:40:27 +02:00
<div id="emailHelp" class="form-text">
Z.B.: Er/Ihn, Sie/Ihr, Es etc..
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-xs-12">
2021-06-24 00:40:27 +02:00
<label for="freetext" class="form-label">Freitext Vorstellung:</label>
<textarea
class="form-control"
id="freetext"
rows="3"
v-model="profile.freetext"
2021-06-24 00:40:27 +02:00
></textarea>
</div>
<div class="col-12 col-xs-12">
2021-06-24 00:40:27 +02:00
<label for="volunteerwork" class="form-label"
>Ehrentamtliche Arbeit:</label
>
<textarea
class="form-control"
id="volunteerwork"
rows="3"
v-model="profile.volunteerwork"
2021-06-24 00:40:27 +02:00
></textarea>
</div>
</div>
2021-07-12 18:32:17 +02:00
<auto-complete
type="skill"
label="Deine Fähigkeiten (Autocomplete)"
:values="profile.skills"
@update-values="profile.skills = $event"
></auto-complete>
<auto-complete
type="language"
label="Deine Sprachen (Autocomplete)"
:values="profile.languages"
@update-values="profile.languages = $event"
></auto-complete>
<auto-complete
type="skill"
label="Ich Suche"
:values="profile.searchtopics"
@update-values="profile.searchtopics = $event"
></auto-complete>
2021-07-12 19:12:51 +02:00
<div class="col-12 col-xs-12">
<label for="volunteerwork" class="form-label"
>Ich bin für Anfragen verfügbar:</label
>
<textarea
class="form-control"
id="availability"
rows="3"
v-model="profile.availability"
></textarea>
</div>
2021-07-12 18:32:17 +02:00
<auto-complete
type="contacttype"
label="Kontaktmöglichkeiten"
:values="profile.contacts"
@update-values="profile.contacts = $event"
></auto-complete>
<div class="row">
<div class="col">
<label for="pzl" class="form-label">PZL</label>
<input
type="text"
class="form-control"
id="pzl"
v-model="profile.address.postcode"
/>
</div>
2021-07-12 18:32:17 +02:00
<div class="col">
<label for="pzl" class="form-label">Stadt</label>
<input
type="text"
class="form-control"
id="pzl"
v-model="profile.address.city"
/>
</div>
2021-07-12 18:32:17 +02:00
<div class="col">
<label for="pzl" class="form-label">Land</label>
<input
type="text"
class="form-control"
id="pzl"
v-model="profile.address.country"
/>
</div>
2021-07-12 18:32:17 +02:00
</div>
2021-06-24 00:40:27 +02:00
<button type="submit" class="btn btn-primary mb-4 mt-4">Speichern</button>
<div
class="alert alert-danger mb-4 mt-4"
role="alert"
v-if="showErrorMessage"
>
Es ist Fehler aufgetreten
</div>
</form>
</div>
2021-06-07 17:41:25 +02:00
</template>
<script>
2021-06-24 00:40:27 +02:00
import axios from "axios";
2021-07-12 18:32:17 +02:00
import AutoComplete from "@/components/AutoComplete";
2021-06-07 17:41:25 +02:00
export default {
name: "profileEdit",
2021-07-12 18:32:17 +02:00
components: {
AutoComplete,
},
data() {
return {
showErrorMessage: false,
profile: {
2021-07-12 19:12:51 +02:00
visible: false,
nickname: "",
pronouns: "",
volunteerwork: "",
freetext: "",
2021-07-12 19:12:51 +02:00
availability: "",
address: {
postcode: "",
city: "",
country: "",
},
skills: [],
languages: [],
2021-07-12 18:32:17 +02:00
searchtopics: [],
contacts: [],
},
};
},
async created() {
try {
const userProfile = await axios.get(
`${process.env.VUE_APP_API_URL}/users/${localStorage.getItem(
"user_id"
)}/profile`,
{
headers: { Authorization: `Bearer ${localStorage.getItem("token")}` },
}
);
console.log(userProfile.data);
2021-07-12 19:12:51 +02:00
this.profile = userProfile.data.profile;
} catch (error) {
console.error(error);
}
},
methods: {
async submitForm() {
try {
const formSubmitResult = await axios.post(
`${process.env.VUE_APP_API_URL}/users/${localStorage.getItem(
"user_id"
)}/profile`,
2021-07-12 18:32:17 +02:00
this.profile,
{
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
}
);
console.log(formSubmitResult);
if (formSubmitResult.status === 200) {
// success
} else {
// failure
}
} catch (error) {
console.error();
this.showErrorMessage = true;
}
2021-07-12 18:32:17 +02:00
}
},
};
2021-06-07 17:41:25 +02:00
</script>