diff --git a/app/modules/loyalty/static/shared/js/loyalty-pins-list.js b/app/modules/loyalty/static/shared/js/loyalty-pins-list.js index 97d5b509..585d8bab 100644 --- a/app/modules/loyalty/static/shared/js/loyalty-pins-list.js +++ b/app/modules/loyalty/static/shared/js/loyalty-pins-list.js @@ -60,35 +60,40 @@ function loyaltyPinsList(config) { // Staff autocomplete state staffSearch: '', + staffSearchResults: [], showStaffDropdown: false, - - // Track which member was selected (to detect when user edits away) + searchingStaff: false, _selectedStaffName: '', - get filteredStaff() { - if (!this.staffSearch) return this.staffMembers; + searchStaff() { + // Client-side filter of loaded staff members + if (!this.staffSearch || this.staffSearch.length < 1) { + this.staffSearchResults = []; + this.showStaffDropdown = false; + return; + } const q = this.staffSearch.toLowerCase(); - return this.staffMembers.filter(m => + this.staffSearchResults = this.staffMembers.filter(m => (m.full_name && m.full_name.toLowerCase().includes(q)) || (m.email && m.email.toLowerCase().includes(q)) ); - }, + this.showStaffDropdown = this.staffSearchResults.length > 0; - selectStaffMember(member) { - this.pinForm.name = member.full_name; - this.pinForm.staff_id = member.email; - this.staffSearch = member.full_name; - this._selectedStaffName = member.full_name; - this.showStaffDropdown = false; - }, - - onStaffSearchInput() { - this.pinForm.name = this.staffSearch; // If user modified the text away from the selected member, clear staff_id if (this._selectedStaffName && this.staffSearch !== this._selectedStaffName) { this.pinForm.staff_id = ''; this._selectedStaffName = ''; } + this.pinForm.name = this.staffSearch; + }, + + selectStaffMember(item) { + this.pinForm.name = item.full_name; + this.pinForm.staff_id = item.email; + this.staffSearch = item.full_name; + this._selectedStaffName = item.full_name; + this.showStaffDropdown = false; + this.staffSearchResults = []; }, clearStaffSelection() { @@ -97,6 +102,7 @@ function loyaltyPinsList(config) { this.pinForm.staff_id = ''; this._selectedStaffName = ''; this.showStaffDropdown = false; + this.staffSearchResults = []; }, // Action state diff --git a/app/modules/loyalty/templates/loyalty/shared/pins-list.html b/app/modules/loyalty/templates/loyalty/shared/pins-list.html index 359b3eed..19c94fb4 100644 --- a/app/modules/loyalty/templates/loyalty/shared/pins-list.html +++ b/app/modules/loyalty/templates/loyalty/shared/pins-list.html @@ -9,6 +9,7 @@ {% from 'shared/macros/alerts.html' import loading_state, error_state %} {% from 'shared/macros/tables.html' import table_wrapper, table_header %} {% from 'shared/macros/modals.html' import modal, confirm_modal %} +{% from 'shared/macros/inputs.html' import search_autocomplete %}
@@ -132,29 +133,22 @@
-
+
- - -
- -
+ {{ search_autocomplete( + search_var='staffSearch', + results_var='staffSearchResults', + show_dropdown_var='showStaffDropdown', + loading_var='searchingStaff', + search_action='searchStaff()', + select_action='selectStaffMember(item)', + display_field='full_name', + secondary_field='email', + placeholder=_('loyalty.shared.pins.pin_name'), + min_chars=1, + no_results_text=_('loyalty.store.terminal.customer_not_found'), + loading_text=_('loyalty.store.terminal.looking_up') + ) }}
@@ -201,29 +195,22 @@
-
+
- - -
- -
+ {{ search_autocomplete( + search_var='staffSearch', + results_var='staffSearchResults', + show_dropdown_var='showStaffDropdown', + loading_var='searchingStaff', + search_action='searchStaff()', + select_action='selectStaffMember(item)', + display_field='full_name', + secondary_field='email', + placeholder=_('loyalty.shared.pins.pin_name'), + min_chars=1, + no_results_text=_('loyalty.store.terminal.customer_not_found'), + loading_text=_('loyalty.store.terminal.looking_up') + ) }}