diff --git a/src/app/@modal/(.)paperless/document/[id]/page.tsx b/src/app/@modal/(.)paperless/document/[id]/page.tsx
index 04cdcb7..6215b79 100644
--- a/src/app/@modal/(.)paperless/document/[id]/page.tsx
+++ b/src/app/@modal/(.)paperless/document/[id]/page.tsx
@@ -1,9 +1,20 @@
-import DocumentModal from "@/components/document-modal";
+import DocumentPreview from "@/components/document-preview";
+import { Modal } from "@/components/modal";
export default function ModalDocumentPage({
params,
}: {
params: { id: number };
}) {
- return ;
+ return (
+
+
+
+ );
}
diff --git a/src/app/paperless/details/[id]/page.tsx b/src/app/paperless/details/[id]/page.tsx
index 8e4324a..652a10e 100644
--- a/src/app/paperless/details/[id]/page.tsx
+++ b/src/app/paperless/details/[id]/page.tsx
@@ -1,9 +1,230 @@
-import DocumentDetails from "@/components/document-details";
+"use client";
-export default function FullPageDocumentPage({
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+ AlertDialogTrigger,
+} from "@/components/ui/alert-dialog";
+import { toast } from "sonner";
+import { getUserData } from "@/app/actions";
+import { buttonVariants } from "@/components/ui/button";
+import { useRouter, useSearchParams } from "next/navigation";
+import {
+ useQuery,
+ QueryClientProvider,
+ QueryClient,
+} from "@tanstack/react-query";
+import type { UsersTableType } from "@/server/db/schema";
+import type { PaperlessDocumentType } from "@/types";
+import React from "react";
+import BodyMessage from "@/components/body-message";
+import Link from "next/link";
+import LoadingSpinner from "@/components/loading-spinner";
+import OpenExternalLink from "@/components/external-link";
+
+const queryClient = new QueryClient();
+
+export async function getPaperlessDocument(
+ documentId: number,
+ userData: UsersTableType,
+): Promise {
+ try {
+ const url = `${userData.paperlessURL}/api/documents/${documentId}/download/`;
+ const response = await fetch(url, {
+ headers: {
+ Authorization: `Token ${userData.paperlessToken}`,
+ },
+ });
+ if (response.ok) {
+ const blob = await response.blob();
+ const objectUrl = URL.createObjectURL(blob);
+ return objectUrl;
+ } else {
+ console.error("Failed to fetch PDF");
+ return null;
+ }
+ } catch (error) {
+ console.error("Error fetching PDF:", error);
+ return null;
+ }
+}
+
+async function deleteDocument(documentId: number) {
+ const userData = await getUserData();
+ if (!userData) {
+ throw new Error("User data not found");
+ }
+ const body = {
+ documents: [documentId],
+ method: "delete",
+ };
+ const response = await fetch(
+ `${userData.paperlessURL}/api/documents/bulk_edit/ `,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Token ${userData.paperlessToken}`,
+ },
+ body: JSON.stringify(body),
+ },
+ );
+ return response;
+}
+
+const fetchUserData = async (): Promise => {
+ const response = await fetch(`/api/getUserData`);
+ if (!response.ok) {
+ throw new Error("Network error");
+ }
+ const data = (await response.json()) as UsersTableType;
+ return data;
+};
+
+async function getPaperlessDocumentData(id: number, userData: UsersTableType) {
+ try {
+ const url = `${userData.paperlessURL}/api/documents/${id}/?truncate_content=true`;
+ const response = await fetch(url, {
+ headers: {
+ Authorization: `Token ${userData.paperlessToken}`,
+ },
+ });
+ if (response.ok) {
+ const data = (await response.json()) as PaperlessDocumentType;
+ return data;
+ } else {
+ console.error("Failed to fetch PD dataF");
+ return null;
+ }
+ } catch (error) {
+ console.error("Error fetching PDF data:", error);
+ return null;
+ }
+}
+
+function DocumentDetailsInner(props: { id: number }) {
+ const router = useRouter();
+ const searchParams = useSearchParams();
+ const query = searchParams.get("query");
+
+ const { data: userData, isLoading: isUserDataLoading } = useQuery({
+ queryKey: ["userData"],
+ queryFn: fetchUserData,
+ staleTime: 24 * 60 * 60 * 1000, // 1 day in milliseconds
+ refetchOnWindowFocus: false,
+ });
+
+ const { data: pdfUrl, isLoading: isPdfUrlLoading } = useQuery({
+ queryKey: ["pdfUrl", props.id, userData], // Include id and userData in the query key
+ queryFn: async () => {
+ const result = await getPaperlessDocument(props.id, userData!);
+ return result;
+ },
+ enabled: !!userData,
+ refetchOnWindowFocus: false,
+ });
+
+ const { data: documentData, isLoading: isdocumentDataLoading } = useQuery({
+ queryKey: ["documentData", props.id, userData], // Include id and userData in the query key
+ queryFn: async () => {
+ const result = await getPaperlessDocumentData(props.id, userData!);
+ return result;
+ },
+ enabled: !!userData,
+ refetchOnWindowFocus: false,
+ });
+
+ if (isUserDataLoading || isdocumentDataLoading || isPdfUrlLoading) {
+ return Loading...;
+ } else if (!userData || !documentData || !pdfUrl) {
+ return Error;
+ }
+ return (
+
+
+
+
+
{documentData?.title}
+
+
+
+
+
+
+
+ Back to search
+
+
+ Open
+
+
+
+ Delete
+
+
+
+ Are you absolutely sure?
+
+ This action cannot be undone. This will permanently delete
+ the pdf.
+
+
+
+ Cancel
+ {
+ const response = await deleteDocument(props.id);
+ if (response.ok) {
+ toast("Pdf deleted", {
+ description: "The pdf has been deleted.",
+ });
+ } else {
+ toast("Error deleting pdf", {
+ description:
+ "An error occurred while deleting the pdf.",
+ });
+ }
+ router.push(`/paperless?query=${query}`);
+ }}
+ >
+ Continue
+
+
+
+
+
+
+
+
+ );
+}
+
+export default function DocumentDetails({
params,
}: {
params: { id: number };
}) {
- return ;
+ return (
+
+
+
+ );
}
diff --git a/src/components/document-details.tsx b/src/components/document-details.tsx
deleted file mode 100644
index 630e752..0000000
--- a/src/components/document-details.tsx
+++ /dev/null
@@ -1,230 +0,0 @@
-"use client";
-
-import {
- AlertDialog,
- AlertDialogAction,
- AlertDialogCancel,
- AlertDialogContent,
- AlertDialogDescription,
- AlertDialogFooter,
- AlertDialogHeader,
- AlertDialogTitle,
- AlertDialogTrigger,
-} from "@/components/ui/alert-dialog";
-import { toast } from "sonner";
-import { getUserData } from "@/app/actions";
-import { buttonVariants } from "@/components/ui/button";
-import { useRouter, useSearchParams } from "next/navigation";
-import {
- useQuery,
- QueryClientProvider,
- QueryClient,
-} from "@tanstack/react-query";
-import type { UsersTableType } from "@/server/db/schema";
-import LoadingSpinner from "./loading-spinner";
-import OpenExternalLink from "./external-link";
-import type { PaperlessDocumentType } from "@/types";
-import React from "react";
-import BodyMessage from "@/components/body-message";
-import Link from "next/link";
-
-const queryClient = new QueryClient();
-
-export async function getPaperlessDocument(
- documentId: number,
- userData: UsersTableType,
-): Promise {
- try {
- const url = `${userData.paperlessURL}/api/documents/${documentId}/download/`;
- const response = await fetch(url, {
- headers: {
- Authorization: `Token ${userData.paperlessToken}`,
- },
- });
- if (response.ok) {
- const blob = await response.blob();
- const objectUrl = URL.createObjectURL(blob);
- return objectUrl;
- } else {
- console.error("Failed to fetch PDF");
- return null;
- }
- } catch (error) {
- console.error("Error fetching PDF:", error);
- return null;
- }
-}
-
-async function deleteDocument(documentId: number) {
- const userData = await getUserData();
- if (!userData) {
- throw new Error("User data not found");
- }
- const body = {
- documents: [documentId],
- method: "delete",
- };
- const response = await fetch(
- `${userData.paperlessURL}/api/documents/bulk_edit/ `,
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Token ${userData.paperlessToken}`,
- },
- body: JSON.stringify(body),
- },
- );
- return response;
-}
-
-const fetchUserData = async (): Promise => {
- const response = await fetch(`/api/getUserData`);
- if (!response.ok) {
- throw new Error("Network error");
- }
- const data = (await response.json()) as UsersTableType;
- return data;
-};
-
-async function getPaperlessDocumentData(id: number, userData: UsersTableType) {
- try {
- const url = `${userData.paperlessURL}/api/documents/${id}/?truncate_content=true`;
- const response = await fetch(url, {
- headers: {
- Authorization: `Token ${userData.paperlessToken}`,
- },
- });
- if (response.ok) {
- const data = (await response.json()) as PaperlessDocumentType;
- return data;
- } else {
- console.error("Failed to fetch PD dataF");
- return null;
- }
- } catch (error) {
- console.error("Error fetching PDF data:", error);
- return null;
- }
-}
-
-function DocumentDetailsInner(props: { id: number }) {
- const router = useRouter();
- const searchParams = useSearchParams();
- const query = searchParams.get("query");
-
- const { data: userData, isLoading: isUserDataLoading } = useQuery({
- queryKey: ["userData"],
- queryFn: fetchUserData,
- staleTime: 24 * 60 * 60 * 1000, // 1 day in milliseconds
- refetchOnWindowFocus: false,
- });
-
- const { data: pdfUrl, isLoading: isPdfUrlLoading } = useQuery({
- queryKey: ["pdfUrl", props.id, userData], // Include id and userData in the query key
- queryFn: async () => {
- const result = await getPaperlessDocument(props.id, userData!);
- return result;
- },
- enabled: !!userData,
- refetchOnWindowFocus: false,
- });
-
- const { data: documentData, isLoading: isdocumentDataLoading } = useQuery({
- queryKey: ["documentData", props.id, userData], // Include id and userData in the query key
- queryFn: async () => {
- const result = await getPaperlessDocumentData(props.id, userData!);
- return result;
- },
- enabled: !!userData,
- refetchOnWindowFocus: false,
- });
-
- if (isUserDataLoading || isdocumentDataLoading || isPdfUrlLoading) {
- return Loading...;
- } else if (!userData || !documentData || !pdfUrl) {
- return Error;
- }
- return (
-
-
-
-
-
{documentData?.title}
-
-
-
-
-
-
-
- Back
-
- {/*
- Download
-
- */}
-
- Open
-
-
-
- Delete
-
-
-
- Are you absolutely sure?
-
- This action cannot be undone. This will permanently delete
- the pdf.
-
-
-
- Cancel
- {
- const response = await deleteDocument(props.id);
- if (response.ok) {
- toast("Pdf deleted", {
- description: "The pdf has been deleted.",
- });
- } else {
- toast("Error deleting pdf", {
- description:
- "An error occurred while deleting the pdf.",
- });
- }
- router.push(`/paperless?query=${query}`);
- }}
- >
- Continue
-
-
-
-
-
-
-
-
- );
-}
-
-export default function DocumentDetails(props: { id: number }) {
- return (
-
-
-
- );
-}
diff --git a/src/components/document-modal.tsx b/src/components/document-modal.tsx
deleted file mode 100644
index 6215b79..0000000
--- a/src/components/document-modal.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-import DocumentPreview from "@/components/document-preview";
-import { Modal } from "@/components/modal";
-
-export default function ModalDocumentPage({
- params,
-}: {
- params: { id: number };
-}) {
- return (
-
-
-
- );
-}