Open source personal finance application
feat(Wallet): remove wallet
ilkome3347032c44a2
diff --git a/components/wallets/form/WalletForm.vue b/components/wallets/form/WalletForm.vueindex 74c04113..0cf7bda1 100644--- a/components/wallets/form/WalletForm.vue+++ b/components/wallets/form/WalletForm.vue@@ -8,12 +8,12 @@ export default {showColors: false,showCurrencies: false,wallet: {- color: this.$store.state.ui.defaultBgColor,+ color: null,countTotal: true,currency: 'RUB',isCredit: false,name: null,- order: Object.keys(this.$store.state.wallets.items).length || 1,+ order: 1,},}},diff --git a/components/wallets/page/id/Edit.vue b/components/wallets/page/id/Edit.vueindex 7a7d2b8c..fd3fdb46 100644--- a/components/wallets/page/id/Edit.vue+++ b/components/wallets/page/id/Edit.vue@@ -1,168 +1,159 @@-<script lang="ts">-import generateId from '~/utils/id'+<script setup lang="ts">import { allColors, popularColors } from '~/assets/js/colorsPopular'-import { random } from '~/assets/js/emo'import { currencies } from '~/components/currencies/currencies'+import { getTrnsIds } from '~/components/trns/functions/getTrns'+import { random, successEmo } from '~/assets/js/emo'+import { removeData } from '~/services/firebase/api'-export default defineComponent({- setup() {- const { $store } = useNuxtApp()- const activeTab = ref('data')-- const wallet = ref({- color: $store.state.ui.defaultBgColor,- countTotal: true,- currency: 'RUB',- isCredit: false,- name: null,- order: 1,- })+const { $store, $notify, nuxt2Context: { i18n } } = useNuxtApp()- function findWalletWithThisColor(color) {- const walletsItems = $store.state.wallets.items- if (!walletsItems) return false- const walletIdWithThisColor = Object.keys(walletsItems)?.find(id => walletsItems[id]?.color === color)- if (!walletIdWithThisColor) return false+const route = useRoute()+const router = useRouter()- return true- }+const activeTab = ref('data')- function onSelectColor(color) {- if (color)- wallet.value.color = color- }-- return {- currencies,- wallet,- activeTab,- popularColors,- allColors,- onSelectColor,- findWalletWithThisColor,- }- },+const walletId = computed(() => route.params.id)+const wallet = computed(() => $store.state.wallets.items[walletId.value])- data() {- return {- showColors: false,- showCurrencies: false,- }- },+const walletForm = ref({+ color: wallet.value?.color || random(popularColors),+ countTotal: wallet.value?.countTotal || true,+ currency: wallet.value?.currency || 'RUB',+ isCredit: wallet.value?.isCredit || false,+ name: wallet.value?.name || null,+ order: wallet.value?.order || 1,+})- head() {- return {- title: `${this.$t('base.edit')}: ${this.wallet.name}`,- }- },+function findWalletWithThisColor(color) {+ const walletsItems = $store.state.wallets.items+ if (!walletsItems) return false+ const walletIdWithThisColor = Object.keys(walletsItems)?.find(id => walletsItems[id]?.color === color)+ if (!walletIdWithThisColor) return false- computed: {- walletId() {- return this.$route.params.id- },- },+ return true+}- watch: {- walletId: {- handler(walletId) {- if (walletId) {- this.wallet = {- ...this.wallet,- ...this.$store.state.wallets.items[this.walletId],- }- }- },- immediate: true,- },- },+function onSelectColor(color) {+ walletForm.value.color = color+}- created() {- this.colors = allColors+function onCurrencySelect(currency) {+ walletForm.value.currency = currency+}- if (!this.walletId)- this.wallet.color = random(popularColors)- },+const trnsItems = computed(() => $store.state.trns.items)+const trnsIds = computed(() =>+ getTrnsIds({+ walletsIds: [walletId.value],+ trnsItems: trnsItems.value,+ }))- methods: {- handleColorSelect(color) {- this.wallet.color = color- this.showColors = false- },- handleCurrencySelect(currency) {- this.wallet.currency = currency- this.showCurrencies = false- },-- handleSubmit() {- if (this.validateForm()) {- const id = this.walletId || generateId()-- const walletsValues = {- color: this.wallet.color,- countTotal: this.wallet.countTotal,- currency: this.wallet.currency,- isCredit: this.wallet.isCredit,- name: this.wallet.name,- order: this.wallet.order,- }+const isShowDeleteConfirm = ref(false)- this.$store.dispatch('wallets/addWallet', { id, values: walletsValues })- this.$router.replace(`/wallets/${id}`)- }- },+// TODO: translate+const deleteDescText = computed(() => {+ if (trnsIds.value.length > 0)+ return `It's also will delete ${trnsIds.value.length} trns in this wallet`+ return null+})- validateForm() {- const wallets = this.$store.state.wallets.items- // name- if (!this.wallet.name) {- this.$notify({- title: '😮',- text: this.$t('wallets.form.name.error'),+// TODO: translate+async function onDeleteConfirm() {+ // Disable reactive to have data when user have already redirected to wallets page+ const uid = JSON.parse(JSON.stringify($store.state.user.user.uid))+ const trnsIdsS = JSON.parse(JSON.stringify(trnsIds.value))+ const walletIdS = JSON.parse(JSON.stringify(walletId.value))++ router.push('/wallets')++ // Give some time to complete redirect+ setTimeout(async() => {+ await this.$store.dispatch('trns/deleteTrnsByIds', trnsIdsS)+ removeData(`users/${uid}/accounts/${walletIdS}`)+ .then(() => {+ $notify({+ type: 'success',+ text: trnsIdsS?.length > 0 ? `Success delete wallet with ${trnsIdsS.length} transactions!` : 'Success delete wallet!',+ title: random(successEmo),})- return false- }+ })+ }, 100)+}++function onSave() {+ const wallets = $store.state.wallets.items++ // name+ if (!walletForm.value.name) {+ $notify({+ title: '😮',+ text: i18n.t('wallets.form.name.error'),+ })+ return false+ }- // currency- if (!this.wallet.currency) {- this.$notify({+ // currency+ if (!walletForm.value.currency) {+ $notify({+ title: '😮',+ text: i18n.t('wallets.form.currency.error'),+ })+ return false+ }++ for (const id in wallets) {+ if (wallets[id].name === walletForm.value.name) {+ if (walletId.value) {+ if (walletId.value !== id) {+ $notify({+ title: '😮',+ text: i18n.t('wallets.form.name.exist'),+ })+ return false+ }+ }+ else {+ $notify({title: '😮',- text: this.$t('wallets.form.currencies.error'),+ text: i18n.t('wallets.form.name.exist'),})return false}+ }+ }- for (const walletId in wallets) {- if (wallets[walletId].name === this.wallet.name) {- if (this.walletId) {- if (this.walletId !== walletId) {- this.$notify({- title: '😮',- text: this.$t('wallets.form.name.exist'),- })- return false- }- }- else {- this.$notify({- title: '😮',- text: this.$t('wallets.form.name.exist'),- })- return false- }- }- }+ const id = walletId.value- return true- },+ const walletsValues = {+ color: walletForm.value.color,+ countTotal: walletForm.value.countTotal,+ currency: walletForm.value.currency,+ isCredit: walletForm.value.isCredit,+ name: walletForm.value.name,+ order: walletForm.value.order,+ }++ $store.dispatch('wallets/addWallet', { id, values: walletsValues })+ router.push(`/wallets/${walletId.value}`)+}+</script>++<script lang="ts">+export default defineComponent({+ head() {+ return {+ title: `${this.$t('base.edit')}: ${this.wallet?.name}`,+ }},})</script><template lang="pug">.h-full.overflow.overflow-x-auto.max-w-3xl.h-full(+ v-if="wallet"class="pb-[44px] md_pb-[52px] lg_pb-0")- template(v-if="wallet")+ .flex.items-startrouter-link(v-slot='{ href, navigate }':to='`/wallets/${walletId}`'@@ -175,142 +166,151 @@ export default defineComponent({.pb-1.text-xs.font-medium(class="dark_text-white/50") {{ $t('wallets.editTitle') }}.flex.items-center.gap-3- .text-neutral-800.dark_text-white.text-2xl.font-semibold {{ wallet.name }}+ .text-neutral-800.dark_text-white.text-2xl.font-semibold {{ wallet.name ? wallet.name : $t('wallets.title') }}.p-1.px-1.rounded.flex-center.text-2xs.text-neutral-50(:style="{ background: wallet.color }") {{ wallet.currency }}- //- Menu- //------------------------------------ .px-3.pb-4- .overflow-hidden.rounded-md.scrollbar.mb-4.bg-gray-50.dark_bg-dark4.dark_shadow- .overflow-hidden.overflow-x-auto.flex.items-center.text-sm.text-center.max-w-md- .cursor-pointer.px-6.py-3.grow.hocus_bg-gray-200.dark_hocus_bg-neutral-800(- :class="{ '_active cursor-default text-blue3 dark_text-blue1 bg-gray-100 dark_bg-232323': activeTab === 'data' }"- @click="activeTab = 'data'"- ) {{ $t('categories.form.data.label') }}-- .cursor-pointer.px-6.py-3.grow.hocus_bg-gray-200.dark_hocus_bg-neutral-800(- :class="{ '_active cursor-default text-blue3 dark_text-blue1 bg-gray-100 dark_bg-232323': activeTab === 'currencies' }"- @click="activeTab = 'currencies'"- ) {{ $t('wallets.form.currencies.label') }}-- .cursor-pointer.px-6.py-3.grow.hocus_bg-gray-200.dark_hocus_bg-neutral-800(- :class="{ '_active cursor-default text-blue3 dark_text-blue1 bg-gray-100 dark_bg-232323': activeTab === 'colors' }"- @click="activeTab = 'colors'"- ) {{ $t('categories.form.colors.label') }}-- //- Content+ .mdi.mdi-delete-empty-outline.cursor-pointer.rounded-full.mt-3.mr-2.w-16.h-16.flex-center.text-2xl.p-4.hocus_text-red-500.hocus_bg-gray-100.dark_hocus_bg-neutral-800(+ @click="isShowDeleteConfirm = true"+ )++ //- Menu+ //-----------------------------------+ .px-3.pb-4+ .overflow-hidden.rounded-md.scrollbar.mb-4.bg-gray-50.dark_bg-dark4.dark_shadow+ .overflow-hidden.overflow-x-auto.flex.items-center.text-sm.text-center.max-w-md+ .cursor-pointer.px-6.py-3.grow.hocus_bg-gray-200.dark_hocus_bg-neutral-800(+ :class="{ '_active cursor-default text-blue3 dark_text-blue1 bg-gray-100 dark_bg-232323': activeTab === 'data' }"+ @click="activeTab = 'data'"+ ) {{ $t('categories.form.data.label') }}++ .cursor-pointer.px-6.py-3.grow.hocus_bg-gray-200.dark_hocus_bg-neutral-800(+ :class="{ '_active cursor-default text-blue3 dark_text-blue1 bg-gray-100 dark_bg-232323': activeTab === 'currencies' }"+ @click="activeTab = 'currencies'"+ ) {{ $t('wallets.form.currencies.label') }}++ .cursor-pointer.px-6.py-3.grow.hocus_bg-gray-200.dark_hocus_bg-neutral-800(+ :class="{ '_active cursor-default text-blue3 dark_text-blue1 bg-gray-100 dark_bg-232323': activeTab === 'colors' }"+ @click="activeTab = 'colors'"+ ) {{ $t('categories.form.colors.label') }}++ //- Content+ //-----------------------------------+ .px-3.max-w-md+ //- Data//------------------------------------ .px-3.max-w-md-- //- Data- //------------------------------------ template(v-if="activeTab === 'data'")- .mb-4- .inputText- .inputText__label {{ $t('wallets.form.name.label') }}- input(- :placeholder="$t('wallets.form.name.placeholder')"- type="text"- v-model="wallet.name"- ).inputText__value-- SharedContextMenuItem(- :checkboxValue="wallet.countTotal"- :title="$t('wallets.form.total.placeholder')"- showCheckbox- @onClick="wallet.countTotal = !wallet.countTotal"+ template(v-if="activeTab === 'data'")+ .mb-4+ .pb-2.text-skin-item-base-down.text-sm.leading-none {{ $t('wallets.form.name.label') }}+ input.w-full.m-0.py-3.px-4.rounded-lg.text-base.font-normal.text-skin-item-base.bg-skin-item-main-bg.border.border-solid.border-skin-item-main-hover.placeholder_text-skin-item-base-down.transition.ease-in-out.focus_text-skin-item-base-up.focus_bg-skin-item-main-hover.focus_border-blue3.focus_outline-none(+ :placeholder="$t('wallets.form.name.placeholder')"+ type="text"+ v-model="walletForm.name")- SharedContextMenuItem(- :checkboxValue="wallet.isCredit"- :title="$t('isCredit')"- showCheckbox- @onClick="wallet.isCredit = !wallet.isCredit"- )+ SharedContextMenuItem(+ :checkboxValue="walletForm.countTotal"+ :title="$t('wallets.form.total.placeholder')"+ showCheckbox+ @onClick="walletForm.countTotal = !walletForm.countTotal"+ )- //- Currencies- //------------------------------------ template(v-if="activeTab === 'currencies'")- div- .border-b.border-gray-50.dark_border-neutral-800.p-3.hocus_bg-gray-200.dark_hocus_bg-neutral-800(- v-for="(item, currency) in $store.state.currencies.rates"- :key="item"- :class="{ '_active cursor-default text-blue3 dark_text-blue1': wallet.currency === currency }"- @click="handleCurrencySelect(currency)"- )- .flex.items-center- .w-14 {{ currency }}- .text-sm(- v-if="currencies.find(c => c.code === currency)"- ) {{ currencies.find(c => c.code === currency).name }}-- //- Colors- //---------------------------------- template(v-if="activeTab === 'colors'")- .form- .subTitle {{ $t('popularColors') }}- .colors- .iconItem(- v-for="(color, idx) in popularColors"- :key="idx"- :class="{ _active: color === wallet.color }"- :style="{ background: color === wallet.color ? color : 'transparent' }"- @click="onSelectColor(color)"- )- template(v-if="color")- template(v-if="findWalletWithThisColor(color)")- Icon(- icon="mdi mdi-circle-small"- :color="color === wallet.color ? null : color"- big- )- template(v-else-if="color === wallet.color")- Icon(- icon="mdi mdi-circle-small"- background="transparent"- big- )- template(v-else)- .colorPreview(:style="{ background: color }")-- .subTitle {{ $t('palette') }}- .colors- .iconItem(- v-for="(color, idx) in allColors"- :key="idx"- :class="{ _active: color === wallet.color, _empty: !color }"- :style="{ background: color === wallet.color ? color : 'transparent' }"- @click="onSelectColor(color)"- )-- template(v-if="color")- template(v-if="findWalletWithThisColor(color)")- Icon(- icon="mdi mdi-circle-small"- :color="color === wallet.color ? null : color"- big- )- template(v-else-if="color === wallet.color")- Icon(- icon="mdi mdi-circle-small"- background="transparent"- big- )- template(v-else)- .colorPreview(:style="{ background: color }")-- .subTitle {{ $t('categories.form.colors.custom') }}- .customColor- input.customColor__value(v-model="wallet.color" type="color")-- .pt-4.pb-6- SharedButton(- :class="['_text-center _blue2 _ml-big', { _inline: $store.state.ui.pc }]"- :title="$t('wallets.form.save')"- @onClick="handleSubmit()"+ SharedContextMenuItem(+ :checkboxValue="walletForm.isCredit"+ :title="$t('isCredit')"+ showCheckbox+ @onClick="walletForm.isCredit = !walletForm.isCredit"+ )++ //- Currencies+ //-----------------------------------+ template(v-if="activeTab === 'currencies'")+ div+ .border-b.border-gray-50.dark_border-neutral-800.p-3.hocus_bg-gray-200.dark_hocus_bg-neutral-800(+ v-for="(item, currency) in $store.state.currencies.rates"+ :key="item"+ :class="{ '_active cursor-default text-blue3 dark_text-blue1': walletForm.currency === currency }"+ @click="onCurrencySelect(currency)")+ .flex.items-center+ .w-14 {{ currency }}+ .text-sm(+ v-if="currencies.find(c => c.code === currency)"+ ) {{ currencies.find(c => c.code === currency).name }}++ //- Colors+ //---------------------------------+ template(v-if="activeTab === 'colors'")+ .form+ .subTitle {{ $t('popularColors') }}+ .colors+ .iconItem(+ v-for="(color, idx) in popularColors"+ :key="idx"+ :class="{ _active: color === walletForm.color }"+ :style="{ background: color === walletForm.color ? color : 'transparent' }"+ @click="onSelectColor(color)"+ )+ template(v-if="color")+ template(v-if="findWalletWithThisColor(color)")+ Icon(+ icon="mdi mdi-circle-small"+ :color="color === walletForm.color ? null : color"+ big+ )+ template(v-else-if="color === walletForm.color")+ Icon(+ icon="mdi mdi-circle-small"+ background="transparent"+ big+ )+ template(v-else-if="color")+ .colorPreview(:style="{ background: color }")++ .subTitle {{ $t('palette') }}+ .colors+ .iconItem(+ v-for="(color, idx) in allColors"+ :key="idx"+ :class="{ _active: color === walletForm.color, _empty: !color }"+ :style="{ background: color === walletForm.color ? color : 'transparent' }"+ @click="onSelectColor(color)"+ )++ template(v-if="color")+ template(v-if="findWalletWithThisColor(color)")+ Icon(+ icon="mdi mdi-circle-small"+ :color="color === walletForm.color ? null : color"+ big+ )+ template(v-else-if="color === walletForm.color")+ Icon(+ icon="mdi mdi-circle-small"+ background="transparent"+ big+ )+ template(v-else-if="color")+ .colorPreview(:style="{ background: color }")++ .subTitle {{ $t('categories.form.colors.custom') }}+ .customColor+ input.customColor__value(v-model="walletForm.color" type="color")++ .pt-4.pb-6+ SharedButton(+ :class="['_text-center _blue2 _ml-big', { _inline: $store.state.ui.pc }]"+ :title="$t('wallets.form.save')"+ @onClick="onSave"+ )++ ModalBottomConfirm(+ :show="isShowDeleteConfirm"+ :description="deleteDescText"+ @onClose="isShowDeleteConfirm = false"+ @onConfirm="onDeleteConfirm"+ )</template><style lang="stylus" scoped>@@ -468,10 +468,13 @@ export default defineComponent({<i18n lang="json5">{"en": {- "isCredit": "Credit account"+ "isCredit": "Credit account",+ "askDelete": "Delete wallet?",},+"ru": {- "isCredit": "Кредитный счёт"+ "isCredit": "Кредитный счёт",+ "askDelete": "Удалить кошелек?",}}</i18n>diff --git a/components/wallets/page/id/Index.vue b/components/wallets/page/id/Index.vueindex 607296a8..026b6055 100644--- a/components/wallets/page/id/Index.vue+++ b/components/wallets/page/id/Index.vue@@ -14,10 +14,10 @@ const wallet = computed(() => $store.state.wallets.items[walletId.value])if (!wallet.value)router.replace('/wallets')-const trnsItems = computed(() => $store.state.trns.items)const total = computed(() => $store.getters['wallets/walletsTotal'][walletId.value].base)-const filter = reactive({ trnType: null })++const trnsItems = computed(() => $store.state.trns.items)const trnsIds = computed(() =>getTrnsIds({walletsIds: [walletId.value],@@ -25,7 +25,7 @@ const trnsIds = computed(() =>trnsItems: trnsItems.value,}))-const filteredTrnsIds = computed(() => $store.getters['trns/selectedTrnsIdsWithDate'].filter(trnId => $store.state.trns.items[trnId].walletId === walletId.value))+const periodTrnsIds = computed(() => $store.getters['trns/selectedTrnsIdsWithDate'].filter(trnId => $store.state.trns.items[trnId].walletId === walletId.value))const showModalConfirm = ref(false)const deleteInfo = computed(() => {@@ -44,10 +44,6 @@ function handleEditClick() {router.push(`/wallets/${walletId.value}/edit`)}-function handleDeleteClick() {- showModalConfirm.value = true-}-function handleDeleteConfirm() {const uid = $store.state.user.user.uidconst id = JSON.parse(JSON.stringify(walletId.value))@@ -125,7 +121,7 @@ export default defineComponent({SharedDate.text-xs.font-medium(class="-mb-1 dark_text-white/50")div(class="-mb-3")StatGroupSum2(- :trnsIds="filteredTrnsIds"+ :trnsIds="periodTrnsIds")//- History