fix: normalize search query whitespace and support first+last name token matching

This commit is contained in:
dvirlabs 2026-03-01 19:09:23 +02:00
parent 71b6828807
commit 259fa7c22a

View File

@ -193,15 +193,25 @@ function GuestList({ eventId, onBack, onShowMembers }) {
// Apply search and filter logic // Apply search and filter logic
const filteredGuests = guests.filter(guest => { const filteredGuests = guests.filter(guest => {
// Text search - search in name, email, phone // Text search normalize whitespace first, then match token-by-token so that:
// trailing/leading spaces don't break results ("דור " == "דור")
// multiple spaces collapse to one ("דור נחמני" == "דור נחמני")
// full-name search works ("דור נחמני" matches first="דור" last="נחמני")
if (searchFilters.query) { if (searchFilters.query) {
const query = searchFilters.query.toLowerCase() const normalized = searchFilters.query.trim().replace(/\s+/g, ' ')
const matchesQuery = if (normalized === '') {
guest.first_name?.toLowerCase().includes(query) || // After normalization the query is blank treat as "no filter"
guest.last_name?.toLowerCase().includes(query) || } else {
guest.email?.toLowerCase().includes(query) || const tokens = normalized.toLowerCase().split(' ').filter(Boolean)
guest.phone_number?.toLowerCase().includes(query) const haystack = [
if (!matchesQuery) return false guest.first_name || '',
guest.last_name || '',
guest.phone_number|| '',
guest.email || '',
].join(' ').toLowerCase()
const matchesQuery = tokens.every(token => haystack.includes(token))
if (!matchesQuery) return false
}
} }
// RSVP Status filter // RSVP Status filter