From acaf9d5c27fdb7bc7b758875bc6add7164a8e64d Mon Sep 17 00:00:00 2001 From: Felipe Coutinho Date: Fri, 3 Apr 2026 18:10:34 +0000 Subject: [PATCH] feat(dados-client): adotar react query em leituras do app --- src/app/layout.tsx | 8 +- .../components/attachment-preview.tsx | 25 ++-- .../attachments/hooks/use-attachment-url.ts | 37 ++++- .../insights/components/insights-page.tsx | 136 +++++++++++------- .../insights/hooks/use-saved-insights.ts | 32 +++++ src/features/insights/queries.ts | 49 +++++++ .../attachments/attachment-section.tsx | 58 ++++---- .../anticipation-history-dialog.tsx | 80 +++++------ .../components/shared/anticipation-card.tsx | 8 +- .../hooks/use-installment-anticipations.ts | 56 ++++++++ .../hooks/use-transaction-attachments.ts | 20 +++ src/shared/components/providers/index.ts | 1 + .../components/providers/query-provider.tsx | 23 +++ src/shared/lib/fetch-json.ts | 26 ++++ 14 files changed, 409 insertions(+), 150 deletions(-) create mode 100644 src/features/insights/hooks/use-saved-insights.ts create mode 100644 src/features/insights/queries.ts create mode 100644 src/features/transactions/hooks/use-installment-anticipations.ts create mode 100644 src/features/transactions/hooks/use-transaction-attachments.ts create mode 100644 src/shared/components/providers/query-provider.tsx create mode 100644 src/shared/lib/fetch-json.ts diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 3988e9b..ecc48c3 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,5 +1,6 @@ import type { Metadata } from "next"; import { Suspense } from "react"; +import { QueryProvider } from "@/shared/components/providers/query-provider"; import { ThemeProvider } from "@/shared/components/providers/theme-provider"; import { Toaster } from "@/shared/components/ui/sonner"; import "./globals.css"; @@ -21,6 +22,7 @@ export default function RootLayout({ }>) { return ( - {children} - + + {children} + + diff --git a/src/features/attachments/components/attachment-preview.tsx b/src/features/attachments/components/attachment-preview.tsx index 0a83618..caed828 100644 --- a/src/features/attachments/components/attachment-preview.tsx +++ b/src/features/attachments/components/attachment-preview.tsx @@ -8,6 +8,7 @@ import { RiExternalLinkLine, } from "@remixicon/react"; import { useEffect, useState } from "react"; +import { useAttachmentUrlQuery } from "@/features/attachments/hooks/use-attachment-url"; import type { AttachmentForPeriod } from "@/features/attachments/queries"; import { Button } from "@/shared/components/ui/button"; import { @@ -30,7 +31,6 @@ export function AttachmentPreview({ onClose, }: AttachmentPreviewProps) { const [currentIndex, setCurrentIndex] = useState(selectedIndex); - const [previewUrl, setPreviewUrl] = useState(null); const open = selectedIndex >= 0; useEffect(() => { @@ -52,17 +52,11 @@ export function AttachmentPreview({ const attachment = attachments[currentIndex]; const attachmentId = attachment?.attachmentId; - - // Busca URL fresca a cada troca de anexo - useEffect(() => { - if (!attachmentId) return; - setPreviewUrl(null); - - fetch(`/api/attachments/${attachmentId}/presign`) - .then((r) => r.json()) - .then((data: { url: string }) => setPreviewUrl(data.url)) - .catch(() => {}); - }, [attachmentId]); + const { + data: previewUrl, + isLoading: isPreviewLoading, + isError: isPreviewError, + } = useAttachmentUrlQuery(attachmentId ?? "", open && Boolean(attachmentId)); if (!attachment) return null; @@ -170,11 +164,16 @@ export function AttachmentPreview({
- {!previewUrl && ( + {isPreviewLoading && (
)} + {isPreviewError && ( +
+ Não foi possível carregar a visualização deste anexo. +
+ )} {isPdf && previewUrl && (