fix(loyalty): use confirm modal for category deletion
Some checks failed
CI / ruff (push) Successful in 17s
CI / pytest (push) Failing after 2h21m18s
CI / validate (push) Successful in 29s
CI / dependency-scanning (push) Successful in 33s
CI / docs (push) Has been skipped
CI / deploy (push) Has been skipped

Replace browser confirm() dialog with the shared confirm_modal
macro for category deletion. Matches the existing program delete
pattern. Shows warning about impact on existing transactions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-25 14:40:29 +02:00
parent 255ac6525e
commit 56c94ac2f4
3 changed files with 23 additions and 5 deletions

View File

@@ -487,6 +487,7 @@
"transaction_categories": "Transaction Categories", "transaction_categories": "Transaction Categories",
"select_store": "Select a store...", "select_store": "Select a store...",
"no_categories": "No categories configured. Click Add to create one.", "no_categories": "No categories configured. Click Add to create one.",
"delete_category_message": "Are you sure you want to delete this category? Existing transactions will keep the category reference but it will no longer be available for new transactions.",
"admin_policy_settings": "Admin Policy Settings", "admin_policy_settings": "Admin Policy Settings",
"staff_pin_policy": "Staff PIN Policy", "staff_pin_policy": "Staff PIN Policy",
"self_enrollment": "Self Enrollment", "self_enrollment": "Self Enrollment",

View File

@@ -41,6 +41,8 @@ function adminLoyaltyMerchantDetail() {
newCategoryTranslations: { fr: '', de: '', lb: '' }, newCategoryTranslations: { fr: '', de: '', lb: '' },
viewingCategoryId: null, viewingCategoryId: null,
editingCategoryId: null, editingCategoryId: null,
showDeleteCategoryModal: false,
categoryToDelete: null,
editCategoryData: { name: '', translations: { fr: '', de: '', lb: '' } }, editCategoryData: { name: '', translations: { fr: '', de: '', lb: '' } },
// State // State
@@ -353,14 +355,17 @@ function adminLoyaltyMerchantDetail() {
} }
}, },
async deleteCategory(catId) { async confirmDeleteCategory() {
if (!confirm('Delete this category?')) return; if (!this.categoryToDelete) return;
try { try {
await apiClient.delete(`/admin/loyalty/stores/${this.selectedCategoryStoreId}/categories/${catId}`); await apiClient.delete(`/admin/loyalty/stores/${this.selectedCategoryStoreId}/categories/${this.categoryToDelete}`);
await this.loadCategoriesForStore(); await this.loadCategoriesForStore();
Utils.showToast('Category deleted', 'success'); Utils.showToast('Category deleted', 'success');
} catch (error) { } catch (error) {
Utils.showToast(error.message || 'Failed to delete category', 'error'); Utils.showToast(error.message || 'Failed to delete category', 'error');
} finally {
this.showDeleteCategoryModal = false;
this.categoryToDelete = null;
} }
} }
}; };

View File

@@ -152,7 +152,7 @@
</div> </div>
</div> </div>
<!-- Delete Confirmation Modal --> <!-- Delete Program Confirmation Modal -->
{{ confirm_modal( {{ confirm_modal(
'deleteProgramModal', 'deleteProgramModal',
_('loyalty.admin.merchant_detail.delete_title'), _('loyalty.admin.merchant_detail.delete_title'),
@@ -164,6 +164,18 @@
'danger' 'danger'
) }} ) }}
<!-- Delete Category Confirmation Modal -->
{{ confirm_modal(
'deleteCategoryModal',
_('loyalty.common.delete'),
_('loyalty.admin.merchant_detail.delete_category_message'),
'confirmDeleteCategory()',
'showDeleteCategoryModal',
_('loyalty.common.delete'),
_('loyalty.common.cancel'),
'danger'
) }}
<!-- Location Breakdown --> <!-- Location Breakdown -->
<div x-show="locations.length > 0" class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800"> <div x-show="locations.length > 0" class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800">
<h3 class="mb-4 text-lg font-semibold text-gray-700 dark:text-gray-200"> <h3 class="mb-4 text-lg font-semibold text-gray-700 dark:text-gray-200">
@@ -287,7 +299,7 @@
class="text-sm" :class="cat.is_active ? 'text-orange-500 hover:text-orange-700' : 'text-green-500 hover:text-green-700'"> class="text-sm" :class="cat.is_active ? 'text-orange-500 hover:text-orange-700' : 'text-green-500 hover:text-green-700'">
<span x-html="$icon(cat.is_active ? 'ban' : 'play', 'w-4 h-4')"></span> <span x-html="$icon(cat.is_active ? 'ban' : 'play', 'w-4 h-4')"></span>
</button> </button>
<button @click="deleteCategory(cat.id)" type="button" <button @click="categoryToDelete = cat.id; showDeleteCategoryModal = true" type="button"
aria-label="{{ _('loyalty.common.delete') }}" aria-label="{{ _('loyalty.common.delete') }}"
class="text-red-500 hover:text-red-700"> class="text-red-500 hover:text-red-700">
<span x-html="$icon('trash', 'w-4 h-4')"></span> <span x-html="$icon('trash', 'w-4 h-4')"></span>