fix: resolve email saving issue and implement email substring search
This commit is contained in:
@@ -147,7 +147,10 @@ const App = () => {
|
||||
const deptMatch = emp.department_name && emp.department_name.toLowerCase().includes(queryClean);
|
||||
const buildingMatch = emp.building && emp.building.toLowerCase().includes(queryClean);
|
||||
|
||||
return nameMatch || phoneMatch || internalPhoneMatch || internalPhoneStringMatch || titleMatch || companyMatch || deptMatch || buildingMatch;
|
||||
// Match email fragment (by start, middle, domain, part before @)
|
||||
const emailMatch = emp.email && emp.email.toLowerCase().includes(queryClean);
|
||||
|
||||
return nameMatch || phoneMatch || internalPhoneMatch || internalPhoneStringMatch || titleMatch || companyMatch || deptMatch || buildingMatch || emailMatch;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -305,12 +305,27 @@ const AdminPanel = ({ token, employees, departments, companies, onRefreshData })
|
||||
};
|
||||
|
||||
// Filter employees within the admin table
|
||||
const filteredEmployees = employees.filter(emp =>
|
||||
emp.name.toLowerCase().includes(adminSearch.toLowerCase()) ||
|
||||
emp.job_title.toLowerCase().includes(adminSearch.toLowerCase()) ||
|
||||
(emp.company_name && emp.company_name.toLowerCase().includes(adminSearch.toLowerCase())) ||
|
||||
(emp.department_name && emp.department_name.toLowerCase().includes(adminSearch.toLowerCase()))
|
||||
);
|
||||
const filteredEmployees = employees.filter(emp => {
|
||||
const cleanSearch = adminSearch.toLowerCase().trim();
|
||||
if (!cleanSearch) return true;
|
||||
|
||||
const nameMatch = emp.name.toLowerCase().includes(cleanSearch);
|
||||
const jobMatch = emp.job_title.toLowerCase().includes(cleanSearch);
|
||||
const companyMatch = emp.company_name && emp.company_name.toLowerCase().includes(cleanSearch);
|
||||
const deptMatch = emp.department_name && emp.department_name.toLowerCase().includes(cleanSearch);
|
||||
const emailMatch = emp.email && emp.email.toLowerCase().includes(cleanSearch);
|
||||
|
||||
// Normalize phone numbers for search
|
||||
const cleanDigits = cleanSearch.replace(/\D/g, '');
|
||||
const empPhoneDigits = emp.phone ? emp.phone.replace(/\D/g, '') : '';
|
||||
const phoneMatch = cleanDigits.length > 0 && empPhoneDigits.includes(cleanDigits);
|
||||
|
||||
const empInternalPhoneDigits = emp.internal_phone ? emp.internal_phone.replace(/\D/g, '') : '';
|
||||
const internalPhoneMatch = cleanDigits.length > 0 && empInternalPhoneDigits.includes(cleanDigits);
|
||||
const internalPhoneStringMatch = emp.internal_phone && emp.internal_phone.toLowerCase().includes(cleanSearch);
|
||||
|
||||
return nameMatch || jobMatch || companyMatch || deptMatch || emailMatch || phoneMatch || internalPhoneMatch || internalPhoneStringMatch;
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="admin-layout">
|
||||
|
||||
Reference in New Issue
Block a user