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 @@