feat: adiciona ações em lote ao inbox

This commit is contained in:
Felipe Coutinho
2026-03-15 23:24:00 +00:00
parent 1823b6be56
commit 173fc86920
3 changed files with 192 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
"use server";
import { and, eq, inArray } from "drizzle-orm";
import { and, eq, inArray, ne } from "drizzle-orm";
import { z } from "zod";
import { inboxItems } from "@/db/schema";
import {
@@ -35,6 +35,10 @@ const bulkDeleteInboxSchema = z.object({
status: z.enum(["processed", "discarded"]),
});
const bulkDeleteSelectedInboxSchema = z.object({
inboxItemIds: z.array(z.string().uuid()).min(1, "Selecione ao menos um item"),
});
function revalidateInbox() {
revalidateForEntity("inbox");
}
@@ -264,6 +268,36 @@ export async function deleteInboxItemAction(
}
}
export async function bulkDeleteSelectedInboxItemsAction(
input: z.infer<typeof bulkDeleteSelectedInboxSchema>,
): Promise<ActionResult> {
try {
const user = await getUser();
const data = bulkDeleteSelectedInboxSchema.parse(input);
const result = await db
.delete(inboxItems)
.where(
and(
inArray(inboxItems.id, data.inboxItemIds),
eq(inboxItems.userId, user.id),
ne(inboxItems.status, "pending"),
),
)
.returning({ id: inboxItems.id });
revalidateInbox();
const count = result.length;
return {
success: true,
message: `${count} item(s) excluído(s).`,
};
} catch (error) {
return handleActionError(error);
}
}
export async function bulkDeleteInboxItemsAction(
input: z.infer<typeof bulkDeleteInboxSchema>,
): Promise<ActionResult> {