Skip to content

The Open Source DocuSign Alternative.

fix: implement feedback

Mythie0835da45ef81
diff --git a/apps/web/src/app/(dashboard)/documents/[id]/page.tsx b/apps/web/src/app/(dashboard)/documents/[id]/page.tsx
index 915547607..3d6dbb954 100644
--- a/apps/web/src/app/(dashboard)/documents/[id]/page.tsx
+++ b/apps/web/src/app/(dashboard)/documents/[id]/page.tsx
@@ -47,8 +47,6 @@ export default async function DocumentPage({ params }: DocumentPageProps) {
.then((buffer) => Buffer.from(buffer).toString('base64'))
.then((data) => `data:application/pdf;base64,${data}`);
- console.log({ documentDataUrl: documentDataUrl.slice(0, 40) });
-
const [recipients, fields] = await Promise.all([
await getRecipientsForDocument({
documentId,
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 02e3ad95c..dd028e0b2 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
@@ -14,15 +14,9 @@ import {
XCircle,
} from 'lucide-react';
import { useSession } from 'next-auth/react';
-import { match } from 'ts-pattern';
-import {
- Document,
- DocumentDataType,
- DocumentStatus,
- Recipient,
- User,
-} from '@documenso/prisma/client';
+import { getFile } from '@documenso/lib/universal/upload/get-file';
+import { Document, DocumentStatus, Recipient, User } from '@documenso/prisma/client';
import { DocumentWithData } from '@documenso/prisma/types/document-with-data';
import { trpc } from '@documenso/trpc/client';
import {
@@ -75,23 +69,7 @@ export const DataTableActionDropdown = ({ row }: DataTableActionDropdownProps) =
return;
}
- const documentBytes = await match(documentData.type)
- .with(DocumentDataType.BYTES, () =>
- Uint8Array.from(documentData.data, (c) => c.charCodeAt(0)),
- )
- .with(DocumentDataType.BYTES_64, () =>
- Uint8Array.from(
- atob(documentData.data)
- .split('')
- .map((c) => c.charCodeAt(0)),
- ),
- )
- .with(DocumentDataType.S3_PATH, async () =>
- fetch(documentData.data)
- .then(async (res) => res.arrayBuffer())
- .then((buffer) => new Uint8Array(buffer)),
- )
- .exhaustive();
+ const documentBytes = await getFile(documentData);
const blob = new Blob([documentBytes], {
type: 'application/pdf',
diff --git a/apps/web/src/app/(signing)/sign/[token]/complete/download-button.tsx b/apps/web/src/app/(signing)/sign/[token]/complete/download-button.tsx
index 088afad33..49b7a8f15 100644
--- a/apps/web/src/app/(signing)/sign/[token]/complete/download-button.tsx
+++ b/apps/web/src/app/(signing)/sign/[token]/complete/download-button.tsx
@@ -7,6 +7,7 @@ import { Download } from 'lucide-react';
import { getFile } from '@documenso/lib/universal/upload/get-file';
import { DocumentData } from '@documenso/prisma/client';
import { Button } from '@documenso/ui/primitives/button';
+import { useToast } from '@documenso/ui/primitives/use-toast';
export type DownloadButtonProps = HTMLAttributes<HTMLButtonElement> & {
disabled?: boolean;
@@ -21,6 +22,8 @@ export const DownloadButton = ({
disabled,
...props
}: DownloadButtonProps) => {
+ const { toast } = useToast();
+
const [isLoading, setIsLoading] = useState(false);
const onDownloadClick = async () => {
@@ -47,6 +50,12 @@ export const DownloadButton = ({
window.URL.revokeObjectURL(link.href);
} catch (err) {
console.error(err);
+
+ toast({
+ title: 'Error',
+ description: 'An error occurred while downloading your document.',
+ variant: 'destructive',
+ });
} finally {
setIsLoading(false);
}
diff --git a/packages/lib/universal/upload/get-file.ts b/packages/lib/universal/upload/get-file.ts
index 2c71c3774..10e624aaf 100644
--- a/packages/lib/universal/upload/get-file.ts
+++ b/packages/lib/universal/upload/get-file.ts
@@ -35,9 +35,15 @@ const getFileFromBytes64 = (data: string) => {
const getFileFromS3 = async (key: string) => {
const { url } = await getPresignGetUrl(key);
- const buffer = await fetch(url, {
+ const response = await fetch(url, {
method: 'GET',
- }).then(async (res) => res.arrayBuffer());
+ });
+
+ if (!response.ok) {
+ throw new Error(`Failed to get file "${key}", failed with status code ${response.status}`);
+ }
+
+ const buffer = await response.arrayBuffer();
const binaryData = new Uint8Array(buffer);
diff --git a/packages/lib/universal/upload/put-file.ts b/packages/lib/universal/upload/put-file.ts
index ccfa96e7b..56ed8eb07 100644
--- a/packages/lib/universal/upload/put-file.ts
+++ b/packages/lib/universal/upload/put-file.ts
@@ -38,7 +38,7 @@ const putFileInS3 = async (file: File) => {
const body = await file.arrayBuffer();
- await fetch(url, {
+ const reponse = await fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/octet-stream',
@@ -46,6 +46,12 @@ const putFileInS3 = async (file: File) => {
body,
});
+ if (!reponse.ok) {
+ throw new Error(
+ `Failed to upload file "${file.name}", failed with status code ${reponse.status}`,
+ );
+ }
+
return {
type: DocumentDataType.S3_PATH,
data: key,
diff --git a/packages/lib/universal/upload/update-file.ts b/packages/lib/universal/upload/update-file.ts
index a7a227bab..e06a8fa5f 100644
--- a/packages/lib/universal/upload/update-file.ts
+++ b/packages/lib/universal/upload/update-file.ts
@@ -42,11 +42,15 @@ const updateFileWithBytes64 = (data: string) => {
const updateFileWithS3 = async (key: string, data: string) => {
const { url } = await getAbsolutePresignPostUrl(key);
- await fetch(url, {
+ const response = await fetch(url, {
method: 'PUT',
body: data,
});
+ if (!response.ok) {
+ throw new Error(`Failed to update file "${key}", failed with status code ${response.status}`);
+ }
+
return {
type: DocumentDataType.S3_PATH,
data: key,
diff --git a/packages/prisma/migrations/20230907080056_add_created_at_and_updated_at_columns/migration.sql b/packages/prisma/migrations/20230907080056_add_created_at_and_updated_at_columns/migration.sql
index 371181e80..3d30cb4e1 100644
--- a/packages/prisma/migrations/20230907080056_add_created_at_and_updated_at_columns/migration.sql
+++ b/packages/prisma/migrations/20230907080056_add_created_at_and_updated_at_columns/migration.sql
@@ -1,5 +1,7 @@
-- AlterTable
ALTER TABLE "Document" ADD COLUMN "createdAt" TIMESTAMP(3);
+
+-- AlterTable
ALTER TABLE "Document" ADD COLUMN "updatedAt" TIMESTAMP(3);
-- DefaultValues
@@ -9,5 +11,9 @@ SET
"updatedAt" = COALESCE("created"::TIMESTAMP, NOW());
-- AlterColumn
-ALTER TABLE "Document" ALTER COLUMN "createdAt" SET NOT NULL DEFAULT NOW();
-ALTER TABLE "Document" ALTER COLUMN "updatedAt" SET NOT NULL DEFAULT NOW();
+ALTER TABLE "Document" ALTER COLUMN "createdAt" SET DEFAULT NOW();
+ALTER TABLE "Document" ALTER COLUMN "createdAt" SET NOT NULL;
+
+-- AlterColumn
+ALTER TABLE "Document" ALTER COLUMN "updatedAt" SET DEFAULT NOW();
+ALTER TABLE "Document" ALTER COLUMN "updatedAt" SET NOT NULL;
diff --git a/packages/prisma/migrations/20230914031347_remove_redundant_created_column/migration.sql b/packages/prisma/migrations/20230914031347_remove_redundant_created_column/migration.sql
new file mode 100644
index 000000000..79902a8e7
--- /dev/null
+++ b/packages/prisma/migrations/20230914031347_remove_redundant_created_column/migration.sql
@@ -0,0 +1,8 @@
+/*
+ Warnings:
+
+ - You are about to drop the column `created` on the `Document` table. All the data in the column will be lost.
+
+*/
+-- AlterTable
+ALTER TABLE "Document" DROP COLUMN "created";
diff --git a/packages/prisma/schema.prisma b/packages/prisma/schema.prisma
index 7e6aa29cf..e80701404 100644
--- a/packages/prisma/schema.prisma
+++ b/packages/prisma/schema.prisma
@@ -92,7 +92,6 @@ enum DocumentStatus {
model Document {
id Int @id @default(autoincrement())
- created DateTime @default(now())
userId Int
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
title String