mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
Merge branch 'main' of https://github.com/documenso/documenso into feat/publicProfile
This commit is contained in:
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -41,7 +41,7 @@ jobs:
|
|||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Cache Docker layers
|
- name: Cache Docker layers
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: /tmp/.buildx-cache
|
path: /tmp/.buildx-cache
|
||||||
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
||||||
|
|||||||
4
.github/workflows/codeql-analysis.yml
vendored
4
.github/workflows/codeql-analysis.yml
vendored
@ -33,9 +33,9 @@ jobs:
|
|||||||
- uses: ./.github/actions/cache-build
|
- uses: ./.github/actions/cache-build
|
||||||
|
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v2
|
uses: github/codeql-action/init@v3
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v2
|
uses: github/codeql-action/analyze@v3
|
||||||
|
|||||||
2
.github/workflows/e2e-tests.yml
vendored
2
.github/workflows/e2e-tests.yml
vendored
@ -33,7 +33,7 @@ jobs:
|
|||||||
- name: Run Playwright tests
|
- name: Run Playwright tests
|
||||||
run: npm run ci
|
run: npm run ci
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
- uses: actions/upload-artifact@v4
|
||||||
if: always()
|
if: always()
|
||||||
with:
|
with:
|
||||||
name: test-results
|
name: test-results
|
||||||
|
|||||||
2
.github/workflows/issue-assignee-check.yml
vendored
2
.github/workflows/issue-assignee-check.yml
vendored
@ -27,7 +27,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Check Assigned User's Issue Count
|
- name: Check Assigned User's Issue Count
|
||||||
id: parse-comment
|
id: parse-comment
|
||||||
uses: actions/github-script@v5
|
uses: actions/github-script@v6
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
|
|||||||
25
.github/workflows/issue-labeler.yml
vendored
Normal file
25
.github/workflows/issue-labeler.yml
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
name: Auto Label Assigned Issues
|
||||||
|
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [assigned]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
label-when-assigned:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Label issue
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
with:
|
||||||
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
script: |
|
||||||
|
const issue = context.issue;
|
||||||
|
// To run only on issues and not on PR
|
||||||
|
if (github.context.payload.issue.pull_request === undefined) {
|
||||||
|
const labelResponse = await github.rest.issues.addLabels({
|
||||||
|
owner: issue.owner,
|
||||||
|
repo: issue.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
labels: ['status: assigned']
|
||||||
|
});
|
||||||
|
}
|
||||||
2
.github/workflows/issue-opened.yml
vendored
2
.github/workflows/issue-opened.yml
vendored
@ -17,5 +17,5 @@ jobs:
|
|||||||
issue_number: context.issue.number,
|
issue_number: context.issue.number,
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
labels: ["needs triage"]
|
labels: ["status: triage"]
|
||||||
})
|
})
|
||||||
|
|||||||
4
.github/workflows/pr-review-reminder.yml
vendored
4
.github/workflows/pr-review-reminder.yml
vendored
@ -2,14 +2,14 @@ name: 'PR Review Reminder'
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
types: ['opened', 'reopened', 'ready_for_review', 'review_requested']
|
types: ['opened', 'ready_for_review']
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
checkPRs:
|
checkPRs:
|
||||||
if: ${{ github.event.pull_request.user.login }} && github.event.action == ('opened' || 'reopened' || 'ready_for_review' || 'review_requested')
|
if: ${{ github.event.pull_request.user.login }} && github.event.action == ('opened' || 'ready_for_review')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
|
|||||||
2
.github/workflows/stale.yml
vendored
2
.github/workflows/stale.yml
vendored
@ -12,7 +12,7 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v4
|
- uses: actions/stale@v5
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
days-before-pr-stale: 90
|
days-before-pr-stale: 90
|
||||||
|
|||||||
@ -8,7 +8,7 @@ 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 { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||||
import { base64 } from '@documenso/lib/universal/base64';
|
import { base64 } from '@documenso/lib/universal/base64';
|
||||||
import { putFile } from '@documenso/lib/universal/upload/put-file';
|
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
||||||
import type { Field, Recipient } from '@documenso/prisma/client';
|
import type { Field, Recipient } from '@documenso/prisma/client';
|
||||||
import { DocumentDataType, Prisma } from '@documenso/prisma/client';
|
import { DocumentDataType, Prisma } from '@documenso/prisma/client';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
@ -115,7 +115,7 @@ export const SinglePlayerClient = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const putFileData = await putFile(uploadedFile.file);
|
const putFileData = await putPdfFile(uploadedFile.file);
|
||||||
|
|
||||||
const documentToken = await createSinglePlayerDocument({
|
const documentToken = await createSinglePlayerDocument({
|
||||||
documentData: {
|
documentData: {
|
||||||
|
|||||||
@ -10,8 +10,9 @@ import { useSession } from 'next-auth/react';
|
|||||||
import { useLimits } from '@documenso/ee/server-only/limits/provider/client';
|
import { useLimits } from '@documenso/ee/server-only/limits/provider/client';
|
||||||
import { useAnalytics } from '@documenso/lib/client-only/hooks/use-analytics';
|
import { useAnalytics } from '@documenso/lib/client-only/hooks/use-analytics';
|
||||||
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
||||||
|
import { AppError } from '@documenso/lib/errors/app-error';
|
||||||
import { createDocumentData } from '@documenso/lib/server-only/document-data/create-document-data';
|
import { createDocumentData } from '@documenso/lib/server-only/document-data/create-document-data';
|
||||||
import { putFile } from '@documenso/lib/universal/upload/put-file';
|
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { TRPCClientError } from '@documenso/trpc/client';
|
import { TRPCClientError } from '@documenso/trpc/client';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
@ -57,7 +58,7 @@ export const UploadDocument = ({ className, team }: UploadDocumentProps) => {
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
const { type, data } = await putFile(file);
|
const { type, data } = await putPdfFile(file);
|
||||||
|
|
||||||
const { id: documentDataId } = await createDocumentData({
|
const { id: documentDataId } = await createDocumentData({
|
||||||
type,
|
type,
|
||||||
@ -83,13 +84,21 @@ export const UploadDocument = ({ className, team }: UploadDocumentProps) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.push(`${formatDocumentsPath(team?.url)}/${id}/edit`);
|
router.push(`${formatDocumentsPath(team?.url)}/${id}/edit`);
|
||||||
} catch (error) {
|
} catch (err) {
|
||||||
console.error(error);
|
const error = AppError.parseError(err);
|
||||||
|
|
||||||
if (error instanceof TRPCClientError) {
|
console.error(err);
|
||||||
|
|
||||||
|
if (error.code === 'INVALID_DOCUMENT_FILE') {
|
||||||
|
toast({
|
||||||
|
title: 'Invalid file',
|
||||||
|
description: 'You cannot upload encrypted PDFs',
|
||||||
|
variant: 'destructive',
|
||||||
|
});
|
||||||
|
} else if (err instanceof TRPCClientError) {
|
||||||
toast({
|
toast({
|
||||||
title: 'Error',
|
title: 'Error',
|
||||||
description: error.message,
|
description: err.message,
|
||||||
variant: 'destructive',
|
variant: 'destructive',
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -141,6 +141,8 @@ export const EditTemplateForm = ({
|
|||||||
recipients={recipients}
|
recipients={recipients}
|
||||||
fields={fields}
|
fields={fields}
|
||||||
onSubmit={onAddTemplatePlaceholderFormSubmit}
|
onSubmit={onAddTemplatePlaceholderFormSubmit}
|
||||||
|
// Todo: Add when we setup template settings.
|
||||||
|
isTemplateOwnerEnterprise={false}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<AddTemplateFieldsFormPartial
|
<AddTemplateFieldsFormPartial
|
||||||
|
|||||||
@ -58,7 +58,7 @@ export const TemplatePageView = async ({ params, team }: TemplatePageViewProps)
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto max-w-screen-xl px-4 md:px-8">
|
<div className="mx-auto -mt-4 max-w-screen-xl px-4 md:px-8">
|
||||||
<Link href="/templates" className="flex items-center text-[#7AC455] hover:opacity-80">
|
<Link href="/templates" className="flex items-center text-[#7AC455] hover:opacity-80">
|
||||||
<ChevronLeft className="mr-2 inline-block h-5 w-5" />
|
<ChevronLeft className="mr-2 inline-block h-5 w-5" />
|
||||||
Templates
|
Templates
|
||||||
@ -73,7 +73,7 @@ export const TemplatePageView = async ({ params, team }: TemplatePageViewProps)
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<EditTemplateForm
|
<EditTemplateForm
|
||||||
className="mt-8"
|
className="mt-6"
|
||||||
template={template}
|
template={template}
|
||||||
user={user}
|
user={user}
|
||||||
recipients={templateRecipients}
|
recipients={templateRecipients}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import * as z from 'zod';
|
|||||||
|
|
||||||
import { createDocumentData } from '@documenso/lib/server-only/document-data/create-document-data';
|
import { createDocumentData } from '@documenso/lib/server-only/document-data/create-document-data';
|
||||||
import { base64 } from '@documenso/lib/universal/base64';
|
import { base64 } from '@documenso/lib/universal/base64';
|
||||||
import { putFile } from '@documenso/lib/universal/upload/put-file';
|
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
||||||
@ -98,7 +98,7 @@ export const NewTemplateDialog = ({ teamId, templateRootPath }: NewTemplateDialo
|
|||||||
const file: File = uploadedFile.file;
|
const file: File = uploadedFile.file;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { type, data } = await putFile(file);
|
const { type, data } = await putPdfFile(file);
|
||||||
|
|
||||||
const { id: templateDocumentDataId } = await createDocumentData({
|
const { id: templateDocumentDataId } = await createDocumentData({
|
||||||
type,
|
type,
|
||||||
|
|||||||
@ -1,14 +1,21 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { Plus } from 'lucide-react';
|
import { InfoIcon, Plus } from 'lucide-react';
|
||||||
import { Controller, useFieldArray, useForm } from 'react-hook-form';
|
import { useFieldArray, useForm } from 'react-hook-form';
|
||||||
import * as z from 'zod';
|
import * as z from 'zod';
|
||||||
|
|
||||||
|
import {
|
||||||
|
TEMPLATE_RECIPIENT_EMAIL_PLACEHOLDER_REGEX,
|
||||||
|
TEMPLATE_RECIPIENT_NAME_PLACEHOLDER_REGEX,
|
||||||
|
} from '@documenso/lib/constants/template';
|
||||||
|
import { AppError } from '@documenso/lib/errors/app-error';
|
||||||
import type { Recipient } from '@documenso/prisma/client';
|
import type { Recipient } from '@documenso/prisma/client';
|
||||||
import { RecipientRole } from '@documenso/prisma/client';
|
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
|
import { Checkbox } from '@documenso/ui/primitives/checkbox';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
@ -19,23 +26,58 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from '@documenso/ui/primitives/dialog';
|
} from '@documenso/ui/primitives/dialog';
|
||||||
import { FormErrorMessage } from '@documenso/ui/primitives/form/form-error-message';
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from '@documenso/ui/primitives/form/form';
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
import { Input } from '@documenso/ui/primitives/input';
|
||||||
import { Label } from '@documenso/ui/primitives/label';
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@documenso/ui/primitives/tooltip';
|
||||||
import { ROLE_ICONS } from '@documenso/ui/primitives/recipient-role-icons';
|
import type { Toast } from '@documenso/ui/primitives/use-toast';
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger } from '@documenso/ui/primitives/select';
|
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
import { useOptionalCurrentTeam } from '~/providers/team';
|
import { useOptionalCurrentTeam } from '~/providers/team';
|
||||||
|
|
||||||
const ZAddRecipientsForNewDocumentSchema = z.object({
|
const ZAddRecipientsForNewDocumentSchema = z
|
||||||
|
.object({
|
||||||
|
sendDocument: z.boolean(),
|
||||||
recipients: z.array(
|
recipients: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
|
id: z.number(),
|
||||||
email: z.string().email(),
|
email: z.string().email(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
role: z.nativeEnum(RecipientRole),
|
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
})
|
||||||
|
// Display exactly which rows are duplicates.
|
||||||
|
.superRefine((items, ctx) => {
|
||||||
|
const uniqueEmails = new Map<string, number>();
|
||||||
|
|
||||||
|
for (const [index, recipients] of items.recipients.entries()) {
|
||||||
|
const email = recipients.email.toLowerCase();
|
||||||
|
|
||||||
|
const firstFoundIndex = uniqueEmails.get(email);
|
||||||
|
|
||||||
|
if (firstFoundIndex === undefined) {
|
||||||
|
uniqueEmails.set(email, index);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: 'Emails must be unique',
|
||||||
|
path: ['recipients', index, 'email'],
|
||||||
|
});
|
||||||
|
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: 'Emails must be unique',
|
||||||
|
path: ['recipients', firstFoundIndex, 'email'],
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
type TAddRecipientsForNewDocumentSchema = z.infer<typeof ZAddRecipientsForNewDocumentSchema>;
|
type TAddRecipientsForNewDocumentSchema = z.infer<typeof ZAddRecipientsForNewDocumentSchema>;
|
||||||
@ -54,35 +96,33 @@ export function UseTemplateDialog({
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
const team = useOptionalCurrentTeam();
|
const team = useOptionalCurrentTeam();
|
||||||
|
|
||||||
const {
|
const form = useForm<TAddRecipientsForNewDocumentSchema>({
|
||||||
control,
|
|
||||||
handleSubmit,
|
|
||||||
formState: { errors, isSubmitting },
|
|
||||||
} = useForm<TAddRecipientsForNewDocumentSchema>({
|
|
||||||
resolver: zodResolver(ZAddRecipientsForNewDocumentSchema),
|
resolver: zodResolver(ZAddRecipientsForNewDocumentSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
recipients:
|
sendDocument: false,
|
||||||
recipients.length > 0
|
recipients: recipients.map((recipient) => {
|
||||||
? recipients.map((recipient) => ({
|
const isRecipientEmailPlaceholder = recipient.email.match(
|
||||||
nativeId: recipient.id,
|
TEMPLATE_RECIPIENT_EMAIL_PLACEHOLDER_REGEX,
|
||||||
formId: String(recipient.id),
|
);
|
||||||
name: recipient.name,
|
|
||||||
email: recipient.email,
|
const isRecipientNamePlaceholder = recipient.name.match(
|
||||||
role: recipient.role,
|
TEMPLATE_RECIPIENT_NAME_PLACEHOLDER_REGEX,
|
||||||
}))
|
);
|
||||||
: [
|
|
||||||
{
|
return {
|
||||||
name: '',
|
id: recipient.id,
|
||||||
email: '',
|
name: !isRecipientNamePlaceholder ? recipient.name : '',
|
||||||
role: RecipientRole.SIGNER,
|
email: !isRecipientEmailPlaceholder ? recipient.email : '',
|
||||||
},
|
};
|
||||||
],
|
}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { mutateAsync: createDocumentFromTemplate, isLoading: isCreatingDocumentFromTemplate } =
|
const { mutateAsync: createDocumentFromTemplate } =
|
||||||
trpc.template.createDocumentFromTemplate.useMutation();
|
trpc.template.createDocumentFromTemplate.useMutation();
|
||||||
|
|
||||||
const onSubmit = async (data: TAddRecipientsForNewDocumentSchema) => {
|
const onSubmit = async (data: TAddRecipientsForNewDocumentSchema) => {
|
||||||
@ -91,6 +131,7 @@ export function UseTemplateDialog({
|
|||||||
templateId,
|
templateId,
|
||||||
teamId: team?.id,
|
teamId: team?.id,
|
||||||
recipients: data.recipients,
|
recipients: data.recipients,
|
||||||
|
sendDocument: data.sendDocument,
|
||||||
});
|
});
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
@ -101,23 +142,35 @@ export function UseTemplateDialog({
|
|||||||
|
|
||||||
router.push(`${documentRootPath}/${id}`);
|
router.push(`${documentRootPath}/${id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
const error = AppError.parseError(err);
|
||||||
|
|
||||||
|
const toastPayload: Toast = {
|
||||||
title: 'Error',
|
title: 'Error',
|
||||||
description: 'An error occurred while creating document from template.',
|
description: 'An error occurred while creating document from template.',
|
||||||
variant: 'destructive',
|
variant: 'destructive',
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (error.code === 'DOCUMENT_SEND_FAILED') {
|
||||||
|
toastPayload.description = 'The document was created but could not be sent to recipients.';
|
||||||
|
}
|
||||||
|
|
||||||
|
toast(toastPayload);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onCreateDocumentFromTemplate = handleSubmit(onSubmit);
|
|
||||||
|
|
||||||
const { fields: formRecipients } = useFieldArray({
|
const { fields: formRecipients } = useFieldArray({
|
||||||
control,
|
control: form.control,
|
||||||
name: 'recipients',
|
name: 'recipients',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) {
|
||||||
|
form.reset();
|
||||||
|
}
|
||||||
|
}, [open, form]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog>
|
<Dialog open={open} onOpenChange={(value) => !form.formState.isSubmitting && setOpen(value)}>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button className="cursor-pointer">
|
<Button className="cursor-pointer">
|
||||||
<Plus className="-ml-1 mr-2 h-4 w-4" />
|
<Plus className="-ml-1 mr-2 h-4 w-4" />
|
||||||
@ -126,121 +179,110 @@ export function UseTemplateDialog({
|
|||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent className="sm:max-w-lg">
|
<DialogContent className="sm:max-w-lg">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Document Recipients</DialogTitle>
|
<DialogTitle>Create document from template</DialogTitle>
|
||||||
<DialogDescription>Add the recipients to create the template with.</DialogDescription>
|
<DialogDescription>
|
||||||
|
{recipients.length === 0
|
||||||
|
? 'A draft document will be created'
|
||||||
|
: 'Add the recipients to create the document with'}
|
||||||
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<div className="flex flex-col space-y-4">
|
|
||||||
{formRecipients.map((recipient, index) => (
|
|
||||||
<div
|
|
||||||
key={recipient.id}
|
|
||||||
data-native-id={recipient.id}
|
|
||||||
className="flex flex-wrap items-end gap-x-4"
|
|
||||||
>
|
|
||||||
<div className="flex-1">
|
|
||||||
<Label htmlFor={`recipient-${recipient.id}-email`}>
|
|
||||||
Email
|
|
||||||
<span className="text-destructive ml-1 inline-block font-medium">*</span>
|
|
||||||
</Label>
|
|
||||||
|
|
||||||
<Controller
|
<Form {...form}>
|
||||||
control={control}
|
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||||
|
<fieldset className="flex h-full flex-col" disabled={form.formState.isSubmitting}>
|
||||||
|
<div className="custom-scrollbar -m-1 max-h-[60vh] space-y-4 overflow-y-auto p-1">
|
||||||
|
{formRecipients.map((recipient, index) => (
|
||||||
|
<div className="flex w-full flex-row space-x-4" key={recipient.id}>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
name={`recipients.${index}.email`}
|
name={`recipients.${index}.email`}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<Input
|
<FormItem className="w-full">
|
||||||
id={`recipient-${recipient.id}-email`}
|
{index === 0 && <FormLabel required>Email</FormLabel>}
|
||||||
type="email"
|
|
||||||
className="bg-background mt-2"
|
<FormControl>
|
||||||
disabled={isSubmitting}
|
<Input {...field} placeholder={recipients[index].email || 'Email'} />
|
||||||
{...field}
|
</FormControl>
|
||||||
/>
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex-1">
|
<FormField
|
||||||
<Label htmlFor={`recipient-${recipient.id}-name`}>Name</Label>
|
control={form.control}
|
||||||
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name={`recipients.${index}.name`}
|
name={`recipients.${index}.name`}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<Input
|
<FormItem className="w-full">
|
||||||
id={`recipient-${recipient.id}-name`}
|
{index === 0 && <FormLabel>Name</FormLabel>}
|
||||||
type="text"
|
|
||||||
className="bg-background mt-2"
|
<FormControl>
|
||||||
disabled={isSubmitting}
|
<Input {...field} placeholder={recipients[index].name || 'Name'} />
|
||||||
{...field}
|
</FormControl>
|
||||||
/>
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-[60px]">
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name={`recipients.${index}.role`}
|
|
||||||
render={({ field: { value, onChange } }) => (
|
|
||||||
<Select value={value} onValueChange={(x) => onChange(x)}>
|
|
||||||
<SelectTrigger className="bg-background">{ROLE_ICONS[value]}</SelectTrigger>
|
|
||||||
|
|
||||||
<SelectContent className="" align="end">
|
|
||||||
<SelectItem value={RecipientRole.SIGNER}>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<span className="mr-2">{ROLE_ICONS[RecipientRole.SIGNER]}</span>
|
|
||||||
Signer
|
|
||||||
</div>
|
|
||||||
</SelectItem>
|
|
||||||
|
|
||||||
<SelectItem value={RecipientRole.CC}>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<span className="mr-2">{ROLE_ICONS[RecipientRole.CC]}</span>
|
|
||||||
Receives copy
|
|
||||||
</div>
|
|
||||||
</SelectItem>
|
|
||||||
|
|
||||||
<SelectItem value={RecipientRole.APPROVER}>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<span className="mr-2">{ROLE_ICONS[RecipientRole.APPROVER]}</span>
|
|
||||||
Approver
|
|
||||||
</div>
|
|
||||||
</SelectItem>
|
|
||||||
|
|
||||||
<SelectItem value={RecipientRole.VIEWER}>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<span className="mr-2">{ROLE_ICONS[RecipientRole.VIEWER]}</span>
|
|
||||||
Viewer
|
|
||||||
</div>
|
|
||||||
</SelectItem>
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="w-full">
|
|
||||||
<FormErrorMessage className="mt-2" error={errors.recipients?.[index]?.email} />
|
|
||||||
<FormErrorMessage className="mt-2" error={errors.recipients?.[index]?.name} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DialogFooter className="justify-end">
|
{recipients.length > 0 && (
|
||||||
|
<div className="mt-4 flex flex-row items-center">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="sendDocument"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<div className="flex flex-row items-center">
|
||||||
|
<Checkbox
|
||||||
|
id="sendDocument"
|
||||||
|
className="h-5 w-5"
|
||||||
|
checkClassName="dark:text-white text-primary"
|
||||||
|
checked={field.value}
|
||||||
|
onCheckedChange={field.onChange}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<label
|
||||||
|
className="text-muted-foreground ml-2 flex items-center text-sm"
|
||||||
|
htmlFor="sendDocument"
|
||||||
|
>
|
||||||
|
Send document
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger type="button">
|
||||||
|
<InfoIcon className="mx-1 h-4 w-4" />
|
||||||
|
</TooltipTrigger>
|
||||||
|
|
||||||
|
<TooltipContent className="text-muted-foreground z-[99999] max-w-md space-y-2 p-4">
|
||||||
|
<p>
|
||||||
|
The document will be immediately sent to recipients if this is
|
||||||
|
checked.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>Otherwise, the document will be created as a draft.</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
<DialogClose asChild>
|
<DialogClose asChild>
|
||||||
<Button type="button" variant="secondary">
|
<Button type="button" variant="secondary">
|
||||||
Close
|
Close
|
||||||
</Button>
|
</Button>
|
||||||
</DialogClose>
|
</DialogClose>
|
||||||
|
|
||||||
<Button
|
<Button type="submit" loading={form.formState.isSubmitting}>
|
||||||
type="button"
|
{form.getValues('sendDocument') ? 'Create and send' : 'Create as draft'}
|
||||||
loading={isCreatingDocumentFromTemplate}
|
|
||||||
disabled={isCreatingDocumentFromTemplate}
|
|
||||||
onClick={onCreateDocumentFromTemplate}
|
|
||||||
>
|
|
||||||
Create Document
|
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||||
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get-server-component-session';
|
import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get-server-component-session';
|
||||||
|
import type { GetTeamTokensResponse } from '@documenso/lib/server-only/public-api/get-all-team-tokens';
|
||||||
import { getTeamTokens } from '@documenso/lib/server-only/public-api/get-all-team-tokens';
|
import { getTeamTokens } from '@documenso/lib/server-only/public-api/get-all-team-tokens';
|
||||||
import { getTeamByUrl } from '@documenso/lib/server-only/team/get-team';
|
import { getTeamByUrl } from '@documenso/lib/server-only/team/get-team';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
@ -23,7 +26,24 @@ export default async function ApiTokensPage({ params }: ApiTokensPageProps) {
|
|||||||
|
|
||||||
const team = await getTeamByUrl({ userId: user.id, teamUrl });
|
const team = await getTeamByUrl({ userId: user.id, teamUrl });
|
||||||
|
|
||||||
const tokens = await getTeamTokens({ userId: user.id, teamId: team.id });
|
let tokens: GetTeamTokensResponse | null = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
tokens = await getTeamTokens({ userId: user.id, teamId: team.id });
|
||||||
|
} catch (err) {
|
||||||
|
const error = AppError.parseError(err);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h3 className="text-2xl font-semibold">API Tokens</h3>
|
||||||
|
<p className="text-muted-foreground mt-2 text-sm">
|
||||||
|
{match(error.code)
|
||||||
|
.with(AppErrorCode.UNAUTHORIZED, () => error.message)
|
||||||
|
.otherwise(() => 'Something went wrong.')}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@ -19,10 +19,10 @@ import { getRecipientById } from '@documenso/lib/server-only/recipient/get-recip
|
|||||||
import { getRecipientsForDocument } from '@documenso/lib/server-only/recipient/get-recipients-for-document';
|
import { getRecipientsForDocument } from '@documenso/lib/server-only/recipient/get-recipients-for-document';
|
||||||
import { setRecipientsForDocument } from '@documenso/lib/server-only/recipient/set-recipients-for-document';
|
import { setRecipientsForDocument } from '@documenso/lib/server-only/recipient/set-recipients-for-document';
|
||||||
import { updateRecipient } from '@documenso/lib/server-only/recipient/update-recipient';
|
import { updateRecipient } from '@documenso/lib/server-only/recipient/update-recipient';
|
||||||
import { createDocumentFromTemplate } from '@documenso/lib/server-only/template/create-document-from-template';
|
import { createDocumentFromTemplateLegacy } from '@documenso/lib/server-only/template/create-document-from-template-legacy';
|
||||||
import { extractNextApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
import { extractNextApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
||||||
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
||||||
import { putFile } from '@documenso/lib/universal/upload/put-file';
|
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
||||||
import {
|
import {
|
||||||
getPresignGetUrl,
|
getPresignGetUrl,
|
||||||
getPresignPostUrl,
|
getPresignPostUrl,
|
||||||
@ -286,7 +286,7 @@ export const ApiContractV1Implementation = createNextRoute(ApiContractV1, {
|
|||||||
|
|
||||||
const fileName = body.title.endsWith('.pdf') ? body.title : `${body.title}.pdf`;
|
const fileName = body.title.endsWith('.pdf') ? body.title : `${body.title}.pdf`;
|
||||||
|
|
||||||
const document = await createDocumentFromTemplate({
|
const document = await createDocumentFromTemplateLegacy({
|
||||||
templateId,
|
templateId,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: team?.id,
|
teamId: team?.id,
|
||||||
@ -303,7 +303,7 @@ export const ApiContractV1Implementation = createNextRoute(ApiContractV1, {
|
|||||||
formValues: body.formValues,
|
formValues: body.formValues,
|
||||||
});
|
});
|
||||||
|
|
||||||
const newDocumentData = await putFile({
|
const newDocumentData = await putPdfFile({
|
||||||
name: fileName,
|
name: fileName,
|
||||||
type: 'application/pdf',
|
type: 'application/pdf',
|
||||||
arrayBuffer: async () => Promise.resolve(prefilled),
|
arrayBuffer: async () => Promise.resolve(prefilled),
|
||||||
|
|||||||
@ -189,7 +189,14 @@ test('[TEMPLATES]: use template', async ({ page }) => {
|
|||||||
|
|
||||||
// Use personal template.
|
// Use personal template.
|
||||||
await page.getByRole('button', { name: 'Use Template' }).click();
|
await page.getByRole('button', { name: 'Use Template' }).click();
|
||||||
await page.getByRole('button', { name: 'Create Document' }).click();
|
|
||||||
|
// Enter template values.
|
||||||
|
await page.getByPlaceholder('recipient.1@documenso.com').click();
|
||||||
|
await page.getByPlaceholder('recipient.1@documenso.com').fill(teamMemberUser.email);
|
||||||
|
await page.getByPlaceholder('Recipient 1').click();
|
||||||
|
await page.getByPlaceholder('Recipient 1').fill('name');
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: 'Create as draft' }).click();
|
||||||
await page.waitForURL(/documents/);
|
await page.waitForURL(/documents/);
|
||||||
await page.getByRole('main').getByRole('link', { name: 'Documents' }).click();
|
await page.getByRole('main').getByRole('link', { name: 'Documents' }).click();
|
||||||
await page.waitForURL('/documents');
|
await page.waitForURL('/documents');
|
||||||
@ -200,7 +207,14 @@ test('[TEMPLATES]: use template', async ({ page }) => {
|
|||||||
|
|
||||||
// Use team template.
|
// Use team template.
|
||||||
await page.getByRole('button', { name: 'Use Template' }).click();
|
await page.getByRole('button', { name: 'Use Template' }).click();
|
||||||
await page.getByRole('button', { name: 'Create Document' }).click();
|
|
||||||
|
// Enter template values.
|
||||||
|
await page.getByPlaceholder('recipient.1@documenso.com').click();
|
||||||
|
await page.getByPlaceholder('recipient.1@documenso.com').fill(teamMemberUser.email);
|
||||||
|
await page.getByPlaceholder('Recipient 1').click();
|
||||||
|
await page.getByPlaceholder('Recipient 1').fill('name');
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: 'Create as draft' }).click();
|
||||||
await page.waitForURL(/\/t\/.+\/documents/);
|
await page.waitForURL(/\/t\/.+\/documents/);
|
||||||
await page.getByRole('main').getByRole('link', { name: 'Documents' }).click();
|
await page.getByRole('main').getByRole('link', { name: 'Documents' }).click();
|
||||||
await page.waitForURL(`/t/${team.url}/documents`);
|
await page.waitForURL(`/t/${team.url}/documents`);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { sealDocument } from '@documenso/lib/server-only/document/seal-document'
|
|||||||
import { redis } from '@documenso/lib/server-only/redis';
|
import { redis } from '@documenso/lib/server-only/redis';
|
||||||
import { stripe } from '@documenso/lib/server-only/stripe';
|
import { stripe } from '@documenso/lib/server-only/stripe';
|
||||||
import { alphaid, nanoid } from '@documenso/lib/universal/id';
|
import { alphaid, nanoid } from '@documenso/lib/universal/id';
|
||||||
import { putFile } from '@documenso/lib/universal/upload/put-file';
|
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import {
|
import {
|
||||||
DocumentStatus,
|
DocumentStatus,
|
||||||
@ -74,7 +74,7 @@ export const onEarlyAdoptersCheckout = async ({ session }: OnEarlyAdoptersChecko
|
|||||||
new URL('@documenso/assets/documenso-supporter-pledge.pdf', import.meta.url),
|
new URL('@documenso/assets/documenso-supporter-pledge.pdf', import.meta.url),
|
||||||
).then(async (res) => res.arrayBuffer());
|
).then(async (res) => res.arrayBuffer());
|
||||||
|
|
||||||
const { id: documentDataId } = await putFile({
|
const { id: documentDataId } = await putPdfFile({
|
||||||
name: 'Documenso Supporter Pledge.pdf',
|
name: 'Documenso Supporter Pledge.pdf',
|
||||||
type: 'application/pdf',
|
type: 'application/pdf',
|
||||||
arrayBuffer: async () => Promise.resolve(documentBuffer),
|
arrayBuffer: async () => Promise.resolve(documentBuffer),
|
||||||
|
|||||||
@ -21,6 +21,7 @@ export const FEATURE_FLAG_POLL_INTERVAL = 30000;
|
|||||||
* Does not take any person or group properties into account.
|
* Does not take any person or group properties into account.
|
||||||
*/
|
*/
|
||||||
export const LOCAL_FEATURE_FLAGS: Record<string, boolean> = {
|
export const LOCAL_FEATURE_FLAGS: Record<string, boolean> = {
|
||||||
|
app_allow_encrypted_documents: false,
|
||||||
app_billing: NEXT_PUBLIC_FEATURE_BILLING_ENABLED() === 'true',
|
app_billing: NEXT_PUBLIC_FEATURE_BILLING_ENABLED() === 'true',
|
||||||
app_document_page_view_history_sheet: false,
|
app_document_page_view_history_sheet: false,
|
||||||
app_passkey: WEBAPP_BASE_URL === 'http://localhost:3000', // Temp feature flag.
|
app_passkey: WEBAPP_BASE_URL === 'http://localhost:3000', // Temp feature flag.
|
||||||
|
|||||||
2
packages/lib/constants/template.ts
Normal file
2
packages/lib/constants/template.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export const TEMPLATE_RECIPIENT_EMAIL_PLACEHOLDER_REGEX = /recipient\.\d+@documenso\.com/i;
|
||||||
|
export const TEMPLATE_RECIPIENT_NAME_PLACEHOLDER_REGEX = /Recipient \d+/i;
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import { TRPCError } from '@trpc/server';
|
import { TRPCError } from '@trpc/server';
|
||||||
|
import { match } from 'ts-pattern';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { TRPCClientError } from '@documenso/trpc/client';
|
import { TRPCClientError } from '@documenso/trpc/client';
|
||||||
@ -149,4 +150,24 @@ export class AppError extends Error {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static toRestAPIError(err: unknown): {
|
||||||
|
status: 400 | 401 | 404 | 500;
|
||||||
|
body: { message: string };
|
||||||
|
} {
|
||||||
|
const error = AppError.parseError(err);
|
||||||
|
|
||||||
|
const status = match(error.code)
|
||||||
|
.with(AppErrorCode.INVALID_BODY, AppErrorCode.INVALID_REQUEST, () => 400 as const)
|
||||||
|
.with(AppErrorCode.UNAUTHORIZED, () => 401 as const)
|
||||||
|
.with(AppErrorCode.NOT_FOUND, () => 404 as const)
|
||||||
|
.otherwise(() => 500 as const);
|
||||||
|
|
||||||
|
return {
|
||||||
|
status,
|
||||||
|
body: {
|
||||||
|
message: status !== 500 ? error.message : 'Something went wrong',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,7 +110,7 @@ export const resendDocument = async ({
|
|||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
signDocumentLink,
|
signDocumentLink,
|
||||||
customBody: renderCustomEmailTemplate(
|
customBody: renderCustomEmailTemplate(
|
||||||
selfSigner ? selfSignerCustomEmail : customEmail?.message || '',
|
selfSigner && !customEmail?.message ? selfSignerCustomEmail : customEmail?.message || '',
|
||||||
customEmailTemplate,
|
customEmailTemplate,
|
||||||
),
|
),
|
||||||
role: recipient.role,
|
role: recipient.role,
|
||||||
@ -135,7 +135,7 @@ export const resendDocument = async ({
|
|||||||
address: FROM_ADDRESS,
|
address: FROM_ADDRESS,
|
||||||
},
|
},
|
||||||
subject: customEmail?.subject
|
subject: customEmail?.subject
|
||||||
? renderCustomEmailTemplate(customEmail.subject, customEmailTemplate)
|
? renderCustomEmailTemplate(`Reminder: ${customEmail.subject}`, customEmailTemplate)
|
||||||
: emailSubject,
|
: emailSubject,
|
||||||
html: render(template),
|
html: render(template),
|
||||||
text: render(template, { plainText: true }),
|
text: render(template, { plainText: true }),
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import { signPdf } from '@documenso/signing';
|
|||||||
|
|
||||||
import type { RequestMetadata } from '../../universal/extract-request-metadata';
|
import type { RequestMetadata } from '../../universal/extract-request-metadata';
|
||||||
import { getFile } from '../../universal/upload/get-file';
|
import { getFile } from '../../universal/upload/get-file';
|
||||||
import { putFile } from '../../universal/upload/put-file';
|
import { putPdfFile } from '../../universal/upload/put-file';
|
||||||
import { getCertificatePdf } from '../htmltopdf/get-certificate-pdf';
|
import { getCertificatePdf } from '../htmltopdf/get-certificate-pdf';
|
||||||
import { flattenAnnotations } from '../pdf/flatten-annotations';
|
import { flattenAnnotations } from '../pdf/flatten-annotations';
|
||||||
import { insertFieldInPDF } from '../pdf/insert-field-in-pdf';
|
import { insertFieldInPDF } from '../pdf/insert-field-in-pdf';
|
||||||
@ -122,7 +122,7 @@ export const sealDocument = async ({
|
|||||||
|
|
||||||
const { name, ext } = path.parse(document.title);
|
const { name, ext } = path.parse(document.title);
|
||||||
|
|
||||||
const { data: newData } = await putFile({
|
const { data: newData } = await putPdfFile({
|
||||||
name: `${name}_signed${ext}`,
|
name: `${name}_signed${ext}`,
|
||||||
type: 'application/pdf',
|
type: 'application/pdf',
|
||||||
arrayBuffer: async () => Promise.resolve(pdfBuffer),
|
arrayBuffer: async () => Promise.resolve(pdfBuffer),
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import { sealDocument } from '@documenso/lib/server-only/document/seal-document'
|
|||||||
import { updateDocument } from '@documenso/lib/server-only/document/update-document';
|
import { updateDocument } from '@documenso/lib/server-only/document/update-document';
|
||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
||||||
import type { RequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
import type { RequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
||||||
|
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
||||||
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
|
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
|
||||||
import { renderCustomEmailTemplate } from '@documenso/lib/utils/render-custom-email-template';
|
import { renderCustomEmailTemplate } from '@documenso/lib/utils/render-custom-email-template';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
@ -20,7 +21,6 @@ import {
|
|||||||
RECIPIENT_ROLE_TO_EMAIL_TYPE,
|
RECIPIENT_ROLE_TO_EMAIL_TYPE,
|
||||||
} from '../../constants/recipient-roles';
|
} from '../../constants/recipient-roles';
|
||||||
import { getFile } from '../../universal/upload/get-file';
|
import { getFile } from '../../universal/upload/get-file';
|
||||||
import { putFile } from '../../universal/upload/put-file';
|
|
||||||
import { insertFormValuesInPdf } from '../pdf/insert-form-values-in-pdf';
|
import { insertFormValuesInPdf } from '../pdf/insert-form-values-in-pdf';
|
||||||
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ export const sendDocument = async ({
|
|||||||
formValues: document.formValues as Record<string, string | number | boolean>,
|
formValues: document.formValues as Record<string, string | number | boolean>,
|
||||||
});
|
});
|
||||||
|
|
||||||
const newDocumentData = await putFile({
|
const newDocumentData = await putPdfFile({
|
||||||
name: document.title,
|
name: document.title,
|
||||||
type: 'application/pdf',
|
type: 'application/pdf',
|
||||||
arrayBuffer: async () => Promise.resolve(prefilled),
|
arrayBuffer: async () => Promise.resolve(prefilled),
|
||||||
@ -151,7 +151,7 @@ export const sendDocument = async ({
|
|||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
signDocumentLink,
|
signDocumentLink,
|
||||||
customBody: renderCustomEmailTemplate(
|
customBody: renderCustomEmailTemplate(
|
||||||
selfSigner ? selfSignerCustomEmail : customEmail?.message || '',
|
selfSigner && !customEmail?.message ? selfSignerCustomEmail : customEmail?.message || '',
|
||||||
customEmailTemplate,
|
customEmailTemplate,
|
||||||
),
|
),
|
||||||
role: recipient.role,
|
role: recipient.role,
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import { TeamMemberRole } from '@documenso/prisma/client';
|
import { TeamMemberRole } from '@documenso/prisma/client';
|
||||||
|
|
||||||
@ -6,6 +7,8 @@ export type GetUserTokensOptions = {
|
|||||||
teamId: number;
|
teamId: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type GetTeamTokensResponse = Awaited<ReturnType<typeof getTeamTokens>>;
|
||||||
|
|
||||||
export const getTeamTokens = async ({ userId, teamId }: GetUserTokensOptions) => {
|
export const getTeamTokens = async ({ userId, teamId }: GetUserTokensOptions) => {
|
||||||
const teamMember = await prisma.teamMember.findFirst({
|
const teamMember = await prisma.teamMember.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@ -15,7 +18,10 @@ export const getTeamTokens = async ({ userId, teamId }: GetUserTokensOptions) =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (teamMember?.role !== TeamMemberRole.ADMIN) {
|
if (teamMember?.role !== TeamMemberRole.ADMIN) {
|
||||||
throw new Error('You do not have permission to view tokens for this team');
|
throw new AppError(
|
||||||
|
AppErrorCode.UNAUTHORIZED,
|
||||||
|
'You do not have the required permissions to view this page.',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await prisma.apiToken.findMany({
|
return await prisma.apiToken.findMany({
|
||||||
|
|||||||
@ -0,0 +1,144 @@
|
|||||||
|
import { nanoid } from '@documenso/lib/universal/id';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
import type { RecipientRole } from '@documenso/prisma/client';
|
||||||
|
|
||||||
|
export type CreateDocumentFromTemplateLegacyOptions = {
|
||||||
|
templateId: number;
|
||||||
|
userId: number;
|
||||||
|
teamId?: number;
|
||||||
|
recipients?: {
|
||||||
|
name?: string;
|
||||||
|
email: string;
|
||||||
|
role?: RecipientRole;
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Legacy server function for /api/v1
|
||||||
|
*/
|
||||||
|
export const createDocumentFromTemplateLegacy = async ({
|
||||||
|
templateId,
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
recipients,
|
||||||
|
}: CreateDocumentFromTemplateLegacyOptions) => {
|
||||||
|
const template = await prisma.template.findUnique({
|
||||||
|
where: {
|
||||||
|
id: templateId,
|
||||||
|
...(teamId
|
||||||
|
? {
|
||||||
|
team: {
|
||||||
|
id: teamId,
|
||||||
|
members: {
|
||||||
|
some: {
|
||||||
|
userId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
userId,
|
||||||
|
teamId: null,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
Recipient: true,
|
||||||
|
Field: true,
|
||||||
|
templateDocumentData: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!template) {
|
||||||
|
throw new Error('Template not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const documentData = await prisma.documentData.create({
|
||||||
|
data: {
|
||||||
|
type: template.templateDocumentData.type,
|
||||||
|
data: template.templateDocumentData.data,
|
||||||
|
initialData: template.templateDocumentData.initialData,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const document = await prisma.document.create({
|
||||||
|
data: {
|
||||||
|
userId,
|
||||||
|
teamId: template.teamId,
|
||||||
|
title: template.title,
|
||||||
|
documentDataId: documentData.id,
|
||||||
|
Recipient: {
|
||||||
|
create: template.Recipient.map((recipient) => ({
|
||||||
|
email: recipient.email,
|
||||||
|
name: recipient.name,
|
||||||
|
role: recipient.role,
|
||||||
|
token: nanoid(),
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
include: {
|
||||||
|
Recipient: {
|
||||||
|
orderBy: {
|
||||||
|
id: 'asc',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await prisma.field.createMany({
|
||||||
|
data: template.Field.map((field) => {
|
||||||
|
const recipient = template.Recipient.find((recipient) => recipient.id === field.recipientId);
|
||||||
|
|
||||||
|
const documentRecipient = document.Recipient.find((doc) => doc.email === recipient?.email);
|
||||||
|
|
||||||
|
if (!documentRecipient) {
|
||||||
|
throw new Error('Recipient not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: field.type,
|
||||||
|
page: field.page,
|
||||||
|
positionX: field.positionX,
|
||||||
|
positionY: field.positionY,
|
||||||
|
width: field.width,
|
||||||
|
height: field.height,
|
||||||
|
customText: field.customText,
|
||||||
|
inserted: field.inserted,
|
||||||
|
documentId: document.id,
|
||||||
|
recipientId: documentRecipient.id,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (recipients && recipients.length > 0) {
|
||||||
|
document.Recipient = await Promise.all(
|
||||||
|
recipients.map(async (recipient, index) => {
|
||||||
|
const existingRecipient = document.Recipient.at(index);
|
||||||
|
|
||||||
|
return await prisma.recipient.upsert({
|
||||||
|
where: {
|
||||||
|
documentId_email: {
|
||||||
|
documentId: document.id,
|
||||||
|
email: existingRecipient?.email ?? recipient.email,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
name: recipient.name,
|
||||||
|
email: recipient.email,
|
||||||
|
role: recipient.role,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
documentId: document.id,
|
||||||
|
email: recipient.email,
|
||||||
|
name: recipient.name,
|
||||||
|
role: recipient.role,
|
||||||
|
token: nanoid(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return document;
|
||||||
|
};
|
||||||
@ -1,16 +1,29 @@
|
|||||||
import { nanoid } from '@documenso/lib/universal/id';
|
import { nanoid } from '@documenso/lib/universal/id';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import type { RecipientRole } from '@documenso/prisma/client';
|
import type { Field } from '@documenso/prisma/client';
|
||||||
|
import { type Recipient, WebhookTriggerEvents } from '@documenso/prisma/client';
|
||||||
|
|
||||||
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '../../types/document-audit-logs';
|
||||||
|
import type { RequestMetadata } from '../../universal/extract-request-metadata';
|
||||||
|
import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
|
||||||
|
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
||||||
|
|
||||||
|
type FinalRecipient = Pick<Recipient, 'name' | 'email' | 'role'> & {
|
||||||
|
templateRecipientId: number;
|
||||||
|
fields: Field[];
|
||||||
|
};
|
||||||
|
|
||||||
export type CreateDocumentFromTemplateOptions = {
|
export type CreateDocumentFromTemplateOptions = {
|
||||||
templateId: number;
|
templateId: number;
|
||||||
userId: number;
|
userId: number;
|
||||||
teamId?: number;
|
teamId?: number;
|
||||||
recipients?: {
|
recipients: {
|
||||||
|
id: number;
|
||||||
name?: string;
|
name?: string;
|
||||||
email: string;
|
email: string;
|
||||||
role?: RecipientRole;
|
|
||||||
}[];
|
}[];
|
||||||
|
requestMetadata?: RequestMetadata;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createDocumentFromTemplate = async ({
|
export const createDocumentFromTemplate = async ({
|
||||||
@ -18,7 +31,14 @@ export const createDocumentFromTemplate = async ({
|
|||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
recipients,
|
recipients,
|
||||||
|
requestMetadata,
|
||||||
}: CreateDocumentFromTemplateOptions) => {
|
}: CreateDocumentFromTemplateOptions) => {
|
||||||
|
const user = await prisma.user.findFirstOrThrow({
|
||||||
|
where: {
|
||||||
|
id: userId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const template = await prisma.template.findUnique({
|
const template = await prisma.template.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: templateId,
|
id: templateId,
|
||||||
@ -39,16 +59,42 @@ export const createDocumentFromTemplate = async ({
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
Recipient: true,
|
Recipient: {
|
||||||
|
include: {
|
||||||
Field: true,
|
Field: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
templateDocumentData: true,
|
templateDocumentData: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!template) {
|
if (!template) {
|
||||||
throw new Error('Template not found.');
|
throw new AppError(AppErrorCode.NOT_FOUND, 'Template not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (recipients.length !== template.Recipient.length) {
|
||||||
|
throw new AppError(AppErrorCode.INVALID_BODY, 'Invalid number of recipients.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const finalRecipients: FinalRecipient[] = template.Recipient.map((templateRecipient) => {
|
||||||
|
const foundRecipient = recipients.find((recipient) => recipient.id === templateRecipient.id);
|
||||||
|
|
||||||
|
if (!foundRecipient) {
|
||||||
|
throw new AppError(
|
||||||
|
AppErrorCode.INVALID_BODY,
|
||||||
|
`Missing template recipient with ID ${templateRecipient.id}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
templateRecipientId: templateRecipient.id,
|
||||||
|
fields: templateRecipient.Field,
|
||||||
|
name: foundRecipient.name ?? '',
|
||||||
|
email: foundRecipient.email,
|
||||||
|
role: templateRecipient.role,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const documentData = await prisma.documentData.create({
|
const documentData = await prisma.documentData.create({
|
||||||
data: {
|
data: {
|
||||||
type: template.templateDocumentData.type,
|
type: template.templateDocumentData.type,
|
||||||
@ -57,14 +103,16 @@ export const createDocumentFromTemplate = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const document = await prisma.document.create({
|
return await prisma.$transaction(async (tx) => {
|
||||||
|
const document = await tx.document.create({
|
||||||
data: {
|
data: {
|
||||||
userId,
|
userId,
|
||||||
teamId: template.teamId,
|
teamId: template.teamId,
|
||||||
title: template.title,
|
title: template.title,
|
||||||
documentDataId: documentData.id,
|
documentDataId: documentData.id,
|
||||||
Recipient: {
|
Recipient: {
|
||||||
create: template.Recipient.map((recipient) => ({
|
createMany: {
|
||||||
|
data: finalRecipients.map((recipient) => ({
|
||||||
email: recipient.email,
|
email: recipient.email,
|
||||||
name: recipient.name,
|
name: recipient.name,
|
||||||
role: recipient.role,
|
role: recipient.role,
|
||||||
@ -72,7 +120,7 @@ export const createDocumentFromTemplate = async ({
|
|||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
include: {
|
include: {
|
||||||
Recipient: {
|
Recipient: {
|
||||||
orderBy: {
|
orderBy: {
|
||||||
@ -83,59 +131,54 @@ export const createDocumentFromTemplate = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await prisma.field.createMany({
|
let fieldsToCreate: Omit<Field, 'id' | 'secondaryId' | 'templateId'>[] = [];
|
||||||
data: template.Field.map((field) => {
|
|
||||||
const recipient = template.Recipient.find((recipient) => recipient.id === field.recipientId);
|
|
||||||
|
|
||||||
const documentRecipient = document.Recipient.find((doc) => doc.email === recipient?.email);
|
Object.values(finalRecipients).forEach(({ email, fields }) => {
|
||||||
|
const recipient = document.Recipient.find((recipient) => recipient.email === email);
|
||||||
|
|
||||||
if (!documentRecipient) {
|
if (!recipient) {
|
||||||
throw new Error('Recipient not found.');
|
throw new Error('Recipient not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
fieldsToCreate = fieldsToCreate.concat(
|
||||||
|
fields.map((field) => ({
|
||||||
|
documentId: document.id,
|
||||||
|
recipientId: recipient.id,
|
||||||
type: field.type,
|
type: field.type,
|
||||||
page: field.page,
|
page: field.page,
|
||||||
positionX: field.positionX,
|
positionX: field.positionX,
|
||||||
positionY: field.positionY,
|
positionY: field.positionY,
|
||||||
width: field.width,
|
width: field.width,
|
||||||
height: field.height,
|
height: field.height,
|
||||||
customText: field.customText,
|
customText: '',
|
||||||
inserted: field.inserted,
|
inserted: false,
|
||||||
documentId: document.id,
|
})),
|
||||||
recipientId: documentRecipient.id,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (recipients && recipients.length > 0) {
|
|
||||||
document.Recipient = await Promise.all(
|
|
||||||
recipients.map(async (recipient, index) => {
|
|
||||||
const existingRecipient = document.Recipient.at(index);
|
|
||||||
|
|
||||||
return await prisma.recipient.upsert({
|
|
||||||
where: {
|
|
||||||
documentId_email: {
|
|
||||||
documentId: document.id,
|
|
||||||
email: existingRecipient?.email ?? recipient.email,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
update: {
|
|
||||||
name: recipient.name,
|
|
||||||
email: recipient.email,
|
|
||||||
role: recipient.role,
|
|
||||||
},
|
|
||||||
create: {
|
|
||||||
documentId: document.id,
|
|
||||||
email: recipient.email,
|
|
||||||
name: recipient.name,
|
|
||||||
role: recipient.role,
|
|
||||||
token: nanoid(),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
|
await tx.field.createMany({
|
||||||
|
data: fieldsToCreate,
|
||||||
|
});
|
||||||
|
|
||||||
|
await tx.documentAuditLog.create({
|
||||||
|
data: createDocumentAuditLogData({
|
||||||
|
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_CREATED,
|
||||||
|
documentId: document.id,
|
||||||
|
user,
|
||||||
|
requestMetadata,
|
||||||
|
data: {
|
||||||
|
title: document.title,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
await triggerWebhook({
|
||||||
|
event: WebhookTriggerEvents.DOCUMENT_CREATED,
|
||||||
|
data: document,
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
});
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
import { base64 } from '@scure/base';
|
import { base64 } from '@scure/base';
|
||||||
import { env } from 'next-runtime-env';
|
import { env } from 'next-runtime-env';
|
||||||
|
import { PDFDocument } from 'pdf-lib';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
|
import { getFlag } from '@documenso/lib/universal/get-feature-flag';
|
||||||
import { DocumentDataType } from '@documenso/prisma/client';
|
import { DocumentDataType } from '@documenso/prisma/client';
|
||||||
|
|
||||||
|
import { AppError } from '../../errors/app-error';
|
||||||
import { createDocumentData } from '../../server-only/document-data/create-document-data';
|
import { createDocumentData } from '../../server-only/document-data/create-document-data';
|
||||||
|
|
||||||
type File = {
|
type File = {
|
||||||
@ -12,14 +15,38 @@ type File = {
|
|||||||
arrayBuffer: () => Promise<ArrayBuffer>;
|
arrayBuffer: () => Promise<ArrayBuffer>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uploads a document file to the appropriate storage location and creates
|
||||||
|
* a document data record.
|
||||||
|
*/
|
||||||
|
export const putPdfFile = async (file: File) => {
|
||||||
|
const isEncryptedDocumentsAllowed = await getFlag('app_allow_encrypted_documents').catch(
|
||||||
|
() => false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// This will prevent uploading encrypted PDFs or anything that can't be opened.
|
||||||
|
if (!isEncryptedDocumentsAllowed) {
|
||||||
|
await PDFDocument.load(await file.arrayBuffer()).catch((e) => {
|
||||||
|
console.error(`PDF upload parse error: ${e.message}`);
|
||||||
|
|
||||||
|
throw new AppError('INVALID_DOCUMENT_FILE');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const { type, data } = await putFile(file);
|
||||||
|
|
||||||
|
return await createDocumentData({ type, data });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uploads a file to the appropriate storage location.
|
||||||
|
*/
|
||||||
export const putFile = async (file: File) => {
|
export const putFile = async (file: File) => {
|
||||||
const NEXT_PUBLIC_UPLOAD_TRANSPORT = env('NEXT_PUBLIC_UPLOAD_TRANSPORT');
|
const NEXT_PUBLIC_UPLOAD_TRANSPORT = env('NEXT_PUBLIC_UPLOAD_TRANSPORT');
|
||||||
|
|
||||||
const { type, data } = await match(NEXT_PUBLIC_UPLOAD_TRANSPORT)
|
return await match(NEXT_PUBLIC_UPLOAD_TRANSPORT)
|
||||||
.with('s3', async () => putFileInS3(file))
|
.with('s3', async () => putFileInS3(file))
|
||||||
.otherwise(async () => putFileInDatabase(file));
|
.otherwise(async () => putFileInDatabase(file));
|
||||||
|
|
||||||
return await createDocumentData({ type, data });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const putFileInDatabase = async (file: File) => {
|
const putFileInDatabase = async (file: File) => {
|
||||||
|
|||||||
@ -90,7 +90,7 @@ export const profileRouter = router({
|
|||||||
try {
|
try {
|
||||||
const { url, bio } = input;
|
const { url, bio } = input;
|
||||||
|
|
||||||
if (IS_BILLING_ENABLED() && url.length <= 6) {
|
if (IS_BILLING_ENABLED() && url.length < 6) {
|
||||||
const subscriptions = await getSubscriptionsByUserId({
|
const subscriptions = await getSubscriptionsByUserId({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
}).then((subscriptions) =>
|
}).then((subscriptions) =>
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import { FROM_ADDRESS, FROM_NAME, SERVICE_USER_EMAIL } from '@documenso/lib/cons
|
|||||||
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 { 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 { putFile } from '@documenso/lib/universal/upload/put-file';
|
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import {
|
import {
|
||||||
DocumentStatus,
|
DocumentStatus,
|
||||||
@ -86,7 +86,7 @@ export const singleplayerRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { id: documentDataId } = await putFile({
|
const { id: documentDataId } = await putPdfFile({
|
||||||
name: `${documentName}.pdf`,
|
name: `${documentName}.pdf`,
|
||||||
type: 'application/pdf',
|
type: 'application/pdf',
|
||||||
arrayBuffer: async () => Promise.resolve(signedPdfBuffer),
|
arrayBuffer: async () => Promise.resolve(signedPdfBuffer),
|
||||||
|
|||||||
@ -1,10 +1,14 @@
|
|||||||
import { TRPCError } from '@trpc/server';
|
import { TRPCError } from '@trpc/server';
|
||||||
|
|
||||||
import { getServerLimits } from '@documenso/ee/server-only/limits/server';
|
import { getServerLimits } from '@documenso/ee/server-only/limits/server';
|
||||||
|
import { AppError } from '@documenso/lib/errors/app-error';
|
||||||
|
import { sendDocument } from '@documenso/lib/server-only/document/send-document';
|
||||||
import { createDocumentFromTemplate } from '@documenso/lib/server-only/template/create-document-from-template';
|
import { createDocumentFromTemplate } from '@documenso/lib/server-only/template/create-document-from-template';
|
||||||
import { createTemplate } from '@documenso/lib/server-only/template/create-template';
|
import { createTemplate } from '@documenso/lib/server-only/template/create-template';
|
||||||
import { deleteTemplate } from '@documenso/lib/server-only/template/delete-template';
|
import { deleteTemplate } from '@documenso/lib/server-only/template/delete-template';
|
||||||
import { duplicateTemplate } from '@documenso/lib/server-only/template/duplicate-template';
|
import { duplicateTemplate } from '@documenso/lib/server-only/template/duplicate-template';
|
||||||
|
import { extractNextApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
||||||
|
import type { Document } from '@documenso/prisma/client';
|
||||||
|
|
||||||
import { authenticatedProcedure, router } from '../trpc';
|
import { authenticatedProcedure, router } from '../trpc';
|
||||||
import {
|
import {
|
||||||
@ -49,19 +53,34 @@ export const templateRouter = router({
|
|||||||
throw new Error('You have reached your document limit.');
|
throw new Error('You have reached your document limit.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return await createDocumentFromTemplate({
|
const requestMetadata = extractNextApiRequestMetadata(ctx.req);
|
||||||
|
|
||||||
|
let document: Document = await createDocumentFromTemplate({
|
||||||
templateId,
|
templateId,
|
||||||
teamId,
|
teamId,
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
recipients: input.recipients,
|
recipients: input.recipients,
|
||||||
|
requestMetadata,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (input.sendDocument) {
|
||||||
|
document = await sendDocument({
|
||||||
|
documentId: document.id,
|
||||||
|
userId: ctx.user.id,
|
||||||
|
teamId,
|
||||||
|
requestMetadata,
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
|
||||||
|
throw new AppError('DOCUMENT_SEND_FAILED');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return document;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
||||||
throw new TRPCError({
|
throw AppError.parseErrorToTRPCError(err);
|
||||||
code: 'BAD_REQUEST',
|
|
||||||
message: 'We were unable to create this document. Please try again later.',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { RecipientRole } from '@documenso/prisma/client';
|
|
||||||
|
|
||||||
export const ZCreateTemplateMutationSchema = z.object({
|
export const ZCreateTemplateMutationSchema = z.object({
|
||||||
title: z.string().min(1).trim(),
|
title: z.string().min(1).trim(),
|
||||||
teamId: z.number().optional(),
|
teamId: z.number().optional(),
|
||||||
@ -14,12 +12,16 @@ export const ZCreateDocumentFromTemplateMutationSchema = z.object({
|
|||||||
recipients: z
|
recipients: z
|
||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
|
id: z.number(),
|
||||||
email: z.string().email(),
|
email: z.string().email(),
|
||||||
name: z.string(),
|
name: z.string().optional(),
|
||||||
role: z.nativeEnum(RecipientRole),
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.optional(),
|
.refine((recipients) => {
|
||||||
|
const emails = recipients.map((signer) => signer.email);
|
||||||
|
return new Set(emails).size === emails.length;
|
||||||
|
}, 'Recipients must have unique emails'),
|
||||||
|
sendDocument: z.boolean().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ZDuplicateTemplateMutationSchema = z.object({
|
export const ZDuplicateTemplateMutationSchema = z.object({
|
||||||
|
|||||||
@ -0,0 +1,80 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import type { SelectProps } from '@radix-ui/react-select';
|
||||||
|
import { InfoIcon } from 'lucide-react';
|
||||||
|
|
||||||
|
import { DOCUMENT_AUTH_TYPES } from '@documenso/lib/constants/document-auth';
|
||||||
|
import { RecipientActionAuth } from '@documenso/lib/types/document-auth';
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@documenso/ui/primitives/select';
|
||||||
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@documenso/ui/primitives/tooltip';
|
||||||
|
|
||||||
|
export type RecipientActionAuthSelectProps = SelectProps;
|
||||||
|
|
||||||
|
export const RecipientActionAuthSelect = (props: RecipientActionAuthSelectProps) => {
|
||||||
|
return (
|
||||||
|
<Select {...props}>
|
||||||
|
<SelectTrigger className="bg-background text-muted-foreground">
|
||||||
|
<SelectValue placeholder="Inherit authentication method" />
|
||||||
|
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger className="-mr-1 ml-auto">
|
||||||
|
<InfoIcon className="mx-2 h-4 w-4" />
|
||||||
|
</TooltipTrigger>
|
||||||
|
|
||||||
|
<TooltipContent className="text-foreground max-w-md p-4">
|
||||||
|
<h2>
|
||||||
|
<strong>Recipient action authentication</strong>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<p>The authentication required for recipients to sign fields</p>
|
||||||
|
|
||||||
|
<p className="mt-2">This will override any global settings.</p>
|
||||||
|
|
||||||
|
<ul className="ml-3.5 list-outside list-disc space-y-0.5 py-2">
|
||||||
|
<li>
|
||||||
|
<strong>Inherit authentication method</strong> - Use the global action signing
|
||||||
|
authentication method configured in the "General Settings" step
|
||||||
|
</li>
|
||||||
|
{/* <li>
|
||||||
|
<strong>Require account</strong> - The recipient must be
|
||||||
|
signed in
|
||||||
|
</li> */}
|
||||||
|
<li>
|
||||||
|
<strong>Require passkey</strong> - The recipient must have an account and passkey
|
||||||
|
configured via their settings
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<strong>Require 2FA</strong> - The recipient must have an account and 2FA enabled
|
||||||
|
via their settings
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<strong>None</strong> - No authentication required
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</SelectTrigger>
|
||||||
|
|
||||||
|
<SelectContent position="popper">
|
||||||
|
{/* Note: -1 is remapped in the Zod schema to the required value. */}
|
||||||
|
<SelectItem value="-1">Inherit authentication method</SelectItem>
|
||||||
|
|
||||||
|
{Object.values(RecipientActionAuth)
|
||||||
|
.filter((auth) => auth !== RecipientActionAuth.ACCOUNT)
|
||||||
|
.map((authType) => (
|
||||||
|
<SelectItem key={authType} value={authType}>
|
||||||
|
{DOCUMENT_AUTH_TYPES[authType].value}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
);
|
||||||
|
};
|
||||||
97
packages/ui/components/recipient/recipient-role-select.tsx
Normal file
97
packages/ui/components/recipient/recipient-role-select.tsx
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import type { SelectProps } from '@radix-ui/react-select';
|
||||||
|
import { InfoIcon } from 'lucide-react';
|
||||||
|
|
||||||
|
import { RecipientRole } from '@documenso/prisma/client';
|
||||||
|
import { ROLE_ICONS } from '@documenso/ui/primitives/recipient-role-icons';
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger } from '@documenso/ui/primitives/select';
|
||||||
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@documenso/ui/primitives/tooltip';
|
||||||
|
|
||||||
|
export type RecipientRoleSelectProps = SelectProps;
|
||||||
|
|
||||||
|
export const RecipientRoleSelect = (props: RecipientRoleSelectProps) => {
|
||||||
|
return (
|
||||||
|
<Select {...props}>
|
||||||
|
<SelectTrigger className="bg-background w-[60px]">
|
||||||
|
{/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */}
|
||||||
|
{ROLE_ICONS[props.value as RecipientRole]}
|
||||||
|
</SelectTrigger>
|
||||||
|
|
||||||
|
<SelectContent align="end">
|
||||||
|
<SelectItem value={RecipientRole.SIGNER}>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<div className="flex w-[150px] items-center">
|
||||||
|
<span className="mr-2">{ROLE_ICONS[RecipientRole.SIGNER]}</span>
|
||||||
|
Needs to sign
|
||||||
|
</div>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger>
|
||||||
|
<InfoIcon className="h-4 w-4" />
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent className="text-foreground z-9999 max-w-md p-4">
|
||||||
|
<p>The recipient is required to sign the document for it to be completed.</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</SelectItem>
|
||||||
|
|
||||||
|
<SelectItem value={RecipientRole.APPROVER}>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<div className="flex w-[150px] items-center">
|
||||||
|
<span className="mr-2">{ROLE_ICONS[RecipientRole.APPROVER]}</span>
|
||||||
|
Needs to approve
|
||||||
|
</div>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger>
|
||||||
|
<InfoIcon className="h-4 w-4" />
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent className="text-foreground z-9999 max-w-md p-4">
|
||||||
|
<p>The recipient is required to approve the document for it to be completed.</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</SelectItem>
|
||||||
|
|
||||||
|
<SelectItem value={RecipientRole.VIEWER}>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<div className="flex w-[150px] items-center">
|
||||||
|
<span className="mr-2">{ROLE_ICONS[RecipientRole.VIEWER]}</span>
|
||||||
|
Needs to view
|
||||||
|
</div>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger>
|
||||||
|
<InfoIcon className="h-4 w-4" />
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent className="text-foreground z-9999 max-w-md p-4">
|
||||||
|
<p>The recipient is required to view the document for it to be completed.</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</SelectItem>
|
||||||
|
|
||||||
|
<SelectItem value={RecipientRole.CC}>
|
||||||
|
<div className="flex items-center">
|
||||||
|
<div className="flex w-[150px] items-center">
|
||||||
|
<span className="mr-2">{ROLE_ICONS[RecipientRole.CC]}</span>
|
||||||
|
Receives copy
|
||||||
|
</div>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger>
|
||||||
|
<InfoIcon className="h-4 w-4" />
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent className="text-foreground z-9999 max-w-md p-4">
|
||||||
|
<p>
|
||||||
|
The recipient is not required to take any action and receives a copy of the
|
||||||
|
document after it is completed.
|
||||||
|
</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
);
|
||||||
|
};
|
||||||
@ -4,20 +4,18 @@ import React, { useId, useMemo, useState } from 'react';
|
|||||||
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import { InfoIcon, Plus, Trash } from 'lucide-react';
|
import { Plus, Trash } from 'lucide-react';
|
||||||
import { useSession } from 'next-auth/react';
|
import { useSession } from 'next-auth/react';
|
||||||
import { useFieldArray, useForm } from 'react-hook-form';
|
import { useFieldArray, useForm } from 'react-hook-form';
|
||||||
|
|
||||||
import { useLimits } from '@documenso/ee/server-only/limits/provider/client';
|
import { useLimits } from '@documenso/ee/server-only/limits/provider/client';
|
||||||
import { DOCUMENT_AUTH_TYPES } from '@documenso/lib/constants/document-auth';
|
import { ZRecipientAuthOptionsSchema } from '@documenso/lib/types/document-auth';
|
||||||
import {
|
|
||||||
RecipientActionAuth,
|
|
||||||
ZRecipientAuthOptionsSchema,
|
|
||||||
} from '@documenso/lib/types/document-auth';
|
|
||||||
import { nanoid } from '@documenso/lib/universal/id';
|
import { nanoid } from '@documenso/lib/universal/id';
|
||||||
import type { Field, Recipient } from '@documenso/prisma/client';
|
import type { Field, Recipient } from '@documenso/prisma/client';
|
||||||
import { RecipientRole, SendStatus } from '@documenso/prisma/client';
|
import { RecipientRole, SendStatus } from '@documenso/prisma/client';
|
||||||
import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out';
|
import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out';
|
||||||
|
import { RecipientActionAuthSelect } from '@documenso/ui/components/recipient/recipient-action-auth-select';
|
||||||
|
import { RecipientRoleSelect } from '@documenso/ui/components/recipient/recipient-role-select';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
|
|
||||||
import { Button } from '../button';
|
import { Button } from '../button';
|
||||||
@ -25,10 +23,7 @@ import { Checkbox } from '../checkbox';
|
|||||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '../form/form';
|
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '../form/form';
|
||||||
import { FormErrorMessage } from '../form/form-error-message';
|
import { FormErrorMessage } from '../form/form-error-message';
|
||||||
import { Input } from '../input';
|
import { Input } from '../input';
|
||||||
import { ROLE_ICONS } from '../recipient-role-icons';
|
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../select';
|
|
||||||
import { useStep } from '../stepper';
|
import { useStep } from '../stepper';
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from '../tooltip';
|
|
||||||
import { useToast } from '../use-toast';
|
import { useToast } from '../use-toast';
|
||||||
import type { TAddSignersFormSchema } from './add-signers.types';
|
import type { TAddSignersFormSchema } from './add-signers.types';
|
||||||
import { ZAddSignersFormSchema } from './add-signers.types';
|
import { ZAddSignersFormSchema } from './add-signers.types';
|
||||||
@ -274,67 +269,11 @@ export const AddSignersFormPartial = ({
|
|||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className="col-span-6">
|
<FormItem className="col-span-6">
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Select
|
<RecipientActionAuthSelect
|
||||||
{...field}
|
{...field}
|
||||||
onValueChange={field.onChange}
|
onValueChange={field.onChange}
|
||||||
disabled={isSubmitting || hasBeenSentToRecipientId(signer.nativeId)}
|
disabled={isSubmitting || hasBeenSentToRecipientId(signer.nativeId)}
|
||||||
>
|
/>
|
||||||
<SelectTrigger className="bg-background text-muted-foreground">
|
|
||||||
<SelectValue placeholder="Inherit authentication method" />
|
|
||||||
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger className="-mr-1 ml-auto">
|
|
||||||
<InfoIcon className="mx-2 h-4 w-4" />
|
|
||||||
</TooltipTrigger>
|
|
||||||
|
|
||||||
<TooltipContent className="text-foreground max-w-md p-4">
|
|
||||||
<h2>
|
|
||||||
<strong>Recipient action authentication</strong>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<p>The authentication required for recipients to sign fields</p>
|
|
||||||
|
|
||||||
<p className="mt-2">This will override any global settings.</p>
|
|
||||||
|
|
||||||
<ul className="ml-3.5 list-outside list-disc space-y-0.5 py-2">
|
|
||||||
<li>
|
|
||||||
<strong>Inherit authentication method</strong> - Use the
|
|
||||||
global action signing authentication method configured in
|
|
||||||
the "General Settings" step
|
|
||||||
</li>
|
|
||||||
{/* <li>
|
|
||||||
<strong>Require account</strong> - The recipient must be
|
|
||||||
signed in
|
|
||||||
</li> */}
|
|
||||||
<li>
|
|
||||||
<strong>Require passkey</strong> - The recipient must have
|
|
||||||
an account and passkey configured via their settings
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<strong>Require 2FA</strong> - The recipient must have an
|
|
||||||
account and 2FA enabled via their settings
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<strong>None</strong> - No authentication required
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</SelectTrigger>
|
|
||||||
|
|
||||||
<SelectContent position="popper">
|
|
||||||
{/* Note: -1 is remapped in the Zod schema to the required value. */}
|
|
||||||
<SelectItem value="-1">Inherit authentication method</SelectItem>
|
|
||||||
|
|
||||||
{Object.values(RecipientActionAuth)
|
|
||||||
.filter((auth) => auth !== RecipientActionAuth.ACCOUNT)
|
|
||||||
.map((authType) => (
|
|
||||||
<SelectItem key={authType} value={authType}>
|
|
||||||
{DOCUMENT_AUTH_TYPES[authType].value}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
@ -348,100 +287,11 @@ export const AddSignersFormPartial = ({
|
|||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className="col-span-1 mt-auto">
|
<FormItem className="col-span-1 mt-auto">
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Select
|
<RecipientRoleSelect
|
||||||
{...field}
|
{...field}
|
||||||
onValueChange={field.onChange}
|
onValueChange={field.onChange}
|
||||||
disabled={isSubmitting || hasBeenSentToRecipientId(signer.nativeId)}
|
disabled={isSubmitting || hasBeenSentToRecipientId(signer.nativeId)}
|
||||||
>
|
/>
|
||||||
<SelectTrigger className="bg-background w-[60px]">
|
|
||||||
{/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */}
|
|
||||||
{ROLE_ICONS[field.value as RecipientRole]}
|
|
||||||
</SelectTrigger>
|
|
||||||
|
|
||||||
<SelectContent align="end">
|
|
||||||
<SelectItem value={RecipientRole.SIGNER}>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<div className="flex w-[150px] items-center">
|
|
||||||
<span className="mr-2">{ROLE_ICONS[RecipientRole.SIGNER]}</span>
|
|
||||||
Needs to sign
|
|
||||||
</div>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger>
|
|
||||||
<InfoIcon className="h-4 w-4" />
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent className="text-foreground z-9999 max-w-md p-4">
|
|
||||||
<p>
|
|
||||||
The recipient is required to sign the document for it to be
|
|
||||||
completed.
|
|
||||||
</p>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
</SelectItem>
|
|
||||||
|
|
||||||
<SelectItem value={RecipientRole.APPROVER}>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<div className="flex w-[150px] items-center">
|
|
||||||
<span className="mr-2">
|
|
||||||
{ROLE_ICONS[RecipientRole.APPROVER]}
|
|
||||||
</span>
|
|
||||||
Needs to approve
|
|
||||||
</div>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger>
|
|
||||||
<InfoIcon className="h-4 w-4" />
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent className="text-foreground z-9999 max-w-md p-4">
|
|
||||||
<p>
|
|
||||||
The recipient is required to approve the document for it to
|
|
||||||
be completed.
|
|
||||||
</p>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
</SelectItem>
|
|
||||||
|
|
||||||
<SelectItem value={RecipientRole.VIEWER}>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<div className="flex w-[150px] items-center">
|
|
||||||
<span className="mr-2">{ROLE_ICONS[RecipientRole.VIEWER]}</span>
|
|
||||||
Needs to view
|
|
||||||
</div>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger>
|
|
||||||
<InfoIcon className="h-4 w-4" />
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent className="text-foreground z-9999 max-w-md p-4">
|
|
||||||
<p>
|
|
||||||
The recipient is required to view the document for it to be
|
|
||||||
completed.
|
|
||||||
</p>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
</SelectItem>
|
|
||||||
|
|
||||||
<SelectItem value={RecipientRole.CC}>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<div className="flex w-[150px] items-center">
|
|
||||||
<span className="mr-2">{ROLE_ICONS[RecipientRole.CC]}</span>
|
|
||||||
Receives copy
|
|
||||||
</div>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger>
|
|
||||||
<InfoIcon className="h-4 w-4" />
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent className="text-foreground z-9999 max-w-md p-4">
|
|
||||||
<p>
|
|
||||||
The recipient is not required to take any action and
|
|
||||||
receives a copy of the document after it is completed.
|
|
||||||
</p>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
</SelectItem>
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|||||||
@ -1,20 +1,25 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import React, { useId, useState } from 'react';
|
import React, { useId, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { AnimatePresence, motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import { InfoIcon, Plus, Trash } from 'lucide-react';
|
import { Plus, Trash } from 'lucide-react';
|
||||||
import { useSession } from 'next-auth/react';
|
import { useSession } from 'next-auth/react';
|
||||||
import { Controller, useFieldArray, useForm } from 'react-hook-form';
|
import { useFieldArray, useForm } from 'react-hook-form';
|
||||||
|
|
||||||
|
import { ZRecipientAuthOptionsSchema } from '@documenso/lib/types/document-auth';
|
||||||
import { nanoid } from '@documenso/lib/universal/id';
|
import { nanoid } from '@documenso/lib/universal/id';
|
||||||
import { type Field, type Recipient, RecipientRole } from '@documenso/prisma/client';
|
import { type Field, type Recipient, RecipientRole } from '@documenso/prisma/client';
|
||||||
|
import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out';
|
||||||
|
import { RecipientActionAuthSelect } from '@documenso/ui/components/recipient/recipient-action-auth-select';
|
||||||
|
import { RecipientRoleSelect } from '@documenso/ui/components/recipient/recipient-role-select';
|
||||||
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import { FormErrorMessage } from '@documenso/ui/primitives/form/form-error-message';
|
import { FormErrorMessage } from '@documenso/ui/primitives/form/form-error-message';
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
import { Input } from '@documenso/ui/primitives/input';
|
||||||
import { Label } from '@documenso/ui/primitives/label';
|
|
||||||
|
|
||||||
|
import { Checkbox } from '../checkbox';
|
||||||
import {
|
import {
|
||||||
DocumentFlowFormContainerActions,
|
DocumentFlowFormContainerActions,
|
||||||
DocumentFlowFormContainerContent,
|
DocumentFlowFormContainerContent,
|
||||||
@ -22,10 +27,8 @@ import {
|
|||||||
DocumentFlowFormContainerStep,
|
DocumentFlowFormContainerStep,
|
||||||
} from '../document-flow/document-flow-root';
|
} from '../document-flow/document-flow-root';
|
||||||
import type { DocumentFlowStep } from '../document-flow/types';
|
import type { DocumentFlowStep } from '../document-flow/types';
|
||||||
import { ROLE_ICONS } from '../recipient-role-icons';
|
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '../form/form';
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger } from '../select';
|
|
||||||
import { useStep } from '../stepper';
|
import { useStep } from '../stepper';
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from '../tooltip';
|
|
||||||
import type { TAddTemplatePlacholderRecipientsFormSchema } from './add-template-placeholder-recipients.types';
|
import type { TAddTemplatePlacholderRecipientsFormSchema } from './add-template-placeholder-recipients.types';
|
||||||
import { ZAddTemplatePlacholderRecipientsFormSchema } from './add-template-placeholder-recipients.types';
|
import { ZAddTemplatePlacholderRecipientsFormSchema } from './add-template-placeholder-recipients.types';
|
||||||
|
|
||||||
@ -33,30 +36,29 @@ export type AddTemplatePlaceholderRecipientsFormProps = {
|
|||||||
documentFlow: DocumentFlowStep;
|
documentFlow: DocumentFlowStep;
|
||||||
recipients: Recipient[];
|
recipients: Recipient[];
|
||||||
fields: Field[];
|
fields: Field[];
|
||||||
|
isTemplateOwnerEnterprise: boolean;
|
||||||
onSubmit: (_data: TAddTemplatePlacholderRecipientsFormSchema) => void;
|
onSubmit: (_data: TAddTemplatePlacholderRecipientsFormSchema) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
||||||
documentFlow,
|
documentFlow,
|
||||||
|
isTemplateOwnerEnterprise,
|
||||||
recipients,
|
recipients,
|
||||||
fields: _fields,
|
fields: _fields,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
}: AddTemplatePlaceholderRecipientsFormProps) => {
|
}: AddTemplatePlaceholderRecipientsFormProps) => {
|
||||||
const initialId = useId();
|
const initialId = useId();
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
|
|
||||||
const user = session?.user;
|
const user = session?.user;
|
||||||
|
|
||||||
const [placeholderRecipientCount, setPlaceholderRecipientCount] = useState(() =>
|
const [placeholderRecipientCount, setPlaceholderRecipientCount] = useState(() =>
|
||||||
recipients.length > 1 ? recipients.length + 1 : 2,
|
recipients.length > 1 ? recipients.length + 1 : 2,
|
||||||
);
|
);
|
||||||
|
|
||||||
const { currentStep, totalSteps, previousStep } = useStep();
|
const { currentStep, totalSteps, previousStep } = useStep();
|
||||||
|
|
||||||
const {
|
const form = useForm<TAddTemplatePlacholderRecipientsFormSchema>({
|
||||||
control,
|
|
||||||
handleSubmit,
|
|
||||||
getValues,
|
|
||||||
formState: { errors, isSubmitting },
|
|
||||||
} = useForm<TAddTemplatePlacholderRecipientsFormSchema>({
|
|
||||||
resolver: zodResolver(ZAddTemplatePlacholderRecipientsFormSchema),
|
resolver: zodResolver(ZAddTemplatePlacholderRecipientsFormSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
signers:
|
signers:
|
||||||
@ -67,6 +69,8 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
|||||||
name: recipient.name,
|
name: recipient.name,
|
||||||
email: recipient.email,
|
email: recipient.email,
|
||||||
role: recipient.role,
|
role: recipient.role,
|
||||||
|
actionAuth:
|
||||||
|
ZRecipientAuthOptionsSchema.parse(recipient.authOptions)?.actionAuth ?? undefined,
|
||||||
}))
|
}))
|
||||||
: [
|
: [
|
||||||
{
|
{
|
||||||
@ -74,12 +78,33 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
|||||||
name: `Recipient 1`,
|
name: `Recipient 1`,
|
||||||
email: `recipient.1@documenso.com`,
|
email: `recipient.1@documenso.com`,
|
||||||
role: RecipientRole.SIGNER,
|
role: RecipientRole.SIGNER,
|
||||||
|
actionAuth: undefined,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const onFormSubmit = handleSubmit(onSubmit);
|
// Always show advanced settings if any recipient has auth options.
|
||||||
|
const alwaysShowAdvancedSettings = useMemo(() => {
|
||||||
|
const recipientHasAuthOptions = recipients.find((recipient) => {
|
||||||
|
const recipientAuthOptions = ZRecipientAuthOptionsSchema.parse(recipient.authOptions);
|
||||||
|
|
||||||
|
return recipientAuthOptions?.accessAuth || recipientAuthOptions?.actionAuth;
|
||||||
|
});
|
||||||
|
|
||||||
|
const formHasActionAuth = form.getValues('signers').find((signer) => signer.actionAuth);
|
||||||
|
|
||||||
|
return recipientHasAuthOptions !== undefined || formHasActionAuth !== undefined;
|
||||||
|
}, [recipients, form]);
|
||||||
|
|
||||||
|
const [showAdvancedSettings, setShowAdvancedSettings] = useState(alwaysShowAdvancedSettings);
|
||||||
|
|
||||||
|
const {
|
||||||
|
formState: { errors, isSubmitting },
|
||||||
|
control,
|
||||||
|
} = form;
|
||||||
|
|
||||||
|
const onFormSubmit = form.handleSubmit(onSubmit);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
append: appendSigner,
|
append: appendSigner,
|
||||||
@ -102,7 +127,9 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
|||||||
const onAddPlaceholderRecipient = () => {
|
const onAddPlaceholderRecipient = () => {
|
||||||
appendSigner({
|
appendSigner({
|
||||||
formId: nanoid(12),
|
formId: nanoid(12),
|
||||||
|
// Update TEMPLATE_RECIPIENT_NAME_PLACEHOLDER_REGEX if this is ever changed.
|
||||||
name: `Recipient ${placeholderRecipientCount}`,
|
name: `Recipient ${placeholderRecipientCount}`,
|
||||||
|
// Update TEMPLATE_RECIPIENT_EMAIL_PLACEHOLDER_REGEX if this is ever changed.
|
||||||
email: `recipient.${placeholderRecipientCount}@documenso.com`,
|
email: `recipient.${placeholderRecipientCount}@documenso.com`,
|
||||||
role: RecipientRole.SIGNER,
|
role: RecipientRole.SIGNER,
|
||||||
});
|
});
|
||||||
@ -117,150 +144,118 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DocumentFlowFormContainerContent>
|
<DocumentFlowFormContainerContent>
|
||||||
<div className="flex w-full flex-col gap-y-4">
|
<AnimateGenericFadeInOut motionKey={showAdvancedSettings ? 'Show' : 'Hide'}>
|
||||||
<AnimatePresence>
|
<Form {...form}>
|
||||||
|
<div className="flex w-full flex-col gap-y-2">
|
||||||
{signers.map((signer, index) => (
|
{signers.map((signer, index) => (
|
||||||
<motion.div
|
<motion.fieldset
|
||||||
key={signer.id}
|
key={signer.id}
|
||||||
data-native-id={signer.nativeId}
|
data-native-id={signer.nativeId}
|
||||||
className="flex flex-wrap items-end gap-x-4"
|
disabled={isSubmitting}
|
||||||
|
className={cn('grid grid-cols-8 gap-4 pb-4', {
|
||||||
|
'border-b pt-2': showAdvancedSettings,
|
||||||
|
})}
|
||||||
>
|
>
|
||||||
<div className="flex-1">
|
<FormField
|
||||||
<Label htmlFor={`signer-${signer.id}-email`}>Email</Label>
|
control={form.control}
|
||||||
|
name={`signers.${index}.email`}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem
|
||||||
|
className={cn('relative', {
|
||||||
|
'col-span-3': !showAdvancedSettings,
|
||||||
|
'col-span-4': showAdvancedSettings,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{!showAdvancedSettings && index === 0 && (
|
||||||
|
<FormLabel required>Email</FormLabel>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<FormControl>
|
||||||
<Input
|
<Input
|
||||||
id={`signer-${signer.id}-email`}
|
|
||||||
type="email"
|
type="email"
|
||||||
value={signer.email}
|
placeholder="Email"
|
||||||
disabled
|
{...field}
|
||||||
className="bg-background mt-2"
|
disabled={isSubmitting || signers[index].email === user?.email}
|
||||||
/>
|
/>
|
||||||
</div>
|
</FormControl>
|
||||||
|
|
||||||
<div className="flex-1">
|
<FormMessage />
|
||||||
<Label htmlFor={`signer-${signer.id}-name`}>Name</Label>
|
</FormItem>
|
||||||
|
)}
|
||||||
<Input
|
/>
|
||||||
id={`signer-${signer.id}-name`}
|
|
||||||
type="text"
|
<FormField
|
||||||
value={signer.name}
|
control={form.control}
|
||||||
disabled
|
name={`signers.${index}.name`}
|
||||||
className="bg-background mt-2"
|
render={({ field }) => (
|
||||||
/>
|
<FormItem
|
||||||
</div>
|
className={cn({
|
||||||
|
'col-span-3': !showAdvancedSettings,
|
||||||
<div className="w-[60px]">
|
'col-span-4': showAdvancedSettings,
|
||||||
<Controller
|
})}
|
||||||
control={control}
|
>
|
||||||
name={`signers.${index}.role`}
|
{!showAdvancedSettings && index === 0 && <FormLabel>Name</FormLabel>}
|
||||||
render={({ field: { value, onChange } }) => (
|
|
||||||
<Select value={value} onValueChange={(x) => onChange(x)}>
|
<FormControl>
|
||||||
<SelectTrigger className="bg-background">{ROLE_ICONS[value]}</SelectTrigger>
|
<Input
|
||||||
|
placeholder="Name"
|
||||||
<SelectContent className="" align="end">
|
{...field}
|
||||||
<SelectItem value={RecipientRole.SIGNER}>
|
disabled={isSubmitting || signers[index].email === user?.email}
|
||||||
<div className="flex items-center">
|
/>
|
||||||
<div className="flex w-[150px] items-center">
|
</FormControl>
|
||||||
<span className="mr-2">{ROLE_ICONS[RecipientRole.SIGNER]}</span>
|
|
||||||
Needs to sign
|
<FormMessage />
|
||||||
</div>
|
</FormItem>
|
||||||
<Tooltip>
|
)}
|
||||||
<TooltipTrigger>
|
/>
|
||||||
<InfoIcon className="h-4 w-4" />
|
|
||||||
</TooltipTrigger>
|
{showAdvancedSettings && isTemplateOwnerEnterprise && (
|
||||||
<TooltipContent className="text-foreground z-9999 max-w-md p-4">
|
<FormField
|
||||||
<p>
|
control={form.control}
|
||||||
The recipient is required to sign the document for it to be
|
name={`signers.${index}.actionAuth`}
|
||||||
completed.
|
render={({ field }) => (
|
||||||
</p>
|
<FormItem className="col-span-6">
|
||||||
</TooltipContent>
|
<FormControl>
|
||||||
</Tooltip>
|
<RecipientActionAuthSelect
|
||||||
</div>
|
{...field}
|
||||||
</SelectItem>
|
onValueChange={field.onChange}
|
||||||
|
disabled={isSubmitting}
|
||||||
<SelectItem value={RecipientRole.APPROVER}>
|
/>
|
||||||
<div className="flex items-center">
|
</FormControl>
|
||||||
<div className="flex w-[150px] items-center">
|
|
||||||
<span className="mr-2">{ROLE_ICONS[RecipientRole.APPROVER]}</span>
|
<FormMessage />
|
||||||
Needs to approve
|
</FormItem>
|
||||||
</div>
|
)}
|
||||||
<Tooltip>
|
/>
|
||||||
<TooltipTrigger>
|
)}
|
||||||
<InfoIcon className="h-4 w-4" />
|
|
||||||
</TooltipTrigger>
|
<FormField
|
||||||
<TooltipContent className="text-foreground z-9999 max-w-md p-4">
|
name={`signers.${index}.role`}
|
||||||
<p>
|
render={({ field }) => (
|
||||||
The recipient is required to approve the document for it to be
|
<FormItem className="col-span-1 mt-auto">
|
||||||
completed.
|
<FormControl>
|
||||||
</p>
|
<RecipientRoleSelect
|
||||||
</TooltipContent>
|
{...field}
|
||||||
</Tooltip>
|
onValueChange={field.onChange}
|
||||||
</div>
|
disabled={isSubmitting}
|
||||||
</SelectItem>
|
/>
|
||||||
|
</FormControl>
|
||||||
<SelectItem value={RecipientRole.VIEWER}>
|
|
||||||
<div className="flex items-center">
|
<FormMessage />
|
||||||
<div className="flex w-[150px] items-center">
|
</FormItem>
|
||||||
<span className="mr-2">{ROLE_ICONS[RecipientRole.VIEWER]}</span>
|
|
||||||
Needs to view
|
|
||||||
</div>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger>
|
|
||||||
<InfoIcon className="h-4 w-4" />
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent className="text-foreground z-9999 max-w-md p-4">
|
|
||||||
<p>
|
|
||||||
The recipient is required to view the document for it to be
|
|
||||||
completed.
|
|
||||||
</p>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
</SelectItem>
|
|
||||||
|
|
||||||
<SelectItem value={RecipientRole.CC}>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<div className="flex w-[150px] items-center">
|
|
||||||
<span className="mr-2">{ROLE_ICONS[RecipientRole.CC]}</span>
|
|
||||||
Receives copy
|
|
||||||
</div>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger>
|
|
||||||
<InfoIcon className="h-4 w-4" />
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent className="text-foreground z-9999 max-w-md p-4">
|
|
||||||
<p>
|
|
||||||
The recipient is not required to take any action and receives a
|
|
||||||
copy of the document after it is completed.
|
|
||||||
</p>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
</SelectItem>
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="inline-flex h-10 w-10 items-center justify-center text-slate-500 hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-50"
|
className="col-span-1 mt-auto inline-flex h-10 w-10 items-center justify-center text-slate-500 hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
disabled={isSubmitting || signers.length === 1}
|
disabled={isSubmitting || signers.length === 1}
|
||||||
onClick={() => onRemoveSigner(index)}
|
onClick={() => onRemoveSigner(index)}
|
||||||
>
|
>
|
||||||
<Trash className="h-5 w-5" />
|
<Trash className="h-5 w-5" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</motion.fieldset>
|
||||||
|
|
||||||
<div className="w-full">
|
|
||||||
<FormErrorMessage className="mt-2" error={errors.signers?.[index]?.email} />
|
|
||||||
<FormErrorMessage className="mt-2" error={errors.signers?.[index]?.name} />
|
|
||||||
</div>
|
|
||||||
</motion.div>
|
|
||||||
))}
|
))}
|
||||||
</AnimatePresence>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<FormErrorMessage
|
<FormErrorMessage
|
||||||
@ -269,7 +264,11 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
|||||||
error={'signers__root' in errors && errors['signers__root']}
|
error={'signers__root' in errors && errors['signers__root']}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="mt-4 flex flex-row items-center space-x-4">
|
<div
|
||||||
|
className={cn('mt-2 flex flex-row items-center space-x-4', {
|
||||||
|
'mt-4': showAdvancedSettings,
|
||||||
|
})}
|
||||||
|
>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
className="flex-1"
|
className="flex-1"
|
||||||
@ -279,12 +278,14 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
|||||||
<Plus className="-ml-1 mr-2 h-5 w-5" />
|
<Plus className="-ml-1 mr-2 h-5 w-5" />
|
||||||
Add Placeholder Recipient
|
Add Placeholder Recipient
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
className="dark:bg-muted dark:hover:bg-muted/80 bg-black/5 hover:bg-black/10"
|
className="dark:bg-muted dark:hover:bg-muted/80 bg-black/5 hover:bg-black/10"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
disabled={
|
disabled={
|
||||||
isSubmitting || getValues('signers').some((signer) => signer.email === user?.email)
|
isSubmitting ||
|
||||||
|
form.getValues('signers').some((signer) => signer.email === user?.email)
|
||||||
}
|
}
|
||||||
onClick={() => onAddPlaceholderSelfRecipient()}
|
onClick={() => onAddPlaceholderSelfRecipient()}
|
||||||
>
|
>
|
||||||
@ -292,6 +293,27 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
|||||||
Add Myself
|
Add Myself
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{!alwaysShowAdvancedSettings && isTemplateOwnerEnterprise && (
|
||||||
|
<div className="mt-4 flex flex-row items-center">
|
||||||
|
<Checkbox
|
||||||
|
id="showAdvancedRecipientSettings"
|
||||||
|
className="h-5 w-5"
|
||||||
|
checkClassName="dark:text-white text-primary"
|
||||||
|
checked={showAdvancedSettings}
|
||||||
|
onCheckedChange={(value) => setShowAdvancedSettings(Boolean(value))}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<label
|
||||||
|
className="text-muted-foreground ml-2 text-sm"
|
||||||
|
htmlFor="showAdvancedRecipientSettings"
|
||||||
|
>
|
||||||
|
Show advanced settings
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Form>
|
||||||
|
</AnimateGenericFadeInOut>
|
||||||
</DocumentFlowFormContainerContent>
|
</DocumentFlowFormContainerContent>
|
||||||
|
|
||||||
<DocumentFlowFormContainerFooter>
|
<DocumentFlowFormContainerFooter>
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
import { ZRecipientActionAuthTypesSchema } from '@documenso/lib/types/document-auth';
|
||||||
|
|
||||||
|
import { ZMapNegativeOneToUndefinedSchema } from '../document-flow/add-settings.types';
|
||||||
import { RecipientRole } from '.prisma/client';
|
import { RecipientRole } from '.prisma/client';
|
||||||
|
|
||||||
export const ZAddTemplatePlacholderRecipientsFormSchema = z
|
export const ZAddTemplatePlacholderRecipientsFormSchema = z
|
||||||
@ -11,6 +14,9 @@ export const ZAddTemplatePlacholderRecipientsFormSchema = z
|
|||||||
email: z.string().min(1).email(),
|
email: z.string().min(1).email(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
role: z.nativeEnum(RecipientRole),
|
role: z.nativeEnum(RecipientRole),
|
||||||
|
actionAuth: ZMapNegativeOneToUndefinedSchema.pipe(
|
||||||
|
ZRecipientActionAuthTypesSchema.optional(),
|
||||||
|
),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user