113 lines
3.3 KiB
Vue
113 lines
3.3 KiB
Vue
<template>
|
||
<div
|
||
class="flex flex-col md:flex-row md:items-center space-y-2 md:space-y-0 md:space-x-6 min-h-[36px] leading-5"
|
||
>
|
||
<p class="font-bold w-[200px]">Имя</p>
|
||
<div class="flex-1">
|
||
<div class="max-w-[748px]">
|
||
{{ store.userSurname }} {{ store.userName }}
|
||
</div>
|
||
</div>
|
||
<VaButton
|
||
:style="buttonStyles"
|
||
class="w-fit h-fit"
|
||
preset="primary"
|
||
@click="emits('openNameModal')"
|
||
>
|
||
Редактировать
|
||
</VaButton>
|
||
</div>
|
||
<VaDivider />
|
||
<div
|
||
class="flex flex-col md:flex-row space-y-2 md:space-y-0 md:space-x-6 min-h-[36px] leading-5"
|
||
>
|
||
<p class="font-bold w-[200px]">Email</p>
|
||
<div class="flex-1">
|
||
<div class="max-w-[748px]">
|
||
{{ store.email }}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div
|
||
class="flex flex-col md:flex-row space-y-2 md:space-y-0 md:space-x-6 min-h-[36px] leading-5"
|
||
>
|
||
<p class="font-bold w-[200px]">Пароль</p>
|
||
<div class="flex-1">
|
||
<div class="max-w-[748px]">•••••••••••••</div>
|
||
</div>
|
||
<VaButton
|
||
:style="buttonStyles"
|
||
class="w-fit h-fit"
|
||
preset="primary"
|
||
@click="emits('openResetPasswordModal')"
|
||
>
|
||
Сбросить пароль
|
||
</VaButton>
|
||
</div>
|
||
<VaDivider />
|
||
<div
|
||
class="flex flex-col md:flex-row md:items-center space-y-2 md:space-y-0 md:space-x-6 min-h-[36px] leading-5"
|
||
>
|
||
<p class="font-bold w-[200px]">{{ t("preferences.weight") }}</p>
|
||
<div class="flex-1 flex items-center gap-2">
|
||
<VaInput
|
||
v-model.number="weightValue"
|
||
type="number"
|
||
class="max-w-[200px]"
|
||
:placeholder="String(store.weight ?? 75)"
|
||
/>
|
||
<span class="text-sm text-gray-500">кг</span>
|
||
<VaButton
|
||
:style="buttonStyles"
|
||
preset="primary"
|
||
size="small"
|
||
class="w-fit h-fit"
|
||
:loading="savingWeight"
|
||
@click="saveWeight"
|
||
>
|
||
Сохранить
|
||
</VaButton>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
<script lang="ts" setup>
|
||
import { ref, inject } from "vue";
|
||
import { useI18n } from "vue-i18n";
|
||
import { useToast } from "vuestic-ui/web-components";
|
||
import { AxiosInstance } from "axios";
|
||
import { useUserStore } from "../../../stores/user-store";
|
||
import { buttonStyles } from "../styles";
|
||
|
||
const { t } = useI18n();
|
||
const { init } = useToast();
|
||
const store = useUserStore();
|
||
const axiosAuth = inject("axiosAuth") as AxiosInstance;
|
||
|
||
const weightValue = ref<number | undefined>(store.weight ?? undefined);
|
||
const savingWeight = ref(false);
|
||
|
||
const emits = defineEmits(["openNameModal", "openResetPasswordModal"]);
|
||
|
||
const saveWeight = () => {
|
||
if (weightValue.value === undefined || weightValue.value === null) return;
|
||
savingWeight.value = true;
|
||
const dataProfile = JSON.parse(localStorage.getItem("profile") || "{}");
|
||
dataProfile.weight = weightValue.value;
|
||
localStorage.setItem("profile", JSON.stringify(dataProfile));
|
||
axiosAuth
|
||
.patch(`/api/v0/profiles/${store.profileID}`, {
|
||
profile: { weight: weightValue.value },
|
||
})
|
||
.then(() => {
|
||
store.setWeight(weightValue.value as number);
|
||
init({ message: "Вес сохранён", color: "success" });
|
||
})
|
||
.catch(() => {
|
||
init({ message: "Ошибка сохранения", color: "error" });
|
||
})
|
||
.finally(() => {
|
||
savingWeight.value = false;
|
||
});
|
||
};
|
||
</script>
|