diff --git a/frontend/src/components/receipts/CategoryEdit.vue b/frontend/src/components/receipts/CategoryEdit.vue new file mode 100644 index 0000000..1109db0 --- /dev/null +++ b/frontend/src/components/receipts/CategoryEdit.vue @@ -0,0 +1,77 @@ + + + diff --git a/frontend/src/components/receipts/CategoryList.vue b/frontend/src/components/receipts/CategoryList.vue new file mode 100644 index 0000000..4d2f85d --- /dev/null +++ b/frontend/src/components/receipts/CategoryList.vue @@ -0,0 +1,61 @@ + + + diff --git a/frontend/src/i18n/en/receipts.en.json b/frontend/src/i18n/en/receipts.en.json index 75cadf1..eb7b08a 100644 --- a/frontend/src/i18n/en/receipts.en.json +++ b/frontend/src/i18n/en/receipts.en.json @@ -1,4 +1,15 @@ { + "categories": { + "delete": { + "confirm": "Do you really want to delete the following category?", + "title": "Delete category" + }, + "title": { + "edit": "Edit category", + "list": "Categories", + "new": "New category" + } + }, "delete": { "confirm": "Do you really want to delete the following receipt?", "success": "The receipt has been deleted.", diff --git a/frontend/src/i18n/fr/receipts.fr.json b/frontend/src/i18n/fr/receipts.fr.json index f0f1f3b..f64e1f4 100644 --- a/frontend/src/i18n/fr/receipts.fr.json +++ b/frontend/src/i18n/fr/receipts.fr.json @@ -1,4 +1,15 @@ { + "categories": { + "delete": { + "confirm": "Désirez-vous vraiment supprimer la catégorie suivante ?", + "title": "Supprimer la catégorie" + }, + "title": { + "edit": "Éditer la catégorie", + "list": "Catégories", + "new": "Nouvelle catégorie" + } + }, "delete": { "confirm": "Désirez-vous vraiment supprimer le reçu suivant ?", "success": "Le reçu a été supprimé.", diff --git a/frontend/src/stores/categories.ts b/frontend/src/stores/categories.ts new file mode 100644 index 0000000..12ad511 --- /dev/null +++ b/frontend/src/stores/categories.ts @@ -0,0 +1,34 @@ +import { defineStore } from "pinia"; +import { ref } from "vue"; + +export const useCategoryStore = defineStore( + "category", + () => { + const categories = ref([]); + + function remove(category: string): boolean { + const index = categories.value.findIndex((c) => c === category); + if (index < 0) { + return false; + } + categories.value.splice(index, 1); + return true; + } + + function save(newCategory: string, oldCategory?: string): boolean { + if (newCategory === oldCategory || categories.value.includes(newCategory)) { + return false; + } + const index = categories.value.findIndex((c) => c === oldCategory); + if (index < 0) { + categories.value.push(newCategory); + } else { + categories.value.splice(index, 1, newCategory); + } + return true; + } + + return { categories, remove, save }; + }, + { persist: true }, +); // TODO(fpion): tests diff --git a/frontend/src/types/receipts.ts b/frontend/src/types/receipts.ts index ef0fc7e..fd79bc1 100644 --- a/frontend/src/types/receipts.ts +++ b/frontend/src/types/receipts.ts @@ -7,6 +7,11 @@ export type CategorizeReceiptPayload = { itemCategories: ReceiptItemCategory[]; }; +export type CategorySavedEvent = { + newCategory: string; + oldCategory?: string; +}; + export type DepartmentSummary = { number: string; displayName: string; diff --git a/frontend/src/views/receipts/ReceiptEdit.vue b/frontend/src/views/receipts/ReceiptEdit.vue index 1eb6ec3..b6ef2f6 100644 --- a/frontend/src/views/receipts/ReceiptEdit.vue +++ b/frontend/src/views/receipts/ReceiptEdit.vue @@ -1,10 +1,12 @@