From 06714a2aeb9e1a712d8e7df8ee79d8263aa69c1e Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan <55143799+dephraiim@users.noreply.github.com> Date: Fri, 17 Nov 2023 01:02:22 +0000 Subject: [PATCH] chore: append _signed to files when downloading (#656) --- .../(dashboard)/documents/data-table-action-button.tsx | 3 ++- .../(dashboard)/documents/data-table-action-dropdown.tsx | 3 ++- .../ui/components/document/document-download-button.tsx | 8 +++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/web/src/app/(dashboard)/documents/data-table-action-button.tsx b/apps/web/src/app/(dashboard)/documents/data-table-action-button.tsx index 17b577c13..4e63c4475 100644 --- a/apps/web/src/app/(dashboard)/documents/data-table-action-button.tsx +++ b/apps/web/src/app/(dashboard)/documents/data-table-action-button.tsx @@ -62,9 +62,10 @@ export const DataTableActionButton = ({ row }: DataTableActionButtonProps) => { }); const link = window.document.createElement('a'); + const baseTitle = row.title.includes('.pdf') ? row.title.split('.pdf')[0] : row.title; link.href = window.URL.createObjectURL(blob); - link.download = row.title || 'document.pdf'; + link.download = baseTitle ? `${baseTitle}_signed.pdf` : 'document.pdf'; link.click(); diff --git a/apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx b/apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx index 11636c016..c3e1f971c 100644 --- a/apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx +++ b/apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx @@ -88,9 +88,10 @@ export const DataTableActionDropdown = ({ row }: DataTableActionDropdownProps) = }); const link = window.document.createElement('a'); + const baseTitle = row.title.includes('.pdf') ? row.title.split('.pdf')[0] : row.title; link.href = window.URL.createObjectURL(blob); - link.download = row.title || 'document.pdf'; + link.download = baseTitle ? `${baseTitle}_signed.pdf` : 'document.pdf'; link.click(); diff --git a/packages/ui/components/document/document-download-button.tsx b/packages/ui/components/document/document-download-button.tsx index d9a4c58e2..e16d236f0 100644 --- a/packages/ui/components/document/document-download-button.tsx +++ b/packages/ui/components/document/document-download-button.tsx @@ -1,11 +1,12 @@ 'use client'; -import { HTMLAttributes, useState } from 'react'; +import type { HTMLAttributes } from 'react'; +import { useState } from 'react'; import { Download } from 'lucide-react'; import { getFile } from '@documenso/lib/universal/upload/get-file'; -import { DocumentData } from '@documenso/prisma/client'; +import type { DocumentData } from '@documenso/prisma/client'; import { Button } from '@documenso/ui/primitives/button'; import { useToast } from '@documenso/ui/primitives/use-toast'; @@ -41,9 +42,10 @@ export const DocumentDownloadButton = ({ }); const link = window.document.createElement('a'); + const baseTitle = fileName?.includes('.pdf') ? fileName.split('.pdf')[0] : fileName; link.href = window.URL.createObjectURL(blob); - link.download = fileName || 'document.pdf'; + link.download = baseTitle ? `${baseTitle}_signed.pdf` : 'document.pdf'; link.click();