Fixed bulk archive button RLS
X-Lovable-Edit-ID: edt-12b379f0-359f-4241-8457-75b96ed9b652 Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
+44
-23
@@ -173,47 +173,68 @@ function CasesList() {
|
||||
if (selected.size === 0) return;
|
||||
setBusy(true);
|
||||
const ids = Array.from(selected);
|
||||
const { error } = await supabase
|
||||
const { data, error } = await supabase
|
||||
.from("cases")
|
||||
.update({ archived_at: archived ? new Date().toISOString() : null })
|
||||
.in("id", ids);
|
||||
.in("id", ids)
|
||||
.select("id");
|
||||
setBusy(false);
|
||||
if (error) toast.error(error.message);
|
||||
else {
|
||||
toast.success(`${ids.length} case(s) ${archived ? "archived" : "restored"}`);
|
||||
setSelected(new Set());
|
||||
load();
|
||||
if (error) {
|
||||
toast.error(error.message);
|
||||
return;
|
||||
}
|
||||
const updatedCount = data?.length ?? 0;
|
||||
if (updatedCount === 0) {
|
||||
toast.error("No cases were updated. You may not have permission.");
|
||||
return;
|
||||
}
|
||||
if (updatedCount < ids.length) {
|
||||
toast.warning(`${updatedCount} of ${ids.length} case(s) ${archived ? "archived" : "restored"} (others skipped due to permissions)`);
|
||||
} else {
|
||||
toast.success(`${updatedCount} case(s) ${archived ? "archived" : "restored"}`);
|
||||
}
|
||||
setSelected(new Set());
|
||||
load();
|
||||
};
|
||||
|
||||
const bulkAssignAttorney = async () => {
|
||||
if (selected.size === 0 || !assignAttorney) return;
|
||||
setBusy(true);
|
||||
const ids = Array.from(selected);
|
||||
const { error } = await supabase.from("cases").update({ assigned_attorney_id: assignAttorney }).in("id", ids);
|
||||
const { data, error } = await supabase
|
||||
.from("cases")
|
||||
.update({ assigned_attorney_id: assignAttorney })
|
||||
.in("id", ids)
|
||||
.select("id");
|
||||
setBusy(false);
|
||||
if (error) toast.error(error.message);
|
||||
else {
|
||||
toast.success(`${ids.length} case(s) reassigned`);
|
||||
setSelected(new Set());
|
||||
setAssignAttorney("");
|
||||
load();
|
||||
}
|
||||
if (error) { toast.error(error.message); return; }
|
||||
const n = data?.length ?? 0;
|
||||
if (n === 0) { toast.error("No cases were updated. You may not have permission."); return; }
|
||||
if (n < ids.length) toast.warning(`${n} of ${ids.length} case(s) reassigned (others skipped)`);
|
||||
else toast.success(`${n} case(s) reassigned`);
|
||||
setSelected(new Set());
|
||||
setAssignAttorney("");
|
||||
load();
|
||||
};
|
||||
|
||||
const bulkAssignClient = async () => {
|
||||
if (selected.size === 0 || !assignClient) return;
|
||||
setBusy(true);
|
||||
const ids = Array.from(selected);
|
||||
const { error } = await supabase.from("cases").update({ client_id: assignClient }).in("id", ids);
|
||||
const { data, error } = await supabase
|
||||
.from("cases")
|
||||
.update({ client_id: assignClient })
|
||||
.in("id", ids)
|
||||
.select("id");
|
||||
setBusy(false);
|
||||
if (error) toast.error(error.message);
|
||||
else {
|
||||
toast.success(`${ids.length} case(s) re-linked to client`);
|
||||
setSelected(new Set());
|
||||
setAssignClient("");
|
||||
load();
|
||||
}
|
||||
if (error) { toast.error(error.message); return; }
|
||||
const n = data?.length ?? 0;
|
||||
if (n === 0) { toast.error("No cases were updated. You may not have permission."); return; }
|
||||
if (n < ids.length) toast.warning(`${n} of ${ids.length} case(s) re-linked (others skipped)`);
|
||||
else toast.success(`${n} case(s) re-linked to client`);
|
||||
setSelected(new Set());
|
||||
setAssignClient("");
|
||||
load();
|
||||
};
|
||||
|
||||
const userOptions = users.map((u) => ({
|
||||
|
||||
Reference in New Issue
Block a user