fix: assorted updates

This commit is contained in:
Mythie
2023-09-25 11:17:59 +10:00
parent 0e486c7b58
commit 1536634fc6
6 changed files with 14 additions and 14 deletions

View File

@ -1,8 +1,9 @@
import { notFound } from 'next/navigation'; import { notFound } from 'next/navigation';
import { getDocumentAndRecipientByToken } from '@documenso/lib/server-only/document/get-document-by-token'; import { getDocumentAndRecipientByToken } from '@documenso/lib/server-only/document/get-document-by-token';
import { DocumentStatus } from '@documenso/prisma/client';
import SinglePlayerModeSuccess from '~/components/(marketing)/single-player-mode/single-player-mode-success'; import { SinglePlayerModeSuccess } from '~/components/(marketing)/single-player-mode/single-player-mode-success';
export type SinglePlayerModeSuccessPageProps = { export type SinglePlayerModeSuccessPageProps = {
params: { params: {
@ -21,7 +22,7 @@ export default async function SinglePlayerModeSuccessPage({
token, token,
}).catch(() => null); }).catch(() => null);
if (!document || document.status !== 'COMPLETED') { if (!document || document.status !== DocumentStatus.COMPLETED) {
return notFound(); return notFound();
} }

View File

@ -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 { base64 } from '@documenso/lib/universal/base64';
import { putFile } from '@documenso/lib/universal/upload/put-file'; 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';
@ -155,7 +156,7 @@ export default function SinglePlayerModePage() {
const onFileDrop = async (file: File) => { const onFileDrop = async (file: File) => {
try { try {
const arrayBuffer = await file.arrayBuffer(); const arrayBuffer = await file.arrayBuffer();
const base64String = Buffer.from(arrayBuffer).toString('base64'); const base64String = base64.encode(new Uint8Array(arrayBuffer));
setUploadedFile({ setUploadedFile({
file, file,

View File

@ -3,7 +3,6 @@
import { createElement } from 'react'; import { createElement } from 'react';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import { nanoid } from 'nanoid';
import { PDFDocument } from 'pdf-lib'; import { PDFDocument } from 'pdf-lib';
import { match } from 'ts-pattern'; import { match } from 'ts-pattern';
import { z } from 'zod'; import { z } from 'zod';
@ -13,6 +12,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 { alphaid } from '@documenso/lib/universal/id';
import { getFile } from '@documenso/lib/universal/upload/get-file'; import { getFile } from '@documenso/lib/universal/upload/get-file';
import { prisma } from '@documenso/prisma'; import { prisma } from '@documenso/prisma';
import { import {
@ -101,7 +101,7 @@ export const createSinglePlayerDocument = async (
const documentToken = await prisma.$transaction( const documentToken = await prisma.$transaction(
async (tx) => { async (tx) => {
const documentToken = nanoid(); const documentToken = alphaid();
// Fetch service user who will be the owner of the document. // Fetch service user who will be the owner of the document.
const serviceUser = await tx.user.findFirstOrThrow({ const serviceUser = await tx.user.findFirstOrThrow({
@ -179,7 +179,7 @@ export const createSinglePlayerDocument = async (
// Todo: Handle `downloadLink` // Todo: Handle `downloadLink`
const template = createElement(DocumentSelfSignedEmailTemplate, { const template = createElement(DocumentSelfSignedEmailTemplate, {
downloadLink: 'https://documenso.com', downloadLink: `${process.env.NEXT_PUBLIC_MARKETING_URL}/single-player-mode/${documentToken}`,
documentName: documentName, documentName: documentName,
assetBaseUrl: process.env.NEXT_PUBLIC_WEBAPP_URL || 'http://localhost:3000', assetBaseUrl: process.env.NEXT_PUBLIC_WEBAPP_URL || 'http://localhost:3000',
}); });

View File

@ -26,10 +26,7 @@ interface SinglePlayerModeSuccessProps {
document: DocumentWithRecipient; document: DocumentWithRecipient;
} }
export default function SinglePlayerModeSuccess({ export const SinglePlayerModeSuccess = ({ className, document }: SinglePlayerModeSuccessProps) => {
className,
document,
}: SinglePlayerModeSuccessProps) {
const { getFlag } = useFeatureFlags(); const { getFlag } = useFeatureFlags();
const isConfettiEnabled = getFlag('marketing_spm_confetti'); const isConfettiEnabled = getFlag('marketing_spm_confetti');
@ -40,7 +37,7 @@ export default function SinglePlayerModeSuccess({
const { toast } = useToast(); const { toast } = useToast();
const handleShowDocumentDialog = async () => { const onShowDocumentClick = async () => {
if (isFetchingDocumentFile) { if (isFetchingDocumentFile) {
return; return;
} }
@ -103,7 +100,7 @@ export default function SinglePlayerModeSuccess({
/> />
<Button <Button
onClick={async () => handleShowDocumentDialog()} onClick={async () => onShowDocumentClick()}
loading={isFetchingDocumentFile} loading={isFetchingDocumentFile}
className="col-span-2" className="col-span-2"
> >
@ -132,4 +129,4 @@ export default function SinglePlayerModeSuccess({
/> />
</div> </div>
); );
} };

View File

@ -0,0 +1 @@
export * from '@scure/base';

View File

@ -1,5 +1,5 @@
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
export const alphaid = customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 10); export const alphaid = customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 21);
export { nanoid } from 'nanoid'; export { nanoid } from 'nanoid';