updates on the saved contacts and fix on the logo in the home page section
This commit is contained in:
@@ -30,6 +30,41 @@ export default function Customers({ embedded = false }) {
|
||||
const { data: customers = [], isLoading, isFetching } = useTenantCustomers();
|
||||
const updateCustomer = useUpdateTenantCustomer();
|
||||
|
||||
const [localSavedContacts] = useState(() => {
|
||||
try {
|
||||
const data = localStorage.getItem('doormile_saved_contacts');
|
||||
return data ? JSON.parse(data) : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
const mergedCustomers = useMemo(() => {
|
||||
const list = [...(customers || [])];
|
||||
const seen = new Set();
|
||||
const result = [];
|
||||
|
||||
for (const sc of localSavedContacts) {
|
||||
const p = String(sc.phone || sc.contactno || '').replace(/\D/g, '').slice(-10);
|
||||
if (p) seen.add(p);
|
||||
result.push({
|
||||
...sc,
|
||||
appcustomerid: sc.id || `saved_${p}`,
|
||||
name: sc.name || sc.firstname,
|
||||
phone: sc.phone || sc.contactno,
|
||||
totalbookings: 0
|
||||
});
|
||||
}
|
||||
|
||||
for (const c of list) {
|
||||
const p = String(c.phone || c.contactno || '').replace(/\D/g, '').slice(-10);
|
||||
if (p && seen.has(p)) continue;
|
||||
if (p) seen.add(p);
|
||||
result.push(c);
|
||||
}
|
||||
return result;
|
||||
}, [customers, localSavedContacts]);
|
||||
|
||||
const [search, setSearch] = useState('');
|
||||
const debouncedSearch = useDebouncedValue(search);
|
||||
const [activeFilter, setActiveFilter] = useState('all');
|
||||
@@ -38,21 +73,21 @@ export default function Customers({ embedded = false }) {
|
||||
const [form, setForm] = useState({ name: '', phone: '', email: '' });
|
||||
|
||||
const stats = useMemo(() => {
|
||||
const total = customers.length;
|
||||
const total = mergedCustomers.length;
|
||||
return {
|
||||
total,
|
||||
withEmail: customers.filter((row) => Boolean(row.email)).length,
|
||||
withPhone: customers.filter((row) => Boolean(row.phone)).length,
|
||||
totalBookings: customers.reduce((sum, row) => sum + (Number(row.totalbookings) || 0), 0),
|
||||
withEmail: mergedCustomers.filter((row) => Boolean(row.email)).length,
|
||||
withPhone: mergedCustomers.filter((row) => Boolean(row.phone)).length,
|
||||
totalBookings: mergedCustomers.reduce((sum, row) => sum + (Number(row.totalbookings) || 0), 0),
|
||||
};
|
||||
}, [customers]);
|
||||
}, [mergedCustomers]);
|
||||
|
||||
const rows = useMemo(() => {
|
||||
let list = customers;
|
||||
let list = mergedCustomers;
|
||||
if (activeFilter === 'withEmail') list = list.filter((row) => Boolean(row.email));
|
||||
else if (activeFilter === 'withPhone') list = list.filter((row) => Boolean(row.phone));
|
||||
return list.filter((row) => matchesQuery(row, [custName, custPhone, custEmail], debouncedSearch));
|
||||
}, [customers, activeFilter, debouncedSearch]);
|
||||
}, [mergedCustomers, activeFilter, debouncedSearch]);
|
||||
|
||||
const toggleFilter = (key) => setActiveFilter((current) => (current === key ? 'all' : key));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user