refactor(inbox): rename caixa-de-entrada to pre-lancamentos e remove colunas não utilizadas
BREAKING CHANGES: - Renomeia rota /caixa-de-entrada para /pre-lancamentos - Remove colunas device_id, parsed_date e discard_reason da tabela inbox_items Mudanças: - Move componentes de caixa-de-entrada para pre-lancamentos - Atualiza sidebar e navegação para nova rota - Remove campos não utilizados do schema, types e APIs - Adiciona migration 0011 para remover colunas do banco - Simplifica lógica de data padrão usando notificationTimestamp
This commit is contained in:
@@ -7,6 +7,7 @@ import { fetchDashboardNotifications } from "@/lib/dashboard/notifications";
|
||||
import { fetchPagadoresWithAccess } from "@/lib/pagadores/access";
|
||||
import { PAGADOR_ROLE_ADMIN } from "@/lib/pagadores/constants";
|
||||
import { parsePeriodParam } from "@/lib/utils/period";
|
||||
import { fetchPendingInboxCount } from "./pre-lancamentos/data";
|
||||
|
||||
export default async function DashboardLayout({
|
||||
children,
|
||||
@@ -40,6 +41,9 @@ export default async function DashboardLayout({
|
||||
currentPeriod,
|
||||
);
|
||||
|
||||
// Buscar contagem de pré-lançamentos pendentes
|
||||
const preLancamentosCount = await fetchPendingInboxCount(session.user.id);
|
||||
|
||||
return (
|
||||
<PrivacyProvider>
|
||||
<SidebarProvider>
|
||||
@@ -52,6 +56,7 @@ export default async function DashboardLayout({
|
||||
avatarUrl: item.avatarUrl,
|
||||
canEdit: item.canEdit,
|
||||
}))}
|
||||
preLancamentosCount={preLancamentosCount}
|
||||
variant="sidebar"
|
||||
/>
|
||||
<SidebarInset>
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
import { inboxItems } from "@/db/schema";
|
||||
import { handleActionError } from "@/lib/actions/helpers";
|
||||
import type { ActionResult } from "@/lib/actions/types";
|
||||
import { db } from "@/lib/db";
|
||||
import { getUser } from "@/lib/auth/server";
|
||||
import { db } from "@/lib/db";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { z } from "zod";
|
||||
@@ -15,7 +15,6 @@ const markProcessedSchema = z.object({
|
||||
|
||||
const discardInboxSchema = z.object({
|
||||
inboxItemId: z.string().uuid("ID do item inválido"),
|
||||
reason: z.string().optional(),
|
||||
});
|
||||
|
||||
const bulkDiscardSchema = z.object({
|
||||
@@ -23,7 +22,7 @@ const bulkDiscardSchema = z.object({
|
||||
});
|
||||
|
||||
function revalidateInbox() {
|
||||
revalidatePath("/caixa-de-entrada");
|
||||
revalidatePath("/pre-lancamentos");
|
||||
revalidatePath("/lancamentos");
|
||||
revalidatePath("/dashboard");
|
||||
}
|
||||
@@ -32,7 +31,7 @@ function revalidateInbox() {
|
||||
* Mark an inbox item as processed after a lancamento was created
|
||||
*/
|
||||
export async function markInboxAsProcessedAction(
|
||||
input: z.infer<typeof markProcessedSchema>
|
||||
input: z.infer<typeof markProcessedSchema>,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
@@ -46,8 +45,8 @@ export async function markInboxAsProcessedAction(
|
||||
and(
|
||||
eq(inboxItems.id, data.inboxItemId),
|
||||
eq(inboxItems.userId, user.id),
|
||||
eq(inboxItems.status, "pending")
|
||||
)
|
||||
eq(inboxItems.status, "pending"),
|
||||
),
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
@@ -74,7 +73,7 @@ export async function markInboxAsProcessedAction(
|
||||
}
|
||||
|
||||
export async function discardInboxItemAction(
|
||||
input: z.infer<typeof discardInboxSchema>
|
||||
input: z.infer<typeof discardInboxSchema>,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
@@ -88,8 +87,8 @@ export async function discardInboxItemAction(
|
||||
and(
|
||||
eq(inboxItems.id, data.inboxItemId),
|
||||
eq(inboxItems.userId, user.id),
|
||||
eq(inboxItems.status, "pending")
|
||||
)
|
||||
eq(inboxItems.status, "pending"),
|
||||
),
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
@@ -103,7 +102,6 @@ export async function discardInboxItemAction(
|
||||
.set({
|
||||
status: "discarded",
|
||||
discardedAt: new Date(),
|
||||
discardReason: data.reason,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(inboxItems.id, data.inboxItemId));
|
||||
@@ -117,7 +115,7 @@ export async function discardInboxItemAction(
|
||||
}
|
||||
|
||||
export async function bulkDiscardInboxItemsAction(
|
||||
input: z.infer<typeof bulkDiscardSchema>
|
||||
input: z.infer<typeof bulkDiscardSchema>,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
@@ -135,8 +133,8 @@ export async function bulkDiscardInboxItemsAction(
|
||||
and(
|
||||
inArray(inboxItems.id, data.inboxItemIds),
|
||||
eq(inboxItems.userId, user.id),
|
||||
eq(inboxItems.status, "pending")
|
||||
)
|
||||
eq(inboxItems.status, "pending"),
|
||||
),
|
||||
);
|
||||
|
||||
revalidateInbox();
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* Data fetching functions for Caixa de Entrada
|
||||
* Data fetching functions for Pré-Lançamentos
|
||||
*/
|
||||
|
||||
import { db } from "@/lib/db";
|
||||
import { inboxItems, categorias, contas, cartoes, lancamentos } from "@/db/schema";
|
||||
import { eq, desc, and, gte } from "drizzle-orm";
|
||||
import type { InboxItem, SelectOption } from "@/components/caixa-de-entrada/types";
|
||||
import type { InboxItem, SelectOption } from "@/components/pre-lancamentos/types";
|
||||
import {
|
||||
fetchLancamentoFilterSources,
|
||||
buildSluggedFilters,
|
||||
@@ -1,8 +1,8 @@
|
||||
import PageDescription from "@/components/page-description";
|
||||
import { RiInbox2Line } from "@remixicon/react";
|
||||
import { RiInboxLine } from "@remixicon/react";
|
||||
|
||||
export const metadata = {
|
||||
title: "Caixa de Entrada | Opensheets",
|
||||
title: "Pré-Lançamentos | Opensheets",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
@@ -13,9 +13,9 @@ export default function RootLayout({
|
||||
return (
|
||||
<section className="space-y-6 px-6">
|
||||
<PageDescription
|
||||
icon={<RiInbox2Line />}
|
||||
title="Caixa de Entrada"
|
||||
subtitle="Visialize seus lançamentos pendentes"
|
||||
icon={<RiInboxLine />}
|
||||
title="Pré-Lançamentos"
|
||||
subtitle="Notificações capturadas aguardando processamento"
|
||||
/>
|
||||
{children}
|
||||
</section>
|
||||
@@ -1,6 +1,6 @@
|
||||
import { InboxPage } from "@/components/caixa-de-entrada/inbox-page";
|
||||
import { InboxPage } from "@/components/pre-lancamentos/inbox-page";
|
||||
import { getUserId } from "@/lib/auth/server";
|
||||
import { fetchInboxItems, fetchInboxDialogData } from "./data";
|
||||
import { fetchInboxDialogData, fetchInboxItems } from "./data";
|
||||
|
||||
export default async function Page() {
|
||||
const userId = await getUserId();
|
||||
@@ -5,12 +5,12 @@
|
||||
* Requer autenticação via API token (formato os_xxx).
|
||||
*/
|
||||
|
||||
import { apiTokens, inboxItems } from "@/db/schema";
|
||||
import { extractBearerToken, hashToken } from "@/lib/auth/api-token";
|
||||
import { db } from "@/lib/db";
|
||||
import { apiTokens, inboxItems } from "@/db/schema";
|
||||
import { eq, and, isNull } from "drizzle-orm";
|
||||
import { NextResponse } from "next/server";
|
||||
import { inboxBatchSchema } from "@/lib/schemas/inbox";
|
||||
import { and, eq, isNull } from "drizzle-orm";
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
|
||||
// Rate limiting simples em memória
|
||||
@@ -51,7 +51,7 @@ export async function POST(request: Request) {
|
||||
if (!token) {
|
||||
return NextResponse.json(
|
||||
{ error: "Token não fornecido" },
|
||||
{ status: 401 }
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export async function POST(request: Request) {
|
||||
if (!token.startsWith("os_")) {
|
||||
return NextResponse.json(
|
||||
{ error: "Formato de token inválido" },
|
||||
{ status: 401 }
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -69,14 +69,14 @@ export async function POST(request: Request) {
|
||||
const tokenRecord = await db.query.apiTokens.findFirst({
|
||||
where: and(
|
||||
eq(apiTokens.tokenHash, tokenHash),
|
||||
isNull(apiTokens.revokedAt)
|
||||
isNull(apiTokens.revokedAt),
|
||||
),
|
||||
});
|
||||
|
||||
if (!tokenRecord) {
|
||||
return NextResponse.json(
|
||||
{ error: "Token inválido ou revogado" },
|
||||
{ status: 401 }
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ export async function POST(request: Request) {
|
||||
if (!checkRateLimit(tokenRecord.userId)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Limite de requisições excedido", retryAfter: 60 },
|
||||
{ status: 429 }
|
||||
{ status: 429 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -103,13 +103,11 @@ export async function POST(request: Request) {
|
||||
userId: tokenRecord.userId,
|
||||
sourceApp: item.sourceApp,
|
||||
sourceAppName: item.sourceAppName,
|
||||
deviceId: item.deviceId,
|
||||
originalTitle: item.originalTitle,
|
||||
originalText: item.originalText,
|
||||
notificationTimestamp: item.notificationTimestamp,
|
||||
parsedName: item.parsedName,
|
||||
parsedAmount: item.parsedAmount?.toString(),
|
||||
parsedDate: item.parsedDate,
|
||||
parsedTransactionType: item.parsedTransactionType,
|
||||
status: "pending",
|
||||
})
|
||||
@@ -130,9 +128,10 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
// Atualizar último uso do token
|
||||
const clientIp = request.headers.get("x-forwarded-for")?.split(",")[0]?.trim()
|
||||
|| request.headers.get("x-real-ip")
|
||||
|| null;
|
||||
const clientIp =
|
||||
request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ||
|
||||
request.headers.get("x-real-ip") ||
|
||||
null;
|
||||
|
||||
await db
|
||||
.update(apiTokens)
|
||||
@@ -153,20 +152,20 @@ export async function POST(request: Request) {
|
||||
failed: failCount,
|
||||
results,
|
||||
},
|
||||
{ status: 201 }
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
return NextResponse.json(
|
||||
{ error: error.issues[0]?.message ?? "Dados inválidos" },
|
||||
{ status: 400 }
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
console.error("[API] Error creating batch inbox items:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Erro ao processar notificações" },
|
||||
{ status: 500 }
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
* Requer autenticação via API token (formato os_xxx).
|
||||
*/
|
||||
|
||||
import { apiTokens, inboxItems } from "@/db/schema";
|
||||
import { extractBearerToken, hashToken } from "@/lib/auth/api-token";
|
||||
import { db } from "@/lib/db";
|
||||
import { apiTokens, inboxItems } from "@/db/schema";
|
||||
import { eq, and, isNull } from "drizzle-orm";
|
||||
import { NextResponse } from "next/server";
|
||||
import { inboxItemSchema } from "@/lib/schemas/inbox";
|
||||
import { and, eq, isNull } from "drizzle-orm";
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
|
||||
// Rate limiting simples em memória (em produção, use Redis)
|
||||
@@ -44,7 +44,7 @@ export async function POST(request: Request) {
|
||||
if (!token) {
|
||||
return NextResponse.json(
|
||||
{ error: "Token não fornecido" },
|
||||
{ status: 401 }
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export async function POST(request: Request) {
|
||||
if (!token.startsWith("os_")) {
|
||||
return NextResponse.json(
|
||||
{ error: "Formato de token inválido" },
|
||||
{ status: 401 }
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,14 +62,14 @@ export async function POST(request: Request) {
|
||||
const tokenRecord = await db.query.apiTokens.findFirst({
|
||||
where: and(
|
||||
eq(apiTokens.tokenHash, tokenHash),
|
||||
isNull(apiTokens.revokedAt)
|
||||
isNull(apiTokens.revokedAt),
|
||||
),
|
||||
});
|
||||
|
||||
if (!tokenRecord) {
|
||||
return NextResponse.json(
|
||||
{ error: "Token inválido ou revogado" },
|
||||
{ status: 401 }
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ export async function POST(request: Request) {
|
||||
if (!checkRateLimit(tokenRecord.userId)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Limite de requisições excedido", retryAfter: 60 },
|
||||
{ status: 429 }
|
||||
{ status: 429 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -92,22 +92,21 @@ export async function POST(request: Request) {
|
||||
userId: tokenRecord.userId,
|
||||
sourceApp: data.sourceApp,
|
||||
sourceAppName: data.sourceAppName,
|
||||
deviceId: data.deviceId,
|
||||
originalTitle: data.originalTitle,
|
||||
originalText: data.originalText,
|
||||
notificationTimestamp: data.notificationTimestamp,
|
||||
parsedName: data.parsedName,
|
||||
parsedAmount: data.parsedAmount?.toString(),
|
||||
parsedDate: data.parsedDate,
|
||||
parsedTransactionType: data.parsedTransactionType,
|
||||
status: "pending",
|
||||
})
|
||||
.returning({ id: inboxItems.id });
|
||||
|
||||
// Atualizar último uso do token
|
||||
const clientIp = request.headers.get("x-forwarded-for")?.split(",")[0]?.trim()
|
||||
|| request.headers.get("x-real-ip")
|
||||
|| null;
|
||||
const clientIp =
|
||||
request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ||
|
||||
request.headers.get("x-real-ip") ||
|
||||
null;
|
||||
|
||||
await db
|
||||
.update(apiTokens)
|
||||
@@ -123,20 +122,20 @@ export async function POST(request: Request) {
|
||||
clientId: data.clientId,
|
||||
message: "Notificação recebida",
|
||||
},
|
||||
{ status: 201 }
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
return NextResponse.json(
|
||||
{ error: error.issues[0]?.message ?? "Dados inválidos" },
|
||||
{ status: 400 }
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
console.error("[API] Error creating inbox item:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Erro ao processar notificação" },
|
||||
{ status: 500 }
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user