From 8daea3ea47dd4f426d398efff85f73cfe66acf97 Mon Sep 17 00:00:00 2001 From: arrelin Date: Sat, 16 May 2026 16:30:38 +0300 Subject: [PATCH] update category --- frontend/src/i18n/locales/en.json | 2 + frontend/src/i18n/locales/ru.json | 2 + frontend/src/pages/FamilyView.tsx | 102 +++++++++++++++++++++++++++--- 3 files changed, 97 insertions(+), 9 deletions(-) diff --git a/frontend/src/i18n/locales/en.json b/frontend/src/i18n/locales/en.json index f002600..17019e2 100644 --- a/frontend/src/i18n/locales/en.json +++ b/frontend/src/i18n/locales/en.json @@ -63,6 +63,8 @@ "addCategory": "Add category", "deleteConfirm": "Delete category?", "resetConfirm": "Delete all expenses for this category?", + "editTitle": "Category settings", + "editError": "Error updating category", "createError": "Error creating category", "deleteError": "Error deleting category", "resetError": "Error resetting expenses" diff --git a/frontend/src/i18n/locales/ru.json b/frontend/src/i18n/locales/ru.json index b9ab84a..8a5a28a 100644 --- a/frontend/src/i18n/locales/ru.json +++ b/frontend/src/i18n/locales/ru.json @@ -63,6 +63,8 @@ "addCategory": "Добавить категорию", "deleteConfirm": "Удалить категорию?", "resetConfirm": "Удалить все траты по этой категории?", + "editTitle": "Настройки категории", + "editError": "Ошибка обновления категории", "createError": "Ошибка создания категории", "deleteError": "Ошибка удаления категории", "resetError": "Ошибка сброса трат" diff --git a/frontend/src/pages/FamilyView.tsx b/frontend/src/pages/FamilyView.tsx index f901793..98e1e05 100644 --- a/frontend/src/pages/FamilyView.tsx +++ b/frontend/src/pages/FamilyView.tsx @@ -23,6 +23,7 @@ import { Copy, Check, User, + Settings, } from 'lucide-react'; import ShoppingListModal from '../components/ShoppingListModal'; @@ -45,6 +46,10 @@ export default function FamilyView() { const [expenseAmount, setExpenseAmount] = useState(''); const [expenseDescription, setExpenseDescription] = useState(''); + const [showEditCategory, setShowEditCategory] = useState(null); + const [editCategoryName, setEditCategoryName] = useState(''); + const [editCategoryLimit, setEditCategoryLimit] = useState(''); + const [showHistory, setShowHistory] = useState(null); const [showArchive, setShowArchive] = useState(null); const [historyData, setHistoryData] = useState(null); @@ -181,6 +186,29 @@ export default function FamilyView() { } }; + const handleOpenEditCategory = (category: Category) => { + setEditCategoryName(category.name); + setEditCategoryLimit(parseFloat(category.limit_amount.toString()).toString()); + setShowEditCategory(category.id); + setShowAddExpense(null); + }; + + const handleUpdateCategory = async (categoryId: number) => { + if (!familyId || !editCategoryName || !editCategoryLimit) return; + + try { + await categoryApi.update(parseInt(familyId), categoryId, { + name: editCategoryName, + limit_amount: parseFloat(editCategoryLimit), + }); + setShowEditCategory(null); + loadCategories(); + } catch (err: any) { + const errorMsg = err.response?.data?.message || err.message || t('category.editError'); + alert(`${t('category.editError')}: ${errorMsg}`); + } + }; + const handleShowHistory = async (categoryId: number) => { if (!familyId) return; @@ -396,15 +424,24 @@ export default function FamilyView() { - {showAddExpense !== category.id && ( - + {showAddExpense !== category.id && showEditCategory !== category.id && ( +
+ + +
)} @@ -511,6 +548,53 @@ export default function FamilyView() { )} + {showEditCategory === category.id && ( +
+

+ {t('category.editTitle')} +

+
+
+ + setEditCategoryName(e.target.value)} + className="w-full px-4 py-3 border-2 border-gray-300 rounded-2xl focus:border-purple-500 focus:ring-2 focus:ring-purple-200 transition-all font-medium" + /> +
+
+ + setEditCategoryLimit(e.target.value)} + className="w-full px-4 py-3 border-2 border-gray-300 rounded-2xl focus:border-purple-500 focus:ring-2 focus:ring-purple-200 transition-all text-center font-semibold text-lg" + /> +
+
+ + +
+
+
+ )} + {showHistory === category.id && historyData && (
-- 2.49.1