Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-18 01:41:55 +00:00
co-authored by renee-png
parent 05550e1191
commit 4ab142e60e
8 changed files with 49 additions and 4 deletions
+39
View File
@@ -0,0 +1,39 @@
import { supabase } from "@/integrations/supabase/client";
import { toast } from "sonner";
export type ArchivableTable = "clients" | "cases" | "contacts" | "homeowners";
const LABELS: Record<ArchivableTable, string> = {
clients: "Client",
cases: "Case",
contacts: "Contact",
homeowners: "Homeowner",
};
/**
* Archive (soft) or restore a row by setting/clearing `archived_at`.
* Returns true on success.
*/
export async function setArchived(
table: ArchivableTable,
id: string,
archived: boolean,
): Promise<boolean> {
const patch = { archived_at: archived ? new Date().toISOString() : null };
const { error } = await (supabase.from(table) as any).update(patch).eq("id", id);
if (error) {
toast.error(`Could not ${archived ? "archive" : "restore"} ${LABELS[table].toLowerCase()}`, {
description: error.message,
});
return false;
}
toast.success(`${LABELS[table]} ${archived ? "archived" : "restored"}`);
return true;
}
/** Coerce common CSV truthy/falsy values into a boolean. */
export function parseArchivedFlag(v: unknown): boolean {
if (typeof v === "boolean") return v;
const s = String(v ?? "").trim().toLowerCase();
return s === "true" || s === "yes" || s === "1" || s === "y" || s === "archived";
}
+3
View File
@@ -32,6 +32,7 @@ export async function fetchClients(): Promise<ClientLite[]> {
.select(
"id,name,address_line1,address_line2,city,state,postal_code,primary_contact_email,primary_contact_phone,annual_interest_rate",
)
.is("archived_at", null)
.order("name");
return (data ?? []) as ClientLite[];
}
@@ -41,6 +42,7 @@ export async function fetchHomeowners(clientId: string): Promise<HomeownerLite[]
.from("homeowners")
.select("id,client_id,first_name,last_name,unit_number,address,email,phone,opening_balance")
.eq("client_id", clientId)
.is("archived_at", null)
.order("last_name");
return (data ?? []) as HomeownerLite[];
}
@@ -193,6 +195,7 @@ export async function fetchAccessibleCases(): Promise<CaseLite[]> {
const { data } = await supabase
.from("cases")
.select("id,case_number,title")
.is("archived_at", null)
.order("opened_at", { ascending: false })
.limit(500);
return (data ?? []) as CaseLite[];