From 5a33f68743da071d67f014deb672077f5d3a7825 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Mon, 23 Mar 2026 21:24:00 +0100 Subject: [PATCH] refactor(loyalty): use search_autocomplete macro for terminal lookup Replace custom inline autocomplete HTML with the shared search_autocomplete macro from inputs.html. Same behavior (debounced search, dropdown with name + email, loading/no-results states) but using the established reusable component. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../static/store/js/loyalty-terminal.js | 4 ++ .../templates/loyalty/store/terminal.html | 58 +++++-------------- 2 files changed, 20 insertions(+), 42 deletions(-) diff --git a/app/modules/loyalty/static/store/js/loyalty-terminal.js b/app/modules/loyalty/static/store/js/loyalty-terminal.js index 11553964..ac5114d8 100644 --- a/app/modules/loyalty/static/store/js/loyalty-terminal.js +++ b/app/modules/loyalty/static/store/js/loyalty-terminal.js @@ -25,6 +25,7 @@ function storeLoyaltyTerminal() { selectedCard: null, searchResults: [], showSearchDropdown: false, + searchingCustomers: false, _searchTimeout: null, // Transaction inputs @@ -161,6 +162,7 @@ function storeLoyaltyTerminal() { }, async searchCustomers() { + this.searchingCustomers = true; try { const params = new URLSearchParams({ search: this.searchQuery, @@ -176,6 +178,8 @@ function storeLoyaltyTerminal() { loyaltyTerminalLog.warn('Search failed:', error.message); this.searchResults = []; this.showSearchDropdown = false; + } finally { + this.searchingCustomers = false; } }, diff --git a/app/modules/loyalty/templates/loyalty/store/terminal.html b/app/modules/loyalty/templates/loyalty/store/terminal.html index ebcca41c..ff6deb9a 100644 --- a/app/modules/loyalty/templates/loyalty/store/terminal.html +++ b/app/modules/loyalty/templates/loyalty/store/terminal.html @@ -3,6 +3,7 @@ {% from 'shared/macros/headers.html' import page_header_flex %} {% from 'shared/macros/alerts.html' import loading_state, error_state %} {% from 'shared/macros/modals.html' import modal_simple %} +{% from 'shared/macros/inputs.html' import search_autocomplete %} {% block title %}{{ _('loyalty.store.terminal.title') }}{% endblock %} @@ -64,48 +65,21 @@
-
- - - - - -
- -
+
+ {{ search_autocomplete( + search_var='searchQuery', + results_var='searchResults', + show_dropdown_var='showSearchDropdown', + loading_var='searchingCustomers', + search_action='debouncedSearchCustomers()', + select_action='selectCustomer(item)', + display_field='customer_name', + secondary_field='customer_email', + placeholder=_('loyalty.store.terminal.search_placeholder'), + min_chars=2, + no_results_text=_('loyalty.store.terminal.customer_not_found'), + loading_text=_('loyalty.store.terminal.looking_up') + ) }}