From 51bcc9f874ca720379b5e6afd452b91e158eaa7b Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Sun, 19 Apr 2026 19:27:55 +0200 Subject: [PATCH] feat(loyalty): inline edit for transaction categories in admin Category list now has a pencil edit button that expands inline with name + FR/DE/LB translation fields. Save updates via PATCH API. View mode shows translations summary next to the name. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../admin/js/loyalty-merchant-detail.js | 34 +++++++++ .../loyalty/admin/merchant-detail.html | 76 +++++++++++++++---- 2 files changed, 95 insertions(+), 15 deletions(-) diff --git a/app/modules/loyalty/static/admin/js/loyalty-merchant-detail.js b/app/modules/loyalty/static/admin/js/loyalty-merchant-detail.js index 45713dc3..e43d4ff1 100644 --- a/app/modules/loyalty/static/admin/js/loyalty-merchant-detail.js +++ b/app/modules/loyalty/static/admin/js/loyalty-merchant-detail.js @@ -39,6 +39,8 @@ function adminLoyaltyMerchantDetail() { showAddCategory: false, newCategoryName: '', newCategoryTranslations: { fr: '', de: '', lb: '' }, + editingCategoryId: null, + editCategoryData: { name: '', translations: { fr: '', de: '', lb: '' } }, // State loading: false, @@ -307,6 +309,38 @@ function adminLoyaltyMerchantDetail() { } }, + startEditCategory(cat) { + this.editingCategoryId = cat.id; + this.editCategoryData = { + name: cat.name, + translations: { + fr: cat.name_translations?.fr || '', + de: cat.name_translations?.de || '', + lb: cat.name_translations?.lb || '', + }, + }; + }, + + async saveEditCategory(catId) { + if (!this.editCategoryData.name) return; + try { + const translations = { en: this.editCategoryData.name }; + for (const [lang, val] of Object.entries(this.editCategoryData.translations)) { + if (val) translations[lang] = val; + } + + await apiClient.patch(`/admin/loyalty/stores/${this.selectedCategoryStoreId}/categories/${catId}`, { + name: this.editCategoryData.name, + name_translations: Object.keys(translations).length > 0 ? translations : null, + }); + this.editingCategoryId = null; + await this.loadCategoriesForStore(); + Utils.showToast('Category updated', 'success'); + } catch (error) { + Utils.showToast(error.message || 'Failed to update category', 'error'); + } + }, + async toggleCategoryActive(cat) { try { await apiClient.patch(`/admin/loyalty/stores/${this.selectedCategoryStoreId}/categories/${cat.id}`, { diff --git a/app/modules/loyalty/templates/loyalty/admin/merchant-detail.html b/app/modules/loyalty/templates/loyalty/admin/merchant-detail.html index b04833bd..01559ce5 100644 --- a/app/modules/loyalty/templates/loyalty/admin/merchant-detail.html +++ b/app/modules/loyalty/templates/loyalty/admin/merchant-detail.html @@ -269,22 +269,68 @@