fix: implement feedback

This commit is contained in:
Mythie
2023-09-14 13:21:03 +10:00
parent 6c12ed4afc
commit 2356f58e7b
9 changed files with 48 additions and 34 deletions

View File

@ -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,

View File

@ -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',

View File

@ -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);
}