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
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) {
const query = searchFilters.query.toLowerCase()
const matchesQuery =
guest.first_name?.toLowerCase().includes(query) ||
guest.last_name?.toLowerCase().includes(query) ||
guest.email?.toLowerCase().includes(query) ||
guest.phone_number?.toLowerCase().includes(query)
if (!matchesQuery) return false
const normalized = searchFilters.query.trim().replace(/\s+/g, ' ')
if (normalized === '') {
// After normalization the query is blank treat as "no filter"
} else {
const tokens = normalized.toLowerCase().split(' ').filter(Boolean)
const haystack = [
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