refactor(loyalty): use search_autocomplete macro for staff PIN lookup

Replace custom inline autocomplete HTML in both create and edit PIN
modals with the shared search_autocomplete macro from inputs.html.
Refactored JS to use staffSearchResults array populated by searchStaff()
(client-side filter) matching the macro's conventions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 21:30:10 +01:00
parent fcde2d68fc
commit 518bace534
2 changed files with 53 additions and 60 deletions

View File

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