diff --git a/apps/remix/app/components/dialogs/envelope-download-dialog.tsx b/apps/remix/app/components/dialogs/envelope-download-dialog.tsx index eb046ac446..811827f3f6 100644 --- a/apps/remix/app/components/dialogs/envelope-download-dialog.tsx +++ b/apps/remix/app/components/dialogs/envelope-download-dialog.tsx @@ -5,6 +5,7 @@ import { Trans } from '@lingui/react/macro'; import { DocumentStatus, type EnvelopeItem } from '@prisma/client'; import { DownloadIcon, FileTextIcon } from 'lucide-react'; +import { downloadEnvelopeZip } from '@documenso/lib/client-only/download-envelope-zip'; import { downloadPDF } from '@documenso/lib/client-only/download-pdf'; import { trpc } from '@documenso/trpc/react'; import { Button } from '@documenso/ui/primitives/button'; @@ -28,6 +29,11 @@ type EnvelopeDownloadDialogProps = { envelopeStatus: DocumentStatus; envelopeItems?: EnvelopeItemToDownload[]; + /** + * The envelope title, used to name the "download all" ZIP archive. + */ + envelopeTitle?: string; + /** * The recipient token to download the document. * @@ -48,6 +54,7 @@ export const EnvelopeDownloadDialog = ({ envelopeId, envelopeStatus, envelopeItems: initialEnvelopeItems, + envelopeTitle, token, canDownloadPartial = false, trigger, @@ -61,6 +68,8 @@ export const EnvelopeDownloadDialog = ({ [envelopeItemIdAndVersion: string]: boolean; }>({}); + const [isDownloadingAll, setIsDownloadingAll] = useState(false); + const generateDownloadKey = (envelopeItemId: string, version: DownloadVersion) => `${envelopeItemId}-${version}`; @@ -121,6 +130,34 @@ export const EnvelopeDownloadDialog = ({ } }; + const onDownloadAll = async () => { + if (isDownloadingAll) { + return; + } + + setIsDownloadingAll(true); + + try { + await downloadEnvelopeZip({ + envelopeId, + token, + fileName: envelopeTitle, + version: envelopeStatus === DocumentStatus.COMPLETED ? 'signed' : 'original', + }); + } catch (error) { + console.error(error); + + toast({ + title: t`Something went wrong`, + description: t`These documents could not be downloaded at this time. Please try again.`, + variant: 'destructive', + duration: 7500, + }); + } finally { + setIsDownloadingAll(false); + } + }; + return ( setOpen(value)}> {trigger} @@ -135,7 +172,20 @@ export const EnvelopeDownloadDialog = ({ -
+ {!isLoadingEnvelopeItems && envelopeItems.length > 1 && ( +
+

+ {t`${envelopeItems.length} documents`} +

+ + +
+ )} + +
{isLoadingEnvelopeItems ? ( <> {Array.from({ length: 1 }).map((_, index) => ( diff --git a/apps/remix/app/components/general/document/document-page-view-button.tsx b/apps/remix/app/components/general/document/document-page-view-button.tsx index e3e7e0afc2..9864d34a6f 100644 --- a/apps/remix/app/components/general/document/document-page-view-button.tsx +++ b/apps/remix/app/components/general/document/document-page-view-button.tsx @@ -74,6 +74,7 @@ export const DocumentPageViewButton = ({ envelope }: DocumentPageViewButtonProps envelopeId={envelope.id} envelopeStatus={envelope.status} envelopeItems={envelope.envelopeItems} + envelopeTitle={envelope.title} token={recipient?.token} trigger={