Skip to content

Open source personal finance application

refactor(wallets): improve validation

Ilya Komichev2ecd9a9610f1
diff --git a/app/components/wallets/Form.vue b/app/components/wallets/Form.vue
index 90293085..7c5f7f9e 100644
--- a/app/components/wallets/Form.vue
+++ b/app/components/wallets/Form.vue
@@ -82,12 +82,20 @@ function validate(values: WalletItem) {
}
async function onSave() {
- if (!validate(props.walletForm))
+ const values = walletItemSchema.safeParse(props.walletForm)
+
+ if (!values.success) {
+ toast.add({
+ color: 'error',
+ description: t('categories.form.name.error'),
+ title: random(errorEmo),
+ })
return
+ }
await walletsStore.createOrUpdateWallet({
id: editWalletId,
- values: walletItemSchema.parse(props.walletForm),
+ values: values.data,
})
emit('afterSave')
}
@@ -130,10 +138,9 @@ async function onSave() {
</template>
<template #value>
- <Icon
- :name="icons[props.walletForm.type ?? 'cash']"
- :style="{ color: props.walletForm.color }"
- class="size-6"
+ <WalletsIcon
+ :color="props.walletForm.color"
+ :name="props.walletForm.name"
/>
</template>
</UiButtonWithRight>
@@ -171,7 +178,7 @@ async function onSave() {
<FormInput
:placeholder="t('wallets.form.credit.limit')"
:value="props.walletForm.creditLimit ?? ''"
- @updateValue="(value: string) => emit('updateValue', 'creditLimit', value)"
+ @updateValue="(value: string) => emit('updateValue', 'creditLimit', +value)"
/>
</FormElement>
diff --git a/app/components/wallets/Item.vue b/app/components/wallets/Item.vue
index ce0605d7..9383d81c 100644
--- a/app/components/wallets/Item.vue
+++ b/app/components/wallets/Item.vue
@@ -5,7 +5,6 @@ import type { WalletId, WalletItemComputed } from '~/components/wallets/types'
import { useCurrenciesStore } from '~/components/currencies/useCurrenciesStore'
import { getStyles } from '~/components/ui/getStyles'
-import { icons } from '~/components/wallets/types'
const props = defineProps<{
activeItemId?: WalletId | null
@@ -74,17 +73,16 @@ if (!props.isSort) {
>
<!-- Icon -->
<template v-if="props.isShowIcon" #leftIcon>
- <Icon
- :name="icons[wallet.type]"
- :style="{ color: wallet.color }"
- size="20"
+ <WalletsIcon
+ :name="wallet.name"
+ :color="wallet.color"
/>
</template>
<!-- Main -->
<template v-if="!props.alt">
<div class="grid grow gap-1">
- <div class="text-sm leading-none text-muted">
+ <div class="text-muted text-sm leading-none font-medium tracking-wide text-nowrap">
{{ wallet.name }}
</div>
@@ -157,7 +155,7 @@ if (!props.isSort) {
<!-- Alternative -->
<template v-if="props.alt">
<div class="grid grow gap-0.5">
- <div class="whitespace-nowrap text-xs leading-none text-2">
+ <div class="text-2 text-xs leading-none whitespace-nowrap">
{{ wallet.name }}
</div>
diff --git a/app/components/wallets/page/id/Index.vue b/app/components/wallets/page/id/Index.vue
index f80f211f..94a8c043 100644
--- a/app/components/wallets/page/id/Index.vue
+++ b/app/components/wallets/page/id/Index.vue
@@ -12,7 +12,6 @@ import { useStatConfig } from '~/components/stat/useStatConfig'
import { getTypesMapping } from '~/components/stat/utils'
import { useTrnsFormStore } from '~/components/trnForm/useTrnsFormStore'
import { useTrnsStore } from '~/components/trns/useTrnsStore'
-import { icons } from '~/components/wallets/types'
import { useWalletsStore } from '~/components/wallets/useWalletsStore'
const { t } = useI18n()
@@ -73,10 +72,9 @@ function onClickEdit() {
router.push(`/wallets/${walletId.value}/edit`)
}
-// TODO: translate
const deleteDescText = computed(() => {
if (trnsIds.value.length > 0)
- return `This action will delete ${trnsIds.value.length} trns in this wallet`
+ return t('wallets.form.delete.alertWithTrns', { trns: t('trns.plural', trnsIds.value.length) })
return undefined
})
@@ -114,18 +112,15 @@ async function onDeleteConfirm() {
<template>
<UiPage v-if="wallet">
<StatHeader
- :config="{
- isShowCategories: true,
- }"
- :filter="{ isShowCategories: true,
- }"
+ :config="{ isShowCategories: true }"
+ :filter="{ isShowCategories: true }"
>
<template #title>
<UiHeaderTitle>
- <Icon
- :name="icons[wallet.type]"
- :style="{ color: wallet.color }"
- class="mt-[-2px] size-5"
+ <WalletsIcon
+ :color="wallet.color"
+ :name="wallet.name"
+ class="mt-[-2px] mr-1"
/>
{{ wallet.name }}
</UiHeaderTitle>
@@ -192,7 +187,10 @@ async function onDeleteConfirm() {
/>
</div>
- <UiTextSm2 v-if="wallet.desc" class="pt-2">
+ <UiTextSm2
+ v-if="wallet.desc"
+ class="pt-2 whitespace-pre"
+ >
{{ wallet.desc }}
</UiTextSm2>
</div>