refactor: alinha features financeiras ao novo naming

This commit is contained in:
Felipe Coutinho
2026-03-14 12:50:55 +00:00
parent ef918a3667
commit 67ad4b9d02
51 changed files with 876 additions and 898 deletions

View File

@@ -2,7 +2,7 @@
import { and, eq } from "drizzle-orm";
import { z } from "zod";
import { anotacoes } from "@/db/schema";
import { notes } from "@/db/schema";
import {
handleActionError,
revalidateForEntity,
@@ -64,8 +64,8 @@ const deleteNoteSchema = z.object({
id: uuidSchema("Anotação"),
});
type NoteCreateInput = z.infer<typeof createNoteSchema>;
type NoteUpdateInput = z.infer<typeof updateNoteSchema>;
type NoteCreateInput = z.input<typeof createNoteSchema>;
type NoteUpdateInput = z.input<typeof updateNoteSchema>;
type NoteDeleteInput = z.infer<typeof deleteNoteSchema>;
export async function createNoteAction(
@@ -75,7 +75,7 @@ export async function createNoteAction(
const user = await getUser();
const data = createNoteSchema.parse(input);
await db.insert(anotacoes).values({
await db.insert(notes).values({
title: data.title,
description: data.description,
type: data.type,
@@ -84,7 +84,7 @@ export async function createNoteAction(
userId: user.id,
});
revalidateForEntity("anotacoes");
revalidateForEntity("notes");
return { success: true, message: "Anotação criada com sucesso." };
} catch (error) {
@@ -100,7 +100,7 @@ export async function updateNoteAction(
const data = updateNoteSchema.parse(input);
const [updated] = await db
.update(anotacoes)
.update(notes)
.set({
title: data.title,
description: data.description,
@@ -110,8 +110,8 @@ export async function updateNoteAction(
? JSON.stringify(data.tasks)
: null,
})
.where(and(eq(anotacoes.id, data.id), eq(anotacoes.userId, user.id)))
.returning({ id: anotacoes.id });
.where(and(eq(notes.id, data.id), eq(notes.userId, user.id)))
.returning({ id: notes.id });
if (!updated) {
return {
@@ -120,7 +120,7 @@ export async function updateNoteAction(
};
}
revalidateForEntity("anotacoes");
revalidateForEntity("notes");
return { success: true, message: "Anotação atualizada com sucesso." };
} catch (error) {
@@ -136,9 +136,9 @@ export async function deleteNoteAction(
const data = deleteNoteSchema.parse(input);
const [deleted] = await db
.delete(anotacoes)
.where(and(eq(anotacoes.id, data.id), eq(anotacoes.userId, user.id)))
.returning({ id: anotacoes.id });
.delete(notes)
.where(and(eq(notes.id, data.id), eq(notes.userId, user.id)))
.returning({ id: notes.id });
if (!deleted) {
return {
@@ -147,7 +147,7 @@ export async function deleteNoteAction(
};
}
revalidateForEntity("anotacoes");
revalidateForEntity("notes");
return { success: true, message: "Anotação removida com sucesso." };
} catch (error) {
@@ -157,12 +157,12 @@ export async function deleteNoteAction(
const arquivarNoteSchema = z.object({
id: uuidSchema("Anotação"),
arquivada: z.boolean(),
archived: z.boolean(),
});
type NoteArquivarInput = z.infer<typeof arquivarNoteSchema>;
export async function arquivarAnotacaoAction(
export async function archiveNoteAction(
input: NoteArquivarInput,
): Promise<ActionResult> {
try {
@@ -170,12 +170,12 @@ export async function arquivarAnotacaoAction(
const data = arquivarNoteSchema.parse(input);
const [updated] = await db
.update(anotacoes)
.update(notes)
.set({
arquivada: data.arquivada,
archived: data.archived,
})
.where(and(eq(anotacoes.id, data.id), eq(anotacoes.userId, user.id)))
.returning({ id: anotacoes.id });
.where(and(eq(notes.id, data.id), eq(notes.userId, user.id)))
.returning({ id: notes.id });
if (!updated) {
return {
@@ -184,12 +184,12 @@ export async function arquivarAnotacaoAction(
};
}
revalidateForEntity("anotacoes");
revalidateForEntity("notes");
return {
success: true,
message: data.arquivada
? "Anotação arquivada com sucesso."
message: data.archived
? "Anotação archived com sucesso."
: "Anotação desarquivada com sucesso.",
};
} catch (error) {

View File

@@ -215,7 +215,7 @@ export function NoteDialog({
setDialogOpen(false);
return;
}
setErrorMessage(result.error);
setErrorMessage(result.error ?? null);
toast.error(result.error);
titleRef.current?.focus();
});

View File

@@ -3,10 +3,7 @@
import { RiAddCircleLine, RiTodoLine } from "@remixicon/react";
import { useMemo, useState } from "react";
import { toast } from "sonner";
import {
arquivarAnotacaoAction,
deleteNoteAction,
} from "@/features/notes/actions";
import { archiveNoteAction, deleteNoteAction } from "@/features/notes/actions";
import { ConfirmActionDialog } from "@/shared/components/confirm-action-dialog";
import { EmptyState } from "@/shared/components/empty-state";
import { Button } from "@/shared/components/ui/button";
@@ -115,9 +112,9 @@ export function NotesPage({ notes, archivedNotes }: NotesPageProps) {
return;
}
const result = await arquivarAnotacaoAction({
const result = await archiveNoteAction({
id: noteToArquivar.id,
arquivada: !isArquivadas,
archived: !isArquivadas,
});
if (result.success) {
@@ -171,7 +168,7 @@ export function NotesPage({ notes, archivedNotes }: NotesPageProps) {
media={<RiTodoLine className="size-6 text-primary" />}
title={
isArchived
? "Nenhuma anotação arquivada"
? "Nenhuma anotação archived"
: "Nenhuma anotação registrada"
}
description={

View File

@@ -12,7 +12,7 @@ export interface Note {
description: string;
type: NoteType;
tasks?: Task[];
arquivada: boolean;
archived: boolean;
createdAt: string;
}

View File

@@ -1,5 +1,5 @@
import { and, eq } from "drizzle-orm";
import { type Anotacao, anotacoes } from "@/db/schema";
import { type Note, notes } from "@/db/schema";
import { db } from "@/shared/lib/db";
export type Task = {
@@ -14,20 +14,17 @@ export type NoteData = {
description: string;
type: "nota" | "tarefa";
tasks?: Task[];
arquivada: boolean;
archived: boolean;
createdAt: string;
};
export async function fetchNotesForUser(userId: string): Promise<NoteData[]> {
const noteRows = await db.query.anotacoes.findMany({
where: and(eq(anotacoes.userId, userId), eq(anotacoes.arquivada, false)),
orderBy: (
note: typeof anotacoes.$inferSelect,
{ desc }: { desc: (field: unknown) => unknown },
) => [desc(note.createdAt)],
const noteRows = await db.query.notes.findMany({
where: and(eq(notes.userId, userId), eq(notes.archived, false)),
orderBy: (table, { desc }) => [desc(table.createdAt)],
});
return noteRows.map((note: Anotacao) => {
return noteRows.map((note: Note) => {
let tasks: Task[] | undefined;
// Parse tasks if they exist
@@ -46,7 +43,7 @@ export async function fetchNotesForUser(userId: string): Promise<NoteData[]> {
description: (note.description ?? "").trim(),
type: (note.type ?? "nota") as "nota" | "tarefa",
tasks,
arquivada: note.arquivada,
archived: note.archived,
createdAt: note.createdAt.toISOString(),
};
});
@@ -57,24 +54,21 @@ export async function fetchAllNotesForUser(
): Promise<{ activeNotes: NoteData[]; archivedNotes: NoteData[] }> {
const [activeNotes, archivedNotes] = await Promise.all([
fetchNotesForUser(userId),
fetchArquivadasForUser(userId),
fetchArchivedForUser(userId),
]);
return { activeNotes, archivedNotes };
}
export async function fetchArquivadasForUser(
export async function fetchArchivedForUser(
userId: string,
): Promise<NoteData[]> {
const noteRows = await db.query.anotacoes.findMany({
where: and(eq(anotacoes.userId, userId), eq(anotacoes.arquivada, true)),
orderBy: (
note: typeof anotacoes.$inferSelect,
{ desc }: { desc: (field: unknown) => unknown },
) => [desc(note.createdAt)],
const noteRows = await db.query.notes.findMany({
where: and(eq(notes.userId, userId), eq(notes.archived, true)),
orderBy: (table, { desc }) => [desc(table.createdAt)],
});
return noteRows.map((note: Anotacao) => {
return noteRows.map((note: Note) => {
let tasks: Task[] | undefined;
// Parse tasks if they exist
@@ -93,7 +87,7 @@ export async function fetchArquivadasForUser(
description: (note.description ?? "").trim(),
type: (note.type ?? "nota") as "nota" | "tarefa",
tasks,
arquivada: note.arquivada,
archived: note.archived,
createdAt: note.createdAt.toISOString(),
};
});