Skip to content

Open source personal finance application

refactor(toast): remove old toast implementation and integrate new toast system - Deleted `toastify.css` and `ToastContent.vue` components. - Updated toast usage across various components to use the new toast API. - Removed unused toast plugin from the project.

Ilya Komichev96f740d4bdfe
diff --git a/app/app.config.ts b/app/app.config.ts
index b1e5244a..464572b5 100644
--- a/app/app.config.ts
+++ b/app/app.config.ts
@@ -29,5 +29,10 @@ export default defineAppConfig({
viewport: 'scrollerBlock',
},
},
+ toast: {
+ slots: {
+ title: 'text-5xl',
+ },
+ },
},
})
diff --git a/app/app.vue b/app/app.vue
index 71a453e3..e991323b 100644
--- a/app/app.vue
+++ b/app/app.vue
@@ -6,6 +6,10 @@ import { useGuard } from '~/components/user/useGuard'
const appConfig = useAppConfig()
const colorMode = useColorMode()
const { t } = useI18n()
+const toaster = {
+ position: 'top-left',
+ progress: false,
+}
const color = computed(() => colorMode.value === 'dark' ? (colors as any)[appConfig.ui.colors.neutral][900] : 'white')
const blackAsPrimary = computed(() => appConfig.theme.blackAsPrimary ? `:root { --ui-primary: black; } .dark { --ui-primary: #ededed; }` : ':root {}')
@@ -42,7 +46,7 @@ useGuard()
</script>
<template>
- <UApp>
+ <UApp :toaster="toaster">
<NuxtLoadingIndicator :height="2" color="var(--ui-primary)" />
<NuxtPwaManifest />
diff --git a/app/assets/css/main.css b/app/assets/css/main.css
index 2c187498..3a428533 100644
--- a/app/assets/css/main.css
+++ b/app/assets/css/main.css
@@ -1,7 +1,6 @@
@import 'tailwindcss' theme(static);
@import '@nuxt/ui';
@import './theme.css';
-@import './toastify.css';
@import './utility.css';
@custom-variant dark (&:where(.dark, .dark *));
diff --git a/app/assets/css/toastify.css b/app/assets/css/toastify.css
deleted file mode 100644
index fb93727a..00000000
--- a/app/assets/css/toastify.css
+++ /dev/null
@@ -1,23 +0,0 @@
-.Toastify__toast-container {
- @apply p-2;
-}
-
-.Toastify__toast {
- @apply cursor-default bg-[var(--item-1)] !ring-2 !ring-item-4 text-1 p-0 min-h-6 rounded-lg hover:bg-item-4;
-}
-
-.Toastify__toast-body {
- @apply p-5 py-5 text-muted;
-}
-
-.Toastify__close-button {
- @apply text-1;
-}
-
-.Toastify__progress-bar {
- @apply hidden;
-}
-
-.Toastify__toast-container--top-left {
- @apply left-1 top-1;
-}
diff --git a/app/components/categories/Form.vue b/app/components/categories/Form.vue
index b5e7dcaf..854c3f27 100644
--- a/app/components/categories/Form.vue
+++ b/app/components/categories/Form.vue
@@ -6,7 +6,6 @@ import type { CategoryForm, CategoryId } from '~/components/categories/types'
import { errorEmo, random } from '~/assets/js/emo'
import icons from '~/assets/js/icons'
import { useCategoriesStore } from '~/components/categories/useCategoriesStore'
-import UiToastContent from '~/components/ui/ToastContent.vue'
const props = defineProps<{
categoryForm: CategoryForm
@@ -15,14 +14,14 @@ const props = defineProps<{
const emit = defineEmits(['updateValue', 'afterSave'])
-const { $toast } = useNuxtApp()
const { t } = useI18n()
const categoriesStore = useCategoriesStore()
+const toast = useToast()
const editCategoryId = props.categoryId ?? generateId()
const isUpdateChildCategoriesColor = ref(true)
const isAllowChangeParent = computed(() =>
- categoriesStore.getChildsIds(props.categoryId).length === 0 && categoriesStore.categoriesForBeParent.length > 0,
+ categoriesStore.getChildsIds(props.categoryId!).length === 0 && categoriesStore.categoriesForBeParent.length > 0,
)
const modals = ref({
@@ -60,13 +59,10 @@ function onParentSelect(parentId: CategoryId | false, close: () => void) {
*/
function validate(values: CategoryForm) {
if (!values.name) {
- $toast(UiToastContent, {
- data: {
- description: t('categories.form.name.error'),
- title: random(errorEmo),
- },
- toastId: 'validate',
- type: 'error',
+ toast.add({
+ color: 'error',
+ description: t('categories.form.name.error'),
+ title: random(errorEmo),
})
return
@@ -77,25 +73,19 @@ function validate(values: CategoryForm) {
if (categoriesStore.items[id].name === values.name && categoriesStore.items[id].parentId === values.parentId) {
if (editCategoryId) {
if (editCategoryId !== id) {
- $toast(UiToastContent, {
- data: {
- description: t('categories.form.name.exist'),
- title: random(errorEmo),
- },
- toastId: 'validate',
- type: 'error',
+ toast.add({
+ color: 'error',
+ description: t('categories.form.name.exist'),
+ title: random(errorEmo),
})
return
}
}
else {
- $toast(UiToastContent, {
- data: {
- description: t('categories.form.name.exist'),
- title: random(errorEmo),
- },
- toastId: 'validate',
- type: 'error',
+ toast.add({
+ color: 'error',
+ description: t('categories.form.name.exist'),
+ title: random(errorEmo),
})
return
}
diff --git a/app/components/categories/page/id/Index.vue b/app/components/categories/page/id/Index.vue
index 3f0e998a..c83e766f 100644
--- a/app/components/categories/page/id/Index.vue
+++ b/app/components/categories/page/id/Index.vue
@@ -14,9 +14,7 @@ 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 UiToastContent from '~/components/ui/ToastContent.vue'
-const { $toast } = useNuxtApp()
const { t } = useI18n()
const categoriesStore = useCategoriesStore()
const route = useRoute()
@@ -24,6 +22,7 @@ const router = useRouter()
const trnsFormStore = useTrnsFormStore()
const trnsStore = useTrnsStore()
const filter = useFilter()
+const toast = useToast()
provide('filter', filter)
@@ -104,13 +103,10 @@ function onClickDelete(close: () => void) {
for (const id in categoriesStore.items) {
if (categoriesStore.items[id]?.parentId === categoryId.value) {
- $toast(UiToastContent, {
- data: {
- description: t('categories.form.delete.errorChilds'),
- title: random(errorEmo),
- },
- toastId: 'delete-category-with-child-error',
- type: 'error',
+ toast.add({
+ color: 'error',
+ description: t('categories.form.delete.errorChilds'),
+ title: random(errorEmo),
})
return false
@@ -132,15 +128,12 @@ async function onDeleteConfirm() {
// Give some time to complete redirect
setTimeout(async () => {
- $toast(UiToastContent, {
- data: {
- description: trnsIdsS?.length > 0
- ? t('categories.form.delete.okWithTrns', { length: trnsIdsS.length, trns: t('trns.plural', trnsIdsS.length) })
- : t('categories.form.delete.okWithoutTrns'),
- title: random(successEmo),
- },
- toastId: 'delete-category-with-child-success',
- type: 'success',
+ toast.add({
+ color: 'success',
+ description: trnsIdsS?.length > 0
+ ? t('categories.form.delete.okWithTrns', { length: trnsIdsS.length, trns: t('trns.plural', trnsIdsS.length) })
+ : t('categories.form.delete.okWithoutTrns'),
+ title: random(successEmo),
})
}, 300)
}
diff --git a/app/components/trnForm/useTrnsFormStore.ts b/app/components/trnForm/useTrnsFormStore.ts
index 824f58ac..3d4570ed 100644
--- a/app/components/trnForm/useTrnsFormStore.ts
+++ b/app/components/trnForm/useTrnsFormStore.ts
@@ -14,7 +14,6 @@ import { formatTransaction, formatTransfer } from '~/components/trnForm/utils/fo
import { validate } from '~/components/trnForm/utils/validate'
import { TrnType } from '~/components/trns/types'
import { useTrnsStore } from '~/components/trns/useTrnsStore'
-import UiToastContent from '~/components/ui/ToastContent.vue'
import { useWalletsStore } from '~/components/wallets/useWalletsStore'
type Values = {
@@ -30,11 +29,12 @@ type Values = {
})
export const useTrnsFormStore = defineStore('trnForm', () => {
- const { $toast } = useNuxtApp()
- const trnsFormStore = useTrnsFormStore()
- const walletsStore = useWalletsStore()
+ const { t } = useI18n()
const categoriesStore = useCategoriesStore()
+ const trnsFormStore = useTrnsFormStore()
const trnsStore = useTrnsStore()
+ const walletsStore = useWalletsStore()
+ const toast = useToast()
const values = reactive<TrnFormValues>({
amount: [0, 0, 0],
@@ -166,13 +166,10 @@ export const useTrnsFormStore = defineStore('trnForm', () => {
const validateStatus = validate(data)
if (validateStatus.error || !data) {
- $toast(UiToastContent, {
- data: {
- description: validateStatus.error ?? 'No data',
- title: random(errorEmo),
- },
- toastId: 'trn-form-error',
- type: 'error',
+ toast.add({
+ color: 'error',
+ description: t(validateStatus.error!) ?? 'No data',
+ title: random(errorEmo),
})
return
}
diff --git a/app/components/trnForm/utils/validate.ts b/app/components/trnForm/utils/validate.ts
index c93a28ea..18876816 100644
--- a/app/components/trnForm/utils/validate.ts
+++ b/app/components/trnForm/utils/validate.ts
@@ -1,31 +1,31 @@
export function validate(values: any) {
if (!values.amount && values.type !== 2) {
return {
- error: 'Amount can not be empty',
+ error: 'trnForm.errors.amountEmpty',
}
}
if (values.amount <= 0 && values.type !== 2) {
return {
- error: 'Amount can not be negative number',
+ error: 'trnForm.errors.amountNegative',
}
}
if (values.amount === 0 && values.type !== 2) {
return {
- error: 'Amount can not be equal Zero',
+ error: 'trnForm.errors.amountZero',
}
}
if (!values.walletId && values.type !== 2) {
return {
- error: 'Please select wallet',
+ error: 'trnForm.errors.selectWallet',
}
}
if (!values.categoryId && values.type !== 2) {
return {
- error: 'Please select category',
+ error: 'trnForm.errors.selectCategory',
}
}
@@ -33,13 +33,13 @@ export function validate(values: any) {
if (values.type === 2) {
if (Number(values.incomeAmount) === 0 || Number(values.expenseAmount) === 0) {
return {
- error: 'Transfer amounts can not be empty',
+ error: 'trnForm.errors.transferAmountEmpty',
}
}
if (values.incomeWalletId === values.expenseWalletId) {
return {
- error: 'Transfer in same wallet',
+ error: 'trnForm.errors.transferSameWallet',
}
}
}
diff --git a/app/components/trns/useTrnsStore.ts b/app/components/trns/useTrnsStore.ts
index 463e83ed..def4a8ca 100644
--- a/app/components/trns/useTrnsStore.ts
+++ b/app/components/trns/useTrnsStore.ts
@@ -92,6 +92,10 @@ export const useTrnsStore = defineStore('trns', () => {
localforage.setItem('finapp.trns', deepUnref({ ...items.value, [id]: valuesWithEditDate }))
setTrns({ ...items.value, [id]: valuesWithEditDate })
+ if (isDemo.value) {
+ return
+ }
+
saveData(`users/${userStore.uid}/trns/${id}`, valuesWithEditDate).then(() => {
isTrnSavedOnline = true
removeTrnToAddLaterLocal(id)
diff --git a/app/components/ui/ToastContent.vue b/app/components/ui/ToastContent.vue
deleted file mode 100644
index edb4e711..00000000
--- a/app/components/ui/ToastContent.vue
+++ /dev/null
@@ -1,19 +0,0 @@
-<script setup lang="ts">
-defineProps<{
- data: {
- description?: string
- title?: string
- }
-}>()
-</script>
-
-<template>
- <div class="grid gap-3">
- <div v-if="data.title" class="text-5xl">
- {{ data.title }}
- </div>
- <div v-if="data.description" class="text-sm">
- {{ data.description }}
- </div>
- </div>
-</template>
diff --git a/app/components/wallets/Form.vue b/app/components/wallets/Form.vue
index 1a2a0c00..90293085 100644
--- a/app/components/wallets/Form.vue
+++ b/app/components/wallets/Form.vue
@@ -5,7 +5,6 @@ import type { CurrencyCode } from '~/components/currencies/types'
import type { WalletId, WalletItem, WalletType } from '~/components/wallets/types'
import { errorEmo, random } from '~/assets/js/emo'
-import UiToastContent from '~/components/ui/ToastContent.vue'
import { icons, types, walletItemSchema } from '~/components/wallets/types'
import { useWalletsStore } from '~/components/wallets/useWalletsStore'
@@ -19,9 +18,9 @@ const emit = defineEmits<{
updateValue: [key: keyof WalletItem, value: WalletItem[keyof WalletItem]]
}>()
-const { $toast } = useNuxtApp()
const { t } = useI18n()
const walletsStore = useWalletsStore()
+const toast = useToast()
const editWalletId = props.walletId ?? generateId()
const walletType = types.map(value => ({
@@ -46,13 +45,10 @@ const walletPlaceholder = computed(() => ({
function validate(values: WalletItem) {
// name
if (!values.name) {
- $toast(UiToastContent, {
- autoClose: 6000,
- data: {
- description: t('wallets.form.name.error'),
- title: random(errorEmo),
- },
- type: 'error',
+ toast.add({
+ color: 'error',
+ description: t('wallets.form.name.error'),
+ title: random(errorEmo),
})
return false
@@ -60,13 +56,10 @@ function validate(values: WalletItem) {
// currency
if (!values.currency) {
- $toast(UiToastContent, {
- autoClose: 6000,
- data: {
- description: t('wallets.form.currency.error'),
- title: random(errorEmo),
- },
- type: 'error',
+ toast.add({
+ color: 'error',
+ description: t('wallets.form.currency.error'),
+ title: random(errorEmo),
})
return false
@@ -77,13 +70,10 @@ function validate(values: WalletItem) {
.find(([id, wallet]) => wallet.name === values.name && id !== editWalletId)
if (existingWallet) {
- $toast(UiToastContent, {
- autoClose: 6000,
- data: {
- description: t('wallets.form.name.exist'),
- title: random(errorEmo),
- },
- type: 'error',
+ toast.add({
+ color: 'error',
+ description: t('wallets.form.name.exist'),
+ title: random(errorEmo),
})
return false
}
diff --git a/app/components/wallets/SortModal.vue b/app/components/wallets/SortModal.vue
index 8776c00e..ee5487ea 100644
--- a/app/components/wallets/SortModal.vue
+++ b/app/components/wallets/SortModal.vue
@@ -3,14 +3,13 @@ import { useDragAndDrop } from '@formkit/drag-and-drop/vue'
import { errorEmo, random } from '~/assets/js/emo'
import { useAppNav } from '~/components/app/useAppNav'
-import UiToastContent from '~/components/ui/ToastContent.vue'
import { useWalletsStore } from '~/components/wallets/useWalletsStore'
const { closeAllModals, isModalOpen } = useAppNav()
const walletsStore = useWalletsStore()
-const { $toast } = useNuxtApp()
const { t } = useI18n()
+const toast = useToast()
const [parent, sortedWalletsIds] = useDragAndDrop([...walletsStore.sortedIds], {
dragHandle: '.sortHandle',
@@ -20,13 +19,10 @@ async function saveWalletsOrder(close: () => void) {
const result = await walletsStore.saveWalletsOrder(sortedWalletsIds.value)
if (result !== 'ok') {
- $toast(UiToastContent, {
- autoClose: 6000,
- data: {
- description: 'Error',
- title: random(errorEmo),
- },
- type: 'error',
+ toast.add({
+ color: 'error',
+ description: 'Error',
+ title: random(errorEmo),
})
return
}
diff --git a/app/components/wallets/page/id/Index.vue b/app/components/wallets/page/id/Index.vue
index 50247975..23708321 100644
--- a/app/components/wallets/page/id/Index.vue
+++ b/app/components/wallets/page/id/Index.vue
@@ -12,11 +12,9 @@ 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 UiToastContent from '~/components/ui/ToastContent.vue'
import { icons } from '~/components/wallets/types'
import { useWalletsStore } from '~/components/wallets/useWalletsStore'
-const { $toast } = useNuxtApp()
const { t } = useI18n()
const route = useRoute()
const router = useRouter()
@@ -24,6 +22,7 @@ const trnsFormStore = useTrnsFormStore()
const trnsStore = useTrnsStore()
const walletsStore = useWalletsStore()
const walletStore = useWalletsStore()
+const toast = useToast()
const filter = useFilter()
provide('filter', filter)
@@ -101,15 +100,12 @@ async function onDeleteConfirm() {
// Give some time to complete redirect
setTimeout(async () => {
- $toast(UiToastContent, {
- data: {
- description: trnsIdsS?.length > 0
- ? t('wallets.form.delete.okWithTrns', { length: trnsIdsS.length, trns: t('trns.plural', trnsIdsS.length) })
- : t('wallets.form.delete.okWithoutTrns'),
- title: random(successEmo),
- },
- toastId: 'delete-wallet',
- type: 'success',
+ toast.add({
+ color: 'success',
+ description: trnsIdsS?.length > 0
+ ? t('wallets.form.delete.okWithTrns', { length: trnsIdsS.length, trns: t('trns.plural', trnsIdsS.length) })
+ : t('wallets.form.delete.okWithoutTrns'),
+ title: random(successEmo),
})
}, 300)
}
diff --git a/app/pages/login.vue b/app/pages/login.vue
index 4453d328..5539ff97 100644
--- a/app/pages/login.vue
+++ b/app/pages/login.vue
@@ -2,9 +2,9 @@
import { GoogleAuthProvider, signInWithPopup } from 'firebase/auth'
import { useDemo } from '~/components/demo/useDemo'
-import UiToastContent from '~/components/ui/ToastContent.vue'
const auth = useFirebaseAuth()!
+const toast = useToast()
definePageMeta({
layout: 'empty',
@@ -17,7 +17,6 @@ useSeoMeta({
title: t('title'),
})
-const { $toast } = useNuxtApp()
const { generateDemoData } = useDemo()
const route = useRoute()
const router = useRouter()
@@ -33,13 +32,10 @@ function signInWithGoogle() {
isLoading.value = true
signInWithPopup(auth, new GoogleAuthProvider()).catch((e) => {
- $toast(UiToastContent, {
- autoClose: 6000,
- data: {
- description: e.message,
- title: 'Error',
- },
- type: 'error',
+ toast.add({
+ color: 'error',
+ description: e.message,
+ title: 'Error',
})
isLoading.value = false
diff --git a/app/pages/settings.vue b/app/pages/settings.vue
index ab8fcb0c..7abbdb5e 100644
--- a/app/pages/settings.vue
+++ b/app/pages/settings.vue
@@ -5,13 +5,13 @@ import { useCurrenciesStore } from '~/components/currencies/useCurrenciesStore'
import { useDemo } from '~/components/demo/useDemo'
import { useUserStore } from '~/components/user/useUserStore'
-const { $toast } = useNuxtApp()
const { locale, t } = useI18n()
const userStore = useUserStore()
const currenciesStore = useCurrenciesStore()
const { generateDemoData } = useDemo()
const { isDemo } = useDemo()
const isShowBaseCurrencyModal = ref(false)
+const toast = useToast()
useSeoMeta({
ogTitle: t('settings.title'),
@@ -24,12 +24,12 @@ const confirmRemoveUserData = ref(false)
function removeUserData() {
confirmRemoveUserData.value = false
userStore.removeUserData()
- $toast.success(t('alerts.removedUserData'))
+ toast.add({ color: 'success', description: t('alerts.removedUserData') })
}
function onGenerateDemoData() {
generateDemoData(locale.value)
- $toast.success(t('demo.updated'))
+ toast.add({ color: 'success', description: t('demo.updated') })
}
</script>
diff --git a/app/plugins/toast.ts b/app/plugins/toast.ts
deleted file mode 100644
index 8cf8acfe..00000000
--- a/app/plugins/toast.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import Vue3Toastify, { toast } from 'vue3-toastify'
-
-import BottomSheetClose from '~/components/bottomSheet/BottomSheetClose.vue'
-
-import 'vue3-toastify/dist/index.css'
-
-export default defineNuxtPlugin((nuxtApp) => {
- nuxtApp.vueApp.use(Vue3Toastify, {
- autoClose: 500000,
- closeButton: BottomSheetClose,
- hideProgressBar: true,
- icon: false,
- limit: 3,
- multiple: true,
- position: toast.POSITION.TOP_LEFT,
- theme: 'dark',
- transition: 'zoom',
- })
-
- return {
- provide: { toast },
- }
-})
diff --git a/i18n/locales/en-US.js b/i18n/locales/en-US.js
index c45f2c72..a54d3a4e 100644
--- a/i18n/locales/en-US.js
+++ b/i18n/locales/en-US.js
@@ -190,6 +190,7 @@ export default {
loginWithGithub: 'Login with Github',
loginWithGoogle: 'Login with Google',
+
money: {
all: 'Total',
also: 'Also',
@@ -348,6 +349,15 @@ export default {
placeholder: 'Write...',
title: 'Description',
},
+ errors: {
+ amountEmpty: 'Amount can not be empty',
+ amountNegative: 'Amount can not be negative number',
+ amountZero: 'Amount can not be equal Zero',
+ selectCategory: 'Please select category',
+ selectWallet: 'Please select wallet',
+ transferAmountEmpty: 'Transfer amounts can not be empty',
+ transferSameWallet: 'Transfer in same wallet',
+ },
filterAll: 'All',
filterWallet: 'Wallet',
filterWalletAndCategory: 'Wallet & Category',
diff --git a/i18n/locales/ru-RU.js b/i18n/locales/ru-RU.js
index c26cc025..9472eecd 100644
--- a/i18n/locales/ru-RU.js
+++ b/i18n/locales/ru-RU.js
@@ -350,6 +350,15 @@ export default {
placeholder: 'Напишите...',
title: 'Описание',
},
+ errors: {
+ amountEmpty: 'Сумма не может быть пустой',
+ amountNegative: 'Сумма не может быть отрицательной',
+ amountZero: 'Сумма не может быть равна нулю',
+ selectCategory: 'Выберите категорию',
+ selectWallet: 'Выберите кошелек',
+ transferAmountEmpty: 'Суммы перевода не могут быть пустыми',
+ transferSameWallet: 'Перевод в тот же кошелек',
+ },
filterAll: 'Все',
filterWallet: 'Кошелек',
filterWalletAndCategory: 'Кошелек и Категория',
diff --git a/nuxt.config.ts b/nuxt.config.ts
index 1025ca47..ea7caaa6 100644
--- a/nuxt.config.ts
+++ b/nuxt.config.ts
@@ -100,8 +100,6 @@ export default defineNuxtConfig({
pattern: ['**/*.vue', '!**/_/**'],
},
- plugins: [{ src: '~/plugins/toast' }],
-
pwa: {
client: {
installPrompt: true,
diff --git a/package.json b/package.json
index d8cff0b5..62095a41 100644
--- a/package.json
+++ b/package.json
@@ -37,8 +37,7 @@
"vaul-vue": "^0.4.1",
"vite": "^7.0.6",
"vue-deepunref": "^1.0.1",
- "vue-echarts": "^7.0.3",
- "vue3-toastify": "^0.2.8"
+ "vue-echarts": "^7.0.3"
},
"devDependencies": {
"@antfu/eslint-config": "^5.1.0",