Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
05550e1191
commit
4ab142e60e
@@ -176,6 +176,7 @@ function ContactPickerDialog({
|
||||
supabase
|
||||
.from("contacts")
|
||||
.select("id, name, company, contact_type, email")
|
||||
.is("archived_at", null)
|
||||
.order("name")
|
||||
.limit(200)
|
||||
.then(({ data }) => setRows(data ?? []));
|
||||
|
||||
@@ -50,7 +50,7 @@ export function GenerateInvoiceDialog({ open, onOpenChange, clientId, clientName
|
||||
(async () => {
|
||||
setLoading(true);
|
||||
const [{ data: cs }, { data: firm }] = await Promise.all([
|
||||
supabase.from("cases").select("id, case_number, title").eq("client_id", clientId),
|
||||
supabase.from("cases").select("id, case_number, title").eq("client_id", clientId).is("archived_at", null),
|
||||
supabase.from("firm_settings").select("default_tax_rate").maybeSingle(),
|
||||
]);
|
||||
const caseIds = (cs ?? []).map((c) => c.id);
|
||||
|
||||
@@ -53,10 +53,11 @@ function useClientsAndCases(open: boolean) {
|
||||
if (!open) return;
|
||||
(async () => {
|
||||
const [{ data: cs }, { data: ks }] = await Promise.all([
|
||||
supabase.from("clients").select("id, name").order("name"),
|
||||
supabase.from("clients").select("id, name").is("archived_at", null).order("name"),
|
||||
supabase
|
||||
.from("cases")
|
||||
.select("id, case_number, title, client_id, default_hourly_rate")
|
||||
.is("archived_at", null)
|
||||
.order("case_number", { ascending: false }),
|
||||
]);
|
||||
setClients(cs ?? []);
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
@@ -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[];
|
||||
|
||||
@@ -47,7 +47,7 @@ function NewCase() {
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const [{ data: cs }, { data: us }] = await Promise.all([
|
||||
supabase.from("clients").select("id, name").order("name"),
|
||||
supabase.from("clients").select("id, name").is("archived_at", null).order("name"),
|
||||
supabase.from("profiles").select("id, full_name, email").order("full_name"),
|
||||
]);
|
||||
setClients(cs ?? []);
|
||||
|
||||
@@ -48,6 +48,7 @@ function StatusUpdatesPage() {
|
||||
const { data, error } = await supabase
|
||||
.from("cases")
|
||||
.select("id, case_number, title, client:clients(name)")
|
||||
.is("archived_at", null)
|
||||
.order("opened_at", { ascending: false })
|
||||
.limit(500);
|
||||
if (error) toast.error("Could not load cases", { description: error.message });
|
||||
|
||||
@@ -93,7 +93,7 @@ function TasksPage() {
|
||||
.order("due_date", { ascending: true, nullsFirst: false }),
|
||||
supabase.from("task_assignees").select("task_id, user_id"),
|
||||
supabase.from("profiles").select("id, full_name, email"),
|
||||
supabase.from("cases").select("id, case_number, title"),
|
||||
supabase.from("cases").select("id, case_number, title").is("archived_at", null),
|
||||
]);
|
||||
setTasks((t.data ?? []) as TaskRow[]);
|
||||
setAssignees((a.data ?? []) as AssigneeRow[]);
|
||||
|
||||
Reference in New Issue
Block a user