mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-15 07:27:33 +08:00
migrate user profile page to composition API and typescript
This commit is contained in:
@@ -3,13 +3,13 @@
|
||||
<v-col cols="12">
|
||||
<v-card :class="{ 'disabled': loading || saving }">
|
||||
<template #title>
|
||||
<span>{{ $t('Basic Settings') }}</span>
|
||||
<span>{{ tt('Basic Settings') }}</span>
|
||||
<v-progress-circular indeterminate size="20" class="ml-3" v-if="loading"></v-progress-circular>
|
||||
</template>
|
||||
|
||||
<v-card-text class="d-flex">
|
||||
<v-avatar rounded="lg" variant="tonal" size="100" class="me-4 user-profile-avatar-icon"
|
||||
:class="{ 'cursor-pointer': oldProfile.avatarProvider === 'internal', 'user-profile-avatar-icon-modifiable': oldProfile.avatarProvider === 'internal' }"
|
||||
:class="{ 'cursor-pointer': avatarProvider === 'internal', 'user-profile-avatar-icon-modifiable': avatarProvider === 'internal' }"
|
||||
:color="currentUserAvatar ? 'rgba(0,0,0,0)' : 'primary'">
|
||||
<v-img :src="currentUserAvatar" v-if="currentUserAvatar">
|
||||
<template #placeholder>
|
||||
@@ -19,28 +19,28 @@
|
||||
</template>
|
||||
</v-img>
|
||||
<v-icon size="48" class="user-profile-avatar-placeholder" :icon="icons.user" v-else-if="!currentUserAvatar"/>
|
||||
<div class="avatar-edit-icon" v-if="oldProfile.avatarProvider === 'internal'">
|
||||
<div class="avatar-edit-icon" v-if="avatarProvider === 'internal'">
|
||||
<v-icon size="48" :icon="icons.pencil"/>
|
||||
</div>
|
||||
<v-menu activator="parent" width="200" location="bottom" offset="14px" v-if="oldProfile.avatarProvider === 'internal'">
|
||||
<v-menu activator="parent" width="200" location="bottom" offset="14px" v-if="avatarProvider === 'internal'">
|
||||
<v-list>
|
||||
<v-list-item :disabled="saving" :title="$t('Update Avatar')" @click="showOpenAvatarDialog"></v-list-item>
|
||||
<v-list-item :disabled="!currentUserAvatar || saving" :title="$t('Remove Avatar')" @click="removeAvatar"></v-list-item>
|
||||
<v-list-item :disabled="saving" :title="tt('Update Avatar')" @click="showOpenAvatarDialog"></v-list-item>
|
||||
<v-list-item :disabled="!currentUserAvatar || saving" :title="tt('Remove Avatar')" @click="removeAvatar"></v-list-item>
|
||||
</v-list>
|
||||
</v-menu>
|
||||
</v-avatar>
|
||||
<div class="d-flex flex-column justify-center gap-3">
|
||||
<div class="d-flex text-body-1">
|
||||
<span class="me-1">{{ $t('Username:') }}</span>
|
||||
<span class="me-1">{{ tt('Username:') }}</span>
|
||||
<v-skeleton-loader class="skeleton-no-margin" type="text" style="width: 100px" :loading="true" v-if="loading"></v-skeleton-loader>
|
||||
<span v-if="!loading">{{ oldProfile.username }}</span>
|
||||
</div>
|
||||
<div class="d-flex text-body-1 align-center" style="height: 40px;">
|
||||
<span v-if="!loading && emailVerified">{{ $t('Email address is verified') }}</span>
|
||||
<span v-if="!loading && !emailVerified">{{ $t('Email address is not verified') }}</span>
|
||||
<span v-if="!loading && emailVerified">{{ tt('Email address is verified') }}</span>
|
||||
<span v-if="!loading && !emailVerified">{{ tt('Email address is not verified') }}</span>
|
||||
<v-btn class="ml-2 px-2" size="small" variant="text" :disabled="loading || resending"
|
||||
@click="resendVerifyEmail" v-if="isUserVerifyEmailEnabled && !loading && !emailVerified">
|
||||
{{ $t('Resend Validation Email') }}
|
||||
@click="resendVerifyEmail" v-if="isUserVerifyEmailEnabled() && !loading && !emailVerified">
|
||||
{{ tt('Resend Validation Email') }}
|
||||
<v-progress-circular indeterminate size="18" class="ml-2" v-if="resending"></v-progress-circular>
|
||||
</v-btn>
|
||||
<v-skeleton-loader class="skeleton-no-margin mt-2 mb-1" type="text" style="width: 160px" :loading="true" v-if="loading"></v-skeleton-loader>
|
||||
@@ -59,8 +59,8 @@
|
||||
autocomplete="nickname"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Nickname')"
|
||||
:placeholder="$t('Your nickname')"
|
||||
:label="tt('Nickname')"
|
||||
:placeholder="tt('Your nickname')"
|
||||
v-model="newProfile.nickname"
|
||||
/>
|
||||
</v-col>
|
||||
@@ -71,8 +71,8 @@
|
||||
autocomplete="email"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('E-mail')"
|
||||
:placeholder="$t('Your email address')"
|
||||
:label="tt('E-mail')"
|
||||
:placeholder="tt('Your email address')"
|
||||
v-model="newProfile.email"
|
||||
/>
|
||||
</v-col>
|
||||
@@ -87,10 +87,10 @@
|
||||
secondary-title-field="name"
|
||||
secondary-icon-field="icon" secondary-icon-type="account" secondary-color-field="color"
|
||||
:disabled="loading || saving || !allVisibleAccounts.length"
|
||||
:label="$t('Default Account')"
|
||||
:placeholder="$t('Default Account')"
|
||||
:label="tt('Default Account')"
|
||||
:placeholder="tt('Default Account')"
|
||||
:items="allVisibleCategorizedAccounts"
|
||||
:no-item-text="$t('Unspecified')"
|
||||
:no-item-text="tt('Unspecified')"
|
||||
v-model="newProfile.defaultAccountId">
|
||||
</two-column-select>
|
||||
</v-col>
|
||||
@@ -101,8 +101,8 @@
|
||||
item-value="type"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Editable Transaction Range')"
|
||||
:placeholder="$t('Editable Transaction Range')"
|
||||
:label="tt('Editable Transaction Range')"
|
||||
:placeholder="tt('Editable Transaction Range')"
|
||||
:items="allTransactionEditScopeTypes"
|
||||
v-model="newProfile.transactionEditScope"
|
||||
/>
|
||||
@@ -120,8 +120,8 @@
|
||||
item-value="languageTag"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Language')"
|
||||
:placeholder="$t('Language')"
|
||||
:label="tt('Language')"
|
||||
:placeholder="tt('Language')"
|
||||
:items="allLanguages"
|
||||
v-model="newProfile.language"
|
||||
/>
|
||||
@@ -134,10 +134,10 @@
|
||||
auto-select-first
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Default Currency')"
|
||||
:placeholder="$t('Default Currency')"
|
||||
:label="tt('Default Currency')"
|
||||
:placeholder="tt('Default Currency')"
|
||||
:items="allCurrencies"
|
||||
:no-data-text="$t('No results')"
|
||||
:no-data-text="tt('No results')"
|
||||
v-model="newProfile.defaultCurrency"
|
||||
>
|
||||
<template #append-inner>
|
||||
@@ -152,8 +152,8 @@
|
||||
item-value="type"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('First Day of Week')"
|
||||
:placeholder="$t('First Day of Week')"
|
||||
:label="tt('First Day of Week')"
|
||||
:placeholder="tt('First Day of Week')"
|
||||
:items="allWeekDays"
|
||||
v-model="newProfile.firstDayOfWeek"
|
||||
/>
|
||||
@@ -171,8 +171,8 @@
|
||||
item-value="type"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Long Date Format')"
|
||||
:placeholder="$t('Long Date Format')"
|
||||
:label="tt('Long Date Format')"
|
||||
:placeholder="tt('Long Date Format')"
|
||||
:items="allLongDateFormats"
|
||||
v-model="newProfile.longDateFormat"
|
||||
/>
|
||||
@@ -184,8 +184,8 @@
|
||||
item-value="type"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Short Date Format')"
|
||||
:placeholder="$t('Short Date Format')"
|
||||
:label="tt('Short Date Format')"
|
||||
:placeholder="tt('Short Date Format')"
|
||||
:items="allShortDateFormats"
|
||||
v-model="newProfile.shortDateFormat"
|
||||
/>
|
||||
@@ -197,8 +197,8 @@
|
||||
item-value="type"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Long Time Format')"
|
||||
:placeholder="$t('Long Time Format')"
|
||||
:label="tt('Long Time Format')"
|
||||
:placeholder="tt('Long Time Format')"
|
||||
:items="allLongTimeFormats"
|
||||
v-model="newProfile.longTimeFormat"
|
||||
/>
|
||||
@@ -210,8 +210,8 @@
|
||||
item-value="type"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Short Time Format')"
|
||||
:placeholder="$t('Short Time Format')"
|
||||
:label="tt('Short Time Format')"
|
||||
:placeholder="tt('Short Time Format')"
|
||||
:items="allShortTimeFormats"
|
||||
v-model="newProfile.shortTimeFormat"
|
||||
/>
|
||||
@@ -229,8 +229,8 @@
|
||||
item-value="type"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Currency Display Mode')"
|
||||
:placeholder="$t('Currency Display Mode')"
|
||||
:label="tt('Currency Display Mode')"
|
||||
:placeholder="tt('Currency Display Mode')"
|
||||
:items="allCurrencyDisplayTypes"
|
||||
v-model="newProfile.currencyDisplayType"
|
||||
/>
|
||||
@@ -242,8 +242,8 @@
|
||||
item-value="type"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Digit Grouping')"
|
||||
:placeholder="$t('Digit Grouping')"
|
||||
:label="tt('Digit Grouping')"
|
||||
:placeholder="tt('Digit Grouping')"
|
||||
:items="allDigitGroupingTypes"
|
||||
v-model="newProfile.digitGrouping"
|
||||
/>
|
||||
@@ -254,9 +254,9 @@
|
||||
item-title="displayName"
|
||||
item-value="type"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving || !getNameByKeyValue(allDigitGroupingTypes, newProfile.digitGrouping, 'type', 'enabled')"
|
||||
:label="$t('Digit Grouping Symbol')"
|
||||
:placeholder="$t('Digit Grouping Symbol')"
|
||||
:disabled="loading || saving || !supportDigitGroupingSymbol"
|
||||
:label="tt('Digit Grouping Symbol')"
|
||||
:placeholder="tt('Digit Grouping Symbol')"
|
||||
:items="allDigitGroupingSymbols"
|
||||
v-model="newProfile.digitGroupingSymbol"
|
||||
/>
|
||||
@@ -268,8 +268,8 @@
|
||||
item-value="type"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Decimal Separator')"
|
||||
:placeholder="$t('Decimal Separator')"
|
||||
:label="tt('Decimal Separator')"
|
||||
:placeholder="tt('Decimal Separator')"
|
||||
:items="allDecimalSeparators"
|
||||
v-model="newProfile.decimalSeparator"
|
||||
/>
|
||||
@@ -287,8 +287,8 @@
|
||||
item-value="type"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Expense Amount Color')"
|
||||
:placeholder="$t('Expense Amount Color')"
|
||||
:label="tt('Expense Amount Color')"
|
||||
:placeholder="tt('Expense Amount Color')"
|
||||
:items="allExpenseAmountColorTypes"
|
||||
v-model="newProfile.expenseAmountColor"
|
||||
/>
|
||||
@@ -300,8 +300,8 @@
|
||||
item-value="type"
|
||||
persistent-placeholder
|
||||
:disabled="loading || saving"
|
||||
:label="$t('Income Amount Color')"
|
||||
:placeholder="$t('Income Amount Color')"
|
||||
:label="tt('Income Amount Color')"
|
||||
:placeholder="tt('Income Amount Color')"
|
||||
:items="allIncomeAmountColorTypes"
|
||||
v-model="newProfile.incomeAmountColor"
|
||||
/>
|
||||
@@ -311,12 +311,12 @@
|
||||
|
||||
<v-card-text class="d-flex flex-wrap gap-4">
|
||||
<v-btn :disabled="inputIsNotChanged || inputIsInvalid || saving" @click="save">
|
||||
{{ $t('Save Changes') }}
|
||||
{{ tt('Save Changes') }}
|
||||
<v-progress-circular indeterminate size="22" class="ml-2" v-if="saving"></v-progress-circular>
|
||||
</v-btn>
|
||||
|
||||
<v-btn color="default" variant="tonal" @click="reset">
|
||||
{{ $t('Reset') }}
|
||||
{{ tt('Reset') }}
|
||||
</v-btn>
|
||||
</v-card-text>
|
||||
</v-form>
|
||||
@@ -326,388 +326,228 @@
|
||||
|
||||
<confirm-dialog ref="confirmDialog"/>
|
||||
<snack-bar ref="snackbar" />
|
||||
<input ref="avatarInput" type="file" style="display: none" :accept="supportedImageExtensions" @change="updateAvatar($event)" />
|
||||
<input ref="avatarInput" type="file" style="display: none" :accept="SUPPORTED_IMAGE_EXTENSIONS" @change="updateAvatar($event)" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapStores } from 'pinia';
|
||||
<script setup lang="ts">
|
||||
import ConfirmDialog from '@/components/desktop/ConfirmDialog.vue';
|
||||
import SnackBar from '@/components/desktop/SnackBar.vue';
|
||||
|
||||
import { ref, computed, useTemplateRef } from 'vue';
|
||||
|
||||
import { useI18n } from '@/locales/helpers.ts';
|
||||
import { useUserProfilePageBase } from '@/views/base/users/UserProfilePageBase.ts';
|
||||
|
||||
import { useRootStore } from '@/stores/index.ts';
|
||||
import { useSettingsStore } from '@/stores/setting.ts';
|
||||
import { useUserStore } from '@/stores/user.ts';
|
||||
import { useAccountsStore } from '@/stores/account.ts';
|
||||
import { useOverviewStore } from '@/stores/overview.ts';
|
||||
|
||||
import { WeekDay } from '@/core/datetime.ts';
|
||||
import { SUPPORTED_IMAGE_EXTENSIONS } from '@/consts/file.ts';
|
||||
import { getNameByKeyValue } from '@/lib/common.ts';
|
||||
import type { UserProfileResponse } from '@/models/user.ts';
|
||||
|
||||
import { generateRandomUUID } from '@/lib/misc.ts';
|
||||
import { getCategorizedAccounts } from '@/lib/account.ts';
|
||||
import { isUserVerifyEmailEnabled } from '@/lib/server_settings.ts';
|
||||
import { setExpenseAndIncomeAmountColor } from '@/lib/ui/common.ts';
|
||||
|
||||
import {
|
||||
mdiAccount,
|
||||
mdiAccountEditOutline
|
||||
} from '@mdi/js';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
const self = this;
|
||||
const defaultFirstDayOfWeekName = self.$locale.getDefaultFirstDayOfWeek();
|
||||
const defaultFirstDayOfWeek = WeekDay.parse(defaultFirstDayOfWeekName) ? WeekDay.parse(defaultFirstDayOfWeekName).type : WeekDay.DefaultFirstDay.type;
|
||||
type ConfirmDialogType = InstanceType<typeof ConfirmDialog>;
|
||||
type SnackBarType = InstanceType<typeof SnackBar>;
|
||||
|
||||
return {
|
||||
newProfile: {
|
||||
email: '',
|
||||
nickname: '',
|
||||
defaultAccountId: 0,
|
||||
transactionEditScope: 1,
|
||||
language: '',
|
||||
defaultCurrency: self.$locale.getDefaultCurrency(),
|
||||
firstDayOfWeek: defaultFirstDayOfWeek,
|
||||
longDateFormat: 0,
|
||||
shortDateFormat: 0,
|
||||
longTimeFormat: 0,
|
||||
shortTimeFormat: 0,
|
||||
decimalSeparator: 0,
|
||||
digitGroupingSymbol: 0,
|
||||
digitGrouping: 0,
|
||||
currencyDisplayType: 0,
|
||||
expenseAmountColor: 0,
|
||||
incomeAmountColor: 0
|
||||
},
|
||||
oldProfile: {
|
||||
email: '',
|
||||
nickname: '',
|
||||
defaultAccountId: 0,
|
||||
transactionEditScope: 1,
|
||||
language: '',
|
||||
defaultCurrency: self.$locale.getDefaultCurrency(),
|
||||
firstDayOfWeek: defaultFirstDayOfWeek,
|
||||
longDateFormat: 0,
|
||||
shortDateFormat: 0,
|
||||
longTimeFormat: 0,
|
||||
shortTimeFormat: 0,
|
||||
decimalSeparator: 0,
|
||||
digitGroupingSymbol: 0,
|
||||
digitGrouping: 0,
|
||||
currencyDisplayType: 0,
|
||||
expenseAmountColor: 0,
|
||||
incomeAmountColor: 0
|
||||
},
|
||||
avatarNoCacheId: '',
|
||||
emailVerified: false,
|
||||
loading: true,
|
||||
resending: false,
|
||||
saving: false,
|
||||
icons: {
|
||||
user: mdiAccount,
|
||||
pencil: mdiAccountEditOutline,
|
||||
}
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapStores(useRootStore, useSettingsStore, useUserStore, useAccountsStore, useOverviewStore),
|
||||
allLanguages() {
|
||||
return this.$locale.getAllLanguageInfoArray(true);
|
||||
},
|
||||
allCurrencies() {
|
||||
return this.$locale.getAllCurrencies();
|
||||
},
|
||||
allAccounts() {
|
||||
return this.accountsStore.allPlainAccounts;
|
||||
},
|
||||
allVisibleAccounts() {
|
||||
return this.accountsStore.allVisiblePlainAccounts;
|
||||
},
|
||||
allVisibleCategorizedAccounts() {
|
||||
return getCategorizedAccounts(this.allVisibleAccounts);
|
||||
},
|
||||
allWeekDays() {
|
||||
return this.$locale.getAllWeekDays();
|
||||
},
|
||||
allLongDateFormats() {
|
||||
return this.$locale.getAllLongDateFormats();
|
||||
},
|
||||
allShortDateFormats() {
|
||||
return this.$locale.getAllShortDateFormats();
|
||||
},
|
||||
allLongTimeFormats() {
|
||||
return this.$locale.getAllLongTimeFormats();
|
||||
},
|
||||
allShortTimeFormats() {
|
||||
return this.$locale.getAllShortTimeFormats();
|
||||
},
|
||||
allDecimalSeparators() {
|
||||
return this.$locale.getAllDecimalSeparators();
|
||||
},
|
||||
allDigitGroupingSymbols() {
|
||||
return this.$locale.getAllDigitGroupingSymbols();
|
||||
},
|
||||
allDigitGroupingTypes() {
|
||||
return this.$locale.getAllDigitGroupingTypes();
|
||||
},
|
||||
allCurrencyDisplayTypes() {
|
||||
return this.$locale.getAllCurrencyDisplayTypes(this.settingsStore, this.userStore);
|
||||
},
|
||||
allExpenseAmountColorTypes() {
|
||||
return this.$locale.getAllExpenseAmountColors();
|
||||
},
|
||||
allIncomeAmountColorTypes() {
|
||||
return this.$locale.getAllIncomeAmountColors();
|
||||
},
|
||||
allTransactionEditScopeTypes() {
|
||||
return this.$locale.getAllTransactionEditScopeTypes();
|
||||
},
|
||||
supportedImageExtensions() {
|
||||
return SUPPORTED_IMAGE_EXTENSIONS;
|
||||
},
|
||||
currentUserAvatar() {
|
||||
return this.userStore.getUserAvatarUrl(this.oldProfile, this.avatarNoCacheId);
|
||||
},
|
||||
isUserVerifyEmailEnabled() {
|
||||
return isUserVerifyEmailEnabled();
|
||||
},
|
||||
inputIsNotChanged() {
|
||||
return !!this.inputIsNotChangedProblemMessage;
|
||||
},
|
||||
inputIsInvalid() {
|
||||
return !!this.inputInvalidProblemMessage;
|
||||
},
|
||||
inputIsNotChangedProblemMessage() {
|
||||
if (!this.newProfile.email && !this.newProfile.nickname) {
|
||||
return 'Nothing has been modified';
|
||||
} else if (this.newProfile.email === this.oldProfile.email &&
|
||||
this.newProfile.nickname === this.oldProfile.nickname &&
|
||||
this.newProfile.defaultAccountId === this.oldProfile.defaultAccountId &&
|
||||
this.newProfile.transactionEditScope === this.oldProfile.transactionEditScope &&
|
||||
this.newProfile.language === this.oldProfile.language &&
|
||||
this.newProfile.defaultCurrency === this.oldProfile.defaultCurrency &&
|
||||
this.newProfile.firstDayOfWeek === this.oldProfile.firstDayOfWeek &&
|
||||
this.newProfile.longDateFormat === this.oldProfile.longDateFormat &&
|
||||
this.newProfile.shortDateFormat === this.oldProfile.shortDateFormat &&
|
||||
this.newProfile.longTimeFormat === this.oldProfile.longTimeFormat &&
|
||||
this.newProfile.shortTimeFormat === this.oldProfile.shortTimeFormat &&
|
||||
this.newProfile.decimalSeparator === this.oldProfile.decimalSeparator &&
|
||||
this.newProfile.digitGroupingSymbol === this.oldProfile.digitGroupingSymbol &&
|
||||
this.newProfile.digitGrouping === this.oldProfile.digitGrouping &&
|
||||
this.newProfile.currencyDisplayType === this.oldProfile.currencyDisplayType &&
|
||||
this.newProfile.expenseAmountColor === this.oldProfile.expenseAmountColor &&
|
||||
this.newProfile.incomeAmountColor === this.oldProfile.incomeAmountColor) {
|
||||
return 'Nothing has been modified';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
inputInvalidProblemMessage() {
|
||||
if (!this.newProfile.email) {
|
||||
return 'Email address cannot be blank';
|
||||
} else if (!this.newProfile.nickname) {
|
||||
return 'Nickname cannot be blank';
|
||||
} else if (!this.newProfile.defaultCurrency) {
|
||||
return 'Default currency cannot be blank';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
extendInputInvalidProblemMessage() {
|
||||
return null;
|
||||
},
|
||||
langAndRegionInputInvalidProblemMessage() {
|
||||
if (!this.newProfile.defaultCurrency) {
|
||||
return 'Default currency cannot be blank';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
const { tt } = useI18n();
|
||||
|
||||
const {
|
||||
newProfile,
|
||||
oldProfile,
|
||||
emailVerified,
|
||||
loading,
|
||||
resending,
|
||||
saving,
|
||||
allLanguages,
|
||||
allCurrencies,
|
||||
allVisibleAccounts,
|
||||
allVisibleCategorizedAccounts,
|
||||
allWeekDays,
|
||||
allLongDateFormats,
|
||||
allShortDateFormats,
|
||||
allLongTimeFormats,
|
||||
allShortTimeFormats,
|
||||
allDecimalSeparators,
|
||||
allDigitGroupingSymbols,
|
||||
allDigitGroupingTypes,
|
||||
allCurrencyDisplayTypes,
|
||||
allExpenseAmountColorTypes,
|
||||
allIncomeAmountColorTypes,
|
||||
allTransactionEditScopeTypes,
|
||||
supportDigitGroupingSymbol,
|
||||
inputIsNotChangedProblemMessage,
|
||||
inputInvalidProblemMessage,
|
||||
langAndRegionInputInvalidProblemMessage,
|
||||
extendInputInvalidProblemMessage,
|
||||
inputIsNotChanged,
|
||||
inputIsInvalid,
|
||||
setCurrentUserProfile,
|
||||
reset,
|
||||
doAfterProfileUpdate
|
||||
} = useUserProfilePageBase();
|
||||
|
||||
const rootStore = useRootStore();
|
||||
const userStore = useUserStore();
|
||||
const accountsStore = useAccountsStore();
|
||||
|
||||
const icons = {
|
||||
user: mdiAccount,
|
||||
pencil: mdiAccountEditOutline,
|
||||
};
|
||||
|
||||
const confirmDialog = useTemplateRef<ConfirmDialogType>('confirmDialog');
|
||||
const snackbar = useTemplateRef<SnackBarType>('snackbar');
|
||||
const avatarInput = useTemplateRef<HTMLInputElement>('avatarInput');
|
||||
|
||||
const avatarUrl = ref<string>('');
|
||||
const avatarProvider = ref<string | undefined>('');
|
||||
const avatarNoCacheId = ref<string>('');
|
||||
|
||||
const currentUserAvatar = computed<string | null>(() => {
|
||||
return userStore.getUserAvatarUrl(avatarUrl.value, avatarNoCacheId.value);
|
||||
});
|
||||
|
||||
function init(): void {
|
||||
loading.value = true;
|
||||
|
||||
const promises = [
|
||||
accountsStore.loadAllAccounts({ force: false }),
|
||||
userStore.getCurrentUserProfile()
|
||||
];
|
||||
|
||||
Promise.all(promises).then(responses => {
|
||||
const profile = responses[1] as UserProfileResponse;
|
||||
setCurrentUserProfile(profile);
|
||||
avatarUrl.value = profile.avatar;
|
||||
avatarProvider.value = profile.avatarProvider;
|
||||
loading.value = false;
|
||||
}).catch(error => {
|
||||
oldProfile.value.nickname = '';
|
||||
oldProfile.value.email = '';
|
||||
newProfile.value.nickname = '';
|
||||
newProfile.value.email = '';
|
||||
loading.value = false;
|
||||
|
||||
if (!error.processed) {
|
||||
snackbar.value?.showError(error);
|
||||
}
|
||||
},
|
||||
created() {
|
||||
const self = this;
|
||||
});
|
||||
}
|
||||
|
||||
self.loading = true;
|
||||
function save(): void {
|
||||
const problemMessage = inputIsNotChangedProblemMessage.value || inputInvalidProblemMessage.value || extendInputInvalidProblemMessage.value || langAndRegionInputInvalidProblemMessage.value;
|
||||
|
||||
const promises = [
|
||||
self.accountsStore.loadAllAccounts({ force: false }),
|
||||
self.userStore.getCurrentUserProfile()
|
||||
];
|
||||
if (problemMessage) {
|
||||
snackbar.value?.showMessage(problemMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
Promise.all(promises).then(responses => {
|
||||
const profile = responses[1];
|
||||
self.setCurrentUserProfile(profile);
|
||||
self.emailVerified = profile.emailVerified;
|
||||
self.loading = false;
|
||||
saving.value = true;
|
||||
|
||||
rootStore.updateUserProfile({
|
||||
profile: newProfile.value
|
||||
}).then(response => {
|
||||
saving.value = false;
|
||||
|
||||
doAfterProfileUpdate(response.user);
|
||||
snackbar.value?.showMessage('Your profile has been successfully updated');
|
||||
}).catch(error => {
|
||||
saving.value = false;
|
||||
|
||||
if (!error.processed) {
|
||||
snackbar.value?.showError(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateAvatar(event: Event): void {
|
||||
if (!event || !event.target) {
|
||||
return;
|
||||
}
|
||||
|
||||
const el = event.target as HTMLInputElement;
|
||||
|
||||
if (!el.files || !el.files.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const avatarFile = el.files[0];
|
||||
|
||||
el.value = '';
|
||||
|
||||
saving.value = true;
|
||||
|
||||
userStore.updateUserAvatar({ avatarFile }).then(response => {
|
||||
saving.value = false;
|
||||
|
||||
if (response) {
|
||||
avatarUrl.value = response.avatar;
|
||||
avatarProvider.value = response.avatarProvider;
|
||||
avatarNoCacheId.value = generateRandomUUID();
|
||||
setCurrentUserProfile(response);
|
||||
}
|
||||
|
||||
snackbar.value?.showMessage('Your avatar has been successfully updated');
|
||||
}).catch(error => {
|
||||
saving.value = false;
|
||||
|
||||
if (!error.processed) {
|
||||
snackbar.value?.showError(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function removeAvatar(): void {
|
||||
confirmDialog.value?.open('Are you sure you want to remove avatar?').then(() => {
|
||||
saving.value = true;
|
||||
|
||||
userStore.removeUserAvatar().then(response => {
|
||||
saving.value = false;
|
||||
|
||||
if (response) {
|
||||
avatarUrl.value = response.avatar;
|
||||
avatarProvider.value = response.avatarProvider;
|
||||
setCurrentUserProfile(response);
|
||||
}
|
||||
|
||||
snackbar.value?.showMessage('Your profile has been successfully updated');
|
||||
}).catch(error => {
|
||||
self.oldProfile.nickname = '';
|
||||
self.oldProfile.email = '';
|
||||
self.newProfile.nickname = '';
|
||||
self.newProfile.email = '';
|
||||
self.loading = false;
|
||||
saving.value = false;
|
||||
|
||||
if (!error.processed) {
|
||||
self.$refs.snackbar.showError(error);
|
||||
snackbar.value?.showError(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
save() {
|
||||
const self = this;
|
||||
});
|
||||
}
|
||||
|
||||
const problemMessage = self.inputIsNotChangedProblemMessage || self.inputInvalidProblemMessage || self.extendInputInvalidProblemMessage || self.langAndRegionInputInvalidProblemMessage;
|
||||
function resendVerifyEmail(): void {
|
||||
resending.value = true;
|
||||
|
||||
if (problemMessage) {
|
||||
self.$refs.snackbar.showMessage(problemMessage);
|
||||
return;
|
||||
}
|
||||
rootStore.resendVerifyEmailByLoginedUser().then(() => {
|
||||
resending.value = false;
|
||||
snackbar.value?.showMessage('Validation email has been sent');
|
||||
}).catch(error => {
|
||||
resending.value = false;
|
||||
|
||||
self.saving = true;
|
||||
|
||||
self.rootStore.updateUserProfile({
|
||||
profile: self.newProfile
|
||||
}).then(response => {
|
||||
self.saving = false;
|
||||
|
||||
if (response.user) {
|
||||
if (response.user.firstDayOfWeek !== self.oldProfile.firstDayOfWeek) {
|
||||
this.overviewStore.resetTransactionOverview();
|
||||
}
|
||||
|
||||
self.setCurrentUserProfile(response.user);
|
||||
self.emailVerified = response.user.emailVerified;
|
||||
|
||||
const localeDefaultSettings = self.$locale.setLanguage(response.user.language);
|
||||
self.settingsStore.updateLocalizedDefaultSettings(localeDefaultSettings);
|
||||
|
||||
setExpenseAndIncomeAmountColor(response.user.expenseAmountColor, response.user.incomeAmountColor);
|
||||
}
|
||||
|
||||
self.$refs.snackbar.showMessage('Your profile has been successfully updated');
|
||||
}).catch(error => {
|
||||
self.saving = false;
|
||||
|
||||
if (!error.processed) {
|
||||
self.$refs.snackbar.showError(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
showOpenAvatarDialog() {
|
||||
this.$refs.avatarInput.click();
|
||||
},
|
||||
updateAvatar(event) {
|
||||
if (!event || !event.target || !event.target.files || !event.target.files.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const self = this;
|
||||
const avatarFile = event.target.files[0];
|
||||
|
||||
event.target.value = null;
|
||||
|
||||
self.saving = true;
|
||||
|
||||
self.userStore.updateUserAvatar({ avatarFile }).then(response => {
|
||||
self.saving = false;
|
||||
|
||||
if (response) {
|
||||
self.avatarNoCacheId = generateRandomUUID();
|
||||
self.setCurrentUserProfile(response);
|
||||
}
|
||||
|
||||
self.$refs.snackbar.showMessage('Your avatar has been successfully updated');
|
||||
}).catch(error => {
|
||||
self.saving = false;
|
||||
|
||||
if (!error.processed) {
|
||||
self.$refs.snackbar.showError(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
removeAvatar() {
|
||||
const self = this;
|
||||
|
||||
self.$refs.confirmDialog.open('Are you sure you want to remove avatar?').then(() => {
|
||||
self.saving = true;
|
||||
|
||||
self.userStore.removeUserAvatar().then(response => {
|
||||
self.saving = false;
|
||||
|
||||
if (response) {
|
||||
self.setCurrentUserProfile(response);
|
||||
}
|
||||
|
||||
self.$refs.snackbar.showMessage('Your profile has been successfully updated');
|
||||
}).catch(error => {
|
||||
self.saving = false;
|
||||
|
||||
if (!error.processed) {
|
||||
self.$refs.snackbar.showError(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
reset() {
|
||||
this.setCurrentUserProfile(this.oldProfile);
|
||||
},
|
||||
resendVerifyEmail() {
|
||||
const self = this;
|
||||
|
||||
self.resending = true;
|
||||
|
||||
self.rootStore.resendVerifyEmailByLoginedUser().then(() => {
|
||||
self.resending = false;
|
||||
self.$refs.snackbar.showMessage('Validation email has been sent');
|
||||
}).catch(error => {
|
||||
self.resending = false;
|
||||
|
||||
if (!error.processed) {
|
||||
self.$refs.snackbar.showError(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
getNameByKeyValue(src, value, keyField, nameField, defaultName) {
|
||||
return getNameByKeyValue(src, value, keyField, nameField, defaultName);
|
||||
},
|
||||
setCurrentUserProfile(profile) {
|
||||
this.oldProfile.username = profile.username;
|
||||
this.oldProfile.email = profile.email;
|
||||
this.oldProfile.nickname = profile.nickname;
|
||||
this.oldProfile.avatar = profile.avatar;
|
||||
this.oldProfile.avatarProvider = profile.avatarProvider;
|
||||
this.oldProfile.defaultAccountId = profile.defaultAccountId;
|
||||
this.oldProfile.transactionEditScope = profile.transactionEditScope;
|
||||
this.oldProfile.language = profile.language;
|
||||
this.oldProfile.defaultCurrency = profile.defaultCurrency;
|
||||
this.oldProfile.firstDayOfWeek = profile.firstDayOfWeek;
|
||||
this.oldProfile.longDateFormat = profile.longDateFormat;
|
||||
this.oldProfile.shortDateFormat = profile.shortDateFormat;
|
||||
this.oldProfile.longTimeFormat = profile.longTimeFormat;
|
||||
this.oldProfile.shortTimeFormat = profile.shortTimeFormat;
|
||||
this.oldProfile.decimalSeparator = profile.decimalSeparator;
|
||||
this.oldProfile.digitGroupingSymbol = profile.digitGroupingSymbol;
|
||||
this.oldProfile.digitGrouping = profile.digitGrouping;
|
||||
this.oldProfile.currencyDisplayType = profile.currencyDisplayType;
|
||||
this.oldProfile.expenseAmountColor = profile.expenseAmountColor;
|
||||
this.oldProfile.incomeAmountColor = profile.incomeAmountColor;
|
||||
|
||||
this.newProfile.email = this.oldProfile.email
|
||||
this.newProfile.nickname = this.oldProfile.nickname;
|
||||
this.newProfile.defaultAccountId = this.oldProfile.defaultAccountId;
|
||||
this.newProfile.transactionEditScope = this.oldProfile.transactionEditScope;
|
||||
this.newProfile.language = this.oldProfile.language;
|
||||
this.newProfile.defaultCurrency = this.oldProfile.defaultCurrency;
|
||||
this.newProfile.firstDayOfWeek = this.oldProfile.firstDayOfWeek;
|
||||
this.newProfile.longDateFormat = this.oldProfile.longDateFormat;
|
||||
this.newProfile.shortDateFormat = this.oldProfile.shortDateFormat;
|
||||
this.newProfile.longTimeFormat = this.oldProfile.longTimeFormat;
|
||||
this.newProfile.shortTimeFormat = this.oldProfile.shortTimeFormat;
|
||||
this.newProfile.decimalSeparator = this.oldProfile.decimalSeparator;
|
||||
this.newProfile.digitGroupingSymbol = this.oldProfile.digitGroupingSymbol;
|
||||
this.newProfile.digitGrouping = this.oldProfile.digitGrouping;
|
||||
this.newProfile.currencyDisplayType = this.oldProfile.currencyDisplayType;
|
||||
this.newProfile.expenseAmountColor = this.oldProfile.expenseAmountColor;
|
||||
this.newProfile.incomeAmountColor = this.oldProfile.incomeAmountColor;
|
||||
if (!error.processed) {
|
||||
snackbar.value?.showError(error);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function showOpenAvatarDialog(): void {
|
||||
avatarInput.value?.click();
|
||||
}
|
||||
|
||||
init();
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
Reference in New Issue
Block a user