From b97f51206e9cbac4d67b30261035043438e20278 Mon Sep 17 00:00:00 2001 From: David Arranz Date: Wed, 21 Aug 2024 11:30:47 +0200 Subject: [PATCH] . --- .../quotes/components/DownloadQuoteDialog.tsx | 66 +++++++++++++++++++ .../app/quotes/components/QuotesDataTable.tsx | 16 +++-- .../DownloadDialog/DownloadDialog.tsx | 44 ------------- client/src/components/DownloadDialog/index.ts | 1 - client/src/components/index.ts | 1 - client/src/locales/en.json | 12 ++++ client/src/locales/es.json | 12 ++++ 7 files changed, 102 insertions(+), 50 deletions(-) create mode 100644 client/src/app/quotes/components/DownloadQuoteDialog.tsx delete mode 100644 client/src/components/DownloadDialog/DownloadDialog.tsx delete mode 100644 client/src/components/DownloadDialog/index.ts diff --git a/client/src/app/quotes/components/DownloadQuoteDialog.tsx b/client/src/app/quotes/components/DownloadQuoteDialog.tsx new file mode 100644 index 0000000..41b2329 --- /dev/null +++ b/client/src/app/quotes/components/DownloadQuoteDialog.tsx @@ -0,0 +1,66 @@ +import { + Button, + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + Label, + Progress, +} from "@/ui"; +import { t } from "i18next"; +import { useEffect } from "react"; +import { UseDownloader } from "react-use-downloader/dist/types"; + +type DownloadQuoteDialogProps = Omit & { + onFinishDownload: () => void; +}; + +export const DownloadQuoteDialog = (props: DownloadQuoteDialogProps) => { + const { percentage, cancel, error, isInProgress, onFinishDownload } = props; + + useEffect(() => { + if (!isInProgress && !error && percentage === 100) { + if (onFinishDownload) { + onFinishDownload(); + } + } + }, [percentage, isInProgress, error, onFinishDownload]); + + return ( + + + + {t("quotes.downloading_dialog.title")} + {t("quotes.downloading_dialog.description")} + +
+ + t("quotes.downloading_dialog.progress.label", {})} + /> + {error &&

Error: {JSON.stringify(error)}

} +
+ + + + + +
+
+ ); +}; diff --git a/client/src/app/quotes/components/QuotesDataTable.tsx b/client/src/app/quotes/components/QuotesDataTable.tsx index 756cb9c..e11fe97 100644 --- a/client/src/app/quotes/components/QuotesDataTable.tsx +++ b/client/src/app/quotes/components/QuotesDataTable.tsx @@ -2,7 +2,6 @@ import { ColorBadge, DataTable, DataTableSkeleton, - DownloadDialog, ErrorOverlay, SimpleEmptyState, } from "@/components"; @@ -24,14 +23,16 @@ import { TooltipContent, TooltipTrigger, } from "@/ui"; +import { useToast } from "@/ui/use-toast"; import { IListQuotes_Response_DTO, MoneyValue, UTCDateValue } from "@shared/contexts"; import { ColumnDef, Row } from "@tanstack/react-table"; import { t } from "i18next"; import { FilePenLineIcon, MoreVerticalIcon } from "lucide-react"; -import { useEffect, useMemo, useState } from "react"; +import { useCallback, useEffect, useMemo, useState } from "react"; import { useNavigate } from "react-router-dom"; import useDownloader from "react-use-downloader"; import { useQuotes } from "../hooks"; +import { DownloadQuoteDialog } from "./DownloadQuoteDialog"; import { QuotePDFPreview } from "./QuotePDFPreview"; export const QuotesDataTable = ({ @@ -42,6 +43,7 @@ export const QuotesDataTable = ({ preview?: boolean; }) => { const navigate = useNavigate(); + const { toast } = useToast(); const { pagination, globalFilter, isFiltered } = useDataTableContext(); const [activeRow, setActiveRow] = useState | undefined>(undefined); @@ -164,7 +166,6 @@ export const QuotesDataTable = ({ Edit { - e.preventDefault(); download(row.original.id, getQuotePDFFilename(row.original)); }} > @@ -204,6 +205,13 @@ export const QuotesDataTable = ({ } }, [data, table]); + const handleFinishDownload = useCallback(() => { + console.log("Download success!!"); + toast({ + description: t("quotes.downloading_dialog.toast_success"), + }); + }, [toast]); + if (isError) { return ; } @@ -258,7 +266,7 @@ export const QuotesDataTable = ({ )} - + ); }; diff --git a/client/src/components/DownloadDialog/DownloadDialog.tsx b/client/src/components/DownloadDialog/DownloadDialog.tsx deleted file mode 100644 index b2a7e29..0000000 --- a/client/src/components/DownloadDialog/DownloadDialog.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import { - Button, - Dialog, - DialogClose, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, - Label, -} from "@/ui"; -import { UseDownloader } from "react-use-downloader/dist/types"; - -export const DownloadDialog = (props: Omit) => { - const { size, elapsed, percentage, cancel, error, isInProgress } = props; - - return ( - - - - Share link - Anyone who has this link will be able to view this. - -
-

Download is in {isInProgress ? "in progress" : "stopped"}

- - -

Download size in bytes {size}

- - -

Elapsed time in seconds {elapsed}

- {error &&

possible error {JSON.stringify(error)}

} -
- - - - - -
-
- ); -}; diff --git a/client/src/components/DownloadDialog/index.ts b/client/src/components/DownloadDialog/index.ts deleted file mode 100644 index 6c079a3..0000000 --- a/client/src/components/DownloadDialog/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./DownloadDialog"; diff --git a/client/src/components/index.ts b/client/src/components/index.ts index 45c4c6b..ce9e226 100644 --- a/client/src/components/index.ts +++ b/client/src/components/index.ts @@ -5,7 +5,6 @@ export * from "./Container"; export * from "./CustomButtons"; export * from "./CustomDialog"; export * from "./DataTable"; -export * from "./DownloadDialog"; export * from "./EmptyState"; export * from "./ErrorOverlay"; export * from "./Forms"; diff --git a/client/src/locales/en.json b/client/src/locales/en.json index 2a568dd..36ee66d 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -161,6 +161,18 @@ "edit": { "title": "Quote" }, + "downloading_dialog": { + "title": "Downloading quote", + "description": "Please wait while your quotation is generated and downloaded in PDF format...", + "progress": { + "label": "Download is in {{status}}", + "status_in_progress": "in progress", + "status_stopped": "stopped", + "value_label": "Elapsed time in seconds {{elapsed}}" + }, + "cancel_button": "Cancel the download", + "toast_success": "Quote downloaded" + }, "status": { "draft": "Draft" }, diff --git a/client/src/locales/es.json b/client/src/locales/es.json index c5a4636..c4a6ff4 100644 --- a/client/src/locales/es.json +++ b/client/src/locales/es.json @@ -158,6 +158,18 @@ "edit": { "title": "Cotización" }, + "downloading_dialog": { + "title": "Descargando cotización", + "description": "Espere mientras se genera la cotización y se descarga en formato PDF...", + "progress": { + "label": "La descarga está {{status}}", + "status_in_progress": "en marcha", + "status_stopped": "parada", + "value_label": "Elapsed time in seconds {{elapsed}}" + }, + "cancel_button": "Cancelar la descarga", + "toast_success": "Quote downloaded" + }, "status": { "draft": "Borrador" },