mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 08:42:12 +10:00
feat: utilise transport layer
This commit is contained in:
@ -6,6 +6,7 @@ import Link from 'next/link';
|
|||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { useAnalytics } from '@documenso/lib/client-only/hooks/use-analytics';
|
import { useAnalytics } from '@documenso/lib/client-only/hooks/use-analytics';
|
||||||
|
import { putFile } from '@documenso/lib/universal/upload/put-file';
|
||||||
import { Field, Prisma, Recipient } from '@documenso/prisma/client';
|
import { Field, Prisma, Recipient } from '@documenso/prisma/client';
|
||||||
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
||||||
import { DocumentDropzone } from '@documenso/ui/primitives/document-dropzone';
|
import { DocumentDropzone } from '@documenso/ui/primitives/document-dropzone';
|
||||||
@ -31,7 +32,7 @@ export default function SinglePlayerModePage() {
|
|||||||
|
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
const [uploadedFile, setUploadedFile] = useState<{ name: string; file: string } | null>();
|
const [uploadedFile, setUploadedFile] = useState<{ file: File; fileBase64: string } | null>();
|
||||||
|
|
||||||
const [step, setStep] = useState<SinglePlayerModeStep>('fields');
|
const [step, setStep] = useState<SinglePlayerModeStep>('fields');
|
||||||
const [fields, setFields] = useState<Field[]>([]);
|
const [fields, setFields] = useState<Field[]>([]);
|
||||||
@ -97,7 +98,7 @@ export default function SinglePlayerModePage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create, sign and send the document.
|
* Upload, create, sign and send the document.
|
||||||
*/
|
*/
|
||||||
const onSignSubmit = async (data: TAddSignatureFormSchema) => {
|
const onSignSubmit = async (data: TAddSignatureFormSchema) => {
|
||||||
if (!uploadedFile) {
|
if (!uploadedFile) {
|
||||||
@ -105,9 +106,14 @@ export default function SinglePlayerModePage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const putFileData = await putFile(uploadedFile.file);
|
||||||
|
|
||||||
const documentToken = await createSinglePlayerDocument({
|
const documentToken = await createSinglePlayerDocument({
|
||||||
document: uploadedFile.file,
|
documentData: {
|
||||||
documentName: uploadedFile.name,
|
type: putFileData.type,
|
||||||
|
data: putFileData.data,
|
||||||
|
},
|
||||||
|
documentName: uploadedFile.file.name,
|
||||||
signer: data,
|
signer: data,
|
||||||
fields: fields.map((field) => ({
|
fields: fields.map((field) => ({
|
||||||
page: field.page,
|
page: field.page,
|
||||||
@ -152,8 +158,8 @@ export default function SinglePlayerModePage() {
|
|||||||
const base64String = Buffer.from(arrayBuffer).toString('base64');
|
const base64String = Buffer.from(arrayBuffer).toString('base64');
|
||||||
|
|
||||||
setUploadedFile({
|
setUploadedFile({
|
||||||
name: file.name,
|
file,
|
||||||
file: `data:application/pdf;base64,${base64String}`,
|
fileBase64: `data:application/pdf;base64,${base64String}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
analytics.capture('Marketing: SPM - Document uploaded');
|
analytics.capture('Marketing: SPM - Document uploaded');
|
||||||
@ -189,7 +195,7 @@ export default function SinglePlayerModePage() {
|
|||||||
{uploadedFile ? (
|
{uploadedFile ? (
|
||||||
<Card gradient>
|
<Card gradient>
|
||||||
<CardContent className="p-2">
|
<CardContent className="p-2">
|
||||||
<LazyPDFViewer document={uploadedFile.file} />
|
<LazyPDFViewer document={uploadedFile.fileBase64} />
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import { render } from '@documenso/email/render';
|
|||||||
import { DocumentSelfSignedEmailTemplate } from '@documenso/email/templates/document-self-signed';
|
import { DocumentSelfSignedEmailTemplate } from '@documenso/email/templates/document-self-signed';
|
||||||
import { FROM_ADDRESS, FROM_NAME, SERVICE_USER_EMAIL } from '@documenso/lib/constants/email';
|
import { FROM_ADDRESS, FROM_NAME, SERVICE_USER_EMAIL } from '@documenso/lib/constants/email';
|
||||||
import { insertFieldInPDF } from '@documenso/lib/server-only/pdf/insert-field-in-pdf';
|
import { insertFieldInPDF } from '@documenso/lib/server-only/pdf/insert-field-in-pdf';
|
||||||
|
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import {
|
import {
|
||||||
DocumentDataType,
|
DocumentDataType,
|
||||||
@ -25,7 +26,10 @@ import {
|
|||||||
} from '@documenso/prisma/client';
|
} from '@documenso/prisma/client';
|
||||||
|
|
||||||
const ZCreateSinglePlayerDocumentSchema = z.object({
|
const ZCreateSinglePlayerDocumentSchema = z.object({
|
||||||
document: z.string(),
|
documentData: z.object({
|
||||||
|
data: z.string(),
|
||||||
|
type: z.nativeEnum(DocumentDataType),
|
||||||
|
}),
|
||||||
documentName: z.string(),
|
documentName: z.string(),
|
||||||
signer: z.object({
|
signer: z.object({
|
||||||
email: z.string().email().min(1),
|
email: z.string().email().min(1),
|
||||||
@ -54,7 +58,13 @@ export type TCreateSinglePlayerDocumentSchema = z.infer<typeof ZCreateSinglePlay
|
|||||||
export const createSinglePlayerDocument = async (
|
export const createSinglePlayerDocument = async (
|
||||||
value: TCreateSinglePlayerDocumentSchema,
|
value: TCreateSinglePlayerDocumentSchema,
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
const { signer, fields, document, documentName } = ZCreateSinglePlayerDocumentSchema.parse(value);
|
const { signer, fields, documentData, documentName } =
|
||||||
|
ZCreateSinglePlayerDocumentSchema.parse(value);
|
||||||
|
|
||||||
|
const document = await getFile({
|
||||||
|
data: documentData.data,
|
||||||
|
type: documentData.type,
|
||||||
|
});
|
||||||
|
|
||||||
const doc = await PDFDocument.load(document);
|
const doc = await PDFDocument.load(document);
|
||||||
const createdAt = new Date();
|
const createdAt = new Date();
|
||||||
|
|||||||
Reference in New Issue
Block a user