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 && (