feat: save profile
This commit is contained in:
parent
befbee23b4
commit
d9fefe1d62
|
|
@ -10,19 +10,25 @@ const user = useUserStore();
|
||||||
const { organisations } = useEntities();
|
const { organisations } = useEntities();
|
||||||
|
|
||||||
const privateAddress = computed(() => {
|
const privateAddress = computed(() => {
|
||||||
let addressText = `${user.street} ${user.street_number}`;
|
let addressText = `${user.street} ${user.street_number}`.trim();
|
||||||
if (user.postal_code || user.city) {
|
if (user.postal_code || user.city) {
|
||||||
addressText += `, ${user.postal_code} ${user.city}`;
|
if (addressText.length) {
|
||||||
|
addressText += ", ";
|
||||||
|
}
|
||||||
|
addressText += `${user.postal_code} ${user.city}`;
|
||||||
}
|
}
|
||||||
if (user.country) {
|
if (user.country) {
|
||||||
addressText += `, ${user.country.name}`;
|
if (addressText.length) {
|
||||||
|
addressText += ", ";
|
||||||
|
}
|
||||||
|
addressText += user.country.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return addressText.trim();
|
return addressText.trim();
|
||||||
});
|
});
|
||||||
|
|
||||||
const organisationName = computed(() => {
|
const organisationName = computed(() => {
|
||||||
const org = organisations.value.find((c) => c.id === user.organisation);
|
const org = organisations.value.find((o) => o.id === user.organisation);
|
||||||
if (org) {
|
if (org) {
|
||||||
return org.name;
|
return org.name;
|
||||||
}
|
}
|
||||||
|
|
@ -30,12 +36,19 @@ const organisationName = computed(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const orgAddress = computed(() => {
|
const orgAddress = computed(() => {
|
||||||
let addressText = `${user.organisation_street} ${user.organisation_street_number}`;
|
let addressText =
|
||||||
|
`${user.organisation_street} ${user.organisation_street_number}`.trim();
|
||||||
if (user.organisation_postal_code || user.organisation_city) {
|
if (user.organisation_postal_code || user.organisation_city) {
|
||||||
addressText += `, ${user.organisation_postal_code} ${user.organisation_city}`;
|
if (addressText.length) {
|
||||||
|
addressText += ", ";
|
||||||
|
}
|
||||||
|
addressText += `${user.organisation_postal_code} ${user.organisation_city}`;
|
||||||
}
|
}
|
||||||
if (user.organisation_country) {
|
if (user.organisation_country) {
|
||||||
addressText += `, ${user.organisation_country.name}`;
|
if (addressText.length) {
|
||||||
|
addressText += ", ";
|
||||||
|
}
|
||||||
|
addressText += user.organisation_country.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return addressText.trim();
|
return addressText.trim();
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,14 @@ import { ref } from "vue";
|
||||||
|
|
||||||
import ProfileView from "@/components/personalProfile/ProfileView.vue";
|
import ProfileView from "@/components/personalProfile/ProfileView.vue";
|
||||||
import ProfileEdit from "@/components/personalProfile/ProfileEdit.vue";
|
import ProfileEdit from "@/components/personalProfile/ProfileEdit.vue";
|
||||||
|
import { useEntities } from "@/services/entities";
|
||||||
|
|
||||||
|
const { countries } = useEntities();
|
||||||
const user = useUserStore();
|
const user = useUserStore();
|
||||||
const editMode = ref(false);
|
const editMode = ref(false);
|
||||||
|
|
||||||
const formData = ref();
|
const formData = ref();
|
||||||
|
const saved = ref(false);
|
||||||
|
|
||||||
function startEditMode() {
|
function startEditMode() {
|
||||||
formData.value = {
|
formData.value = {
|
||||||
|
|
@ -29,16 +32,24 @@ function startEditMode() {
|
||||||
organisation_country: user.organisation_country?.id,
|
organisation_country: user.organisation_country?.id,
|
||||||
invoice_address: user.invoice_address,
|
invoice_address: user.invoice_address,
|
||||||
};
|
};
|
||||||
console.log("Start Edit", formData.value);
|
|
||||||
editMode.value = true;
|
editMode.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
const profileData = Object.assign({}, formData.value);
|
const profileData = Object.assign({}, formData.value);
|
||||||
profileData.country = { id: profileData.country };
|
profileData.country = countries.value.find(
|
||||||
profileData.organisation_country = { id: profileData.organisation_country };
|
(c) => c.id === parseInt(profileData.country)
|
||||||
await user.setUserProfile(profileData);
|
);
|
||||||
|
profileData.organisation_country = countries.value.find(
|
||||||
|
(c) => c.id === parseInt(profileData.organisation_country)
|
||||||
|
);
|
||||||
|
profileData.organisation = parseInt(profileData.organisation);
|
||||||
|
await user.updateUserProfile(profileData);
|
||||||
editMode.value = false;
|
editMode.value = false;
|
||||||
|
saved.value = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
saved.value = false;
|
||||||
|
}, 10 * 1000);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -72,6 +83,10 @@ async function save() {
|
||||||
</button>
|
</button>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="saved" class="flex items-center space-x-3 bg-green-200 px-6 py-3">
|
||||||
|
<it-icon-check class="h-10 w-10 text-green-800" />
|
||||||
|
<span>{{ $t("a.Deine Änderungen wurden gespeichert") }}.</span>
|
||||||
|
</div>
|
||||||
<template v-if="editMode">
|
<template v-if="editMode">
|
||||||
<ProfileEdit v-model="formData" />
|
<ProfileEdit v-model="formData" />
|
||||||
<div class="flex justify-end space-x-4">
|
<div class="flex justify-end space-x-4">
|
||||||
|
|
|
||||||
|
|
@ -183,9 +183,9 @@ export const useUserStore = defineStore({
|
||||||
const r = await directUpload("/api/core/avatar/", file);
|
const r = await directUpload("/api/core/avatar/", file);
|
||||||
this.$state.avatar_url = r.url;
|
this.$state.avatar_url = r.url;
|
||||||
},
|
},
|
||||||
async setUserProfile(profileData: UserProfile) {
|
async updateUserProfile(profileData: UserProfile) {
|
||||||
console.log("Save", profileData);
|
|
||||||
await itPost("/api/core/me/", profileData, { method: "PUT" });
|
await itPost("/api/core/me/", profileData, { method: "PUT" });
|
||||||
|
Object.assign(this.$state, profileData);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class CountrySerializer(serializers.ModelSerializer):
|
||||||
if country_id is not None:
|
if country_id is not None:
|
||||||
try:
|
try:
|
||||||
country = Country.objects.get(country_id=country_id)
|
country = Country.objects.get(country_id=country_id)
|
||||||
return {"id": country.country_id, "name": "Belize"}
|
return {"id": country.country_id, "name": self.get_name(country)}
|
||||||
except Country.DoesNotExist:
|
except Country.DoesNotExist:
|
||||||
raise serializers.ValidationError({"id": "Invalid country ID"})
|
raise serializers.ValidationError({"id": "Invalid country ID"})
|
||||||
return super().to_internal_value(data)
|
return super().to_internal_value(data)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue