diff --git a/client/src/app/quotes/components/PDFGenerationLoading.tsx b/client/src/app/quotes/components/PDFGenerationLoading.tsx new file mode 100644 index 0000000..a6ec238 --- /dev/null +++ b/client/src/app/quotes/components/PDFGenerationLoading.tsx @@ -0,0 +1,77 @@ +"use client"; + +import { ErrorMessage } from "@/lib/hooks/useDownloader/types"; +import { cn } from "@/lib/utils"; +import { Button, Card, CardContent, CardHeader, CardTitle, Progress } from "@/ui"; +import { FileText, Loader2, XCircleIcon } from "lucide-react"; +import { useEffect, useState } from "react"; + +interface PDFGenerationLoadingProps { + className?: string; + isInProgress: boolean; + percentage: number; + elapsed: number; + cancel: () => void; + error: ErrorMessage; +} + +export const PDFGenerationLoading = ({ + isInProgress, + percentage, + elapsed, + cancel, + error, + className, +}: PDFGenerationLoadingProps) => { + const [estimatedTime, setEstimatedTime] = useState(10); + + useEffect(() => { + if (isInProgress && percentage > 0) { + const estimatedTotal = (elapsed / percentage) * 100; + setEstimatedTime(Math.max(0, Math.round(estimatedTotal - elapsed))); + } + }, [isInProgress, percentage, elapsed]); + + if (!isInProgress && !error?.errorMessage) return null; + + return ( + + + + {error?.errorMessage ? "Error en la generación del PDF" : "Generando PDF"} + {isInProgress && } + {error?.errorMessage && } + + + + {error?.errorMessage ? ( +
{error?.errorMessage}
+ ) : ( +
+
+
+ +
+ +
+

Progreso: {percentage}%

+
+

Tiempo transcurrido: {elapsed} segundos

+ {estimatedTime > 0 &&

Tiempo estimado restante: {estimatedTime} segundos

} +
+
+ +
+ )} + + + ); +}; diff --git a/client/src/app/quotes/components/QuotePDFPreview.tsx b/client/src/app/quotes/components/QuotePDFPreview.tsx index 9c1cde1..b2a8b1b 100644 --- a/client/src/app/quotes/components/QuotePDFPreview.tsx +++ b/client/src/app/quotes/components/QuotePDFPreview.tsx @@ -1,9 +1,10 @@ import { PDFViewer } from "@/components"; import { cn } from "@/lib/utils"; -import { Card, CardContent, CardHeader, Skeleton } from "@/ui"; +import { Card, CardContent } from "@/ui"; import { IListQuotes_Response_DTO } from "@shared/contexts"; import { useCallback, useEffect, useState } from "react"; import { useQuotes } from "../hooks"; +import { PDFGenerationLoading } from "./PDFGenerationLoading"; const QuotePDFPreview = ({ quote, @@ -16,7 +17,7 @@ const QuotePDFPreview = ({ //const { toast } = useToast(); const { useReport, getQuotePDFFilename, useDownloader } = useQuotes(); const { download } = useDownloader(); - const { report, preview, isInProgress } = useReport(); + const { report, preview, isInProgress, ...otherReportProps } = useReport(); const [URLReport, setURLReport] = useState(undefined); /*const handleFinishDownload = useCallback(() => { @@ -66,17 +67,7 @@ const QuotePDFPreview = ({ } if (isInProgress) { - return ( - - - - - - - - - - ); + return ; } return (