Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
c021726aea
commit
57821307b7
@@ -55,6 +55,35 @@ export function CaseExpensesTab({ caseId }: { caseId: string }) {
|
||||
|
||||
useEffect(() => { load(); }, [caseId]);
|
||||
|
||||
// Load case client_id for placeholder invoice creation
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const { data } = await supabase.from("cases").select("client_id").eq("id", caseId).maybeSingle();
|
||||
setClientId((data as any)?.client_id ?? null);
|
||||
})();
|
||||
}, [caseId]);
|
||||
|
||||
const toggleInvoiced = async (item: any) => {
|
||||
if (item.invoice_id) {
|
||||
const { error } = await supabase.from("expenses").update({ invoice_id: null }).eq("id", item.id);
|
||||
if (error) { toast.error(error.message); return; }
|
||||
toast.success("Marked as unbilled");
|
||||
load();
|
||||
} else {
|
||||
if (!user?.id) { toast.error("Not signed in"); return; }
|
||||
if (!clientId) { toast.error("Case has no client to invoice against"); return; }
|
||||
try {
|
||||
const invId = await ensureMarkedInvoicedPlaceholder(clientId, caseId, user.id);
|
||||
const { error } = await supabase.from("expenses").update({ invoice_id: invId }).eq("id", item.id);
|
||||
if (error) throw error;
|
||||
toast.success("Marked as invoiced");
|
||||
load();
|
||||
} catch (err: any) {
|
||||
toast.error(err?.message ?? "Could not mark as invoiced");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const { data } = await supabase
|
||||
|
||||
Reference in New Issue
Block a user