Skip to content

Open source personal finance application

feat(wallets): add wallet page

ilkome0f60aad0614d
diff --git a/components/wallets/page/List.vue b/components/wallets/page/List.vue
index 34649852..f45516fe 100644
--- a/components/wallets/page/List.vue
+++ b/components/wallets/page/List.vue
@@ -41,7 +41,7 @@ export default defineComponent({
//- Add
.cursor-pointer.group.w-10.h-10.flex-center.rounded-full.bg-gray-50.dark_bg-dark5.hocus-text-white.hocus_bg-blue2(
- @click="$store.dispatch('ui/setActiveTab', 'createWallet')"
+ @click="$router.push('/wallets/new')"
)
svg.group-hover_text-white.w-6.h-6(xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12")
path(fill="currentColor" d="M6 1.5a.5.5 0 0 0-1 0V5H1.5a.5.5 0 0 0 0 1H5v3.5a.5.5 0 0 0 1 0V6h3.5a.5.5 0 0 0 0-1H6V1.5Z")
@@ -91,7 +91,7 @@ export default defineComponent({
//- Create
.cursor-pointer.grow.py-3.px-5.flex-center.rounded-full.text-sm.bg-skin-item-main-bg.hocus_bg-skin-item-main-hover(
class="basis-1/2 max-w-[280px]"
- @click="$store.dispatch('ui/setActiveTab', 'createWallet')"
+ @click="$router.push('/wallets/new')"
) {{ $t('wallets.new') }}
//- Sort
@@ -130,23 +130,4 @@ export default defineComponent({
//- v-if="activeTab === 'walletsSort'"
//- @closeModal="close"
//- )
-
- //- Create
- Portal(
- v-if="activeTab === 'createWallet'"
- to="modal"
- )
- BaseBottomSheet(
- :maxHeight="height"
- insideClass="bg-skin-layout-main"
- @closed="$store.dispatch('ui/setActiveTab', null)"
- )
- template(#handler="{ close }")
- BaseBottomSheetHandler
- BaseBottomSheetClose(@onClick="close")
-
- template(#default="{ close }")
- WalletsFormWalletForm(
- @callback="close"
- )
</template>
diff --git a/components/wallets/page/New.vue b/components/wallets/page/New.vue
new file mode 100644
index 00000000..72526373
--- /dev/null
+++ b/components/wallets/page/New.vue
@@ -0,0 +1,111 @@
+<script setup lang="ts">
+import { popularColors } from '~/assets/js/colorsPopular'
+import { random } from '~/assets/js/emo'
+import generateId from '~/utils/id'
+
+const { $store, $notify, nuxt2Context: { i18n } } = useNuxtApp()
+const router = useRouter()
+
+const walletId = computed(() => generateId())
+
+const walletForm = ref({
+ color: random(popularColors),
+ countTotal: true,
+ currency: 'USD',
+ isCredit: false,
+ name: null,
+ order: 1,
+})
+
+function updateValue(id, value) {
+ walletForm.value[id] = value
+}
+
+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 (!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: i18n.t('wallets.form.name.exist'),
+ })
+ return false
+ }
+ }
+ }
+
+ const id = walletId.value
+
+ 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/')
+}
+</script>
+
+<script lang="ts">
+export default defineComponent({
+ head() {
+ return {
+ title: `${this.$t('base.edit')}: ${this.wallet?.name}`,
+ }
+ },
+})
+</script>
+
+<template lang="pug">
+.overflow.overflow-x-auto.h-full.max-w-3xl(
+ class="pb-[44px] md_pb-[52px] lg_pb-0"
+)
+ .mb-3.py-5.px-3.font-nunito
+ .pb-1.text-xs.font-medium.text-skin-item-base-down
+ | {{ $t("wallets.createNewTitle") }}
+
+ .flex.items-center.gap-3
+ .text-skin-item-base-up.text-2xl.font-semibold
+ | {{ walletForm.name ? walletForm.name : $t("wallets.form.name.label") }}
+ .p-1.flex-center.rounded.text-skin-icon-base.text-2xs(:style="{ background: walletForm.color }")
+ | {{ walletForm.currency }}
+
+ WalletsForm(
+ :walletForm="walletForm"
+ @onSave="onSave"
+ @updateValue="updateValue"
+ )
+</template>
diff --git a/pages/wallets/new.vue b/pages/wallets/new.vue
new file mode 100644
index 00000000..0eb43e64
--- /dev/null
+++ b/pages/wallets/new.vue
@@ -0,0 +1,3 @@
+<template lang="pug">
+WalletsPageNew
+</template>