Skip to content

Open source personal finance application

fix (Categories): back to category after edit

ilkomeb9cb7d172a2e
diff --git a/components/categories/pages/id/Edit.vue b/components/categories/pages/id/Edit.vue
index ecaa6600..e70fbd01 100644
--- a/components/categories/pages/id/Edit.vue
+++ b/components/categories/pages/id/Edit.vue
@@ -117,66 +117,68 @@ export default defineComponent({
},
handleSubmit() {
- if (this.validateForm()) {
- const uid = this.$store.state.user.user.uid
- const id = this.categoryId || generateId()
- const categories = this.$store.state.categories.items
-
- const categoriesValues = {
- order: this.category.order || null,
- color: this.category.color,
- icon: this.category.icon,
- name: this.category.name,
- childIds: this.category.childIds || [],
- parentId: this.category.parentId,
- showInLastUsed: this.category.showInLastUsed,
- showInQuickSelector: this.category.showInQuickSelector,
- showStat: true,
- }
+ if (!this.validateForm())
+ return
- // ad or remove from parent
- if (this.originalParentId !== this.category.parentId) {
- // remove from old parent
- if (this.originalParentId !== 0) {
- const originalParent = categories[this.originalParentId]
- if (originalParent) {
- saveData(`users/${uid}/categories/${this.originalParentId}`, {
- ...originalParent,
- childIds: originalParent.childIds.filter(cId => cId !== id),
- })
- }
- }
+ const uid = this.$store.state.user.user.uid
+ const id = this.categoryId || generateId()
+ const categories = this.$store.state.categories.items
+
+ const categoriesValues = {
+ order: this.category.order || null,
+ color: this.category.color,
+ icon: this.category.icon,
+ name: this.category.name,
+ childIds: this.category.childIds || [],
+ parentId: this.category.parentId,
+ showInLastUsed: this.category.showInLastUsed,
+ showInQuickSelector: this.category.showInQuickSelector,
+ showStat: true,
+ }
- // add to new parent
- if (this.category.parentId !== 0) {
- const parenCategory = categories[this.category.parentId]
- const childIds = parenCategory.childIds
- ? [...parenCategory.childIds.filter(cId => cId !== id), id]
- : [id]
-
- saveData(`users/${uid}/categories/${this.category.parentId}`, {
- ...parenCategory,
- showInLastUsed: false,
- showInQuickSelector: false,
- childIds,
+ // ad or remove from parent
+ if (this.originalParentId !== this.category.parentId) {
+ // remove from old parent
+ if (this.originalParentId !== 0) {
+ const originalParent = categories[this.originalParentId]
+ if (originalParent) {
+ saveData(`users/${uid}/categories/${this.originalParentId}`, {
+ ...originalParent,
+ childIds: originalParent.childIds.filter(cId => cId !== id),
})
}
}
- const childIds = this.$store.getters['categories/getChildCategoriesIds'](id)
+ // add to new parent
+ if (this.category.parentId !== 0) {
+ const parenCategory = categories[this.category.parentId]
+ const childIds = parenCategory.childIds
+ ? [...parenCategory.childIds.filter(cId => cId !== id), id]
+ : [id]
+
+ saveData(`users/${uid}/categories/${this.category.parentId}`, {
+ ...parenCategory,
+ showInLastUsed: false,
+ showInQuickSelector: false,
+ childIds,
+ })
+ }
+ }
- // update category
- saveData(`users/${uid}/categories/${id}`, {
- ...categoriesValues,
- childIds,
- })
+ const childIds = this.$store.getters['categories/getChildCategoriesIds'](id)
- // update child categories colors
- if (this.applyChildColor) {
- for (const childId of childIds)
- saveData(`users/${uid}/categories/${childId}/color`, categoriesValues.color)
- }
+ // update category
+ saveData(`users/${uid}/categories/${id}`, {
+ ...categoriesValues,
+ })
+
+ // update child categories colors
+ if (this.applyChildColor) {
+ for (const childId of childIds)
+ saveData(`users/${uid}/categories/${childId}/color`, categoriesValues.color)
}
+
+ this.$router.replace(`/categories/${id}`)
},
validateForm() {