Fixed clients pagination bug

X-Lovable-Edit-ID: edt-dbfbf7c3-248c-4f01-a5fa-5df1c2f0ac1a
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-19 23:00:12 +00:00
co-authored by renee-png
2 changed files with 37 additions and 5 deletions
+19 -5
View File
@@ -35,11 +35,25 @@ function ClientsList() {
const [busy, setBusy] = useState(false);
const load = async () => {
const [{ data: cli }, { data: usr }] = await Promise.all([
supabase.from("clients").select("*").order("name", { ascending: true }),
supabase.from("profiles").select("id, full_name, email").order("full_name", { ascending: true }),
]);
setClients(cli ?? []);
// Page through clients so we never silently hit Supabase's 1000-row cap.
const pageSize = 1000;
const all: any[] = [];
for (let from = 0; ; from += pageSize) {
const { data, error } = await supabase
.from("clients")
.select("*")
.order("name", { ascending: true })
.range(from, from + pageSize - 1);
if (error) { toast.error(error.message); break; }
const batch = data ?? [];
all.push(...batch);
if (batch.length < pageSize) break;
}
const { data: usr } = await supabase
.from("profiles")
.select("id, full_name, email")
.order("full_name", { ascending: true });
setClients(all);
setUsers(usr ?? []);
};
@@ -0,0 +1,18 @@
-- Delete the 7,953 placeholder clients created by the bad invoice import.
-- These are archived, have numeric external_id (e.g. "10008057"), and have
-- no linked cases, invoices, homeowners, contacts, or field values.
DELETE FROM public.client_field_values
WHERE client_id IN (
SELECT id FROM public.clients
WHERE archived_at IS NOT NULL AND external_id ~ '^[0-9]+$'
);
DELETE FROM public.client_contacts
WHERE client_id IN (
SELECT id FROM public.clients
WHERE archived_at IS NOT NULL AND external_id ~ '^[0-9]+$'
);
DELETE FROM public.clients
WHERE archived_at IS NOT NULL
AND external_id ~ '^[0-9]+$';