mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
Compare commits
1 Commits
feat/bin-t
...
fix/team-m
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e443b1795 |
23
.github/actions/cache-build/action.yml
vendored
Normal file
23
.github/actions/cache-build/action.yml
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
name: Cache production build binaries
|
||||||
|
description: 'Cache or restore if necessary'
|
||||||
|
inputs:
|
||||||
|
node_version:
|
||||||
|
required: false
|
||||||
|
default: v22.x
|
||||||
|
runs:
|
||||||
|
using: 'composite'
|
||||||
|
steps:
|
||||||
|
- name: Cache production build
|
||||||
|
uses: actions/cache@v3
|
||||||
|
id: production-build-cache
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
${{ github.workspace }}/apps/web/.next
|
||||||
|
**/.turbo/**
|
||||||
|
**/dist/**
|
||||||
|
|
||||||
|
key: prod-build-${{ github.run_id }}-${{ hashFiles('package-lock.json') }}
|
||||||
|
restore-keys: prod-build-
|
||||||
|
|
||||||
|
- run: npm run build
|
||||||
|
shell: bash
|
||||||
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -26,8 +26,7 @@ jobs:
|
|||||||
- name: Copy env
|
- name: Copy env
|
||||||
run: cp .env.example .env
|
run: cp .env.example .env
|
||||||
|
|
||||||
- name: Build app
|
- uses: ./.github/actions/cache-build
|
||||||
run: npm run build
|
|
||||||
|
|
||||||
build_docker:
|
build_docker:
|
||||||
name: Build Docker Image
|
name: Build Docker Image
|
||||||
|
|||||||
29
.github/workflows/clean-cache.yml
vendored
Normal file
29
.github/workflows/clean-cache.yml
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
name: cleanup caches by a branch
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- closed
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
cleanup:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Cleanup
|
||||||
|
run: |
|
||||||
|
gh extension install actions/gh-actions-cache
|
||||||
|
|
||||||
|
echo "Fetching list of cache key"
|
||||||
|
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
|
||||||
|
|
||||||
|
## Setting this to not fail the workflow while deleting cache keys.
|
||||||
|
set +e
|
||||||
|
echo "Deleting caches..."
|
||||||
|
for cacheKey in $cacheKeysForPR
|
||||||
|
do
|
||||||
|
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
|
||||||
|
done
|
||||||
|
echo "Done"
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
|
||||||
5
.github/workflows/codeql-analysis.yml
vendored
5
.github/workflows/codeql-analysis.yml
vendored
@ -10,7 +10,7 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
analyze:
|
analyze:
|
||||||
name: Analyze
|
name: Analyze
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-22.04
|
||||||
permissions:
|
permissions:
|
||||||
actions: read
|
actions: read
|
||||||
contents: read
|
contents: read
|
||||||
@ -30,8 +30,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: ./.github/actions/node-install
|
- uses: ./.github/actions/node-install
|
||||||
|
|
||||||
- name: Build app
|
- uses: ./.github/actions/cache-build
|
||||||
run: npm run build
|
|
||||||
|
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v3
|
uses: github/codeql-action/init@v3
|
||||||
|
|||||||
3
.github/workflows/e2e-tests.yml
vendored
3
.github/workflows/e2e-tests.yml
vendored
@ -28,8 +28,7 @@ jobs:
|
|||||||
- name: Seed the database
|
- name: Seed the database
|
||||||
run: npm run prisma:seed
|
run: npm run prisma:seed
|
||||||
|
|
||||||
- name: Build app
|
- uses: ./.github/actions/cache-build
|
||||||
run: npm run build
|
|
||||||
|
|
||||||
- name: Run Playwright tests
|
- name: Run Playwright tests
|
||||||
run: npm run ci
|
run: npm run ci
|
||||||
|
|||||||
@ -1 +1,4 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
. "$(dirname -- "$0")/_/husky.sh"
|
||||||
|
|
||||||
npm run commitlint -- $1
|
npm run commitlint -- $1
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
. "$(dirname -- "$0")/_/husky.sh"
|
||||||
|
|
||||||
SCRIPT_DIR="$(readlink -f "$(dirname "$0")")"
|
SCRIPT_DIR="$(readlink -f "$(dirname "$0")")"
|
||||||
MONOREPO_ROOT="$(readlink -f "$SCRIPT_DIR/../")"
|
MONOREPO_ROOT="$(readlink -f "$SCRIPT_DIR/../")"
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,5 @@
|
|||||||
"solid": "Solid Integration",
|
"solid": "Solid Integration",
|
||||||
"preact": "Preact Integration",
|
"preact": "Preact Integration",
|
||||||
"angular": "Angular Integration",
|
"angular": "Angular Integration",
|
||||||
"css-variables": "CSS Variables",
|
"css-variables": "CSS Variables"
|
||||||
"authoring": "Authoring"
|
|
||||||
}
|
}
|
||||||
@ -1,167 +0,0 @@
|
|||||||
---
|
|
||||||
title: Authoring
|
|
||||||
description: Learn how to use embedded authoring to create documents and templates in your application
|
|
||||||
---
|
|
||||||
|
|
||||||
# Embedded Authoring
|
|
||||||
|
|
||||||
In addition to embedding signing experiences, Documenso now supports embedded authoring, allowing you to integrate document and template creation directly within your application.
|
|
||||||
|
|
||||||
## How Embedded Authoring Works
|
|
||||||
|
|
||||||
The embedded authoring feature enables your users to create new documents without leaving your application. This process works through secure presign tokens that authenticate the embedding session and manage permissions.
|
|
||||||
|
|
||||||
## Creating Documents with Embedded Authoring
|
|
||||||
|
|
||||||
To implement document creation in your application, use the `EmbedCreateDocument` component from our SDK:
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
import { unstable_EmbedCreateDocument as EmbedCreateDocument } from '@documenso/embed-react';
|
|
||||||
|
|
||||||
const DocumentCreator = () => {
|
|
||||||
// You'll need to obtain a presign token using your API key
|
|
||||||
const presignToken = 'YOUR_PRESIGN_TOKEN';
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{ height: '800px', width: '100%' }}>
|
|
||||||
<EmbedCreateDocument
|
|
||||||
presignToken={presignToken}
|
|
||||||
externalId="order-12345"
|
|
||||||
onDocumentCreated={(data) => {
|
|
||||||
console.log('Document created with ID:', data.documentId);
|
|
||||||
console.log('External reference ID:', data.externalId);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
## Obtaining a Presign Token
|
|
||||||
|
|
||||||
Before using the `EmbedCreateDocument` component, you'll need to obtain a presign token from your backend. This token authorizes the embedding session.
|
|
||||||
|
|
||||||
You can create a presign token by making a request to:
|
|
||||||
|
|
||||||
```
|
|
||||||
POST /api/v2-beta/embedding/create-presign-token
|
|
||||||
```
|
|
||||||
|
|
||||||
This API endpoint requires authentication with your Documenso API key. The token has a default expiration of 1 hour, but you can customize this duration based on your security requirements.
|
|
||||||
|
|
||||||
You can find more details on this request at our [API Documentation](https://openapi.documenso.com/reference#tag/embedding)
|
|
||||||
|
|
||||||
## Configuration Options
|
|
||||||
|
|
||||||
The `EmbedCreateDocument` component accepts several configuration options:
|
|
||||||
|
|
||||||
| Option | Type | Description |
|
|
||||||
| ------------------ | ------- | ------------------------------------------------------------------ |
|
|
||||||
| `presignToken` | string | **Required**. The authentication token for the embedding session. |
|
|
||||||
| `externalId` | string | Optional reference ID from your system to link with the document. |
|
|
||||||
| `host` | string | Optional custom host URL. Defaults to `https://app.documenso.com`. |
|
|
||||||
| `css` | string | Optional custom CSS to style the embedded component. |
|
|
||||||
| `cssVars` | object | Optional CSS variables for colors, spacing, and more. |
|
|
||||||
| `darkModeDisabled` | boolean | Optional flag to disable dark mode. |
|
|
||||||
| `className` | string | Optional CSS class name for the iframe. |
|
|
||||||
|
|
||||||
## Feature Toggles
|
|
||||||
|
|
||||||
You can customize the authoring experience by enabling or disabling specific features:
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
<EmbedCreateDocument
|
|
||||||
presignToken="YOUR_PRESIGN_TOKEN"
|
|
||||||
features={{
|
|
||||||
allowConfigureSignatureTypes: true,
|
|
||||||
allowConfigureLanguage: true,
|
|
||||||
allowConfigureDateFormat: true,
|
|
||||||
allowConfigureTimezone: true,
|
|
||||||
allowConfigureRedirectUrl: true,
|
|
||||||
allowConfigureCommunication: true,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
```
|
|
||||||
|
|
||||||
## Handling Document Creation Events
|
|
||||||
|
|
||||||
The `onDocumentCreated` callback is triggered when a document is successfully created, providing both the document ID and your external reference ID:
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
<EmbedCreateDocument
|
|
||||||
presignToken="YOUR_PRESIGN_TOKEN"
|
|
||||||
externalId="order-12345"
|
|
||||||
onDocumentCreated={(data) => {
|
|
||||||
// Navigate to a success page
|
|
||||||
navigate(`/documents/success?id=${data.documentId}`);
|
|
||||||
|
|
||||||
// Or update your database with the document ID
|
|
||||||
updateOrderDocument(data.externalId, data.documentId);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
```
|
|
||||||
|
|
||||||
## Styling the Embedded Component
|
|
||||||
|
|
||||||
You can customize the appearance of the embedded component using standard CSS classes:
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
<EmbedCreateDocument
|
|
||||||
className="h-screen w-full rounded-lg border-none shadow-md"
|
|
||||||
presignToken="YOUR_PRESIGN_TOKEN"
|
|
||||||
css={`
|
|
||||||
.documenso-embed {
|
|
||||||
border-radius: 8px;
|
|
||||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
cssVars={{
|
|
||||||
primary: '#0000FF',
|
|
||||||
background: '#F5F5F5',
|
|
||||||
radius: '8px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
```
|
|
||||||
|
|
||||||
## Complete Integration Example
|
|
||||||
|
|
||||||
Here's a complete example of integrating document creation in a React application:
|
|
||||||
|
|
||||||
```tsx
|
|
||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
import { unstable_EmbedCreateDocument as EmbedCreateDocument } from '@documenso/embed-react';
|
|
||||||
|
|
||||||
function DocumentCreator() {
|
|
||||||
// In a real application, you would fetch this token from your backend
|
|
||||||
// using your API key at /api/v2-beta/embedding/create-presign-token
|
|
||||||
const presignToken = 'YOUR_PRESIGN_TOKEN';
|
|
||||||
const [documentId, setDocumentId] = useState<number | null>(null);
|
|
||||||
|
|
||||||
if (documentId) {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h2>Document Created Successfully!</h2>
|
|
||||||
<p>Document ID: {documentId}</p>
|
|
||||||
<button onClick={() => setDocumentId(null)}>Create Another Document</button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{ height: '800px', width: '100%' }}>
|
|
||||||
<EmbedCreateDocument
|
|
||||||
presignToken={presignToken}
|
|
||||||
externalId="order-12345"
|
|
||||||
onDocumentCreated={(data) => {
|
|
||||||
setDocumentId(data.documentId);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default DocumentCreator;
|
|
||||||
```
|
|
||||||
|
|
||||||
With embedded authoring, your users can seamlessly create documents within your application, enhancing the overall user experience and streamlining document workflows.
|
|
||||||
@ -52,9 +52,9 @@ Platform customers have access to advanced styling options to customize the embe
|
|||||||
<EmbedDirectTemplate
|
<EmbedDirectTemplate
|
||||||
token={token}
|
token={token}
|
||||||
cssVars={{
|
cssVars={{
|
||||||
primary: '#0000FF',
|
colorPrimary: '#0000FF',
|
||||||
background: '#F5F5F5',
|
colorBackground: '#F5F5F5',
|
||||||
radius: '8px',
|
borderRadius: '8px',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
@ -169,19 +169,6 @@ Once you've obtained the appropriate tokens, you can integrate the signing exper
|
|||||||
|
|
||||||
If you're using **web components**, the integration process is slightly different. Keep in mind that web components are currently less tested but can still provide flexibility for general use cases.
|
If you're using **web components**, the integration process is slightly different. Keep in mind that web components are currently less tested but can still provide flexibility for general use cases.
|
||||||
|
|
||||||
## Embedded Authoring
|
|
||||||
|
|
||||||
In addition to embedding signing experiences, Documenso now supports **embedded authoring**, allowing your users to create documents and templates directly within your application.
|
|
||||||
|
|
||||||
With embedded authoring, you can:
|
|
||||||
|
|
||||||
- Create new documents with custom fields
|
|
||||||
- Configure document properties and settings
|
|
||||||
- Set up recipients and signing workflows
|
|
||||||
- Customize the authoring experience
|
|
||||||
|
|
||||||
For detailed implementation instructions and code examples, see our [Embedded Authoring](/developers/embedding/authoring) guide.
|
|
||||||
|
|
||||||
## Related
|
## Related
|
||||||
|
|
||||||
- [React Integration](/developers/embedding/react)
|
- [React Integration](/developers/embedding/react)
|
||||||
@ -191,4 +178,3 @@ For detailed implementation instructions and code examples, see our [Embedded Au
|
|||||||
- [Preact Integration](/developers/embedding/preact)
|
- [Preact Integration](/developers/embedding/preact)
|
||||||
- [Angular Integration](/developers/embedding/angular)
|
- [Angular Integration](/developers/embedding/angular)
|
||||||
- [CSS Variables](/developers/embedding/css-variables)
|
- [CSS Variables](/developers/embedding/css-variables)
|
||||||
- [Embedded Authoring](/developers/embedding/authoring)
|
|
||||||
|
|||||||
@ -95,9 +95,9 @@ const MyEmbeddingComponent = () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const cssVars = {
|
const cssVars = {
|
||||||
primary: '#0000FF',
|
colorPrimary: '#0000FF',
|
||||||
background: '#F5F5F5',
|
colorBackground: '#F5F5F5',
|
||||||
radius: '8px',
|
borderRadius: '8px',
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -99,9 +99,9 @@ const MyEmbeddingComponent = () => {
|
|||||||
`}
|
`}
|
||||||
// CSS Variables
|
// CSS Variables
|
||||||
cssVars={{
|
cssVars={{
|
||||||
primary: '#0000FF',
|
colorPrimary: '#0000FF',
|
||||||
background: '#F5F5F5',
|
colorBackground: '#F5F5F5',
|
||||||
radius: '8px',
|
borderRadius: '8px',
|
||||||
}}
|
}}
|
||||||
// Dark Mode Control
|
// Dark Mode Control
|
||||||
darkModeDisabled={true}
|
darkModeDisabled={true}
|
||||||
|
|||||||
@ -95,9 +95,9 @@ const MyEmbeddingComponent = () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const cssVars = {
|
const cssVars = {
|
||||||
primary: '#0000FF',
|
colorPrimary: '#0000FF',
|
||||||
background: '#F5F5F5',
|
colorBackground: '#F5F5F5',
|
||||||
radius: '8px',
|
borderRadius: '8px',
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -97,9 +97,9 @@ Platform customers have access to advanced styling options:
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const cssVars = {
|
const cssVars = {
|
||||||
primary: '#0000FF',
|
colorPrimary: '#0000FF',
|
||||||
background: '#F5F5F5',
|
colorBackground: '#F5F5F5',
|
||||||
radius: '8px',
|
borderRadius: '8px',
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -97,9 +97,9 @@ Platform customers have access to advanced styling options:
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const cssVars = {
|
const cssVars = {
|
||||||
primary: '#0000FF',
|
colorPrimary: '#0000FF',
|
||||||
background: '#F5F5F5',
|
colorBackground: '#F5F5F5',
|
||||||
radius: '8px',
|
borderRadius: '8px',
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -532,93 +532,3 @@ Replace the `text` value with the corresponding field type:
|
|||||||
- For the `SELECT` field it should be `select`. (check this before merge)
|
- For the `SELECT` field it should be `select`. (check this before merge)
|
||||||
|
|
||||||
You must pass this property at all times, even if you don't need to set any other properties. If you don't, the endpoint will throw an error.
|
You must pass this property at all times, even if you don't need to set any other properties. If you don't, the endpoint will throw an error.
|
||||||
|
|
||||||
## Pre-fill Fields On Document Creation
|
|
||||||
|
|
||||||
The API allows you to pre-fill fields on document creation. This is useful when you want to create a document from an existing template and pre-fill the fields with specific values.
|
|
||||||
|
|
||||||
To pre-fill a field, you need to make a `POST` request to the `/api/v1/templates/{templateId}/generate-document` endpoint with the field information. Here's an example:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"title": "my-document.pdf",
|
|
||||||
"recipients": [
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"name": "Example User",
|
|
||||||
"email": "example@documenso.com",
|
|
||||||
"signingOrder": 1,
|
|
||||||
"role": "SIGNER"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"prefillFields": [
|
|
||||||
{
|
|
||||||
"id": 21,
|
|
||||||
"type": "text",
|
|
||||||
"label": "my-label",
|
|
||||||
"placeholder": "my-placeholder",
|
|
||||||
"value": "my-value"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 22,
|
|
||||||
"type": "number",
|
|
||||||
"label": "my-label",
|
|
||||||
"placeholder": "my-placeholder",
|
|
||||||
"value": "123"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 23,
|
|
||||||
"type": "checkbox",
|
|
||||||
"label": "my-label",
|
|
||||||
"placeholder": "my-placeholder",
|
|
||||||
"value": ["option-1", "option-2"]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Check out the endpoint in the [API V1 documentation](https://app.documenso.com/api/v1/openapi#:~:text=/%7BtemplateId%7D/-,generate,-%2Ddocument).
|
|
||||||
|
|
||||||
### API V2
|
|
||||||
|
|
||||||
For API V2, you need to make a `POST` request to the `/api/v2-beta/template/use` endpoint with the field(s) information. Here's an example:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"templateId": 111,
|
|
||||||
"recipients": [
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"name": "Example User",
|
|
||||||
"email": "example@documenso.com",
|
|
||||||
"signingOrder": 1,
|
|
||||||
"role": "SIGNER"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"prefillFields": [
|
|
||||||
{
|
|
||||||
"id": 21,
|
|
||||||
"type": "text",
|
|
||||||
"label": "my-label",
|
|
||||||
"placeholder": "my-placeholder",
|
|
||||||
"value": "my-value"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 22,
|
|
||||||
"type": "number",
|
|
||||||
"label": "my-label",
|
|
||||||
"placeholder": "my-placeholder",
|
|
||||||
"value": "123"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 23,
|
|
||||||
"type": "checkbox",
|
|
||||||
"label": "my-label",
|
|
||||||
"placeholder": "my-placeholder",
|
|
||||||
"value": ["option-1", "option-2"]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Check out the endpoint in the [API V2 documentation](https://openapi.documenso.com/reference#tag/template/POST/template/use).
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import NextPlausibleProvider from 'next-plausible';
|
import NextPlausibleProvider from 'next-plausible';
|
||||||
|
|||||||
@ -1,54 +0,0 @@
|
|||||||
import { DateTime } from 'luxon';
|
|
||||||
|
|
||||||
export interface TransformedData {
|
|
||||||
labels: string[];
|
|
||||||
datasets: Array<{
|
|
||||||
label: string;
|
|
||||||
data: number[];
|
|
||||||
}>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addZeroMonth(transformedData: TransformedData): TransformedData {
|
|
||||||
const result = {
|
|
||||||
labels: [...transformedData.labels],
|
|
||||||
datasets: transformedData.datasets.map((dataset) => ({
|
|
||||||
label: dataset.label,
|
|
||||||
data: [...dataset.data],
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (result.labels.length === 0) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.datasets.every((dataset) => dataset.data[0] === 0)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
let firstMonth = DateTime.fromFormat(result.labels[0], 'MMM yyyy');
|
|
||||||
if (!firstMonth.isValid) {
|
|
||||||
const formats = ['MMM yyyy', 'MMMM yyyy', 'MM/yyyy', 'yyyy-MM'];
|
|
||||||
|
|
||||||
for (const format of formats) {
|
|
||||||
firstMonth = DateTime.fromFormat(result.labels[0], format);
|
|
||||||
if (firstMonth.isValid) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!firstMonth.isValid) {
|
|
||||||
console.warn(`Could not parse date: "${result.labels[0]}"`);
|
|
||||||
return transformedData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const zeroMonth = firstMonth.minus({ months: 1 }).toFormat('MMM yyyy');
|
|
||||||
result.labels.unshift(zeroMonth);
|
|
||||||
result.datasets.forEach((dataset) => {
|
|
||||||
dataset.data.unshift(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
} catch (error) {
|
|
||||||
return transformedData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +1,7 @@
|
|||||||
import { DocumentStatus } from '@prisma/client';
|
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
import { kyselyPrisma, sql } from '@documenso/prisma';
|
import { kyselyPrisma, sql } from '@documenso/prisma';
|
||||||
|
import { DocumentStatus } from '@documenso/prisma/client';
|
||||||
import { addZeroMonth } from '../add-zero-month';
|
|
||||||
|
|
||||||
export const getCompletedDocumentsMonthly = async (type: 'count' | 'cumulative' = 'count') => {
|
export const getCompletedDocumentsMonthly = async (type: 'count' | 'cumulative' = 'count') => {
|
||||||
const qb = kyselyPrisma.$kysely
|
const qb = kyselyPrisma.$kysely
|
||||||
@ -37,7 +35,7 @@ export const getCompletedDocumentsMonthly = async (type: 'count' | 'cumulative'
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
return addZeroMonth(transformedData);
|
return transformedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GetCompletedDocumentsMonthlyResult = Awaited<
|
export type GetCompletedDocumentsMonthlyResult = Awaited<
|
||||||
|
|||||||
@ -2,8 +2,6 @@ import { DateTime } from 'luxon';
|
|||||||
|
|
||||||
import { kyselyPrisma, sql } from '@documenso/prisma';
|
import { kyselyPrisma, sql } from '@documenso/prisma';
|
||||||
|
|
||||||
import { addZeroMonth } from '../add-zero-month';
|
|
||||||
|
|
||||||
export const getSignerConversionMonthly = async (type: 'count' | 'cumulative' = 'count') => {
|
export const getSignerConversionMonthly = async (type: 'count' | 'cumulative' = 'count') => {
|
||||||
const qb = kyselyPrisma.$kysely
|
const qb = kyselyPrisma.$kysely
|
||||||
.selectFrom('Recipient')
|
.selectFrom('Recipient')
|
||||||
@ -36,7 +34,7 @@ export const getSignerConversionMonthly = async (type: 'count' | 'cumulative' =
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
return addZeroMonth(transformedData);
|
return transformedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GetSignerConversionMonthlyResult = Awaited<
|
export type GetSignerConversionMonthlyResult = Awaited<
|
||||||
|
|||||||
@ -2,8 +2,6 @@ import { DateTime } from 'luxon';
|
|||||||
|
|
||||||
import { kyselyPrisma, sql } from '@documenso/prisma';
|
import { kyselyPrisma, sql } from '@documenso/prisma';
|
||||||
|
|
||||||
import { addZeroMonth } from '../add-zero-month';
|
|
||||||
|
|
||||||
export const getUserMonthlyGrowth = async (type: 'count' | 'cumulative' = 'count') => {
|
export const getUserMonthlyGrowth = async (type: 'count' | 'cumulative' = 'count') => {
|
||||||
const qb = kyselyPrisma.$kysely
|
const qb = kyselyPrisma.$kysely
|
||||||
.selectFrom('User')
|
.selectFrom('User')
|
||||||
@ -34,7 +32,7 @@ export const getUserMonthlyGrowth = async (type: 'count' | 'cumulative' = 'count
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
return addZeroMonth(transformedData);
|
return transformedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GetUserMonthlyGrowthResult = Awaited<ReturnType<typeof getUserMonthlyGrowth>>;
|
export type GetUserMonthlyGrowthResult = Awaited<ReturnType<typeof getUserMonthlyGrowth>>;
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
import { addZeroMonth } from './add-zero-month';
|
|
||||||
|
|
||||||
type MetricKeys = {
|
type MetricKeys = {
|
||||||
stars: number;
|
stars: number;
|
||||||
forks: number;
|
forks: number;
|
||||||
@ -39,77 +37,31 @@ export function transformData({
|
|||||||
data: DataEntry;
|
data: DataEntry;
|
||||||
metric: MetricKey;
|
metric: MetricKey;
|
||||||
}): TransformData {
|
}): TransformData {
|
||||||
try {
|
|
||||||
if (!data || Object.keys(data).length === 0) {
|
|
||||||
return {
|
|
||||||
labels: [],
|
|
||||||
datasets: [{ label: `Total ${FRIENDLY_METRIC_NAMES[metric]}`, data: [] }],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const sortedEntries = Object.entries(data).sort(([dateA], [dateB]) => {
|
const sortedEntries = Object.entries(data).sort(([dateA], [dateB]) => {
|
||||||
try {
|
|
||||||
const [yearA, monthA] = dateA.split('-').map(Number);
|
const [yearA, monthA] = dateA.split('-').map(Number);
|
||||||
const [yearB, monthB] = dateB.split('-').map(Number);
|
const [yearB, monthB] = dateB.split('-').map(Number);
|
||||||
|
|
||||||
if (isNaN(yearA) || isNaN(monthA) || isNaN(yearB) || isNaN(monthB)) {
|
|
||||||
console.warn(`Invalid date format: ${dateA} or ${dateB}`);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return DateTime.local(yearA, monthA).toMillis() - DateTime.local(yearB, monthB).toMillis();
|
return DateTime.local(yearA, monthA).toMillis() - DateTime.local(yearB, monthB).toMillis();
|
||||||
} catch (error) {
|
|
||||||
console.error('Error sorting entries:', error);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const labels = sortedEntries.map(([date]) => {
|
const labels = sortedEntries.map(([date]) => {
|
||||||
try {
|
|
||||||
const [year, month] = date.split('-');
|
const [year, month] = date.split('-');
|
||||||
|
|
||||||
if (!year || !month || isNaN(Number(year)) || isNaN(Number(month))) {
|
|
||||||
console.warn(`Invalid date format: ${date}`);
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dateTime = DateTime.fromObject({
|
const dateTime = DateTime.fromObject({
|
||||||
year: Number(year),
|
year: Number(year),
|
||||||
month: Number(month),
|
month: Number(month),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!dateTime.isValid) {
|
|
||||||
console.warn(`Invalid DateTime object for: ${date}`);
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dateTime.toFormat('MMM yyyy');
|
return dateTime.toFormat('MMM yyyy');
|
||||||
} catch (error) {
|
|
||||||
console.error('Error formatting date:', error, date);
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const transformedData = {
|
return {
|
||||||
labels,
|
labels,
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: `Total ${FRIENDLY_METRIC_NAMES[metric]}`,
|
label: `Total ${FRIENDLY_METRIC_NAMES[metric]}`,
|
||||||
data: sortedEntries.map(([_, stats]) => {
|
data: sortedEntries.map(([_, stats]) => stats[metric]),
|
||||||
const value = stats[metric];
|
|
||||||
return typeof value === 'number' && !isNaN(value) ? value : 0;
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
return addZeroMonth(transformedData);
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
labels: [],
|
|
||||||
datasets: [{ label: `Total ${FRIENDLY_METRIC_NAMES[metric]}`, data: [] }],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// To be on the safer side
|
// To be on the safer side
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
# Exit on error.
|
# Exit on error.
|
||||||
set -e
|
set -eo pipefail
|
||||||
|
|
||||||
SCRIPT_DIR="$(readlink -f "$(dirname "$0")")"
|
SCRIPT_DIR="$(readlink -f "$(dirname "$0")")"
|
||||||
WEB_APP_DIR="$SCRIPT_DIR/.."
|
WEB_APP_DIR="$SCRIPT_DIR/.."
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { useForm } from 'react-hook-form';
|
|
||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import {
|
import {
|
||||||
@ -12,171 +9,64 @@ import {
|
|||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from '@documenso/ui/primitives/dialog';
|
} from '@documenso/ui/primitives/dialog';
|
||||||
import {
|
|
||||||
Form,
|
|
||||||
FormControl,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormMessage,
|
|
||||||
} from '@documenso/ui/primitives/form/form';
|
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
|
||||||
|
|
||||||
import { DocumentSigningDisclosure } from '../general/document-signing/document-signing-disclosure';
|
import { DocumentSigningDisclosure } from '../general/document-signing/document-signing-disclosure';
|
||||||
|
|
||||||
export type NextSigner = {
|
|
||||||
name: string;
|
|
||||||
email: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type ConfirmationDialogProps = {
|
type ConfirmationDialogProps = {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onConfirm: (nextSigner?: NextSigner) => void;
|
onConfirm: () => void;
|
||||||
hasUninsertedFields: boolean;
|
hasUninsertedFields: boolean;
|
||||||
isSubmitting: boolean;
|
isSubmitting: boolean;
|
||||||
allowDictateNextSigner?: boolean;
|
|
||||||
defaultNextSigner?: NextSigner;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const ZNextSignerFormSchema = z.object({
|
|
||||||
name: z.string().min(1, 'Name is required'),
|
|
||||||
email: z.string().email('Invalid email address'),
|
|
||||||
});
|
|
||||||
|
|
||||||
type TNextSignerFormSchema = z.infer<typeof ZNextSignerFormSchema>;
|
|
||||||
|
|
||||||
export function AssistantConfirmationDialog({
|
export function AssistantConfirmationDialog({
|
||||||
isOpen,
|
isOpen,
|
||||||
onClose,
|
onClose,
|
||||||
onConfirm,
|
onConfirm,
|
||||||
hasUninsertedFields,
|
hasUninsertedFields,
|
||||||
isSubmitting,
|
isSubmitting,
|
||||||
allowDictateNextSigner = false,
|
|
||||||
defaultNextSigner,
|
|
||||||
}: ConfirmationDialogProps) {
|
}: ConfirmationDialogProps) {
|
||||||
const form = useForm<TNextSignerFormSchema>({
|
|
||||||
resolver: zodResolver(ZNextSignerFormSchema),
|
|
||||||
defaultValues: {
|
|
||||||
name: defaultNextSigner?.name ?? '',
|
|
||||||
email: defaultNextSigner?.email ?? '',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const onOpenChange = () => {
|
const onOpenChange = () => {
|
||||||
if (isSubmitting) {
|
if (isSubmitting) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
form.reset({
|
|
||||||
name: defaultNextSigner?.name ?? '',
|
|
||||||
email: defaultNextSigner?.email ?? '',
|
|
||||||
});
|
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = () => {
|
|
||||||
// Validate the form and submit it if dictate signer is enabled.
|
|
||||||
if (allowDictateNextSigner) {
|
|
||||||
void form.handleSubmit(onConfirm)();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
onConfirm();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={isOpen} onOpenChange={onOpenChange}>
|
<Dialog open={isOpen} onOpenChange={onOpenChange}>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<Form {...form}>
|
|
||||||
<form>
|
|
||||||
<fieldset disabled={isSubmitting} className="border-none p-0">
|
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
<Trans>Complete Document</Trans>
|
<Trans>Complete Document</Trans>
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
<Trans>
|
<Trans>
|
||||||
Are you sure you want to complete the document? This action cannot be undone.
|
Are you sure you want to complete the document? This action cannot be undone. Please
|
||||||
Please ensure that you have completed prefilling all relevant fields before
|
ensure that you have completed prefilling all relevant fields before proceeding.
|
||||||
proceeding.
|
|
||||||
</Trans>
|
</Trans>
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="mt-4 flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
{allowDictateNextSigner && (
|
<DocumentSigningDisclosure />
|
||||||
<div className="my-2">
|
|
||||||
<p className="text-muted-foreground mb-1 text-sm font-semibold">
|
|
||||||
The next recipient to sign this document will be{' '}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div className="flex flex-col gap-4 rounded-xl border p-4 md:flex-row">
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="name"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="flex-1">
|
|
||||||
<FormLabel>
|
|
||||||
<Trans>Name</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
className="mt-2"
|
|
||||||
placeholder="Enter the next signer's name"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="email"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="flex-1">
|
|
||||||
<FormLabel>
|
|
||||||
<Trans>Email</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
type="email"
|
|
||||||
className="mt-2"
|
|
||||||
placeholder="Enter the next signer's email"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<DocumentSigningDisclosure className="mt-4" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DialogFooter className="mt-4">
|
<DialogFooter className="mt-4">
|
||||||
<Button type="button" variant="secondary" onClick={onClose} disabled={isSubmitting}>
|
<Button variant="secondary" onClick={onClose} disabled={isSubmitting}>
|
||||||
<Trans>Cancel</Trans>
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
|
||||||
variant={hasUninsertedFields ? 'destructive' : 'default'}
|
variant={hasUninsertedFields ? 'destructive' : 'default'}
|
||||||
|
onClick={onConfirm}
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
onClick={handleSubmit}
|
|
||||||
loading={isSubmitting}
|
loading={isSubmitting}
|
||||||
>
|
>
|
||||||
{hasUninsertedFields ? <Trans>Proceed</Trans> : <Trans>Continue</Trans>}
|
{isSubmitting ? 'Submitting...' : hasUninsertedFields ? 'Proceed' : 'Continue'}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</fieldset>
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { msg } from '@lingui/core/macro';
|
|||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { DocumentStatus } from '@prisma/client';
|
import { DocumentStatus } from '@prisma/client';
|
||||||
import { P, match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
import { useLimits } from '@documenso/ee/server-only/limits/provider/client';
|
import { useLimits } from '@documenso/ee/server-only/limits/provider/client';
|
||||||
import { trpc as trpcReact } from '@documenso/trpc/react';
|
import { trpc as trpcReact } from '@documenso/trpc/react';
|
||||||
@ -146,7 +146,7 @@ export const DocumentDeleteDialog = ({
|
|||||||
</ul>
|
</ul>
|
||||||
</AlertDescription>
|
</AlertDescription>
|
||||||
))
|
))
|
||||||
.with(P.union(DocumentStatus.COMPLETED, DocumentStatus.REJECTED), () => (
|
.with(DocumentStatus.COMPLETED, () => (
|
||||||
<AlertDescription>
|
<AlertDescription>
|
||||||
<p>
|
<p>
|
||||||
<Trans>By deleting this document, the following will occur:</Trans>
|
<Trans>By deleting this document, the following will occur:</Trans>
|
||||||
@ -162,16 +162,7 @@ export const DocumentDeleteDialog = ({
|
|||||||
</ul>
|
</ul>
|
||||||
</AlertDescription>
|
</AlertDescription>
|
||||||
))
|
))
|
||||||
// DocumentStatus.REJECTED isnt working currently so this is a fallback to prevent 500 error.
|
.exhaustive()}
|
||||||
// The union should work but currently its not
|
|
||||||
.otherwise(() => (
|
|
||||||
<AlertDescription>
|
|
||||||
<Trans>
|
|
||||||
Please note that this action is <strong>irreversible</strong>. Once confirmed,
|
|
||||||
this document will be permanently deleted.
|
|
||||||
</Trans>
|
|
||||||
</AlertDescription>
|
|
||||||
))}
|
|
||||||
</Alert>
|
</Alert>
|
||||||
) : (
|
) : (
|
||||||
<Alert variant="warning" className="-mt-1">
|
<Alert variant="warning" className="-mt-1">
|
||||||
|
|||||||
@ -1,119 +0,0 @@
|
|||||||
import { msg } from '@lingui/core/macro';
|
|
||||||
import { useLingui } from '@lingui/react';
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
|
||||||
|
|
||||||
import { useLimits } from '@documenso/ee/server-only/limits/provider/client';
|
|
||||||
import { trpc as trpcReact } from '@documenso/trpc/react';
|
|
||||||
import { Alert, AlertDescription } from '@documenso/ui/primitives/alert';
|
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
} from '@documenso/ui/primitives/dialog';
|
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
||||||
|
|
||||||
type DocumentRestoreDialogProps = {
|
|
||||||
id: number;
|
|
||||||
open: boolean;
|
|
||||||
onOpenChange: (_open: boolean) => void;
|
|
||||||
onRestore?: () => Promise<void> | void;
|
|
||||||
documentTitle: string;
|
|
||||||
teamId?: number;
|
|
||||||
canManageDocument: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DocumentRestoreDialog = ({
|
|
||||||
id,
|
|
||||||
open,
|
|
||||||
onOpenChange,
|
|
||||||
onRestore,
|
|
||||||
documentTitle,
|
|
||||||
canManageDocument,
|
|
||||||
}: DocumentRestoreDialogProps) => {
|
|
||||||
const { toast } = useToast();
|
|
||||||
const { refreshLimits } = useLimits();
|
|
||||||
const { _ } = useLingui();
|
|
||||||
|
|
||||||
const { mutateAsync: restoreDocument, isPending } =
|
|
||||||
trpcReact.document.restoreDocument.useMutation({
|
|
||||||
onSuccess: async () => {
|
|
||||||
void refreshLimits();
|
|
||||||
|
|
||||||
toast({
|
|
||||||
title: _(msg`Document restored`),
|
|
||||||
description: _(msg`"${documentTitle}" has been successfully restored`),
|
|
||||||
duration: 5000,
|
|
||||||
});
|
|
||||||
|
|
||||||
await onRestore?.();
|
|
||||||
|
|
||||||
onOpenChange(false);
|
|
||||||
},
|
|
||||||
onError: () => {
|
|
||||||
toast({
|
|
||||||
title: _(msg`Something went wrong`),
|
|
||||||
description: _(msg`This document could not be restored at this time. Please try again.`),
|
|
||||||
variant: 'destructive',
|
|
||||||
duration: 7500,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog open={open} onOpenChange={(value) => !isPending && onOpenChange(value)}>
|
|
||||||
<DialogContent>
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>
|
|
||||||
<Trans>Restore Document</Trans>
|
|
||||||
</DialogTitle>
|
|
||||||
|
|
||||||
<DialogDescription>
|
|
||||||
{canManageDocument ? (
|
|
||||||
<Trans>
|
|
||||||
You are about to restore <strong>"{documentTitle}"</strong>
|
|
||||||
</Trans>
|
|
||||||
) : (
|
|
||||||
<Trans>
|
|
||||||
You are about to unhide <strong>"{documentTitle}"</strong>
|
|
||||||
</Trans>
|
|
||||||
)}
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<Alert variant="neutral" className="-mt-1">
|
|
||||||
<AlertDescription>
|
|
||||||
{canManageDocument ? (
|
|
||||||
<Trans>
|
|
||||||
The document will be restored to your account and will be available in your
|
|
||||||
documents list.
|
|
||||||
</Trans>
|
|
||||||
) : (
|
|
||||||
<Trans>
|
|
||||||
The document will be unhidden from your account and will be available in your
|
|
||||||
documents list.
|
|
||||||
</Trans>
|
|
||||||
)}
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
|
|
||||||
<DialogFooter>
|
|
||||||
<Button type="button" variant="secondary" onClick={() => onOpenChange(false)}>
|
|
||||||
<Trans>Cancel</Trans>
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
loading={isPending}
|
|
||||||
onClick={() => void restoreDocument({ documentId: id })}
|
|
||||||
>
|
|
||||||
<Trans>Restore</Trans>
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@ -1,355 +0,0 @@
|
|||||||
import { useLingui } from '@lingui/react';
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
|
||||||
import { DocumentDistributionMethod } from '@prisma/client';
|
|
||||||
import { InfoIcon } from 'lucide-react';
|
|
||||||
import type { Control } from 'react-hook-form';
|
|
||||||
import { useFormContext } from 'react-hook-form';
|
|
||||||
|
|
||||||
import { DATE_FORMATS } from '@documenso/lib/constants/date-formats';
|
|
||||||
import { DOCUMENT_SIGNATURE_TYPES } from '@documenso/lib/constants/document';
|
|
||||||
import { SUPPORTED_LANGUAGES } from '@documenso/lib/constants/i18n';
|
|
||||||
import { TIME_ZONES } from '@documenso/lib/constants/time-zones';
|
|
||||||
import { DocumentEmailCheckboxes } from '@documenso/ui/components/document/document-email-checkboxes';
|
|
||||||
import { DocumentSendEmailMessageHelper } from '@documenso/ui/components/document/document-send-email-message-helper';
|
|
||||||
import { Combobox } from '@documenso/ui/primitives/combobox';
|
|
||||||
import {
|
|
||||||
FormControl,
|
|
||||||
FormDescription,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormMessage,
|
|
||||||
} from '@documenso/ui/primitives/form/form';
|
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
|
||||||
import { MultiSelectCombobox } from '@documenso/ui/primitives/multi-select-combobox';
|
|
||||||
import {
|
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
} from '@documenso/ui/primitives/select';
|
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@documenso/ui/primitives/tabs';
|
|
||||||
import { Textarea } from '@documenso/ui/primitives/textarea';
|
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@documenso/ui/primitives/tooltip';
|
|
||||||
|
|
||||||
import { useConfigureDocument } from './configure-document-context';
|
|
||||||
import type { TConfigureEmbedFormSchema } from './configure-document-view.types';
|
|
||||||
|
|
||||||
interface ConfigureDocumentAdvancedSettingsProps {
|
|
||||||
control: Control<TConfigureEmbedFormSchema>;
|
|
||||||
isSubmitting: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ConfigureDocumentAdvancedSettings = ({
|
|
||||||
control,
|
|
||||||
isSubmitting,
|
|
||||||
}: ConfigureDocumentAdvancedSettingsProps) => {
|
|
||||||
const { _ } = useLingui();
|
|
||||||
|
|
||||||
const form = useFormContext<TConfigureEmbedFormSchema>();
|
|
||||||
const { features } = useConfigureDocument();
|
|
||||||
|
|
||||||
const { watch, setValue } = form;
|
|
||||||
|
|
||||||
// Lift watch() calls to reduce re-renders
|
|
||||||
const distributionMethod = watch('meta.distributionMethod');
|
|
||||||
const emailSettings = watch('meta.emailSettings');
|
|
||||||
const isEmailDistribution = distributionMethod === DocumentDistributionMethod.EMAIL;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h3 className="text-foreground mb-1 text-lg font-medium">
|
|
||||||
<Trans>Advanced Settings</Trans>
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<p className="text-muted-foreground mb-6 text-sm">
|
|
||||||
<Trans>Configure additional options and preferences</Trans>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<Tabs defaultValue="general">
|
|
||||||
<TabsList className="mb-6 inline-flex">
|
|
||||||
<TabsTrigger value="general" className="px-4">
|
|
||||||
<Trans>General</Trans>
|
|
||||||
</TabsTrigger>
|
|
||||||
|
|
||||||
{features.allowConfigureCommunication && (
|
|
||||||
<TabsTrigger value="communication" className="px-4">
|
|
||||||
<Trans>Communication</Trans>
|
|
||||||
</TabsTrigger>
|
|
||||||
)}
|
|
||||||
</TabsList>
|
|
||||||
|
|
||||||
<TabsContent value="general" className="mt-0">
|
|
||||||
<div className="flex flex-col space-y-6">
|
|
||||||
{/* <FormField
|
|
||||||
control={control}
|
|
||||||
name="meta.externalId"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel className="flex flex-row items-center">
|
|
||||||
<Trans>External ID</Trans>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger>
|
|
||||||
<InfoIcon className="mx-2 h-4 w-4" />
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent className="text-muted-foreground max-w-xs">
|
|
||||||
<Trans>
|
|
||||||
Add an external ID to the document. This can be used to identify the
|
|
||||||
document in external systems.
|
|
||||||
</Trans>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input className="bg-background" {...field} disabled={isSubmitting} />
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/> */}
|
|
||||||
|
|
||||||
{features.allowConfigureSignatureTypes && (
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name="meta.signatureTypes"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>
|
|
||||||
<Trans>Allowed Signature Types</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<MultiSelectCombobox
|
|
||||||
options={Object.values(DOCUMENT_SIGNATURE_TYPES).map((option) => ({
|
|
||||||
label: _(option.label),
|
|
||||||
value: option.value,
|
|
||||||
}))}
|
|
||||||
selectedValues={field.value}
|
|
||||||
onChange={field.onChange}
|
|
||||||
className="bg-background w-full"
|
|
||||||
emptySelectionPlaceholder="Select signature types"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{features.allowConfigureLanguage && (
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name="meta.language"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>
|
|
||||||
<Trans>Language</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Select {...field} onValueChange={field.onChange} disabled={isSubmitting}>
|
|
||||||
<SelectTrigger className="bg-background">
|
|
||||||
<SelectValue />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{Object.entries(SUPPORTED_LANGUAGES).map(([code, language]) => (
|
|
||||||
<SelectItem key={code} value={code}>
|
|
||||||
{language.full}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{features.allowConfigureDateFormat && (
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name="meta.dateFormat"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>
|
|
||||||
<Trans>Date Format</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Select {...field} onValueChange={field.onChange} disabled={isSubmitting}>
|
|
||||||
<SelectTrigger className="bg-background">
|
|
||||||
<SelectValue />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{DATE_FORMATS.map((format) => (
|
|
||||||
<SelectItem key={format.key} value={format.value}>
|
|
||||||
{format.label}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{features.allowConfigureTimezone && (
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name="meta.timezone"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>
|
|
||||||
<Trans>Time Zone</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Combobox
|
|
||||||
className="bg-background"
|
|
||||||
options={TIME_ZONES}
|
|
||||||
{...field}
|
|
||||||
onChange={(value) => value && field.onChange(value)}
|
|
||||||
disabled={isSubmitting}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{features.allowConfigureRedirectUrl && (
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name="meta.redirectUrl"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel className="flex flex-row items-center">
|
|
||||||
<Trans>Redirect URL</Trans>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger>
|
|
||||||
<InfoIcon className="mx-2 h-4 w-4" />
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent className="text-muted-foreground max-w-xs">
|
|
||||||
<Trans>
|
|
||||||
Add a URL to redirect the user to once the document is signed
|
|
||||||
</Trans>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input className="bg-background" {...field} disabled={isSubmitting} />
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</TabsContent>
|
|
||||||
|
|
||||||
{features.allowConfigureCommunication && (
|
|
||||||
<TabsContent value="communication" className="mt-0">
|
|
||||||
<div className="flex flex-col space-y-6">
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name="meta.distributionMethod"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>
|
|
||||||
<Trans>Distribution Method</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
|
|
||||||
<FormControl>
|
|
||||||
<Select {...field} onValueChange={field.onChange} disabled={isSubmitting}>
|
|
||||||
<SelectTrigger className="bg-background">
|
|
||||||
<SelectValue />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
<SelectItem value={DocumentDistributionMethod.EMAIL}>
|
|
||||||
<Trans>Email</Trans>
|
|
||||||
</SelectItem>
|
|
||||||
<SelectItem value={DocumentDistributionMethod.NONE}>
|
|
||||||
<Trans>None</Trans>
|
|
||||||
</SelectItem>
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
<FormDescription>
|
|
||||||
<Trans>
|
|
||||||
Choose how to distribute your document to recipients. Email will send
|
|
||||||
notifications, None will generate signing links for manual distribution.
|
|
||||||
</Trans>
|
|
||||||
</FormDescription>
|
|
||||||
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<fieldset
|
|
||||||
className="flex flex-col space-y-6 disabled:cursor-not-allowed disabled:opacity-60"
|
|
||||||
disabled={!isEmailDistribution}
|
|
||||||
>
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name="meta.subject"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel htmlFor="subject">
|
|
||||||
<Trans>
|
|
||||||
Subject <span className="text-muted-foreground">(Optional)</span>
|
|
||||||
</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
id="subject"
|
|
||||||
className="bg-background mt-2"
|
|
||||||
disabled={isSubmitting || !isEmailDistribution}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name="meta.message"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel htmlFor="message">
|
|
||||||
<Trans>
|
|
||||||
Message <span className="text-muted-foreground">(Optional)</span>
|
|
||||||
</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Textarea
|
|
||||||
id="message"
|
|
||||||
className="bg-background mt-2 h-32 resize-none"
|
|
||||||
disabled={isSubmitting || !isEmailDistribution}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<DocumentSendEmailMessageHelper />
|
|
||||||
|
|
||||||
<DocumentEmailCheckboxes
|
|
||||||
className={`mt-2 ${!isEmailDistribution ? 'pointer-events-none' : ''}`}
|
|
||||||
value={emailSettings}
|
|
||||||
onChange={(value) => setValue('meta.emailSettings', value)}
|
|
||||||
/>
|
|
||||||
</fieldset>
|
|
||||||
</div>
|
|
||||||
</TabsContent>
|
|
||||||
)}
|
|
||||||
</Tabs>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@ -1,68 +0,0 @@
|
|||||||
import { createContext, useContext } from 'react';
|
|
||||||
|
|
||||||
export type ConfigureDocumentContext = {
|
|
||||||
// General
|
|
||||||
isTemplate: boolean;
|
|
||||||
isPersisted: boolean;
|
|
||||||
// Features
|
|
||||||
features: {
|
|
||||||
allowConfigureSignatureTypes?: boolean;
|
|
||||||
allowConfigureLanguage?: boolean;
|
|
||||||
allowConfigureDateFormat?: boolean;
|
|
||||||
allowConfigureTimezone?: boolean;
|
|
||||||
allowConfigureRedirectUrl?: boolean;
|
|
||||||
allowConfigureCommunication?: boolean;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const ConfigureDocumentContext = createContext<ConfigureDocumentContext | null>(null);
|
|
||||||
|
|
||||||
export type ConfigureDocumentProviderProps = {
|
|
||||||
isTemplate?: boolean;
|
|
||||||
isPersisted?: boolean;
|
|
||||||
features: {
|
|
||||||
allowConfigureSignatureTypes?: boolean;
|
|
||||||
allowConfigureLanguage?: boolean;
|
|
||||||
allowConfigureDateFormat?: boolean;
|
|
||||||
allowConfigureTimezone?: boolean;
|
|
||||||
allowConfigureRedirectUrl?: boolean;
|
|
||||||
allowConfigureCommunication?: boolean;
|
|
||||||
};
|
|
||||||
children: React.ReactNode;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ConfigureDocumentProvider = ({
|
|
||||||
isTemplate,
|
|
||||||
isPersisted,
|
|
||||||
features,
|
|
||||||
children,
|
|
||||||
}: ConfigureDocumentProviderProps) => {
|
|
||||||
return (
|
|
||||||
<ConfigureDocumentContext.Provider
|
|
||||||
value={{
|
|
||||||
isTemplate: isTemplate ?? false,
|
|
||||||
isPersisted: isPersisted ?? false,
|
|
||||||
features: {
|
|
||||||
allowConfigureSignatureTypes: features.allowConfigureSignatureTypes ?? true,
|
|
||||||
allowConfigureLanguage: features.allowConfigureLanguage ?? true,
|
|
||||||
allowConfigureDateFormat: features.allowConfigureDateFormat ?? true,
|
|
||||||
allowConfigureTimezone: features.allowConfigureTimezone ?? true,
|
|
||||||
allowConfigureRedirectUrl: features.allowConfigureRedirectUrl ?? true,
|
|
||||||
allowConfigureCommunication: features.allowConfigureCommunication ?? true,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</ConfigureDocumentContext.Provider>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useConfigureDocument = () => {
|
|
||||||
const context = useContext(ConfigureDocumentContext);
|
|
||||||
|
|
||||||
if (!context) {
|
|
||||||
throw new Error('useConfigureDocument must be used within a ConfigureDocumentProvider');
|
|
||||||
}
|
|
||||||
|
|
||||||
return context;
|
|
||||||
};
|
|
||||||
@ -1,393 +0,0 @@
|
|||||||
import { useCallback, useRef } from 'react';
|
|
||||||
|
|
||||||
import type { DropResult, SensorAPI } from '@hello-pangea/dnd';
|
|
||||||
import { DragDropContext, Draggable, Droppable } from '@hello-pangea/dnd';
|
|
||||||
import { msg } from '@lingui/core/macro';
|
|
||||||
import { useLingui } from '@lingui/react';
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
|
||||||
import { DocumentSigningOrder, RecipientRole } from '@prisma/client';
|
|
||||||
import { motion } from 'framer-motion';
|
|
||||||
import { GripVertical, HelpCircle, Plus, Trash } from 'lucide-react';
|
|
||||||
import { nanoid } from 'nanoid';
|
|
||||||
import type { Control } from 'react-hook-form';
|
|
||||||
import { useFieldArray, useFormContext, useFormState } from 'react-hook-form';
|
|
||||||
|
|
||||||
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 { Checkbox } from '@documenso/ui/primitives/checkbox';
|
|
||||||
import {
|
|
||||||
FormControl,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormMessage,
|
|
||||||
} from '@documenso/ui/primitives/form/form';
|
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@documenso/ui/primitives/tooltip';
|
|
||||||
|
|
||||||
import { useConfigureDocument } from './configure-document-context';
|
|
||||||
import type { TConfigureEmbedFormSchema } from './configure-document-view.types';
|
|
||||||
|
|
||||||
// Define a type for signer items
|
|
||||||
type SignerItem = TConfigureEmbedFormSchema['signers'][number];
|
|
||||||
|
|
||||||
export interface ConfigureDocumentRecipientsProps {
|
|
||||||
control: Control<TConfigureEmbedFormSchema>;
|
|
||||||
isSubmitting: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ConfigureDocumentRecipients = ({
|
|
||||||
control,
|
|
||||||
isSubmitting,
|
|
||||||
}: ConfigureDocumentRecipientsProps) => {
|
|
||||||
const { _ } = useLingui();
|
|
||||||
const { isTemplate } = useConfigureDocument();
|
|
||||||
|
|
||||||
const $sensorApi = useRef<SensorAPI | null>(null);
|
|
||||||
|
|
||||||
const {
|
|
||||||
fields: signers,
|
|
||||||
append: appendSigner,
|
|
||||||
remove: removeSigner,
|
|
||||||
replace,
|
|
||||||
move,
|
|
||||||
} = useFieldArray({
|
|
||||||
control,
|
|
||||||
name: 'signers',
|
|
||||||
});
|
|
||||||
|
|
||||||
const { getValues, watch } = useFormContext<TConfigureEmbedFormSchema>();
|
|
||||||
|
|
||||||
const signingOrder = watch('meta.signingOrder');
|
|
||||||
|
|
||||||
const { errors } = useFormState({
|
|
||||||
control,
|
|
||||||
});
|
|
||||||
|
|
||||||
const onAddSigner = useCallback(() => {
|
|
||||||
const signerNumber = signers.length + 1;
|
|
||||||
|
|
||||||
appendSigner({
|
|
||||||
formId: nanoid(8),
|
|
||||||
name: isTemplate ? `Recipient ${signerNumber}` : '',
|
|
||||||
email: isTemplate ? `recipient.${signerNumber}@document.com` : '',
|
|
||||||
role: RecipientRole.SIGNER,
|
|
||||||
signingOrder: signers.length > 0 ? (signers[signers.length - 1]?.signingOrder || 0) + 1 : 1,
|
|
||||||
});
|
|
||||||
}, [appendSigner, signers]);
|
|
||||||
|
|
||||||
const isSigningOrderEnabled = signingOrder === DocumentSigningOrder.SEQUENTIAL;
|
|
||||||
|
|
||||||
const handleSigningOrderChange = useCallback(
|
|
||||||
(index: number, newOrderString: string) => {
|
|
||||||
const trimmedOrderString = newOrderString.trim();
|
|
||||||
if (!trimmedOrderString) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const newOrder = Number(trimmedOrderString);
|
|
||||||
if (!Number.isInteger(newOrder) || newOrder < 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current form values to preserve unsaved input data
|
|
||||||
const currentSigners = getValues('signers') || [...signers];
|
|
||||||
const signer = currentSigners[index];
|
|
||||||
|
|
||||||
// Remove signer from current position and insert at new position
|
|
||||||
const remainingSigners = currentSigners.filter((_: unknown, idx: number) => idx !== index);
|
|
||||||
const newPosition = Math.min(Math.max(0, newOrder - 1), currentSigners.length - 1);
|
|
||||||
remainingSigners.splice(newPosition, 0, signer);
|
|
||||||
|
|
||||||
// Update signing order for each item
|
|
||||||
const updatedSigners = remainingSigners.map((s: SignerItem, idx: number) => ({
|
|
||||||
...s,
|
|
||||||
signingOrder: idx + 1,
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Update the form
|
|
||||||
replace(updatedSigners);
|
|
||||||
},
|
|
||||||
[signers, replace, getValues],
|
|
||||||
);
|
|
||||||
|
|
||||||
const onDragEnd = useCallback(
|
|
||||||
(result: DropResult) => {
|
|
||||||
if (!result.destination) return;
|
|
||||||
|
|
||||||
// Use the move function from useFieldArray which preserves input values
|
|
||||||
move(result.source.index, result.destination.index);
|
|
||||||
|
|
||||||
// Update signing orders after move
|
|
||||||
const currentSigners = getValues('signers');
|
|
||||||
const updatedSigners = currentSigners.map((signer: SignerItem, index: number) => ({
|
|
||||||
...signer,
|
|
||||||
signingOrder: index + 1,
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Update the form with new ordering
|
|
||||||
replace(updatedSigners);
|
|
||||||
},
|
|
||||||
[move, replace, getValues],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h3 className="text-foreground mb-1 text-lg font-medium">
|
|
||||||
<Trans>Recipients</Trans>
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<p className="text-muted-foreground mb-6 text-sm">
|
|
||||||
<Trans>Add signers and configure signing preferences</Trans>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name="meta.signingOrder"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="mb-6 flex flex-row items-center space-x-2 space-y-0">
|
|
||||||
<FormControl>
|
|
||||||
<Checkbox
|
|
||||||
{...field}
|
|
||||||
id="signingOrder"
|
|
||||||
checked={field.value === DocumentSigningOrder.SEQUENTIAL}
|
|
||||||
onCheckedChange={(checked) => {
|
|
||||||
field.onChange(
|
|
||||||
checked ? DocumentSigningOrder.SEQUENTIAL : DocumentSigningOrder.PARALLEL,
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
disabled={isSubmitting}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormLabel
|
|
||||||
htmlFor="signingOrder"
|
|
||||||
className="text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
||||||
>
|
|
||||||
<Trans>Enable signing order</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name="meta.allowDictateNextSigner"
|
|
||||||
render={({ field: { value, ...field } }) => (
|
|
||||||
<FormItem className="mb-6 flex flex-row items-center space-x-2 space-y-0">
|
|
||||||
<FormControl>
|
|
||||||
<Checkbox
|
|
||||||
{...field}
|
|
||||||
id="allowDictateNextSigner"
|
|
||||||
checked={value}
|
|
||||||
onCheckedChange={field.onChange}
|
|
||||||
disabled={isSubmitting || !isSigningOrderEnabled}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<FormLabel
|
|
||||||
htmlFor="allowDictateNextSigner"
|
|
||||||
className="text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
||||||
>
|
|
||||||
<Trans>Allow signers to dictate next signer</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<span className="text-muted-foreground ml-1 cursor-help">
|
|
||||||
<HelpCircle className="h-3.5 w-3.5" />
|
|
||||||
</span>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent className="max-w-80 p-4">
|
|
||||||
<p>
|
|
||||||
<Trans>
|
|
||||||
When enabled, signers can choose who should sign next in the sequence instead
|
|
||||||
of following the predefined order.
|
|
||||||
</Trans>
|
|
||||||
</p>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<DragDropContext
|
|
||||||
onDragEnd={onDragEnd}
|
|
||||||
sensors={[
|
|
||||||
(api: SensorAPI) => {
|
|
||||||
$sensorApi.current = api;
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Droppable droppableId="signers">
|
|
||||||
{(provided) => (
|
|
||||||
<div {...provided.droppableProps} ref={provided.innerRef} className="space-y-2">
|
|
||||||
{signers.map((signer, index) => (
|
|
||||||
<Draggable
|
|
||||||
key={signer.id}
|
|
||||||
draggableId={signer.id}
|
|
||||||
index={index}
|
|
||||||
isDragDisabled={!isSigningOrderEnabled || isSubmitting}
|
|
||||||
>
|
|
||||||
{(provided, snapshot) => (
|
|
||||||
<div
|
|
||||||
ref={provided.innerRef}
|
|
||||||
{...provided.draggableProps}
|
|
||||||
{...provided.dragHandleProps}
|
|
||||||
className={cn('py-1', {
|
|
||||||
'bg-widget-foreground pointer-events-none rounded-md pt-2':
|
|
||||||
snapshot.isDragging,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<motion.div
|
|
||||||
className={cn('flex items-end gap-2 pb-2', {
|
|
||||||
'border-destructive/50': errors?.signers?.[index],
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
{isSigningOrderEnabled && (
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name={`signers.${index}.signingOrder`}
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem
|
|
||||||
className={cn('flex w-16 flex-none items-center gap-x-1', {
|
|
||||||
'mb-6':
|
|
||||||
errors?.signers?.[index] &&
|
|
||||||
!errors?.signers?.[index]?.signingOrder,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<GripVertical className="h-5 w-5 flex-shrink-0 opacity-40" />
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
type="number"
|
|
||||||
max={signers.length}
|
|
||||||
min={1}
|
|
||||||
className="w-full text-center [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none"
|
|
||||||
{...field}
|
|
||||||
disabled={isSubmitting || snapshot.isDragging}
|
|
||||||
onChange={(e) => {
|
|
||||||
field.onChange(e);
|
|
||||||
}}
|
|
||||||
onBlur={(e) => {
|
|
||||||
field.onBlur();
|
|
||||||
handleSigningOrderChange(index, e.target.value);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name={`signers.${index}.name`}
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem
|
|
||||||
className={cn('flex-1', {
|
|
||||||
'mb-6': errors?.signers?.[index] && !errors?.signers?.[index]?.name,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<FormLabel className="sr-only">
|
|
||||||
<Trans>Name</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
placeholder={_(msg`Name`)}
|
|
||||||
className="w-full"
|
|
||||||
{...field}
|
|
||||||
disabled={isSubmitting || snapshot.isDragging}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name={`signers.${index}.email`}
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem
|
|
||||||
className={cn('flex-1', {
|
|
||||||
'mb-6':
|
|
||||||
errors?.signers?.[index] && !errors?.signers?.[index]?.email,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<FormLabel className="sr-only">
|
|
||||||
<Trans>Email</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
type="email"
|
|
||||||
placeholder={_(msg`Email`)}
|
|
||||||
className="w-full"
|
|
||||||
{...field}
|
|
||||||
disabled={isSubmitting || snapshot.isDragging}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name={`signers.${index}.role`}
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem
|
|
||||||
className={cn('flex-none', {
|
|
||||||
'mb-6': errors?.signers?.[index] && !errors?.signers?.[index]?.role,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<FormLabel className="sr-only">
|
|
||||||
<Trans>Role</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<RecipientRoleSelect
|
|
||||||
{...field}
|
|
||||||
isAssistantEnabled={isSigningOrderEnabled}
|
|
||||||
onValueChange={field.onChange}
|
|
||||||
disabled={isSubmitting || snapshot.isDragging}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="ghost"
|
|
||||||
disabled={isSubmitting || signers.length === 1 || snapshot.isDragging}
|
|
||||||
onClick={() => removeSigner(index)}
|
|
||||||
>
|
|
||||||
<Trash className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</motion.div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Draggable>
|
|
||||||
))}
|
|
||||||
{provided.placeholder}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Droppable>
|
|
||||||
</DragDropContext>
|
|
||||||
|
|
||||||
<div className="mt-4 flex justify-end">
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="outline"
|
|
||||||
className="w-auto"
|
|
||||||
disabled={isSubmitting}
|
|
||||||
onClick={onAddSigner}
|
|
||||||
>
|
|
||||||
<Plus className="-ml-1 mr-2 h-5 w-5" />
|
|
||||||
<Trans>Add Signer</Trans>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@ -1,238 +0,0 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
|
||||||
import { useLingui } from '@lingui/react';
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
|
||||||
import { Cloud, FileText, Loader, X } from 'lucide-react';
|
|
||||||
import { useDropzone } from 'react-dropzone';
|
|
||||||
import { useFormContext } from 'react-hook-form';
|
|
||||||
|
|
||||||
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
|
||||||
import {
|
|
||||||
FormControl,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormMessage,
|
|
||||||
} from '@documenso/ui/primitives/form/form';
|
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
||||||
|
|
||||||
import { useConfigureDocument } from './configure-document-context';
|
|
||||||
import type { TConfigureEmbedFormSchema } from './configure-document-view.types';
|
|
||||||
|
|
||||||
export interface ConfigureDocumentUploadProps {
|
|
||||||
isSubmitting?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ConfigureDocumentUpload = ({ isSubmitting = false }: ConfigureDocumentUploadProps) => {
|
|
||||||
const { _ } = useLingui();
|
|
||||||
const { toast } = useToast();
|
|
||||||
const { isPersisted } = useConfigureDocument();
|
|
||||||
|
|
||||||
const form = useFormContext<TConfigureEmbedFormSchema>();
|
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
|
|
||||||
// Watch the documentData field from the form
|
|
||||||
const documentData = form.watch('documentData');
|
|
||||||
|
|
||||||
const onFileDrop = async (acceptedFiles: File[]) => {
|
|
||||||
try {
|
|
||||||
const file = acceptedFiles[0];
|
|
||||||
|
|
||||||
if (!file) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsLoading(true);
|
|
||||||
|
|
||||||
// Convert file to UInt8Array
|
|
||||||
const arrayBuffer = await file.arrayBuffer();
|
|
||||||
const uint8Array = new Uint8Array(arrayBuffer);
|
|
||||||
|
|
||||||
// Store file metadata and UInt8Array in form data
|
|
||||||
form.setValue('documentData', {
|
|
||||||
name: file.name,
|
|
||||||
type: file.type,
|
|
||||||
size: file.size,
|
|
||||||
data: uint8Array, // Store as UInt8Array
|
|
||||||
});
|
|
||||||
|
|
||||||
// Auto-populate title if it's empty
|
|
||||||
const currentTitle = form.getValues('title');
|
|
||||||
|
|
||||||
if (!currentTitle) {
|
|
||||||
// Get filename without extension
|
|
||||||
const fileNameWithoutExtension = file.name.replace(/\.[^/.]+$/, '');
|
|
||||||
form.setValue('title', fileNameWithoutExtension);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error uploading file', error);
|
|
||||||
|
|
||||||
toast({
|
|
||||||
title: _(msg`Error uploading file`),
|
|
||||||
description: _(msg`There was an error uploading your file. Please try again.`),
|
|
||||||
variant: 'destructive',
|
|
||||||
duration: 5000,
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDropRejected = () => {
|
|
||||||
toast({
|
|
||||||
title: _(msg`Your document failed to upload.`),
|
|
||||||
description: _(msg`File cannot be larger than ${APP_DOCUMENT_UPLOAD_SIZE_LIMIT}MB`),
|
|
||||||
duration: 5000,
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const onRemoveFile = () => {
|
|
||||||
if (isPersisted) {
|
|
||||||
toast({
|
|
||||||
title: _(msg`Cannot remove document`),
|
|
||||||
description: _(msg`The document is already saved and cannot be changed.`),
|
|
||||||
duration: 5000,
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
form.unregister('documentData');
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatFileSize = (bytes: number) => {
|
|
||||||
if (bytes === 0) return '0 Bytes';
|
|
||||||
|
|
||||||
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
|
||||||
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
||||||
return `${parseFloat((bytes / Math.pow(1024, i)).toFixed(2))} ${sizes[i]}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
||||||
accept: {
|
|
||||||
'application/pdf': ['.pdf'],
|
|
||||||
},
|
|
||||||
maxSize: APP_DOCUMENT_UPLOAD_SIZE_LIMIT * 1024 * 1024,
|
|
||||||
multiple: false,
|
|
||||||
disabled: isSubmitting || isLoading || isPersisted,
|
|
||||||
onDrop: (files) => {
|
|
||||||
void onFileDrop(files);
|
|
||||||
},
|
|
||||||
onDropRejected,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="documentData"
|
|
||||||
render={() => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel required>
|
|
||||||
<Trans>Upload Document</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
|
|
||||||
<div className="relative">
|
|
||||||
{!documentData ? (
|
|
||||||
<div className="relative">
|
|
||||||
<FormControl>
|
|
||||||
<div
|
|
||||||
{...getRootProps()}
|
|
||||||
className={cn(
|
|
||||||
'border-border bg-background relative flex min-h-[160px] cursor-pointer flex-col items-center justify-center rounded-lg border border-dashed transition',
|
|
||||||
{
|
|
||||||
'border-primary/50 bg-primary/5': isDragActive,
|
|
||||||
'hover:bg-muted/30':
|
|
||||||
!isDragActive && !isSubmitting && !isLoading && !isPersisted,
|
|
||||||
'cursor-not-allowed opacity-60': isSubmitting || isLoading || isPersisted,
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<input {...getInputProps()} />
|
|
||||||
|
|
||||||
<div className="flex flex-col items-center justify-center gap-y-2 px-4 py-4 text-center">
|
|
||||||
<Cloud
|
|
||||||
className={cn('h-10 w-10', {
|
|
||||||
'text-primary': isDragActive,
|
|
||||||
'text-muted-foreground': !isDragActive,
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div
|
|
||||||
className={cn('flex flex-col space-y-1', {
|
|
||||||
'text-primary': isDragActive,
|
|
||||||
'text-muted-foreground': !isDragActive,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<p className="text-sm font-medium">
|
|
||||||
{isDragActive ? (
|
|
||||||
<Trans>Drop your document here</Trans>
|
|
||||||
) : isPersisted ? (
|
|
||||||
<Trans>Document is already uploaded</Trans>
|
|
||||||
) : (
|
|
||||||
<Trans>Drag and drop or click to upload</Trans>
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
<p className="text-xs">
|
|
||||||
{isPersisted ? (
|
|
||||||
<Trans>This document cannot be changed</Trans>
|
|
||||||
) : (
|
|
||||||
<Trans>
|
|
||||||
.PDF documents accepted (max {APP_DOCUMENT_UPLOAD_SIZE_LIMIT}MB)
|
|
||||||
</Trans>
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
{isLoading && (
|
|
||||||
<div className="bg-background/50 absolute inset-0 flex items-center justify-center rounded-lg">
|
|
||||||
<Loader className="text-muted-foreground h-10 w-10 animate-spin" />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="mt-2 rounded-lg border p-4">
|
|
||||||
<div className="flex items-center gap-x-4">
|
|
||||||
<div className="bg-primary/10 text-primary flex h-12 w-12 items-center justify-center rounded-md">
|
|
||||||
<FileText className="h-6 w-6" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex-1">
|
|
||||||
<div className="text-sm font-medium">{documentData.name}</div>
|
|
||||||
<div className="text-muted-foreground text-xs">
|
|
||||||
{formatFileSize(documentData.size)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{!isPersisted && (
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={onRemoveFile}
|
|
||||||
disabled={isSubmitting}
|
|
||||||
className="h-8 w-8 p-0"
|
|
||||||
>
|
|
||||||
<X className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@ -1,131 +0,0 @@
|
|||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
|
||||||
import { DocumentDistributionMethod, DocumentSigningOrder, RecipientRole } from '@prisma/client';
|
|
||||||
import { nanoid } from 'nanoid';
|
|
||||||
import { useForm } from 'react-hook-form';
|
|
||||||
|
|
||||||
import { DEFAULT_DOCUMENT_DATE_FORMAT } from '@documenso/lib/constants/date-formats';
|
|
||||||
import { DEFAULT_DOCUMENT_TIME_ZONE } from '@documenso/lib/constants/time-zones';
|
|
||||||
import { ZDocumentEmailSettingsSchema } from '@documenso/lib/types/document-email';
|
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
|
||||||
import {
|
|
||||||
Form,
|
|
||||||
FormControl,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormMessage,
|
|
||||||
} from '@documenso/ui/primitives/form/form';
|
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
|
||||||
|
|
||||||
import { ConfigureDocumentAdvancedSettings } from './configure-document-advanced-settings';
|
|
||||||
import { useConfigureDocument } from './configure-document-context';
|
|
||||||
import { ConfigureDocumentRecipients } from './configure-document-recipients';
|
|
||||||
import { ConfigureDocumentUpload } from './configure-document-upload';
|
|
||||||
import {
|
|
||||||
type TConfigureEmbedFormSchema,
|
|
||||||
ZConfigureEmbedFormSchema,
|
|
||||||
} from './configure-document-view.types';
|
|
||||||
|
|
||||||
export interface ConfigureDocumentViewProps {
|
|
||||||
onSubmit: (data: TConfigureEmbedFormSchema) => void | Promise<void>;
|
|
||||||
defaultValues?: Partial<TConfigureEmbedFormSchema>;
|
|
||||||
isSubmitting?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ConfigureDocumentView = ({ onSubmit, defaultValues }: ConfigureDocumentViewProps) => {
|
|
||||||
const { isTemplate } = useConfigureDocument();
|
|
||||||
|
|
||||||
const form = useForm<TConfigureEmbedFormSchema>({
|
|
||||||
resolver: zodResolver(ZConfigureEmbedFormSchema),
|
|
||||||
defaultValues: {
|
|
||||||
title: defaultValues?.title || '',
|
|
||||||
signers: defaultValues?.signers || [
|
|
||||||
{
|
|
||||||
formId: nanoid(8),
|
|
||||||
name: isTemplate ? `Recipient ${1}` : '',
|
|
||||||
email: isTemplate ? `recipient.${1}@document.com` : '',
|
|
||||||
role: RecipientRole.SIGNER,
|
|
||||||
signingOrder: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
meta: {
|
|
||||||
subject: defaultValues?.meta?.subject || '',
|
|
||||||
message: defaultValues?.meta?.message || '',
|
|
||||||
distributionMethod:
|
|
||||||
defaultValues?.meta?.distributionMethod || DocumentDistributionMethod.EMAIL,
|
|
||||||
emailSettings: defaultValues?.meta?.emailSettings || ZDocumentEmailSettingsSchema.parse({}),
|
|
||||||
dateFormat: defaultValues?.meta?.dateFormat || DEFAULT_DOCUMENT_DATE_FORMAT,
|
|
||||||
timezone: defaultValues?.meta?.timezone || DEFAULT_DOCUMENT_TIME_ZONE,
|
|
||||||
redirectUrl: defaultValues?.meta?.redirectUrl || '',
|
|
||||||
language: defaultValues?.meta?.language || 'en',
|
|
||||||
signatureTypes: defaultValues?.meta?.signatureTypes || [],
|
|
||||||
signingOrder: defaultValues?.meta?.signingOrder || DocumentSigningOrder.PARALLEL,
|
|
||||||
allowDictateNextSigner: defaultValues?.meta?.allowDictateNextSigner || false,
|
|
||||||
externalId: defaultValues?.meta?.externalId || '',
|
|
||||||
},
|
|
||||||
documentData: defaultValues?.documentData,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const { control, handleSubmit } = form;
|
|
||||||
|
|
||||||
const isSubmitting = form.formState.isSubmitting;
|
|
||||||
|
|
||||||
const onFormSubmit = handleSubmit(onSubmit);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex w-full flex-col space-y-8">
|
|
||||||
<div>
|
|
||||||
<h2 className="text-foreground mb-1 text-xl font-semibold">
|
|
||||||
{isTemplate ? <Trans>Configure Template</Trans> : <Trans>Configure Document</Trans>}
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<p className="text-muted-foreground text-sm">
|
|
||||||
{isTemplate ? (
|
|
||||||
<Trans>Set up your template properties and recipient information</Trans>
|
|
||||||
) : (
|
|
||||||
<Trans>Set up your document properties and recipient information</Trans>
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Form {...form}>
|
|
||||||
<div className="flex flex-col space-y-8">
|
|
||||||
<div>
|
|
||||||
<FormField
|
|
||||||
control={control}
|
|
||||||
name="title"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel required>
|
|
||||||
<Trans>Title</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input {...field} disabled={isSubmitting} />
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ConfigureDocumentUpload isSubmitting={isSubmitting} />
|
|
||||||
<ConfigureDocumentRecipients control={control} isSubmitting={isSubmitting} />
|
|
||||||
<ConfigureDocumentAdvancedSettings control={control} isSubmitting={isSubmitting} />
|
|
||||||
|
|
||||||
<div className="flex justify-end">
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
onClick={onFormSubmit}
|
|
||||||
disabled={isSubmitting}
|
|
||||||
className="w-full sm:w-auto"
|
|
||||||
>
|
|
||||||
<Trans>Continue</Trans>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Form>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@ -1,48 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { ZDocumentEmailSettingsSchema } from '@documenso/lib/types/document-email';
|
|
||||||
import { DocumentDistributionMethod } from '@documenso/prisma/generated/types';
|
|
||||||
import {
|
|
||||||
ZDocumentMetaDateFormatSchema,
|
|
||||||
ZDocumentMetaLanguageSchema,
|
|
||||||
} from '@documenso/trpc/server/document-router/schema';
|
|
||||||
|
|
||||||
// Define the schema for configuration
|
|
||||||
export type TConfigureEmbedFormSchema = z.infer<typeof ZConfigureEmbedFormSchema>;
|
|
||||||
|
|
||||||
export const ZConfigureEmbedFormSchema = z.object({
|
|
||||||
title: z.string().min(1, { message: 'Title is required' }),
|
|
||||||
signers: z
|
|
||||||
.array(
|
|
||||||
z.object({
|
|
||||||
formId: z.string(),
|
|
||||||
name: z.string().min(1, { message: 'Name is required' }),
|
|
||||||
email: z.string().email('Invalid email address'),
|
|
||||||
role: z.enum(['SIGNER', 'CC', 'APPROVER', 'VIEWER', 'ASSISTANT']),
|
|
||||||
signingOrder: z.number().optional(),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.min(1, { message: 'At least one signer is required' }),
|
|
||||||
meta: z.object({
|
|
||||||
subject: z.string().optional(),
|
|
||||||
message: z.string().optional(),
|
|
||||||
distributionMethod: z.nativeEnum(DocumentDistributionMethod),
|
|
||||||
emailSettings: ZDocumentEmailSettingsSchema,
|
|
||||||
dateFormat: ZDocumentMetaDateFormatSchema.optional(),
|
|
||||||
timezone: z.string().min(1, 'Timezone is required'),
|
|
||||||
redirectUrl: z.string().optional(),
|
|
||||||
language: ZDocumentMetaLanguageSchema.optional(),
|
|
||||||
signatureTypes: z.array(z.string()).default([]),
|
|
||||||
signingOrder: z.enum(['SEQUENTIAL', 'PARALLEL']),
|
|
||||||
allowDictateNextSigner: z.boolean().default(false),
|
|
||||||
externalId: z.string().optional(),
|
|
||||||
}),
|
|
||||||
documentData: z
|
|
||||||
.object({
|
|
||||||
name: z.string(),
|
|
||||||
type: z.string(),
|
|
||||||
size: z.number(),
|
|
||||||
data: z.instanceof(Uint8Array), // UInt8Array can't be directly validated by zod
|
|
||||||
})
|
|
||||||
.optional(),
|
|
||||||
});
|
|
||||||
@ -1,661 +0,0 @@
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
||||||
|
|
||||||
import { useLingui } from '@lingui/react';
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
|
||||||
import type { DocumentData } from '@prisma/client';
|
|
||||||
import { FieldType, ReadStatus, type Recipient, SendStatus, SigningStatus } from '@prisma/client';
|
|
||||||
import { ChevronsUpDown } from 'lucide-react';
|
|
||||||
import { useFieldArray, useForm } from 'react-hook-form';
|
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
|
||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { getBoundingClientRect } from '@documenso/lib/client-only/get-bounding-client-rect';
|
|
||||||
import { useDocumentElement } from '@documenso/lib/client-only/hooks/use-document-element';
|
|
||||||
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
|
||||||
import { type TFieldMetaSchema, ZFieldMetaSchema } from '@documenso/lib/types/field-meta';
|
|
||||||
import { base64 } from '@documenso/lib/universal/base64';
|
|
||||||
import { nanoid } from '@documenso/lib/universal/id';
|
|
||||||
import { ADVANCED_FIELD_TYPES_WITH_OPTIONAL_SETTING } from '@documenso/lib/utils/advanced-fields-helpers';
|
|
||||||
import { useSignerColors } from '@documenso/ui/lib/signer-colors';
|
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
|
||||||
import { FieldItem } from '@documenso/ui/primitives/document-flow/field-item';
|
|
||||||
import { FRIENDLY_FIELD_TYPE } from '@documenso/ui/primitives/document-flow/types';
|
|
||||||
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
|
||||||
import { FieldSelector } from '@documenso/ui/primitives/field-selector';
|
|
||||||
import { Form } from '@documenso/ui/primitives/form/form';
|
|
||||||
import PDFViewer from '@documenso/ui/primitives/pdf-viewer';
|
|
||||||
import { RecipientSelector } from '@documenso/ui/primitives/recipient-selector';
|
|
||||||
import { Sheet, SheetContent, SheetTrigger } from '@documenso/ui/primitives/sheet';
|
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
||||||
|
|
||||||
import type { TConfigureEmbedFormSchema } from './configure-document-view.types';
|
|
||||||
import { FieldAdvancedSettingsDrawer } from './field-advanced-settings-drawer';
|
|
||||||
|
|
||||||
const MIN_HEIGHT_PX = 12;
|
|
||||||
const MIN_WIDTH_PX = 36;
|
|
||||||
|
|
||||||
const DEFAULT_HEIGHT_PX = MIN_HEIGHT_PX * 2.5;
|
|
||||||
const DEFAULT_WIDTH_PX = MIN_WIDTH_PX * 2.5;
|
|
||||||
|
|
||||||
export const ZConfigureFieldsFormSchema = z.object({
|
|
||||||
fields: z.array(
|
|
||||||
z.object({
|
|
||||||
formId: z.string().min(1),
|
|
||||||
id: z.string().min(1),
|
|
||||||
type: z.nativeEnum(FieldType),
|
|
||||||
signerEmail: z.string().min(1),
|
|
||||||
recipientId: z.number().min(0),
|
|
||||||
pageNumber: z.number().min(1),
|
|
||||||
pageX: z.number().min(0),
|
|
||||||
pageY: z.number().min(0),
|
|
||||||
pageWidth: z.number().min(0),
|
|
||||||
pageHeight: z.number().min(0),
|
|
||||||
fieldMeta: ZFieldMetaSchema.optional(),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
export type TConfigureFieldsFormSchema = z.infer<typeof ZConfigureFieldsFormSchema>;
|
|
||||||
|
|
||||||
export type ConfigureFieldsViewProps = {
|
|
||||||
configData: TConfigureEmbedFormSchema;
|
|
||||||
defaultValues?: Partial<TConfigureFieldsFormSchema>;
|
|
||||||
onBack: (data: TConfigureFieldsFormSchema) => void;
|
|
||||||
onSubmit: (data: TConfigureFieldsFormSchema) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ConfigureFieldsView = ({
|
|
||||||
configData,
|
|
||||||
defaultValues,
|
|
||||||
onBack,
|
|
||||||
onSubmit,
|
|
||||||
}: ConfigureFieldsViewProps) => {
|
|
||||||
const { toast } = useToast();
|
|
||||||
const { isWithinPageBounds, getFieldPosition, getPage } = useDocumentElement();
|
|
||||||
const { _ } = useLingui();
|
|
||||||
|
|
||||||
// Track if we're on a mobile device
|
|
||||||
const [isMobile, setIsMobile] = useState(false);
|
|
||||||
|
|
||||||
// State for managing the mobile drawer
|
|
||||||
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
|
||||||
|
|
||||||
// Check for mobile viewport on component mount and resize
|
|
||||||
useEffect(() => {
|
|
||||||
const checkIfMobile = () => {
|
|
||||||
setIsMobile(window.innerWidth < 768);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initial check
|
|
||||||
checkIfMobile();
|
|
||||||
|
|
||||||
// Add resize listener
|
|
||||||
window.addEventListener('resize', checkIfMobile);
|
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener('resize', checkIfMobile);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const documentData = useMemo(() => {
|
|
||||||
if (!configData.documentData) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = base64.encode(configData.documentData?.data);
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: 'preview',
|
|
||||||
type: 'BYTES_64',
|
|
||||||
data,
|
|
||||||
initialData: data,
|
|
||||||
} satisfies DocumentData;
|
|
||||||
}, [configData.documentData]);
|
|
||||||
|
|
||||||
const recipients = useMemo(() => {
|
|
||||||
return configData.signers.map<Recipient>((signer, index) => ({
|
|
||||||
id: index,
|
|
||||||
name: signer.name || '',
|
|
||||||
email: signer.email || '',
|
|
||||||
role: signer.role,
|
|
||||||
signingOrder: signer.signingOrder || null,
|
|
||||||
documentId: null,
|
|
||||||
templateId: null,
|
|
||||||
token: '',
|
|
||||||
documentDeletedAt: null,
|
|
||||||
expired: null,
|
|
||||||
signedAt: null,
|
|
||||||
authOptions: null,
|
|
||||||
rejectionReason: null,
|
|
||||||
sendStatus: SendStatus.NOT_SENT,
|
|
||||||
readStatus: ReadStatus.NOT_OPENED,
|
|
||||||
signingStatus: SigningStatus.NOT_SIGNED,
|
|
||||||
}));
|
|
||||||
}, [configData.signers]);
|
|
||||||
|
|
||||||
const [selectedRecipient, setSelectedRecipient] = useState<Recipient | null>(
|
|
||||||
() => recipients[0] || null,
|
|
||||||
);
|
|
||||||
const [selectedField, setSelectedField] = useState<FieldType | null>(null);
|
|
||||||
const [isFieldWithinBounds, setIsFieldWithinBounds] = useState(false);
|
|
||||||
const [coords, setCoords] = useState({
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
});
|
|
||||||
const [activeFieldId, setActiveFieldId] = useState<string | null>(null);
|
|
||||||
const [lastActiveField, setLastActiveField] = useState<
|
|
||||||
TConfigureFieldsFormSchema['fields'][0] | null
|
|
||||||
>(null);
|
|
||||||
const [fieldClipboard, setFieldClipboard] = useState<
|
|
||||||
TConfigureFieldsFormSchema['fields'][0] | null
|
|
||||||
>(null);
|
|
||||||
const [showAdvancedSettings, setShowAdvancedSettings] = useState(false);
|
|
||||||
const [currentField, setCurrentField] = useState<TConfigureFieldsFormSchema['fields'][0] | null>(
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
|
|
||||||
const fieldBounds = useRef({
|
|
||||||
height: DEFAULT_HEIGHT_PX,
|
|
||||||
width: DEFAULT_WIDTH_PX,
|
|
||||||
});
|
|
||||||
|
|
||||||
const selectedRecipientIndex = recipients.findIndex((r) => r.id === selectedRecipient?.id);
|
|
||||||
const selectedSignerStyles = useSignerColors(
|
|
||||||
selectedRecipientIndex === -1 ? 0 : selectedRecipientIndex,
|
|
||||||
);
|
|
||||||
|
|
||||||
const form = useForm<TConfigureFieldsFormSchema>({
|
|
||||||
defaultValues: {
|
|
||||||
fields: defaultValues?.fields ?? [],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const { control, handleSubmit } = form;
|
|
||||||
|
|
||||||
const onFormSubmit = handleSubmit(onSubmit);
|
|
||||||
|
|
||||||
const {
|
|
||||||
append,
|
|
||||||
remove,
|
|
||||||
update,
|
|
||||||
fields: localFields,
|
|
||||||
} = useFieldArray({
|
|
||||||
control: control,
|
|
||||||
name: 'fields',
|
|
||||||
});
|
|
||||||
|
|
||||||
const onFieldCopy = useCallback(
|
|
||||||
(event?: KeyboardEvent | null, options?: { duplicate?: boolean }) => {
|
|
||||||
const { duplicate = false } = options ?? {};
|
|
||||||
|
|
||||||
if (lastActiveField) {
|
|
||||||
event?.preventDefault();
|
|
||||||
|
|
||||||
if (!duplicate) {
|
|
||||||
setFieldClipboard(lastActiveField);
|
|
||||||
|
|
||||||
toast({
|
|
||||||
title: 'Copied field',
|
|
||||||
description: 'Copied field to clipboard',
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const newField: TConfigureFieldsFormSchema['fields'][0] = {
|
|
||||||
...structuredClone(lastActiveField),
|
|
||||||
formId: nanoid(12),
|
|
||||||
id: nanoid(12),
|
|
||||||
signerEmail: selectedRecipient?.email ?? lastActiveField.signerEmail,
|
|
||||||
recipientId: selectedRecipient?.id ?? lastActiveField.recipientId,
|
|
||||||
pageX: lastActiveField.pageX + 3,
|
|
||||||
pageY: lastActiveField.pageY + 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
append(newField);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[append, lastActiveField, selectedRecipient?.email, selectedRecipient?.id, toast],
|
|
||||||
);
|
|
||||||
|
|
||||||
const onFieldPaste = useCallback(
|
|
||||||
(event: KeyboardEvent) => {
|
|
||||||
if (fieldClipboard) {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
const copiedField = structuredClone(fieldClipboard);
|
|
||||||
|
|
||||||
append({
|
|
||||||
...copiedField,
|
|
||||||
formId: nanoid(12),
|
|
||||||
id: nanoid(12),
|
|
||||||
signerEmail: selectedRecipient?.email ?? copiedField.signerEmail,
|
|
||||||
recipientId: selectedRecipient?.id ?? copiedField.recipientId,
|
|
||||||
pageX: copiedField.pageX + 3,
|
|
||||||
pageY: copiedField.pageY + 3,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[append, fieldClipboard, selectedRecipient?.email, selectedRecipient?.id],
|
|
||||||
);
|
|
||||||
|
|
||||||
useHotkeys(['ctrl+c', 'meta+c'], (evt) => onFieldCopy(evt));
|
|
||||||
useHotkeys(['ctrl+v', 'meta+v'], (evt) => onFieldPaste(evt));
|
|
||||||
useHotkeys(['ctrl+d', 'meta+d'], (evt) => onFieldCopy(evt, { duplicate: true }));
|
|
||||||
|
|
||||||
const onMouseMove = useCallback(
|
|
||||||
(event: MouseEvent) => {
|
|
||||||
if (!selectedField) return;
|
|
||||||
|
|
||||||
setIsFieldWithinBounds(
|
|
||||||
isWithinPageBounds(
|
|
||||||
event,
|
|
||||||
PDF_VIEWER_PAGE_SELECTOR,
|
|
||||||
fieldBounds.current.width,
|
|
||||||
fieldBounds.current.height,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
setCoords({
|
|
||||||
x: event.clientX - fieldBounds.current.width / 2,
|
|
||||||
y: event.clientY - fieldBounds.current.height / 2,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[isWithinPageBounds, selectedField],
|
|
||||||
);
|
|
||||||
|
|
||||||
const onMouseClick = useCallback(
|
|
||||||
(event: MouseEvent) => {
|
|
||||||
if (!selectedField || !selectedRecipient) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const $page = getPage(event, PDF_VIEWER_PAGE_SELECTOR);
|
|
||||||
|
|
||||||
if (
|
|
||||||
!$page ||
|
|
||||||
!isWithinPageBounds(
|
|
||||||
event,
|
|
||||||
PDF_VIEWER_PAGE_SELECTOR,
|
|
||||||
fieldBounds.current.width,
|
|
||||||
fieldBounds.current.height,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { top, left, height, width } = getBoundingClientRect($page);
|
|
||||||
|
|
||||||
const pageNumber = parseInt($page.getAttribute('data-page-number') ?? '1', 10);
|
|
||||||
|
|
||||||
// Calculate x and y as a percentage of the page width and height
|
|
||||||
let pageX = ((event.pageX - left) / width) * 100;
|
|
||||||
let pageY = ((event.pageY - top) / height) * 100;
|
|
||||||
|
|
||||||
// Get the bounds as a percentage of the page width and height
|
|
||||||
const fieldPageWidth = (fieldBounds.current.width / width) * 100;
|
|
||||||
const fieldPageHeight = (fieldBounds.current.height / height) * 100;
|
|
||||||
|
|
||||||
// And center it based on the bounds
|
|
||||||
pageX -= fieldPageWidth / 2;
|
|
||||||
pageY -= fieldPageHeight / 2;
|
|
||||||
|
|
||||||
const field = {
|
|
||||||
id: nanoid(12),
|
|
||||||
formId: nanoid(12),
|
|
||||||
type: selectedField,
|
|
||||||
pageNumber,
|
|
||||||
pageX,
|
|
||||||
pageY,
|
|
||||||
pageWidth: fieldPageWidth,
|
|
||||||
pageHeight: fieldPageHeight,
|
|
||||||
recipientId: selectedRecipient.id,
|
|
||||||
signerEmail: selectedRecipient.email,
|
|
||||||
fieldMeta: undefined,
|
|
||||||
};
|
|
||||||
|
|
||||||
append(field);
|
|
||||||
|
|
||||||
// Automatically open advanced settings for field types that need configuration
|
|
||||||
if (ADVANCED_FIELD_TYPES_WITH_OPTIONAL_SETTING.includes(selectedField)) {
|
|
||||||
setCurrentField(field);
|
|
||||||
setShowAdvancedSettings(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
setSelectedField(null);
|
|
||||||
},
|
|
||||||
[append, getPage, isWithinPageBounds, selectedField, selectedRecipient],
|
|
||||||
);
|
|
||||||
|
|
||||||
const onFieldResize = useCallback(
|
|
||||||
(node: HTMLElement, index: number) => {
|
|
||||||
const field = localFields[index];
|
|
||||||
|
|
||||||
const $page = window.document.querySelector<HTMLElement>(
|
|
||||||
`${PDF_VIEWER_PAGE_SELECTOR}[data-page-number="${field.pageNumber}"]`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!$page) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
|
||||||
x: pageX,
|
|
||||||
y: pageY,
|
|
||||||
width: pageWidth,
|
|
||||||
height: pageHeight,
|
|
||||||
} = getFieldPosition($page, node);
|
|
||||||
|
|
||||||
update(index, {
|
|
||||||
...field,
|
|
||||||
pageX,
|
|
||||||
pageY,
|
|
||||||
pageWidth,
|
|
||||||
pageHeight,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[getFieldPosition, localFields, update],
|
|
||||||
);
|
|
||||||
|
|
||||||
const onFieldMove = useCallback(
|
|
||||||
(node: HTMLElement, index: number) => {
|
|
||||||
const field = localFields[index];
|
|
||||||
|
|
||||||
const $page = window.document.querySelector<HTMLElement>(
|
|
||||||
`${PDF_VIEWER_PAGE_SELECTOR}[data-page-number="${field.pageNumber}"]`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!$page) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { x: pageX, y: pageY } = getFieldPosition($page, node);
|
|
||||||
|
|
||||||
update(index, {
|
|
||||||
...field,
|
|
||||||
pageX,
|
|
||||||
pageY,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[getFieldPosition, localFields, update],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleUpdateFieldMeta = useCallback(
|
|
||||||
(formId: string, fieldMeta: TFieldMetaSchema) => {
|
|
||||||
const fieldIndex = localFields.findIndex((field) => field.formId === formId);
|
|
||||||
|
|
||||||
if (fieldIndex !== -1) {
|
|
||||||
const parsedFieldMeta = ZFieldMetaSchema.parse(fieldMeta);
|
|
||||||
|
|
||||||
update(fieldIndex, {
|
|
||||||
...localFields[fieldIndex],
|
|
||||||
fieldMeta: parsedFieldMeta,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[localFields, update],
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (selectedField) {
|
|
||||||
window.addEventListener('mousemove', onMouseMove);
|
|
||||||
window.addEventListener('mouseup', onMouseClick);
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener('mousemove', onMouseMove);
|
|
||||||
window.removeEventListener('mouseup', onMouseClick);
|
|
||||||
};
|
|
||||||
}, [onMouseClick, onMouseMove, selectedField]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const observer = new MutationObserver((_mutations) => {
|
|
||||||
const $page = document.querySelector(PDF_VIEWER_PAGE_SELECTOR);
|
|
||||||
|
|
||||||
if (!$page) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldBounds.current = {
|
|
||||||
height: Math.max(DEFAULT_HEIGHT_PX),
|
|
||||||
width: Math.max(DEFAULT_WIDTH_PX),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(document.body, {
|
|
||||||
childList: true,
|
|
||||||
subtree: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
observer.disconnect();
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Close drawer when a field is selected on mobile
|
|
||||||
useEffect(() => {
|
|
||||||
if (isMobile && selectedField) {
|
|
||||||
setIsDrawerOpen(false);
|
|
||||||
}
|
|
||||||
}, [isMobile, selectedField]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="grid w-full grid-cols-12 gap-4">
|
|
||||||
{/* Desktop sidebar */}
|
|
||||||
{!isMobile && (
|
|
||||||
<div className="order-2 col-span-12 md:order-1 md:col-span-4">
|
|
||||||
<div className="bg-widget border-border sticky top-4 max-h-[calc(100vh-2rem)] rounded-lg border p-4 pb-6">
|
|
||||||
<h2 className="mb-1 text-lg font-medium">
|
|
||||||
<Trans>Configure Fields</Trans>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<p className="text-muted-foreground mb-6 text-sm">
|
|
||||||
<Trans>Configure the fields you want to place on the document.</Trans>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<RecipientSelector
|
|
||||||
selectedRecipient={selectedRecipient}
|
|
||||||
onSelectedRecipientChange={setSelectedRecipient}
|
|
||||||
recipients={recipients}
|
|
||||||
className="w-full"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<hr className="my-6" />
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
<FieldSelector
|
|
||||||
selectedField={selectedField}
|
|
||||||
onSelectedFieldChange={setSelectedField}
|
|
||||||
className="w-full"
|
|
||||||
disabled={!selectedRecipient}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="mt-6 flex gap-2">
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="ghost"
|
|
||||||
className="flex-1"
|
|
||||||
loading={form.formState.isSubmitting}
|
|
||||||
onClick={() => onBack(form.getValues())}
|
|
||||||
>
|
|
||||||
<Trans>Back</Trans>
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
className="flex-1"
|
|
||||||
type="button"
|
|
||||||
loading={form.formState.isSubmitting}
|
|
||||||
disabled={!form.formState.isValid}
|
|
||||||
onClick={async () => onFormSubmit()}
|
|
||||||
>
|
|
||||||
<Trans>Save</Trans>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className={cn('order-1 col-span-12 md:order-2', !isMobile && 'md:col-span-8')}>
|
|
||||||
<div className="relative">
|
|
||||||
{selectedField && (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'text-muted-foreground dark:text-muted-background pointer-events-none fixed z-50 flex cursor-pointer flex-col items-center justify-center bg-white transition duration-200 [container-type:size]',
|
|
||||||
selectedSignerStyles.default.base,
|
|
||||||
{
|
|
||||||
'-rotate-6 scale-90 opacity-50 dark:bg-black/20': !isFieldWithinBounds,
|
|
||||||
'dark:text-black/60': isFieldWithinBounds,
|
|
||||||
},
|
|
||||||
selectedField === 'SIGNATURE' && 'font-signature',
|
|
||||||
)}
|
|
||||||
style={{
|
|
||||||
top: coords.y,
|
|
||||||
left: coords.x,
|
|
||||||
height: fieldBounds.current.height,
|
|
||||||
width: fieldBounds.current.width,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span className="text-[clamp(0.425rem,25cqw,0.825rem)]">
|
|
||||||
{_(FRIENDLY_FIELD_TYPE[selectedField])}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Form {...form}>
|
|
||||||
{documentData && (
|
|
||||||
<div>
|
|
||||||
<PDFViewer documentData={documentData} />
|
|
||||||
|
|
||||||
<ElementVisible target={PDF_VIEWER_PAGE_SELECTOR}>
|
|
||||||
{localFields.map((field, index) => {
|
|
||||||
const recipientIndex = recipients.findIndex(
|
|
||||||
(r) => r.id === field.recipientId,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<FieldItem
|
|
||||||
key={field.formId}
|
|
||||||
field={field}
|
|
||||||
minHeight={MIN_HEIGHT_PX}
|
|
||||||
minWidth={MIN_WIDTH_PX}
|
|
||||||
defaultHeight={DEFAULT_HEIGHT_PX}
|
|
||||||
defaultWidth={DEFAULT_WIDTH_PX}
|
|
||||||
onResize={(node) => onFieldResize(node, index)}
|
|
||||||
onMove={(node) => onFieldMove(node, index)}
|
|
||||||
onRemove={() => remove(index)}
|
|
||||||
onDuplicate={() => onFieldCopy(null, { duplicate: true })}
|
|
||||||
onFocus={() => setLastActiveField(field)}
|
|
||||||
onBlur={() => setLastActiveField(null)}
|
|
||||||
onAdvancedSettings={() => {
|
|
||||||
setCurrentField(field);
|
|
||||||
setShowAdvancedSettings(true);
|
|
||||||
}}
|
|
||||||
recipientIndex={recipientIndex}
|
|
||||||
active={activeFieldId === field.formId}
|
|
||||||
onFieldActivate={() => setActiveFieldId(field.formId)}
|
|
||||||
onFieldDeactivate={() => setActiveFieldId(null)}
|
|
||||||
disabled={selectedRecipient?.id !== field.recipientId}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</ElementVisible>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Mobile Floating Action Bar and Drawer */}
|
|
||||||
{isMobile && (
|
|
||||||
<Sheet open={isDrawerOpen} onOpenChange={setIsDrawerOpen}>
|
|
||||||
<SheetTrigger asChild>
|
|
||||||
<div className="bg-widget border-border fixed bottom-6 left-6 right-6 z-50 flex items-center justify-between gap-2 rounded-lg border p-4">
|
|
||||||
<span className="text-lg font-medium">
|
|
||||||
<Trans>Configure Fields</Trans>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="border-border text-muted-foreground inline-flex h-10 w-10 items-center justify-center rounded-lg border"
|
|
||||||
>
|
|
||||||
<ChevronsUpDown className="h-6 w-6" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</SheetTrigger>
|
|
||||||
|
|
||||||
<SheetContent
|
|
||||||
position="bottom"
|
|
||||||
size="xl"
|
|
||||||
className="bg-widget h-fit max-h-[80vh] overflow-y-auto rounded-t-xl p-4"
|
|
||||||
>
|
|
||||||
<h2 className="mb-1 text-lg font-medium">
|
|
||||||
<Trans>Configure Fields</Trans>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<p className="text-muted-foreground mb-6 text-sm">
|
|
||||||
<Trans>Configure the fields you want to place on the document.</Trans>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<RecipientSelector
|
|
||||||
selectedRecipient={selectedRecipient}
|
|
||||||
onSelectedRecipientChange={setSelectedRecipient}
|
|
||||||
recipients={recipients}
|
|
||||||
className="w-full"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<hr className="my-6" />
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
<FieldSelector
|
|
||||||
selectedField={selectedField}
|
|
||||||
onSelectedFieldChange={(field) => {
|
|
||||||
setSelectedField(field);
|
|
||||||
if (field) {
|
|
||||||
setIsDrawerOpen(false);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className="w-full"
|
|
||||||
disabled={!selectedRecipient}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="mt-6 flex gap-2">
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="ghost"
|
|
||||||
className="flex-1"
|
|
||||||
loading={form.formState.isSubmitting}
|
|
||||||
onClick={() => onBack(form.getValues())}
|
|
||||||
>
|
|
||||||
<Trans>Back</Trans>
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
className="flex-1"
|
|
||||||
type="button"
|
|
||||||
loading={form.formState.isSubmitting}
|
|
||||||
disabled={!form.formState.isValid}
|
|
||||||
onClick={async () => onFormSubmit()}
|
|
||||||
>
|
|
||||||
<Trans>Save</Trans>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</SheetContent>
|
|
||||||
</Sheet>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<FieldAdvancedSettingsDrawer
|
|
||||||
isOpen={showAdvancedSettings}
|
|
||||||
onOpenChange={setShowAdvancedSettings}
|
|
||||||
currentField={currentField}
|
|
||||||
fields={localFields}
|
|
||||||
onFieldUpdate={handleUpdateFieldMeta}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@ -1,83 +0,0 @@
|
|||||||
import { msg } from '@lingui/core/macro';
|
|
||||||
import { useLingui } from '@lingui/react';
|
|
||||||
import type { FieldType } from '@prisma/client';
|
|
||||||
|
|
||||||
import { type TFieldMetaSchema as FieldMeta } from '@documenso/lib/types/field-meta';
|
|
||||||
import { parseMessageDescriptor } from '@documenso/lib/utils/i18n';
|
|
||||||
import { FieldAdvancedSettings } from '@documenso/ui/primitives/document-flow/field-item-advanced-settings';
|
|
||||||
import { FRIENDLY_FIELD_TYPE } from '@documenso/ui/primitives/document-flow/types';
|
|
||||||
import { Sheet, SheetContent, SheetTitle } from '@documenso/ui/primitives/sheet';
|
|
||||||
|
|
||||||
export type FieldAdvancedSettingsDrawerProps = {
|
|
||||||
isOpen: boolean;
|
|
||||||
onOpenChange: (isOpen: boolean) => void;
|
|
||||||
currentField: {
|
|
||||||
id: string;
|
|
||||||
formId: string;
|
|
||||||
type: FieldType;
|
|
||||||
pageNumber: number;
|
|
||||||
pageX: number;
|
|
||||||
pageY: number;
|
|
||||||
pageWidth: number;
|
|
||||||
pageHeight: number;
|
|
||||||
recipientId: number;
|
|
||||||
signerEmail: string;
|
|
||||||
fieldMeta?: FieldMeta;
|
|
||||||
} | null;
|
|
||||||
fields: Array<{
|
|
||||||
id: string;
|
|
||||||
formId: string;
|
|
||||||
type: FieldType;
|
|
||||||
pageNumber: number;
|
|
||||||
pageX: number;
|
|
||||||
pageY: number;
|
|
||||||
pageWidth: number;
|
|
||||||
pageHeight: number;
|
|
||||||
recipientId: number;
|
|
||||||
signerEmail: string;
|
|
||||||
fieldMeta?: FieldMeta;
|
|
||||||
}>;
|
|
||||||
onFieldUpdate: (formId: string, fieldMeta: FieldMeta) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const FieldAdvancedSettingsDrawer = ({
|
|
||||||
isOpen,
|
|
||||||
onOpenChange,
|
|
||||||
currentField,
|
|
||||||
fields,
|
|
||||||
onFieldUpdate,
|
|
||||||
}: FieldAdvancedSettingsDrawerProps) => {
|
|
||||||
const { _ } = useLingui();
|
|
||||||
|
|
||||||
if (!currentField) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Sheet open={isOpen} onOpenChange={onOpenChange}>
|
|
||||||
<SheetContent position="right" size="lg" className="w-9/12 max-w-sm overflow-y-auto">
|
|
||||||
<SheetTitle className="sr-only">
|
|
||||||
{parseMessageDescriptor(
|
|
||||||
_,
|
|
||||||
msg`Configure ${parseMessageDescriptor(_, FRIENDLY_FIELD_TYPE[currentField.type])} Field`,
|
|
||||||
)}
|
|
||||||
</SheetTitle>
|
|
||||||
|
|
||||||
<FieldAdvancedSettings
|
|
||||||
title={msg`Advanced settings`}
|
|
||||||
description={msg`Configure the ${parseMessageDescriptor(
|
|
||||||
_,
|
|
||||||
FRIENDLY_FIELD_TYPE[currentField.type],
|
|
||||||
)} field`}
|
|
||||||
field={currentField}
|
|
||||||
fields={fields}
|
|
||||||
onAdvancedSettings={() => onOpenChange(false)}
|
|
||||||
onSave={(fieldMeta) => {
|
|
||||||
onFieldUpdate(currentField.formId, fieldMeta);
|
|
||||||
onOpenChange(false);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</SheetContent>
|
|
||||||
</Sheet>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@ -1,11 +1,7 @@
|
|||||||
import { Loader } from 'lucide-react';
|
|
||||||
|
|
||||||
export const EmbedClientLoading = () => {
|
export const EmbedClientLoading = () => {
|
||||||
return (
|
return (
|
||||||
<div className="bg-background fixed left-0 top-0 z-[9999] flex h-full w-full items-center justify-center">
|
<div className="bg-background fixed left-0 top-0 z-[9999] flex h-full w-full items-center justify-center">
|
||||||
<Loader className="mr-2 h-4 w-4 animate-spin" />
|
Loading...
|
||||||
|
|
||||||
<span>Loading...</span>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3,8 +3,8 @@ import { useEffect, useLayoutEffect, useState } from 'react';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { DocumentMeta, Recipient, Signature, TemplateMeta } from '@prisma/client';
|
|
||||||
import { type DocumentData, type Field, FieldType } from '@prisma/client';
|
import { type DocumentData, type Field, FieldType } from '@prisma/client';
|
||||||
|
import type { DocumentMeta, Recipient, Signature, TemplateMeta } from '@prisma/client';
|
||||||
import { LucideChevronDown, LucideChevronUp } from 'lucide-react';
|
import { LucideChevronDown, LucideChevronUp } from 'lucide-react';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import { useSearchParams } from 'react-router';
|
import { useSearchParams } from 'react-router';
|
||||||
@ -13,10 +13,6 @@ import { useThrottleFn } from '@documenso/lib/client-only/hooks/use-throttle-fn'
|
|||||||
import { DEFAULT_DOCUMENT_DATE_FORMAT } from '@documenso/lib/constants/date-formats';
|
import { DEFAULT_DOCUMENT_DATE_FORMAT } from '@documenso/lib/constants/date-formats';
|
||||||
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
||||||
import { DEFAULT_DOCUMENT_TIME_ZONE } from '@documenso/lib/constants/time-zones';
|
import { DEFAULT_DOCUMENT_TIME_ZONE } from '@documenso/lib/constants/time-zones';
|
||||||
import {
|
|
||||||
isFieldUnsignedAndRequired,
|
|
||||||
isRequiredField,
|
|
||||||
} from '@documenso/lib/utils/advanced-fields-helpers';
|
|
||||||
import { validateFieldsInserted } from '@documenso/lib/utils/fields';
|
import { validateFieldsInserted } from '@documenso/lib/utils/fields';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import type {
|
import type {
|
||||||
@ -25,11 +21,12 @@ import type {
|
|||||||
} from '@documenso/trpc/server/field-router/schema';
|
} from '@documenso/trpc/server/field-router/schema';
|
||||||
import { FieldToolTip } from '@documenso/ui/components/field/field-tooltip';
|
import { FieldToolTip } from '@documenso/ui/components/field/field-tooltip';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
|
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
||||||
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
import { Input } from '@documenso/ui/primitives/input';
|
||||||
import { Label } from '@documenso/ui/primitives/label';
|
import { Label } from '@documenso/ui/primitives/label';
|
||||||
import { PDFViewer } from '@documenso/ui/primitives/pdf-viewer';
|
import { PDFViewer } from '@documenso/ui/primitives/pdf-viewer';
|
||||||
import { SignaturePadDialog } from '@documenso/ui/primitives/signature-pad/signature-pad-dialog';
|
import { SignaturePad } from '@documenso/ui/primitives/signature-pad';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
import { BrandingLogo } from '~/components/general/branding-logo';
|
import { BrandingLogo } from '~/components/general/branding-logo';
|
||||||
@ -68,8 +65,16 @@ export const EmbedDirectTemplateClientPage = ({
|
|||||||
|
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
|
|
||||||
const { fullName, email, signature, setFullName, setEmail, setSignature } =
|
const {
|
||||||
useRequiredDocumentSigningContext();
|
fullName,
|
||||||
|
email,
|
||||||
|
signature,
|
||||||
|
signatureValid,
|
||||||
|
setFullName,
|
||||||
|
setEmail,
|
||||||
|
setSignature,
|
||||||
|
setSignatureValid,
|
||||||
|
} = useRequiredDocumentSigningContext();
|
||||||
|
|
||||||
const [hasFinishedInit, setHasFinishedInit] = useState(false);
|
const [hasFinishedInit, setHasFinishedInit] = useState(false);
|
||||||
const [hasDocumentLoaded, setHasDocumentLoaded] = useState(false);
|
const [hasDocumentLoaded, setHasDocumentLoaded] = useState(false);
|
||||||
@ -87,7 +92,7 @@ export const EmbedDirectTemplateClientPage = ({
|
|||||||
const [localFields, setLocalFields] = useState<DirectTemplateLocalField[]>(() => fields);
|
const [localFields, setLocalFields] = useState<DirectTemplateLocalField[]>(() => fields);
|
||||||
|
|
||||||
const [pendingFields, _completedFields] = [
|
const [pendingFields, _completedFields] = [
|
||||||
localFields.filter((field) => isFieldUnsignedAndRequired(field)),
|
localFields.filter((field) => !field.inserted),
|
||||||
localFields.filter((field) => field.inserted),
|
localFields.filter((field) => field.inserted),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -105,7 +110,7 @@ export const EmbedDirectTemplateClientPage = ({
|
|||||||
|
|
||||||
const newField: DirectTemplateLocalField = structuredClone({
|
const newField: DirectTemplateLocalField = structuredClone({
|
||||||
...field,
|
...field,
|
||||||
customText: payload.value ?? '',
|
customText: payload.value,
|
||||||
inserted: true,
|
inserted: true,
|
||||||
signedValue: payload,
|
signedValue: payload,
|
||||||
});
|
});
|
||||||
@ -116,10 +121,8 @@ export const EmbedDirectTemplateClientPage = ({
|
|||||||
created: new Date(),
|
created: new Date(),
|
||||||
recipientId: 1,
|
recipientId: 1,
|
||||||
fieldId: 1,
|
fieldId: 1,
|
||||||
signatureImageAsBase64:
|
signatureImageAsBase64: payload.value.startsWith('data:') ? payload.value : null,
|
||||||
payload.value && payload.value.startsWith('data:') ? payload.value : null,
|
typedSignature: payload.value.startsWith('data:') ? null : payload.value,
|
||||||
typedSignature:
|
|
||||||
payload.value && !payload.value.startsWith('data:') ? payload.value : null,
|
|
||||||
} satisfies Signature;
|
} satisfies Signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +180,7 @@ export const EmbedDirectTemplateClientPage = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onNextFieldClick = () => {
|
const onNextFieldClick = () => {
|
||||||
validateFieldsInserted(pendingFields);
|
validateFieldsInserted(localFields);
|
||||||
|
|
||||||
setShowPendingFieldTooltip(true);
|
setShowPendingFieldTooltip(true);
|
||||||
setIsExpanded(false);
|
setIsExpanded(false);
|
||||||
@ -185,7 +188,11 @@ export const EmbedDirectTemplateClientPage = ({
|
|||||||
|
|
||||||
const onCompleteClick = async () => {
|
const onCompleteClick = async () => {
|
||||||
try {
|
try {
|
||||||
const valid = validateFieldsInserted(pendingFields);
|
if (hasSignatureField && !signatureValid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const valid = validateFieldsInserted(localFields);
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
setShowPendingFieldTooltip(true);
|
setShowPendingFieldTooltip(true);
|
||||||
@ -198,6 +205,12 @@ export const EmbedDirectTemplateClientPage = ({
|
|||||||
directTemplateExternalId = decodeURIComponent(directTemplateExternalId);
|
directTemplateExternalId = decodeURIComponent(directTemplateExternalId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localFields.forEach((field) => {
|
||||||
|
if (!field.signedValue) {
|
||||||
|
throw new Error('Invalid configuration');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
documentId,
|
documentId,
|
||||||
token: documentToken,
|
token: documentToken,
|
||||||
@ -208,11 +221,13 @@ export const EmbedDirectTemplateClientPage = ({
|
|||||||
directRecipientName: fullName,
|
directRecipientName: fullName,
|
||||||
directRecipientEmail: email,
|
directRecipientEmail: email,
|
||||||
templateUpdatedAt: updatedAt,
|
templateUpdatedAt: updatedAt,
|
||||||
signedFieldValues: localFields
|
signedFieldValues: localFields.map((field) => {
|
||||||
.filter((field) => {
|
if (!field.signedValue) {
|
||||||
return field.signedValue && (isRequiredField(field) || field.inserted);
|
throw new Error('Invalid configuration');
|
||||||
})
|
}
|
||||||
.map((field) => field.signedValue!),
|
|
||||||
|
return field.signedValue;
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (window.parent) {
|
if (window.parent) {
|
||||||
@ -332,7 +347,7 @@ export const EmbedDirectTemplateClientPage = ({
|
|||||||
{/* Widget */}
|
{/* Widget */}
|
||||||
<div
|
<div
|
||||||
key={isExpanded ? 'expanded' : 'collapsed'}
|
key={isExpanded ? 'expanded' : 'collapsed'}
|
||||||
className="group/document-widget fixed bottom-8 left-0 z-50 h-fit max-h-[calc(100dvh-2rem)] w-full flex-shrink-0 px-6 md:sticky md:top-4 md:z-auto md:w-[350px] md:px-0"
|
className="group/document-widget fixed bottom-8 left-0 z-50 h-fit w-full flex-shrink-0 px-6 md:sticky md:top-4 md:z-auto md:w-[350px] md:px-0"
|
||||||
data-expanded={isExpanded || undefined}
|
data-expanded={isExpanded || undefined}
|
||||||
>
|
>
|
||||||
<div className="border-border bg-widget flex h-fit w-full flex-col rounded-xl border px-4 py-4 md:min-h-[min(calc(100dvh-2rem),48rem)] md:py-6">
|
<div className="border-border bg-widget flex h-fit w-full flex-col rounded-xl border px-4 py-4 md:min-h-[min(calc(100dvh-2rem),48rem)] md:py-6">
|
||||||
@ -400,26 +415,42 @@ export const EmbedDirectTemplateClientPage = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{hasSignatureField && (
|
|
||||||
<div>
|
<div>
|
||||||
<Label htmlFor="Signature">
|
<Label htmlFor="Signature">
|
||||||
<Trans>Signature</Trans>
|
<Trans>Signature</Trans>
|
||||||
</Label>
|
</Label>
|
||||||
|
|
||||||
<SignaturePadDialog
|
<Card className="mt-2" gradient degrees={-120}>
|
||||||
className="mt-2"
|
<CardContent className="p-0">
|
||||||
|
<SignaturePad
|
||||||
|
className="h-44 w-full"
|
||||||
disabled={isThrottled || isSubmitting}
|
disabled={isThrottled || isSubmitting}
|
||||||
disableAnimation
|
defaultValue={signature ?? undefined}
|
||||||
value={signature ?? ''}
|
onChange={(value) => {
|
||||||
onChange={(v) => setSignature(v ?? '')}
|
setSignature(value);
|
||||||
typedSignatureEnabled={metadata?.typedSignatureEnabled}
|
}}
|
||||||
uploadSignatureEnabled={metadata?.uploadSignatureEnabled}
|
onValidityChange={(isValid) => {
|
||||||
drawSignatureEnabled={metadata?.drawSignatureEnabled}
|
setSignatureValid(isValid);
|
||||||
|
}}
|
||||||
|
allowTypedSignature={Boolean(
|
||||||
|
metadata &&
|
||||||
|
'typedSignatureEnabled' in metadata &&
|
||||||
|
metadata.typedSignatureEnabled,
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{hasSignatureField && !signatureValid && (
|
||||||
|
<div className="text-destructive mt-2 text-sm">
|
||||||
|
<Trans>
|
||||||
|
Signature is too small. Please provide a more complete signature.
|
||||||
|
</Trans>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="hidden flex-1 group-data-[expanded]/document-widget:block md:block" />
|
<div className="hidden flex-1 group-data-[expanded]/document-widget:block md:block" />
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@ export type EmbedDocumentCompletedPageProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const EmbedDocumentCompleted = ({ name, signature }: EmbedDocumentCompletedPageProps) => {
|
export const EmbedDocumentCompleted = ({ name, signature }: EmbedDocumentCompletedPageProps) => {
|
||||||
|
console.log({ signature });
|
||||||
return (
|
return (
|
||||||
<div className="embed--DocumentCompleted relative mx-auto flex min-h-[100dvh] max-w-screen-lg flex-col items-center justify-center p-6">
|
<div className="embed--DocumentCompleted relative mx-auto flex min-h-[100dvh] max-w-screen-lg flex-col items-center justify-center p-6">
|
||||||
<h3 className="text-foreground text-2xl font-semibold">
|
<h3 className="text-foreground text-2xl font-semibold">
|
||||||
|
|||||||
@ -54,8 +54,6 @@ export const EmbedDocumentFields = ({
|
|||||||
onSignField={onSignField}
|
onSignField={onSignField}
|
||||||
onUnsignField={onUnsignField}
|
onUnsignField={onUnsignField}
|
||||||
typedSignatureEnabled={metadata?.typedSignatureEnabled}
|
typedSignatureEnabled={metadata?.typedSignatureEnabled}
|
||||||
uploadSignatureEnabled={metadata?.uploadSignatureEnabled}
|
|
||||||
drawSignatureEnabled={metadata?.drawSignatureEnabled}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.with(FieldType.INITIALS, () => (
|
.with(FieldType.INITIALS, () => (
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useId, useLayoutEffect, useMemo, useState } from 'react';
|
import { useEffect, useId, useLayoutEffect, useState } from 'react';
|
||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
@ -15,19 +15,18 @@ import { LucideChevronDown, LucideChevronUp } from 'lucide-react';
|
|||||||
|
|
||||||
import { useThrottleFn } from '@documenso/lib/client-only/hooks/use-throttle-fn';
|
import { useThrottleFn } from '@documenso/lib/client-only/hooks/use-throttle-fn';
|
||||||
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
||||||
import type { DocumentField } from '@documenso/lib/server-only/field/get-fields-for-document';
|
|
||||||
import { isFieldUnsignedAndRequired } from '@documenso/lib/utils/advanced-fields-helpers';
|
|
||||||
import { validateFieldsInserted } from '@documenso/lib/utils/fields';
|
import { validateFieldsInserted } from '@documenso/lib/utils/fields';
|
||||||
import type { RecipientWithFields } from '@documenso/prisma/types/recipient-with-fields';
|
import type { RecipientWithFields } from '@documenso/prisma/types/recipient-with-fields';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import { FieldToolTip } from '@documenso/ui/components/field/field-tooltip';
|
import { FieldToolTip } from '@documenso/ui/components/field/field-tooltip';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
|
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
||||||
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
import { Input } from '@documenso/ui/primitives/input';
|
||||||
import { Label } from '@documenso/ui/primitives/label';
|
import { Label } from '@documenso/ui/primitives/label';
|
||||||
import { PDFViewer } from '@documenso/ui/primitives/pdf-viewer';
|
import { PDFViewer } from '@documenso/ui/primitives/pdf-viewer';
|
||||||
import { RadioGroup, RadioGroupItem } from '@documenso/ui/primitives/radio-group';
|
import { RadioGroup, RadioGroupItem } from '@documenso/ui/primitives/radio-group';
|
||||||
import { SignaturePadDialog } from '@documenso/ui/primitives/signature-pad/signature-pad-dialog';
|
import { SignaturePad } from '@documenso/ui/primitives/signature-pad';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
import { BrandingLogo } from '~/components/general/branding-logo';
|
import { BrandingLogo } from '~/components/general/branding-logo';
|
||||||
@ -37,7 +36,6 @@ import { ZSignDocumentEmbedDataSchema } from '../../types/embed-document-sign-sc
|
|||||||
import { useRequiredDocumentSigningContext } from '../general/document-signing/document-signing-provider';
|
import { useRequiredDocumentSigningContext } from '../general/document-signing/document-signing-provider';
|
||||||
import { DocumentSigningRecipientProvider } from '../general/document-signing/document-signing-recipient-provider';
|
import { DocumentSigningRecipientProvider } from '../general/document-signing/document-signing-recipient-provider';
|
||||||
import { DocumentSigningRejectDialog } from '../general/document-signing/document-signing-reject-dialog';
|
import { DocumentSigningRejectDialog } from '../general/document-signing/document-signing-reject-dialog';
|
||||||
import { DocumentReadOnlyFields } from '../general/document/document-read-only-fields';
|
|
||||||
import { EmbedClientLoading } from './embed-client-loading';
|
import { EmbedClientLoading } from './embed-client-loading';
|
||||||
import { EmbedDocumentCompleted } from './embed-document-completed';
|
import { EmbedDocumentCompleted } from './embed-document-completed';
|
||||||
import { EmbedDocumentFields } from './embed-document-fields';
|
import { EmbedDocumentFields } from './embed-document-fields';
|
||||||
@ -49,7 +47,6 @@ export type EmbedSignDocumentClientPageProps = {
|
|||||||
documentData: DocumentData;
|
documentData: DocumentData;
|
||||||
recipient: RecipientWithFields;
|
recipient: RecipientWithFields;
|
||||||
fields: Field[];
|
fields: Field[];
|
||||||
completedFields: DocumentField[];
|
|
||||||
metadata?: DocumentMeta | TemplateMeta | null;
|
metadata?: DocumentMeta | TemplateMeta | null;
|
||||||
isCompleted?: boolean;
|
isCompleted?: boolean;
|
||||||
hidePoweredBy?: boolean;
|
hidePoweredBy?: boolean;
|
||||||
@ -63,7 +60,6 @@ export const EmbedSignDocumentClientPage = ({
|
|||||||
documentData,
|
documentData,
|
||||||
recipient,
|
recipient,
|
||||||
fields,
|
fields,
|
||||||
completedFields,
|
|
||||||
metadata,
|
metadata,
|
||||||
isCompleted,
|
isCompleted,
|
||||||
hidePoweredBy = false,
|
hidePoweredBy = false,
|
||||||
@ -73,8 +69,15 @@ export const EmbedSignDocumentClientPage = ({
|
|||||||
const { _ } = useLingui();
|
const { _ } = useLingui();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
const { fullName, email, signature, setFullName, setSignature } =
|
const {
|
||||||
useRequiredDocumentSigningContext();
|
fullName,
|
||||||
|
email,
|
||||||
|
signature,
|
||||||
|
signatureValid,
|
||||||
|
setFullName,
|
||||||
|
setSignature,
|
||||||
|
setSignatureValid,
|
||||||
|
} = useRequiredDocumentSigningContext();
|
||||||
|
|
||||||
const [hasFinishedInit, setHasFinishedInit] = useState(false);
|
const [hasFinishedInit, setHasFinishedInit] = useState(false);
|
||||||
const [hasDocumentLoaded, setHasDocumentLoaded] = useState(false);
|
const [hasDocumentLoaded, setHasDocumentLoaded] = useState(false);
|
||||||
@ -89,8 +92,6 @@ export const EmbedSignDocumentClientPage = ({
|
|||||||
const [isExpanded, setIsExpanded] = useState(false);
|
const [isExpanded, setIsExpanded] = useState(false);
|
||||||
const [isNameLocked, setIsNameLocked] = useState(false);
|
const [isNameLocked, setIsNameLocked] = useState(false);
|
||||||
const [showPendingFieldTooltip, setShowPendingFieldTooltip] = useState(false);
|
const [showPendingFieldTooltip, setShowPendingFieldTooltip] = useState(false);
|
||||||
const [showOtherRecipientsCompletedFields, setShowOtherRecipientsCompletedFields] =
|
|
||||||
useState(false);
|
|
||||||
|
|
||||||
const [allowDocumentRejection, setAllowDocumentRejection] = useState(false);
|
const [allowDocumentRejection, setAllowDocumentRejection] = useState(false);
|
||||||
|
|
||||||
@ -100,26 +101,19 @@ export const EmbedSignDocumentClientPage = ({
|
|||||||
const [throttledOnCompleteClick, isThrottled] = useThrottleFn(() => void onCompleteClick(), 500);
|
const [throttledOnCompleteClick, isThrottled] = useThrottleFn(() => void onCompleteClick(), 500);
|
||||||
|
|
||||||
const [pendingFields, _completedFields] = [
|
const [pendingFields, _completedFields] = [
|
||||||
fields.filter(
|
fields.filter((field) => field.recipientId === recipient.id && !field.inserted),
|
||||||
(field) => field.recipientId === recipient.id && isFieldUnsignedAndRequired(field),
|
|
||||||
),
|
|
||||||
fields.filter((field) => field.inserted),
|
fields.filter((field) => field.inserted),
|
||||||
];
|
];
|
||||||
|
|
||||||
const { mutateAsync: completeDocumentWithToken, isPending: isSubmitting } =
|
const { mutateAsync: completeDocumentWithToken, isPending: isSubmitting } =
|
||||||
trpc.recipient.completeDocumentWithToken.useMutation();
|
trpc.recipient.completeDocumentWithToken.useMutation();
|
||||||
|
|
||||||
const fieldsRequiringValidation = useMemo(
|
|
||||||
() => fields.filter(isFieldUnsignedAndRequired),
|
|
||||||
[fields],
|
|
||||||
);
|
|
||||||
|
|
||||||
const hasSignatureField = fields.some((field) => field.type === FieldType.SIGNATURE);
|
const hasSignatureField = fields.some((field) => field.type === FieldType.SIGNATURE);
|
||||||
|
|
||||||
const assistantSignersId = useId();
|
const assistantSignersId = useId();
|
||||||
|
|
||||||
const onNextFieldClick = () => {
|
const onNextFieldClick = () => {
|
||||||
validateFieldsInserted(fieldsRequiringValidation);
|
validateFieldsInserted(fields);
|
||||||
|
|
||||||
setShowPendingFieldTooltip(true);
|
setShowPendingFieldTooltip(true);
|
||||||
setIsExpanded(false);
|
setIsExpanded(false);
|
||||||
@ -127,7 +121,11 @@ export const EmbedSignDocumentClientPage = ({
|
|||||||
|
|
||||||
const onCompleteClick = async () => {
|
const onCompleteClick = async () => {
|
||||||
try {
|
try {
|
||||||
const valid = validateFieldsInserted(fieldsRequiringValidation);
|
if (hasSignatureField && !signatureValid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const valid = validateFieldsInserted(fields);
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
setShowPendingFieldTooltip(true);
|
setShowPendingFieldTooltip(true);
|
||||||
@ -208,7 +206,6 @@ export const EmbedSignDocumentClientPage = ({
|
|||||||
// a to be provided by the parent application, unlike direct templates.
|
// a to be provided by the parent application, unlike direct templates.
|
||||||
setIsNameLocked(!!data.lockName);
|
setIsNameLocked(!!data.lockName);
|
||||||
setAllowDocumentRejection(!!data.allowDocumentRejection);
|
setAllowDocumentRejection(!!data.allowDocumentRejection);
|
||||||
setShowOtherRecipientsCompletedFields(!!data.showOtherRecipientsCompletedFields);
|
|
||||||
|
|
||||||
if (data.darkModeDisabled) {
|
if (data.darkModeDisabled) {
|
||||||
document.documentElement.classList.add('dark-mode-disabled');
|
document.documentElement.classList.add('dark-mode-disabled');
|
||||||
@ -290,7 +287,7 @@ export const EmbedSignDocumentClientPage = ({
|
|||||||
{/* Widget */}
|
{/* Widget */}
|
||||||
<div
|
<div
|
||||||
key={isExpanded ? 'expanded' : 'collapsed'}
|
key={isExpanded ? 'expanded' : 'collapsed'}
|
||||||
className="embed--DocumentWidgetContainer group/document-widget fixed bottom-8 left-0 z-50 h-fit max-h-[calc(100dvh-2rem)] w-full flex-shrink-0 px-6 md:sticky md:top-4 md:z-auto md:w-[350px] md:px-0"
|
className="embed--DocumentWidgetContainer group/document-widget fixed bottom-8 left-0 z-50 h-fit w-full flex-shrink-0 px-6 md:sticky md:top-4 md:z-auto md:w-[350px] md:px-0"
|
||||||
data-expanded={isExpanded || undefined}
|
data-expanded={isExpanded || undefined}
|
||||||
>
|
>
|
||||||
<div className="embed--DocumentWidget border-border bg-widget flex w-full flex-col rounded-xl border px-4 py-4 md:py-6">
|
<div className="embed--DocumentWidget border-border bg-widget flex w-full flex-col rounded-xl border px-4 py-4 md:py-6">
|
||||||
@ -421,24 +418,40 @@ export const EmbedSignDocumentClientPage = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{hasSignatureField && (
|
|
||||||
<div>
|
<div>
|
||||||
<Label htmlFor="Signature">
|
<Label htmlFor="Signature">
|
||||||
<Trans>Signature</Trans>
|
<Trans>Signature</Trans>
|
||||||
</Label>
|
</Label>
|
||||||
|
|
||||||
<SignaturePadDialog
|
<Card className="mt-2" gradient degrees={-120}>
|
||||||
className="mt-2"
|
<CardContent className="p-0">
|
||||||
|
<SignaturePad
|
||||||
|
className="h-44 w-full"
|
||||||
disabled={isThrottled || isSubmitting}
|
disabled={isThrottled || isSubmitting}
|
||||||
disableAnimation
|
defaultValue={signature ?? undefined}
|
||||||
value={signature ?? ''}
|
onChange={(value) => {
|
||||||
onChange={(v) => setSignature(v ?? '')}
|
setSignature(value);
|
||||||
typedSignatureEnabled={metadata?.typedSignatureEnabled}
|
}}
|
||||||
uploadSignatureEnabled={metadata?.uploadSignatureEnabled}
|
onValidityChange={(isValid) => {
|
||||||
drawSignatureEnabled={metadata?.drawSignatureEnabled}
|
setSignatureValid(isValid);
|
||||||
|
}}
|
||||||
|
allowTypedSignature={Boolean(
|
||||||
|
metadata &&
|
||||||
|
'typedSignatureEnabled' in metadata &&
|
||||||
|
metadata.typedSignatureEnabled,
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{hasSignatureField && !signatureValid && (
|
||||||
|
<div className="text-destructive mt-2 text-sm">
|
||||||
|
<Trans>
|
||||||
|
Signature is too small. Please provide a more complete signature.
|
||||||
|
</Trans>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@ -454,7 +467,9 @@ export const EmbedSignDocumentClientPage = ({
|
|||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
className={allowDocumentRejection ? 'col-start-2' : 'col-span-2'}
|
className={allowDocumentRejection ? 'col-start-2' : 'col-span-2'}
|
||||||
disabled={isThrottled}
|
disabled={
|
||||||
|
isThrottled || (!isAssistantMode && hasSignatureField && !signatureValid)
|
||||||
|
}
|
||||||
loading={isSubmitting}
|
loading={isSubmitting}
|
||||||
onClick={() => throttledOnCompleteClick()}
|
onClick={() => throttledOnCompleteClick()}
|
||||||
>
|
>
|
||||||
@ -475,9 +490,6 @@ export const EmbedSignDocumentClientPage = ({
|
|||||||
|
|
||||||
{/* Fields */}
|
{/* Fields */}
|
||||||
<EmbedDocumentFields fields={fields} metadata={metadata} />
|
<EmbedDocumentFields fields={fields} metadata={metadata} />
|
||||||
|
|
||||||
{/* Completed fields */}
|
|
||||||
<DocumentReadOnlyFields documentMeta={metadata || undefined} fields={completedFields} />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!hidePoweredBy && (
|
{!hidePoweredBy && (
|
||||||
|
|||||||
@ -6,10 +6,10 @@ import { useLingui } from '@lingui/react';
|
|||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { flushSync } from 'react-dom';
|
import { flushSync } from 'react-dom';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { useRevalidator } from 'react-router';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { authClient } from '@documenso/auth/client';
|
import { authClient } from '@documenso/auth/client';
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@ -42,7 +42,7 @@ export type TDisable2FAForm = z.infer<typeof ZDisable2FAForm>;
|
|||||||
export const DisableAuthenticatorAppDialog = () => {
|
export const DisableAuthenticatorAppDialog = () => {
|
||||||
const { _ } = useLingui();
|
const { _ } = useLingui();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { refreshSession } = useSession();
|
const { revalidate } = useRevalidator();
|
||||||
|
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [twoFactorDisableMethod, setTwoFactorDisableMethod] = useState<'totp' | 'backup'>('totp');
|
const [twoFactorDisableMethod, setTwoFactorDisableMethod] = useState<'totp' | 'backup'>('totp');
|
||||||
@ -92,7 +92,7 @@ export const DisableAuthenticatorAppDialog = () => {
|
|||||||
onCloseTwoFactorDisableDialog();
|
onCloseTwoFactorDisableDialog();
|
||||||
});
|
});
|
||||||
|
|
||||||
await refreshSession();
|
await revalidate();
|
||||||
} catch (_err) {
|
} catch (_err) {
|
||||||
toast({
|
toast({
|
||||||
title: _(msg`Unable to disable two-factor authentication`),
|
title: _(msg`Unable to disable two-factor authentication`),
|
||||||
|
|||||||
@ -5,12 +5,12 @@ import { msg } from '@lingui/core/macro';
|
|||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { useRevalidator } from 'react-router';
|
||||||
import { renderSVG } from 'uqr';
|
import { renderSVG } from 'uqr';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { authClient } from '@documenso/auth/client';
|
import { authClient } from '@documenso/auth/client';
|
||||||
import { downloadFile } from '@documenso/lib/client-only/download-file';
|
import { downloadFile } from '@documenso/lib/client-only/download-file';
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@ -48,7 +48,7 @@ export type EnableAuthenticatorAppDialogProps = {
|
|||||||
export const EnableAuthenticatorAppDialog = ({ onSuccess }: EnableAuthenticatorAppDialogProps) => {
|
export const EnableAuthenticatorAppDialog = ({ onSuccess }: EnableAuthenticatorAppDialogProps) => {
|
||||||
const { _ } = useLingui();
|
const { _ } = useLingui();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { refreshSession } = useSession();
|
const { revalidate } = useRevalidator();
|
||||||
|
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [recoveryCodes, setRecoveryCodes] = useState<string[] | null>(null);
|
const [recoveryCodes, setRecoveryCodes] = useState<string[] | null>(null);
|
||||||
@ -74,7 +74,6 @@ export const EnableAuthenticatorAppDialog = ({ onSuccess }: EnableAuthenticatorA
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await authClient.twoFactor.setup();
|
const data = await authClient.twoFactor.setup();
|
||||||
await refreshSession();
|
|
||||||
|
|
||||||
setSetup2FAData(data);
|
setSetup2FAData(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -93,7 +92,6 @@ export const EnableAuthenticatorAppDialog = ({ onSuccess }: EnableAuthenticatorA
|
|||||||
const onEnable2FAFormSubmit = async ({ token }: TEnable2FAForm) => {
|
const onEnable2FAFormSubmit = async ({ token }: TEnable2FAForm) => {
|
||||||
try {
|
try {
|
||||||
const data = await authClient.twoFactor.enable({ code: token });
|
const data = await authClient.twoFactor.enable({ code: token });
|
||||||
await refreshSession();
|
|
||||||
|
|
||||||
setRecoveryCodes(data.recoveryCodes);
|
setRecoveryCodes(data.recoveryCodes);
|
||||||
onSuccess?.();
|
onSuccess?.();
|
||||||
@ -141,6 +139,7 @@ export const EnableAuthenticatorAppDialog = ({ onSuccess }: EnableAuthenticatorA
|
|||||||
|
|
||||||
if (!isOpen && recoveryCodes && recoveryCodes.length > 0) {
|
if (!isOpen && recoveryCodes && recoveryCodes.length > 0) {
|
||||||
setRecoveryCodes(null);
|
setRecoveryCodes(null);
|
||||||
|
void revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
|||||||
@ -19,15 +19,12 @@ import {
|
|||||||
} from '@documenso/ui/primitives/form/form';
|
} 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 { Label } from '@documenso/ui/primitives/label';
|
||||||
import { SignaturePadDialog } from '@documenso/ui/primitives/signature-pad/signature-pad-dialog';
|
import { SignaturePad } from '@documenso/ui/primitives/signature-pad';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
export const ZProfileFormSchema = z.object({
|
export const ZProfileFormSchema = z.object({
|
||||||
name: z
|
name: z.string().trim().min(1, { message: 'Please enter a valid name.' }),
|
||||||
.string()
|
signature: z.string().min(1, 'Signature Pad cannot be empty'),
|
||||||
.trim()
|
|
||||||
.min(1, { message: msg`Please enter a valid name.`.id }),
|
|
||||||
signature: z.string().min(1, { message: msg`Signature Pad cannot be empty.`.id }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ZTwoFactorAuthTokenSchema = z.object({
|
export const ZTwoFactorAuthTokenSchema = z.object({
|
||||||
@ -112,20 +109,22 @@ export const ProfileForm = ({ className }: ProfileFormProps) => {
|
|||||||
</Label>
|
</Label>
|
||||||
<Input id="email" type="email" className="bg-muted mt-2" value={user.email} disabled />
|
<Input id="email" type="email" className="bg-muted mt-2" value={user.email} disabled />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="signature"
|
name="signature"
|
||||||
render={({ field: { onChange, value } }) => (
|
render={({ field: { onChange } }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>
|
<FormLabel>
|
||||||
<Trans>Signature</Trans>
|
<Trans>Signature</Trans>
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SignaturePadDialog
|
<SignaturePad
|
||||||
|
className="h-44 w-full"
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
value={value}
|
containerClassName={cn('rounded-lg border bg-background')}
|
||||||
|
defaultValue={user.signature ?? undefined}
|
||||||
onChange={(v) => onChange(v ?? '')}
|
onChange={(v) => onChange(v ?? '')}
|
||||||
|
allowTypedSignature={true}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
@ -135,7 +134,7 @@ export const ProfileForm = ({ className }: ProfileFormProps) => {
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<Button type="submit" loading={isSubmitting} className="self-end">
|
<Button type="submit" loading={isSubmitting} className="self-end">
|
||||||
<Trans>Update profile</Trans>
|
{isSubmitting ? <Trans>Updating profile...</Trans> : <Trans>Update profile</Trans>}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
|
|||||||
@ -30,7 +30,7 @@ import {
|
|||||||
} from '@documenso/ui/primitives/form/form';
|
} from '@documenso/ui/primitives/form/form';
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
import { Input } from '@documenso/ui/primitives/input';
|
||||||
import { PasswordInput } from '@documenso/ui/primitives/password-input';
|
import { PasswordInput } from '@documenso/ui/primitives/password-input';
|
||||||
import { SignaturePadDialog } from '@documenso/ui/primitives/signature-pad/signature-pad-dialog';
|
import { SignaturePad } from '@documenso/ui/primitives/signature-pad';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
import { UserProfileSkeleton } from '~/components/general/user-profile-skeleton';
|
import { UserProfileSkeleton } from '~/components/general/user-profile-skeleton';
|
||||||
@ -353,15 +353,16 @@ export const SignUpForm = ({
|
|||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="signature"
|
name="signature"
|
||||||
render={({ field: { onChange, value } }) => (
|
render={({ field: { onChange } }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>
|
<FormLabel>
|
||||||
<Trans>Sign Here</Trans>
|
<Trans>Sign Here</Trans>
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SignaturePadDialog
|
<SignaturePad
|
||||||
|
className="h-36 w-full"
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
value={value}
|
containerClassName="mt-2 rounded-lg border bg-background"
|
||||||
onChange={(v) => onChange(v ?? '')}
|
onChange={(v) => onChange(v ?? '')}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@ -530,27 +531,6 @@ export const SignUpForm = ({
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
<p className="text-muted-foreground mt-6 text-xs">
|
|
||||||
<Trans>
|
|
||||||
By proceeding, you agree to our{' '}
|
|
||||||
<Link
|
|
||||||
to="https://documen.so/terms"
|
|
||||||
target="_blank"
|
|
||||||
className="text-documenso-700 duration-200 hover:opacity-70"
|
|
||||||
>
|
|
||||||
Terms of Service
|
|
||||||
</Link>{' '}
|
|
||||||
and{' '}
|
|
||||||
<Link
|
|
||||||
to="https://documen.so/privacy"
|
|
||||||
target="_blank"
|
|
||||||
className="text-documenso-700 duration-200 hover:opacity-70"
|
|
||||||
>
|
|
||||||
Privacy Policy
|
|
||||||
</Link>
|
|
||||||
.
|
|
||||||
</Trans>
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -308,7 +308,7 @@ export function TeamBrandingPreferencesForm({ team, settings }: TeamBrandingPref
|
|||||||
|
|
||||||
<div className="flex flex-row justify-end space-x-4">
|
<div className="flex flex-row justify-end space-x-4">
|
||||||
<Button type="submit" loading={form.formState.isSubmitting}>
|
<Button type="submit" loading={form.formState.isSubmitting}>
|
||||||
<Trans>Update</Trans>
|
<Trans>Save</Trans>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|||||||
@ -8,15 +8,12 @@ import { useForm } from 'react-hook-form';
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import { DOCUMENT_SIGNATURE_TYPES, DocumentSignatureType } from '@documenso/lib/constants/document';
|
|
||||||
import {
|
import {
|
||||||
SUPPORTED_LANGUAGES,
|
SUPPORTED_LANGUAGES,
|
||||||
SUPPORTED_LANGUAGE_CODES,
|
SUPPORTED_LANGUAGE_CODES,
|
||||||
isValidLanguageCode,
|
isValidLanguageCode,
|
||||||
} from '@documenso/lib/constants/i18n';
|
} from '@documenso/lib/constants/i18n';
|
||||||
import { extractTeamSignatureSettings } from '@documenso/lib/utils/teams';
|
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import { DocumentSignatureSettingsTooltip } from '@documenso/ui/components/document/document-signature-settings-tooltip';
|
|
||||||
import { Alert } from '@documenso/ui/primitives/alert';
|
import { Alert } from '@documenso/ui/primitives/alert';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import {
|
import {
|
||||||
@ -26,9 +23,7 @@ import {
|
|||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage,
|
|
||||||
} from '@documenso/ui/primitives/form/form';
|
} from '@documenso/ui/primitives/form/form';
|
||||||
import { MultiSelectCombobox } from '@documenso/ui/primitives/multi-select-combobox';
|
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@ -43,10 +38,8 @@ const ZTeamDocumentPreferencesFormSchema = z.object({
|
|||||||
documentVisibility: z.nativeEnum(DocumentVisibility),
|
documentVisibility: z.nativeEnum(DocumentVisibility),
|
||||||
documentLanguage: z.enum(SUPPORTED_LANGUAGE_CODES),
|
documentLanguage: z.enum(SUPPORTED_LANGUAGE_CODES),
|
||||||
includeSenderDetails: z.boolean(),
|
includeSenderDetails: z.boolean(),
|
||||||
|
typedSignatureEnabled: z.boolean(),
|
||||||
includeSigningCertificate: z.boolean(),
|
includeSigningCertificate: z.boolean(),
|
||||||
signatureTypes: z.array(z.nativeEnum(DocumentSignatureType)).min(1, {
|
|
||||||
message: msg`At least one signature type must be enabled`.id,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
type TTeamDocumentPreferencesFormSchema = z.infer<typeof ZTeamDocumentPreferencesFormSchema>;
|
type TTeamDocumentPreferencesFormSchema = z.infer<typeof ZTeamDocumentPreferencesFormSchema>;
|
||||||
@ -76,8 +69,8 @@ export const TeamDocumentPreferencesForm = ({
|
|||||||
? settings?.documentLanguage
|
? settings?.documentLanguage
|
||||||
: 'en',
|
: 'en',
|
||||||
includeSenderDetails: settings?.includeSenderDetails ?? false,
|
includeSenderDetails: settings?.includeSenderDetails ?? false,
|
||||||
|
typedSignatureEnabled: settings?.typedSignatureEnabled ?? true,
|
||||||
includeSigningCertificate: settings?.includeSigningCertificate ?? true,
|
includeSigningCertificate: settings?.includeSigningCertificate ?? true,
|
||||||
signatureTypes: extractTeamSignatureSettings(settings),
|
|
||||||
},
|
},
|
||||||
resolver: zodResolver(ZTeamDocumentPreferencesFormSchema),
|
resolver: zodResolver(ZTeamDocumentPreferencesFormSchema),
|
||||||
});
|
});
|
||||||
@ -91,7 +84,7 @@ export const TeamDocumentPreferencesForm = ({
|
|||||||
documentLanguage,
|
documentLanguage,
|
||||||
includeSenderDetails,
|
includeSenderDetails,
|
||||||
includeSigningCertificate,
|
includeSigningCertificate,
|
||||||
signatureTypes,
|
typedSignatureEnabled,
|
||||||
} = data;
|
} = data;
|
||||||
|
|
||||||
await updateTeamDocumentPreferences({
|
await updateTeamDocumentPreferences({
|
||||||
@ -100,10 +93,8 @@ export const TeamDocumentPreferencesForm = ({
|
|||||||
documentVisibility,
|
documentVisibility,
|
||||||
documentLanguage,
|
documentLanguage,
|
||||||
includeSenderDetails,
|
includeSenderDetails,
|
||||||
|
typedSignatureEnabled,
|
||||||
includeSigningCertificate,
|
includeSigningCertificate,
|
||||||
typedSignatureEnabled: signatureTypes.includes(DocumentSignatureType.TYPE),
|
|
||||||
uploadSignatureEnabled: signatureTypes.includes(DocumentSignatureType.UPLOAD),
|
|
||||||
drawSignatureEnabled: signatureTypes.includes(DocumentSignatureType.DRAW),
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -199,44 +190,6 @@ export const TeamDocumentPreferencesForm = ({
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="signatureTypes"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="flex-1">
|
|
||||||
<FormLabel className="flex flex-row items-center">
|
|
||||||
<Trans>Default Signature Settings</Trans>
|
|
||||||
<DocumentSignatureSettingsTooltip />
|
|
||||||
</FormLabel>
|
|
||||||
|
|
||||||
<FormControl>
|
|
||||||
<MultiSelectCombobox
|
|
||||||
options={Object.values(DOCUMENT_SIGNATURE_TYPES).map((option) => ({
|
|
||||||
label: _(option.label),
|
|
||||||
value: option.value,
|
|
||||||
}))}
|
|
||||||
selectedValues={field.value}
|
|
||||||
onChange={field.onChange}
|
|
||||||
className="bg-background w-full"
|
|
||||||
enableSearch={false}
|
|
||||||
emptySelectionPlaceholder="Select signature types"
|
|
||||||
testId="signature-types-combobox"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
{form.formState.errors.signatureTypes ? (
|
|
||||||
<FormMessage />
|
|
||||||
) : (
|
|
||||||
<FormDescription>
|
|
||||||
<Trans>
|
|
||||||
Controls which signatures are allowed to be used when signing a document.
|
|
||||||
</Trans>
|
|
||||||
</FormDescription>
|
|
||||||
)}
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="includeSenderDetails"
|
name="includeSenderDetails"
|
||||||
@ -285,6 +238,36 @@ export const TeamDocumentPreferencesForm = ({
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="typedSignatureEnabled"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex-1">
|
||||||
|
<FormLabel>
|
||||||
|
<Trans>Enable Typed Signature</Trans>
|
||||||
|
</FormLabel>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<FormControl className="block">
|
||||||
|
<Switch
|
||||||
|
ref={field.ref}
|
||||||
|
name={field.name}
|
||||||
|
checked={field.value}
|
||||||
|
onCheckedChange={field.onChange}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FormDescription>
|
||||||
|
<Trans>
|
||||||
|
Controls whether the recipients can sign the documents using a typed signature.
|
||||||
|
Enable or disable the typed signature globally.
|
||||||
|
</Trans>
|
||||||
|
</FormDescription>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="includeSigningCertificate"
|
name="includeSigningCertificate"
|
||||||
@ -318,7 +301,7 @@ export const TeamDocumentPreferencesForm = ({
|
|||||||
|
|
||||||
<div className="flex flex-row justify-end space-x-4">
|
<div className="flex flex-row justify-end space-x-4">
|
||||||
<Button type="submit" loading={form.formState.isSubmitting}>
|
<Button type="submit" loading={form.formState.isSubmitting}>
|
||||||
<Trans>Update</Trans>
|
<Trans>Save</Trans>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|||||||
@ -76,7 +76,7 @@ export const AppNavDesktop = ({
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="text-muted-foreground flex w-full max-w-96 items-center justify-between rounded-lg"
|
className="text-muted-foreground flex w-96 items-center justify-between rounded-lg"
|
||||||
onClick={() => setIsCommandMenuOpen(true)}
|
onClick={() => setIsCommandMenuOpen(true)}
|
||||||
>
|
>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
|
|||||||
@ -113,11 +113,7 @@ export const DirectTemplatePageView = ({
|
|||||||
|
|
||||||
const redirectUrl = template.templateMeta?.redirectUrl;
|
const redirectUrl = template.templateMeta?.redirectUrl;
|
||||||
|
|
||||||
if (redirectUrl) {
|
await (redirectUrl ? navigate(redirectUrl) : navigate(`/sign/${token}/complete`));
|
||||||
window.location.href = redirectUrl;
|
|
||||||
} else {
|
|
||||||
await navigate(`/sign/${token}/complete`);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
title: _(msg`Something went wrong`),
|
title: _(msg`Something went wrong`),
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Field, Recipient, Signature } from '@prisma/client';
|
import type { Field, Recipient, Signature } from '@prisma/client';
|
||||||
@ -24,6 +24,7 @@ import type {
|
|||||||
} from '@documenso/trpc/server/field-router/schema';
|
} from '@documenso/trpc/server/field-router/schema';
|
||||||
import { FieldToolTip } from '@documenso/ui/components/field/field-tooltip';
|
import { FieldToolTip } from '@documenso/ui/components/field/field-tooltip';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
|
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
||||||
import {
|
import {
|
||||||
DocumentFlowFormContainerContent,
|
DocumentFlowFormContainerContent,
|
||||||
DocumentFlowFormContainerFooter,
|
DocumentFlowFormContainerFooter,
|
||||||
@ -34,7 +35,7 @@ import type { DocumentFlowStep } from '@documenso/ui/primitives/document-flow/ty
|
|||||||
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
import { Input } from '@documenso/ui/primitives/input';
|
||||||
import { Label } from '@documenso/ui/primitives/label';
|
import { Label } from '@documenso/ui/primitives/label';
|
||||||
import { SignaturePadDialog } from '@documenso/ui/primitives/signature-pad/signature-pad-dialog';
|
import { SignaturePad } from '@documenso/ui/primitives/signature-pad';
|
||||||
import { useStep } from '@documenso/ui/primitives/stepper';
|
import { useStep } from '@documenso/ui/primitives/stepper';
|
||||||
|
|
||||||
import { DocumentSigningCheckboxField } from '~/components/general/document-signing/document-signing-checkbox-field';
|
import { DocumentSigningCheckboxField } from '~/components/general/document-signing/document-signing-checkbox-field';
|
||||||
@ -72,7 +73,8 @@ export const DirectTemplateSigningForm = ({
|
|||||||
template,
|
template,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
}: DirectTemplateSigningFormProps) => {
|
}: DirectTemplateSigningFormProps) => {
|
||||||
const { fullName, signature, setFullName, setSignature } = useRequiredDocumentSigningContext();
|
const { fullName, signature, signatureValid, setFullName, setSignature } =
|
||||||
|
useRequiredDocumentSigningContext();
|
||||||
|
|
||||||
const [localFields, setLocalFields] = useState<DirectTemplateLocalField[]>(directRecipientFields);
|
const [localFields, setLocalFields] = useState<DirectTemplateLocalField[]>(directRecipientFields);
|
||||||
const [validateUninsertedFields, setValidateUninsertedFields] = useState(false);
|
const [validateUninsertedFields, setValidateUninsertedFields] = useState(false);
|
||||||
@ -89,7 +91,7 @@ export const DirectTemplateSigningForm = ({
|
|||||||
|
|
||||||
const tempField: DirectTemplateLocalField = {
|
const tempField: DirectTemplateLocalField = {
|
||||||
...field,
|
...field,
|
||||||
customText: value.value ?? '',
|
customText: value.value,
|
||||||
inserted: true,
|
inserted: true,
|
||||||
signedValue: value,
|
signedValue: value,
|
||||||
};
|
};
|
||||||
@ -100,8 +102,8 @@ export const DirectTemplateSigningForm = ({
|
|||||||
created: new Date(),
|
created: new Date(),
|
||||||
recipientId: 1,
|
recipientId: 1,
|
||||||
fieldId: 1,
|
fieldId: 1,
|
||||||
signatureImageAsBase64: value.value?.startsWith('data:') ? value.value : null,
|
signatureImageAsBase64: value.value.startsWith('data:') ? value.value : null,
|
||||||
typedSignature: value.value && !value.value.startsWith('data:') ? value.value : null,
|
typedSignature: value.value.startsWith('data:') ? null : value.value,
|
||||||
} satisfies Signature;
|
} satisfies Signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +135,8 @@ export const DirectTemplateSigningForm = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hasSignatureField = localFields.some((field) => field.type === FieldType.SIGNATURE);
|
||||||
|
|
||||||
const uninsertedFields = useMemo(() => {
|
const uninsertedFields = useMemo(() => {
|
||||||
return sortFieldsByPosition(localFields.filter((field) => !field.inserted));
|
return sortFieldsByPosition(localFields.filter((field) => !field.inserted));
|
||||||
}, [localFields]);
|
}, [localFields]);
|
||||||
@ -145,6 +149,10 @@ export const DirectTemplateSigningForm = ({
|
|||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
setValidateUninsertedFields(true);
|
setValidateUninsertedFields(true);
|
||||||
|
|
||||||
|
if (hasSignatureField && !signatureValid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const isFieldsValid = validateFieldsInserted(localFields);
|
const isFieldsValid = validateFieldsInserted(localFields);
|
||||||
|
|
||||||
if (!isFieldsValid) {
|
if (!isFieldsValid) {
|
||||||
@ -162,55 +170,6 @@ export const DirectTemplateSigningForm = ({
|
|||||||
// Do not reset to false since we do a redirect.
|
// Do not reset to false since we do a redirect.
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const updatedFields = [...localFields];
|
|
||||||
|
|
||||||
localFields.forEach((field) => {
|
|
||||||
const index = updatedFields.findIndex((f) => f.id === field.id);
|
|
||||||
let value = '';
|
|
||||||
|
|
||||||
match(field.type)
|
|
||||||
.with(FieldType.TEXT, () => {
|
|
||||||
const meta = field.fieldMeta ? ZTextFieldMeta.safeParse(field.fieldMeta) : null;
|
|
||||||
|
|
||||||
if (meta?.success) {
|
|
||||||
value = meta.data.text ?? '';
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.with(FieldType.NUMBER, () => {
|
|
||||||
const meta = field.fieldMeta ? ZNumberFieldMeta.safeParse(field.fieldMeta) : null;
|
|
||||||
|
|
||||||
if (meta?.success) {
|
|
||||||
value = meta.data.value ?? '';
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.with(FieldType.DROPDOWN, () => {
|
|
||||||
const meta = field.fieldMeta ? ZDropdownFieldMeta.safeParse(field.fieldMeta) : null;
|
|
||||||
|
|
||||||
if (meta?.success) {
|
|
||||||
value = meta.data.defaultValue ?? '';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (value) {
|
|
||||||
const signedValue = {
|
|
||||||
token: directRecipient.token,
|
|
||||||
fieldId: field.id,
|
|
||||||
value,
|
|
||||||
};
|
|
||||||
|
|
||||||
updatedFields[index] = {
|
|
||||||
...field,
|
|
||||||
customText: value,
|
|
||||||
inserted: true,
|
|
||||||
signedValue,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setLocalFields(updatedFields);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DocumentSigningRecipientProvider recipient={directRecipient}>
|
<DocumentSigningRecipientProvider recipient={directRecipient}>
|
||||||
<DocumentFlowFormContainerHeader title={flowStep.title} description={flowStep.description} />
|
<DocumentFlowFormContainerHeader title={flowStep.title} description={flowStep.description} />
|
||||||
@ -232,8 +191,6 @@ export const DirectTemplateSigningForm = ({
|
|||||||
onSignField={onSignField}
|
onSignField={onSignField}
|
||||||
onUnsignField={onUnsignField}
|
onUnsignField={onUnsignField}
|
||||||
typedSignatureEnabled={template.templateMeta?.typedSignatureEnabled}
|
typedSignatureEnabled={template.templateMeta?.typedSignatureEnabled}
|
||||||
uploadSignatureEnabled={template.templateMeta?.uploadSignatureEnabled}
|
|
||||||
drawSignatureEnabled={template.templateMeta?.drawSignatureEnabled}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.with(FieldType.INITIALS, () => (
|
.with(FieldType.INITIALS, () => (
|
||||||
@ -378,15 +335,19 @@ export const DirectTemplateSigningForm = ({
|
|||||||
<Trans>Signature</Trans>
|
<Trans>Signature</Trans>
|
||||||
</Label>
|
</Label>
|
||||||
|
|
||||||
<SignaturePadDialog
|
<Card className="mt-2" gradient degrees={-120}>
|
||||||
className="mt-2"
|
<CardContent className="p-0">
|
||||||
|
<SignaturePad
|
||||||
|
className="h-44 w-full"
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
value={signature ?? ''}
|
defaultValue={signature ?? undefined}
|
||||||
onChange={(value) => setSignature(value)}
|
onChange={(value) => {
|
||||||
typedSignatureEnabled={template.templateMeta?.typedSignatureEnabled}
|
setSignature(value);
|
||||||
uploadSignatureEnabled={template.templateMeta?.uploadSignatureEnabled}
|
}}
|
||||||
drawSignatureEnabled={template.templateMeta?.drawSignatureEnabled}
|
allowTypedSignature={template.templateMeta?.typedSignatureEnabled}
|
||||||
/>
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -97,10 +97,6 @@ export const DocumentSigningCheckboxField = ({
|
|||||||
|
|
||||||
const onSign = async (authOptions?: TRecipientActionAuth) => {
|
const onSign = async (authOptions?: TRecipientActionAuth) => {
|
||||||
try {
|
try {
|
||||||
if (!isLengthConditionMet) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const payload: TSignFieldWithTokenMutationSchema = {
|
const payload: TSignFieldWithTokenMutationSchema = {
|
||||||
token: recipient.token,
|
token: recipient.token,
|
||||||
fieldId: field.id,
|
fieldId: field.id,
|
||||||
@ -198,30 +194,18 @@ export const DocumentSigningCheckboxField = ({
|
|||||||
|
|
||||||
setCheckedValues(updatedValues);
|
setCheckedValues(updatedValues);
|
||||||
|
|
||||||
const removePayload: TRemovedSignedFieldWithTokenMutationSchema = {
|
await removeSignedFieldWithToken({
|
||||||
token: recipient.token,
|
token: recipient.token,
|
||||||
fieldId: field.id,
|
fieldId: field.id,
|
||||||
};
|
});
|
||||||
|
|
||||||
if (onUnsignField) {
|
if (updatedValues.length > 0) {
|
||||||
await onUnsignField(removePayload);
|
await signFieldWithToken({
|
||||||
} else {
|
|
||||||
await removeSignedFieldWithToken(removePayload);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updatedValues.length > 0 && shouldAutoSignField) {
|
|
||||||
const signPayload: TSignFieldWithTokenMutationSchema = {
|
|
||||||
token: recipient.token,
|
token: recipient.token,
|
||||||
fieldId: field.id,
|
fieldId: field.id,
|
||||||
value: toCheckboxValue(updatedValues),
|
value: toCheckboxValue(updatedValues),
|
||||||
isBase64: true,
|
isBase64: true,
|
||||||
};
|
});
|
||||||
|
|
||||||
if (onSignField) {
|
|
||||||
await onSignField(signPayload);
|
|
||||||
} else {
|
|
||||||
await signFieldWithToken(signPayload);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|||||||
@ -1,12 +1,8 @@
|
|||||||
import { useMemo, useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { Field } from '@prisma/client';
|
import type { Field } from '@prisma/client';
|
||||||
import { RecipientRole } from '@prisma/client';
|
import { RecipientRole } from '@prisma/client';
|
||||||
import { useForm } from 'react-hook-form';
|
|
||||||
import { match } from 'ts-pattern';
|
|
||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { fieldsContainUnsignedRequiredField } from '@documenso/lib/utils/advanced-fields-helpers';
|
import { fieldsContainUnsignedRequiredField } from '@documenso/lib/utils/advanced-fields-helpers';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
@ -17,15 +13,6 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from '@documenso/ui/primitives/dialog';
|
} from '@documenso/ui/primitives/dialog';
|
||||||
import {
|
|
||||||
Form,
|
|
||||||
FormControl,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormMessage,
|
|
||||||
} from '@documenso/ui/primitives/form/form';
|
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
|
||||||
|
|
||||||
import { DocumentSigningDisclosure } from '~/components/general/document-signing/document-signing-disclosure';
|
import { DocumentSigningDisclosure } from '~/components/general/document-signing/document-signing-disclosure';
|
||||||
|
|
||||||
@ -34,23 +21,11 @@ export type DocumentSigningCompleteDialogProps = {
|
|||||||
documentTitle: string;
|
documentTitle: string;
|
||||||
fields: Field[];
|
fields: Field[];
|
||||||
fieldsValidated: () => void | Promise<void>;
|
fieldsValidated: () => void | Promise<void>;
|
||||||
onSignatureComplete: (nextSigner?: { name: string; email: string }) => void | Promise<void>;
|
onSignatureComplete: () => void | Promise<void>;
|
||||||
role: RecipientRole;
|
role: RecipientRole;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
allowDictateNextSigner?: boolean;
|
|
||||||
defaultNextSigner?: {
|
|
||||||
name: string;
|
|
||||||
email: string;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const ZNextSignerFormSchema = z.object({
|
|
||||||
name: z.string().min(1, 'Name is required'),
|
|
||||||
email: z.string().email('Invalid email address'),
|
|
||||||
});
|
|
||||||
|
|
||||||
type TNextSignerFormSchema = z.infer<typeof ZNextSignerFormSchema>;
|
|
||||||
|
|
||||||
export const DocumentSigningCompleteDialog = ({
|
export const DocumentSigningCompleteDialog = ({
|
||||||
isSubmitting,
|
isSubmitting,
|
||||||
documentTitle,
|
documentTitle,
|
||||||
@ -59,54 +34,19 @@ export const DocumentSigningCompleteDialog = ({
|
|||||||
onSignatureComplete,
|
onSignatureComplete,
|
||||||
role,
|
role,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
allowDictateNextSigner = false,
|
|
||||||
defaultNextSigner,
|
|
||||||
}: DocumentSigningCompleteDialogProps) => {
|
}: DocumentSigningCompleteDialogProps) => {
|
||||||
const [showDialog, setShowDialog] = useState(false);
|
const [showDialog, setShowDialog] = useState(false);
|
||||||
const [isEditingNextSigner, setIsEditingNextSigner] = useState(false);
|
|
||||||
|
|
||||||
const form = useForm<TNextSignerFormSchema>({
|
|
||||||
resolver: allowDictateNextSigner ? zodResolver(ZNextSignerFormSchema) : undefined,
|
|
||||||
defaultValues: {
|
|
||||||
name: defaultNextSigner?.name ?? '',
|
|
||||||
email: defaultNextSigner?.email ?? '',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const isComplete = useMemo(() => !fieldsContainUnsignedRequiredField(fields), [fields]);
|
const isComplete = useMemo(() => !fieldsContainUnsignedRequiredField(fields), [fields]);
|
||||||
|
|
||||||
const handleOpenChange = (open: boolean) => {
|
const handleOpenChange = (open: boolean) => {
|
||||||
if (form.formState.isSubmitting || !isComplete) {
|
if (isSubmitting || !isComplete) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (open) {
|
|
||||||
form.reset({
|
|
||||||
name: defaultNextSigner?.name ?? '',
|
|
||||||
email: defaultNextSigner?.email ?? '',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsEditingNextSigner(false);
|
|
||||||
setShowDialog(open);
|
setShowDialog(open);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onFormSubmit = async (data: TNextSignerFormSchema) => {
|
|
||||||
console.log('data', data);
|
|
||||||
console.log('form.formState.errors', form.formState.errors);
|
|
||||||
try {
|
|
||||||
if (allowDictateNextSigner && data.name && data.email) {
|
|
||||||
await onSignatureComplete({ name: data.name, email: data.email });
|
|
||||||
} else {
|
|
||||||
await onSignatureComplete();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error completing signature:', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const isNextSignerValid = !allowDictateNextSigner || (form.watch('name') && form.watch('email'));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={showDialog} onOpenChange={handleOpenChange}>
|
<Dialog open={showDialog} onOpenChange={handleOpenChange}>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
@ -118,36 +58,21 @@ export const DocumentSigningCompleteDialog = ({
|
|||||||
loading={isSubmitting}
|
loading={isSubmitting}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
{match({ isComplete, role })
|
{isComplete ? <Trans>Complete</Trans> : <Trans>Next field</Trans>}
|
||||||
.with({ isComplete: false }, () => <Trans>Next field</Trans>)
|
|
||||||
.with({ isComplete: true, role: RecipientRole.APPROVER }, () => <Trans>Approve</Trans>)
|
|
||||||
.with({ isComplete: true, role: RecipientRole.VIEWER }, () => (
|
|
||||||
<Trans>Mark as viewed</Trans>
|
|
||||||
))
|
|
||||||
.with({ isComplete: true }, () => <Trans>Complete</Trans>)
|
|
||||||
.exhaustive()}
|
|
||||||
</Button>
|
</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
|
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<Form {...form}>
|
|
||||||
<form onSubmit={form.handleSubmit(onFormSubmit)}>
|
|
||||||
<fieldset disabled={form.formState.isSubmitting} className="border-none p-0">
|
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
<div className="text-foreground text-xl font-semibold">
|
<div className="text-foreground text-xl font-semibold">
|
||||||
{match(role)
|
{role === RecipientRole.VIEWER && <Trans>Complete Viewing</Trans>}
|
||||||
.with(RecipientRole.VIEWER, () => <Trans>Complete Viewing</Trans>)
|
{role === RecipientRole.SIGNER && <Trans>Complete Signing</Trans>}
|
||||||
.with(RecipientRole.SIGNER, () => <Trans>Complete Signing</Trans>)
|
{role === RecipientRole.APPROVER && <Trans>Complete Approval</Trans>}
|
||||||
.with(RecipientRole.APPROVER, () => <Trans>Complete Approval</Trans>)
|
|
||||||
.with(RecipientRole.CC, () => <Trans>Complete Viewing</Trans>)
|
|
||||||
.with(RecipientRole.ASSISTANT, () => <Trans>Complete Assisting</Trans>)
|
|
||||||
.exhaustive()}
|
|
||||||
</div>
|
</div>
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
|
|
||||||
<div className="text-muted-foreground max-w-[50ch]">
|
<div className="text-muted-foreground max-w-[50ch]">
|
||||||
{match(role)
|
{role === RecipientRole.VIEWER && (
|
||||||
.with(RecipientRole.VIEWER, () => (
|
|
||||||
<span>
|
<span>
|
||||||
<Trans>
|
<Trans>
|
||||||
<span className="inline-flex flex-wrap">
|
<span className="inline-flex flex-wrap">
|
||||||
@ -160,8 +85,8 @@ export const DocumentSigningCompleteDialog = ({
|
|||||||
<br /> Are you sure?
|
<br /> Are you sure?
|
||||||
</Trans>
|
</Trans>
|
||||||
</span>
|
</span>
|
||||||
))
|
)}
|
||||||
.with(RecipientRole.SIGNER, () => (
|
{role === RecipientRole.SIGNER && (
|
||||||
<span>
|
<span>
|
||||||
<Trans>
|
<Trans>
|
||||||
<span className="inline-flex flex-wrap">
|
<span className="inline-flex flex-wrap">
|
||||||
@ -174,8 +99,8 @@ export const DocumentSigningCompleteDialog = ({
|
|||||||
<br /> Are you sure?
|
<br /> Are you sure?
|
||||||
</Trans>
|
</Trans>
|
||||||
</span>
|
</span>
|
||||||
))
|
)}
|
||||||
.with(RecipientRole.APPROVER, () => (
|
{role === RecipientRole.APPROVER && (
|
||||||
<span>
|
<span>
|
||||||
<Trans>
|
<Trans>
|
||||||
<span className="inline-flex flex-wrap">
|
<span className="inline-flex flex-wrap">
|
||||||
@ -188,126 +113,37 @@ export const DocumentSigningCompleteDialog = ({
|
|||||||
<br /> Are you sure?
|
<br /> Are you sure?
|
||||||
</Trans>
|
</Trans>
|
||||||
</span>
|
</span>
|
||||||
))
|
|
||||||
.otherwise(() => (
|
|
||||||
<span>
|
|
||||||
<Trans>
|
|
||||||
<span className="inline-flex flex-wrap">
|
|
||||||
You are about to complete viewing "
|
|
||||||
<span className="inline-block max-w-[11rem] truncate align-baseline">
|
|
||||||
{documentTitle}
|
|
||||||
</span>
|
|
||||||
".
|
|
||||||
</span>
|
|
||||||
<br /> Are you sure?
|
|
||||||
</Trans>
|
|
||||||
</span>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{allowDictateNextSigner && (
|
|
||||||
<div className="mt-4 flex flex-col gap-4">
|
|
||||||
{!isEditingNextSigner && (
|
|
||||||
<div>
|
|
||||||
<p className="text-muted-foreground text-sm">
|
|
||||||
The next recipient to sign this document will be{' '}
|
|
||||||
<span className="font-semibold">{form.watch('name')}</span> (
|
|
||||||
<span className="font-semibold">{form.watch('email')}</span>).
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
className="mt-2"
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => setIsEditingNextSigner((prev) => !prev)}
|
|
||||||
>
|
|
||||||
<Trans>Update Recipient</Trans>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{isEditingNextSigner && (
|
|
||||||
<div className="flex flex-col gap-4 md:flex-row">
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="name"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="flex-1">
|
|
||||||
<FormLabel>
|
|
||||||
<Trans>Name</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
className="mt-2"
|
|
||||||
placeholder="Enter the next signer's name"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="email"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="flex-1">
|
|
||||||
<FormLabel>
|
|
||||||
<Trans>Email</Trans>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
type="email"
|
|
||||||
className="mt-2"
|
|
||||||
placeholder="Enter the next signer's email"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
|
|
||||||
<DocumentSigningDisclosure className="mt-4" />
|
<DocumentSigningDisclosure className="mt-4" />
|
||||||
|
|
||||||
<DialogFooter className="mt-4">
|
<DialogFooter>
|
||||||
<div className="flex w-full flex-1 flex-nowrap gap-4">
|
<div className="flex w-full flex-1 flex-nowrap gap-4">
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
className="dark:bg-muted dark:hover:bg-muted/80 flex-1 bg-black/5 hover:bg-black/10"
|
className="dark:bg-muted dark:hover:bg-muted/80 flex-1 bg-black/5 hover:bg-black/10"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
onClick={() => setShowDialog(false)}
|
onClick={() => {
|
||||||
disabled={form.formState.isSubmitting}
|
setShowDialog(false);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Trans>Cancel</Trans>
|
<Trans>Cancel</Trans>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="button"
|
||||||
className="flex-1"
|
className="flex-1"
|
||||||
disabled={!isComplete || !isNextSignerValid}
|
disabled={!isComplete}
|
||||||
loading={form.formState.isSubmitting}
|
loading={isSubmitting}
|
||||||
|
onClick={onSignatureComplete}
|
||||||
>
|
>
|
||||||
{match(role)
|
{role === RecipientRole.VIEWER && <Trans>Mark as Viewed</Trans>}
|
||||||
.with(RecipientRole.VIEWER, () => <Trans>Mark as Viewed</Trans>)
|
{role === RecipientRole.SIGNER && <Trans>Sign</Trans>}
|
||||||
.with(RecipientRole.SIGNER, () => <Trans>Sign</Trans>)
|
{role === RecipientRole.APPROVER && <Trans>Approve</Trans>}
|
||||||
.with(RecipientRole.APPROVER, () => <Trans>Approve</Trans>)
|
|
||||||
.with(RecipientRole.CC, () => <Trans>Mark as Viewed</Trans>)
|
|
||||||
.with(RecipientRole.ASSISTANT, () => <Trans>Complete</Trans>)
|
|
||||||
.exhaustive()}
|
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</fieldset>
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -181,23 +181,6 @@ export const DocumentSigningFieldContainer = ({
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(field.type === FieldType.RADIO || field.type === FieldType.CHECKBOX) &&
|
|
||||||
field.fieldMeta?.label && (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'absolute -top-16 left-0 right-0 rounded-md p-2 text-center text-xs text-gray-700',
|
|
||||||
{
|
|
||||||
'bg-foreground/5 border-border border': !field.inserted,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'bg-documenso-200 border-primary border': field.inserted,
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{field.fieldMeta.label}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{children}
|
{children}
|
||||||
</FieldRootContainer>
|
</FieldRootContainer>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -18,16 +18,14 @@ import { trpc } from '@documenso/trpc/react';
|
|||||||
import { FieldToolTip } from '@documenso/ui/components/field/field-tooltip';
|
import { FieldToolTip } from '@documenso/ui/components/field/field-tooltip';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
|
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
import { Input } from '@documenso/ui/primitives/input';
|
||||||
import { Label } from '@documenso/ui/primitives/label';
|
import { Label } from '@documenso/ui/primitives/label';
|
||||||
import { RadioGroup, RadioGroupItem } from '@documenso/ui/primitives/radio-group';
|
import { RadioGroup, RadioGroupItem } from '@documenso/ui/primitives/radio-group';
|
||||||
import { SignaturePadDialog } from '@documenso/ui/primitives/signature-pad/signature-pad-dialog';
|
import { SignaturePad } from '@documenso/ui/primitives/signature-pad';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
import {
|
import { AssistantConfirmationDialog } from '../../dialogs/assistant-confirmation-dialog';
|
||||||
AssistantConfirmationDialog,
|
|
||||||
type NextSigner,
|
|
||||||
} from '../../dialogs/assistant-confirmation-dialog';
|
|
||||||
import { DocumentSigningCompleteDialog } from './document-signing-complete-dialog';
|
import { DocumentSigningCompleteDialog } from './document-signing-complete-dialog';
|
||||||
import { useRequiredDocumentSigningContext } from './document-signing-provider';
|
import { useRequiredDocumentSigningContext } from './document-signing-provider';
|
||||||
|
|
||||||
@ -61,17 +59,15 @@ export const DocumentSigningForm = ({
|
|||||||
|
|
||||||
const assistantSignersId = useId();
|
const assistantSignersId = useId();
|
||||||
|
|
||||||
const { fullName, signature, setFullName, setSignature } = useRequiredDocumentSigningContext();
|
const { fullName, signature, setFullName, setSignature, signatureValid, setSignatureValid } =
|
||||||
|
useRequiredDocumentSigningContext();
|
||||||
|
|
||||||
const [validateUninsertedFields, setValidateUninsertedFields] = useState(false);
|
const [validateUninsertedFields, setValidateUninsertedFields] = useState(false);
|
||||||
const [isConfirmationDialogOpen, setIsConfirmationDialogOpen] = useState(false);
|
const [isConfirmationDialogOpen, setIsConfirmationDialogOpen] = useState(false);
|
||||||
const [isAssistantSubmitting, setIsAssistantSubmitting] = useState(false);
|
const [isAssistantSubmitting, setIsAssistantSubmitting] = useState(false);
|
||||||
|
|
||||||
const {
|
const { mutateAsync: completeDocumentWithToken } =
|
||||||
mutateAsync: completeDocumentWithToken,
|
trpc.recipient.completeDocumentWithToken.useMutation();
|
||||||
isPending,
|
|
||||||
isSuccess,
|
|
||||||
} = trpc.recipient.completeDocumentWithToken.useMutation();
|
|
||||||
|
|
||||||
const assistantForm = useForm<{ selectedSignerId: number | undefined }>({
|
const assistantForm = useForm<{ selectedSignerId: number | undefined }>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
@ -79,8 +75,10 @@ export const DocumentSigningForm = ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { handleSubmit, formState } = useForm();
|
||||||
|
|
||||||
// Keep the loading state going if successful since the redirect may take some time.
|
// Keep the loading state going if successful since the redirect may take some time.
|
||||||
const isSubmitting = isPending || isSuccess;
|
const isSubmitting = formState.isSubmitting || formState.isSubmitSuccessful;
|
||||||
|
|
||||||
const fieldsRequiringValidation = useMemo(
|
const fieldsRequiringValidation = useMemo(
|
||||||
() => fields.filter(isFieldUnsignedAndRequired),
|
() => fields.filter(isFieldUnsignedAndRequired),
|
||||||
@ -102,6 +100,22 @@ export const DocumentSigningForm = ({
|
|||||||
validateFieldsInserted(fieldsRequiringValidation);
|
validateFieldsInserted(fieldsRequiringValidation);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onFormSubmit = async () => {
|
||||||
|
setValidateUninsertedFields(true);
|
||||||
|
|
||||||
|
const isFieldsValid = validateFieldsInserted(fieldsRequiringValidation);
|
||||||
|
|
||||||
|
if (hasSignatureField && !signatureValid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isFieldsValid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await completeDocument();
|
||||||
|
};
|
||||||
|
|
||||||
const onAssistantFormSubmit = () => {
|
const onAssistantFormSubmit = () => {
|
||||||
if (uninsertedRecipientFields.length > 0) {
|
if (uninsertedRecipientFields.length > 0) {
|
||||||
return;
|
return;
|
||||||
@ -110,11 +124,11 @@ export const DocumentSigningForm = ({
|
|||||||
setIsConfirmationDialogOpen(true);
|
setIsConfirmationDialogOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAssistantConfirmDialogSubmit = async (nextSigner?: NextSigner) => {
|
const handleAssistantConfirmDialogSubmit = async () => {
|
||||||
setIsAssistantSubmitting(true);
|
setIsAssistantSubmitting(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await completeDocument(undefined, nextSigner);
|
await completeDocument();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
title: 'Error',
|
title: 'Error',
|
||||||
@ -127,18 +141,12 @@ export const DocumentSigningForm = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const completeDocument = async (
|
const completeDocument = async (authOptions?: TRecipientActionAuth) => {
|
||||||
authOptions?: TRecipientActionAuth,
|
await completeDocumentWithToken({
|
||||||
nextSigner?: { email: string; name: string },
|
|
||||||
) => {
|
|
||||||
const payload = {
|
|
||||||
token: recipient.token,
|
token: recipient.token,
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
authOptions,
|
authOptions,
|
||||||
...(nextSigner?.email && nextSigner?.name ? { nextSigner } : {}),
|
});
|
||||||
};
|
|
||||||
|
|
||||||
await completeDocumentWithToken(payload);
|
|
||||||
|
|
||||||
analytics.capture('App: Recipient has completed signing', {
|
analytics.capture('App: Recipient has completed signing', {
|
||||||
signerId: recipient.id,
|
signerId: recipient.id,
|
||||||
@ -153,29 +161,6 @@ export const DocumentSigningForm = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const nextRecipient = useMemo(() => {
|
|
||||||
if (
|
|
||||||
!document.documentMeta?.signingOrder ||
|
|
||||||
document.documentMeta.signingOrder !== 'SEQUENTIAL'
|
|
||||||
) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const sortedRecipients = allRecipients.sort((a, b) => {
|
|
||||||
// Sort by signingOrder first (nulls last), then by id
|
|
||||||
if (a.signingOrder === null && b.signingOrder === null) return a.id - b.id;
|
|
||||||
if (a.signingOrder === null) return 1;
|
|
||||||
if (b.signingOrder === null) return -1;
|
|
||||||
if (a.signingOrder === b.signingOrder) return a.id - b.id;
|
|
||||||
return a.signingOrder - b.signingOrder;
|
|
||||||
});
|
|
||||||
|
|
||||||
const currentIndex = sortedRecipients.findIndex((r) => r.id === recipient.id);
|
|
||||||
return currentIndex !== -1 && currentIndex < sortedRecipients.length - 1
|
|
||||||
? sortedRecipients[currentIndex + 1]
|
|
||||||
: undefined;
|
|
||||||
}, [document.documentMeta?.signingOrder, allRecipients, recipient.id]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
@ -225,19 +210,12 @@ export const DocumentSigningForm = ({
|
|||||||
|
|
||||||
<DocumentSigningCompleteDialog
|
<DocumentSigningCompleteDialog
|
||||||
isSubmitting={isSubmitting}
|
isSubmitting={isSubmitting}
|
||||||
|
onSignatureComplete={handleSubmit(onFormSubmit)}
|
||||||
documentTitle={document.title}
|
documentTitle={document.title}
|
||||||
fields={fields}
|
fields={fields}
|
||||||
fieldsValidated={fieldsValidated}
|
fieldsValidated={fieldsValidated}
|
||||||
onSignatureComplete={async (nextSigner) => {
|
|
||||||
await completeDocument(undefined, nextSigner);
|
|
||||||
}}
|
|
||||||
role={recipient.role}
|
role={recipient.role}
|
||||||
allowDictateNextSigner={document.documentMeta?.allowDictateNextSigner}
|
disabled={!isRecipientsTurn}
|
||||||
defaultNextSigner={
|
|
||||||
nextRecipient
|
|
||||||
? { name: nextRecipient.name, email: nextRecipient.email }
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -316,8 +294,9 @@ export const DocumentSigningForm = ({
|
|||||||
className="w-full"
|
className="w-full"
|
||||||
size="lg"
|
size="lg"
|
||||||
loading={isAssistantSubmitting}
|
loading={isAssistantSubmitting}
|
||||||
|
disabled={isAssistantSubmitting || uninsertedRecipientFields.length > 0}
|
||||||
>
|
>
|
||||||
<Trans>Continue</Trans>
|
{isAssistantSubmitting ? <Trans>Submitting...</Trans> : <Trans>Continue</Trans>}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -327,26 +306,14 @@ export const DocumentSigningForm = ({
|
|||||||
onClose={() => !isAssistantSubmitting && setIsConfirmationDialogOpen(false)}
|
onClose={() => !isAssistantSubmitting && setIsConfirmationDialogOpen(false)}
|
||||||
onConfirm={handleAssistantConfirmDialogSubmit}
|
onConfirm={handleAssistantConfirmDialogSubmit}
|
||||||
isSubmitting={isAssistantSubmitting}
|
isSubmitting={isAssistantSubmitting}
|
||||||
allowDictateNextSigner={
|
|
||||||
nextRecipient && document.documentMeta?.allowDictateNextSigner
|
|
||||||
}
|
|
||||||
defaultNextSigner={
|
|
||||||
nextRecipient
|
|
||||||
? { name: nextRecipient.name, email: nextRecipient.email }
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div>
|
<form onSubmit={handleSubmit(onFormSubmit)}>
|
||||||
<p className="text-muted-foreground mt-2 text-sm">
|
<p className="text-muted-foreground mt-2 text-sm">
|
||||||
{recipient.role === RecipientRole.APPROVER && !hasSignatureField ? (
|
|
||||||
<Trans>Please review the document before approving.</Trans>
|
|
||||||
) : (
|
|
||||||
<Trans>Please review the document before signing.</Trans>
|
<Trans>Please review the document before signing.</Trans>
|
||||||
)}
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<hr className="border-border mb-8 mt-4" />
|
<hr className="border-border mb-8 mt-4" />
|
||||||
@ -370,27 +337,41 @@ export const DocumentSigningForm = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{hasSignatureField && (
|
|
||||||
<div>
|
<div>
|
||||||
<Label htmlFor="Signature">
|
<Label htmlFor="Signature">
|
||||||
<Trans>Signature</Trans>
|
<Trans>Signature</Trans>
|
||||||
</Label>
|
</Label>
|
||||||
|
|
||||||
<SignaturePadDialog
|
<Card className="mt-2" gradient degrees={-120}>
|
||||||
className="mt-2"
|
<CardContent className="p-0">
|
||||||
|
<SignaturePad
|
||||||
|
className="h-44 w-full"
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
value={signature ?? ''}
|
defaultValue={signature ?? undefined}
|
||||||
onChange={(v) => setSignature(v ?? '')}
|
onValidityChange={(isValid) => {
|
||||||
typedSignatureEnabled={document.documentMeta?.typedSignatureEnabled}
|
setSignatureValid(isValid);
|
||||||
uploadSignatureEnabled={document.documentMeta?.uploadSignatureEnabled}
|
}}
|
||||||
drawSignatureEnabled={document.documentMeta?.drawSignatureEnabled}
|
onChange={(value) => {
|
||||||
|
if (signatureValid) {
|
||||||
|
setSignature(value);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
allowTypedSignature={document.documentMeta?.typedSignatureEnabled}
|
||||||
/>
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{hasSignatureField && !signatureValid && (
|
||||||
|
<div className="text-destructive mt-2 text-sm">
|
||||||
|
<Trans>
|
||||||
|
Signature is too small. Please provide a more complete signature.
|
||||||
|
</Trans>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</div>
|
||||||
|
|
||||||
<div className="mt-6 flex flex-col gap-4 md:flex-row">
|
<div className="flex flex-col gap-4 md:flex-row">
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
className="dark:bg-muted dark:hover:bg-muted/80 w-full bg-black/5 hover:bg-black/10"
|
className="dark:bg-muted dark:hover:bg-muted/80 w-full bg-black/5 hover:bg-black/10"
|
||||||
@ -403,26 +384,17 @@ export const DocumentSigningForm = ({
|
|||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<DocumentSigningCompleteDialog
|
<DocumentSigningCompleteDialog
|
||||||
isSubmitting={isSubmitting || isAssistantSubmitting}
|
isSubmitting={isSubmitting}
|
||||||
|
onSignatureComplete={handleSubmit(onFormSubmit)}
|
||||||
documentTitle={document.title}
|
documentTitle={document.title}
|
||||||
fields={fields}
|
fields={fields}
|
||||||
fieldsValidated={fieldsValidated}
|
fieldsValidated={fieldsValidated}
|
||||||
disabled={!isRecipientsTurn}
|
|
||||||
onSignatureComplete={async (nextSigner) => {
|
|
||||||
await completeDocument(undefined, nextSigner);
|
|
||||||
}}
|
|
||||||
role={recipient.role}
|
role={recipient.role}
|
||||||
allowDictateNextSigner={
|
disabled={!isRecipientsTurn}
|
||||||
nextRecipient && document.documentMeta?.allowDictateNextSigner
|
|
||||||
}
|
|
||||||
defaultNextSigner={
|
|
||||||
nextRecipient
|
|
||||||
? { name: nextRecipient.name, email: nextRecipient.email }
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</fieldset>
|
||||||
|
</form>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -40,9 +40,9 @@ import { DocumentReadOnlyFields } from '~/components/general/document/document-r
|
|||||||
|
|
||||||
import { DocumentSigningRecipientProvider } from './document-signing-recipient-provider';
|
import { DocumentSigningRecipientProvider } from './document-signing-recipient-provider';
|
||||||
|
|
||||||
export type DocumentSigningPageViewProps = {
|
export type SigningPageViewProps = {
|
||||||
recipient: RecipientWithFields;
|
|
||||||
document: DocumentAndSender;
|
document: DocumentAndSender;
|
||||||
|
recipient: RecipientWithFields;
|
||||||
fields: Field[];
|
fields: Field[];
|
||||||
completedFields: CompletedField[];
|
completedFields: CompletedField[];
|
||||||
isRecipientsTurn: boolean;
|
isRecipientsTurn: boolean;
|
||||||
@ -50,13 +50,13 @@ export type DocumentSigningPageViewProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const DocumentSigningPageView = ({
|
export const DocumentSigningPageView = ({
|
||||||
recipient,
|
|
||||||
document,
|
document,
|
||||||
|
recipient,
|
||||||
fields,
|
fields,
|
||||||
completedFields,
|
completedFields,
|
||||||
isRecipientsTurn,
|
isRecipientsTurn,
|
||||||
allRecipients = [],
|
allRecipients = [],
|
||||||
}: DocumentSigningPageViewProps) => {
|
}: SigningPageViewProps) => {
|
||||||
const { documentData, documentMeta } = document;
|
const { documentData, documentMeta } = document;
|
||||||
|
|
||||||
const [selectedSignerId, setSelectedSignerId] = useState<number | null>(allRecipients?.[0]?.id);
|
const [selectedSignerId, setSelectedSignerId] = useState<number | null>(allRecipients?.[0]?.id);
|
||||||
@ -157,7 +157,7 @@ export const DocumentSigningPageView = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DocumentReadOnlyFields documentMeta={documentMeta || undefined} fields={completedFields} />
|
<DocumentReadOnlyFields fields={completedFields} />
|
||||||
|
|
||||||
{recipient.role !== RecipientRole.ASSISTANT && (
|
{recipient.role !== RecipientRole.ASSISTANT && (
|
||||||
<DocumentSigningAutoSign recipient={recipient} fields={fields} />
|
<DocumentSigningAutoSign recipient={recipient} fields={fields} />
|
||||||
@ -177,8 +177,6 @@ export const DocumentSigningPageView = ({
|
|||||||
key={field.id}
|
key={field.id}
|
||||||
field={field}
|
field={field}
|
||||||
typedSignatureEnabled={documentMeta?.typedSignatureEnabled}
|
typedSignatureEnabled={documentMeta?.typedSignatureEnabled}
|
||||||
uploadSignatureEnabled={documentMeta?.uploadSignatureEnabled}
|
|
||||||
drawSignatureEnabled={documentMeta?.drawSignatureEnabled}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.with(FieldType.INITIALS, () => (
|
.with(FieldType.INITIALS, () => (
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
import { createContext, useContext, useState } from 'react';
|
import { createContext, useContext, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { isBase64Image } from '@documenso/lib/constants/signatures';
|
|
||||||
|
|
||||||
export type DocumentSigningContextValue = {
|
export type DocumentSigningContextValue = {
|
||||||
fullName: string;
|
fullName: string;
|
||||||
@ -9,6 +7,8 @@ export type DocumentSigningContextValue = {
|
|||||||
setEmail: (_value: string) => void;
|
setEmail: (_value: string) => void;
|
||||||
signature: string | null;
|
signature: string | null;
|
||||||
setSignature: (_value: string | null) => void;
|
setSignature: (_value: string | null) => void;
|
||||||
|
signatureValid: boolean;
|
||||||
|
setSignatureValid: (_valid: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DocumentSigningContext = createContext<DocumentSigningContextValue | null>(null);
|
const DocumentSigningContext = createContext<DocumentSigningContextValue | null>(null);
|
||||||
@ -31,9 +31,6 @@ export interface DocumentSigningProviderProps {
|
|||||||
fullName?: string | null;
|
fullName?: string | null;
|
||||||
email?: string | null;
|
email?: string | null;
|
||||||
signature?: string | null;
|
signature?: string | null;
|
||||||
typedSignatureEnabled?: boolean;
|
|
||||||
uploadSignatureEnabled?: boolean;
|
|
||||||
drawSignatureEnabled?: boolean;
|
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,31 +38,18 @@ export const DocumentSigningProvider = ({
|
|||||||
fullName: initialFullName,
|
fullName: initialFullName,
|
||||||
email: initialEmail,
|
email: initialEmail,
|
||||||
signature: initialSignature,
|
signature: initialSignature,
|
||||||
typedSignatureEnabled = true,
|
|
||||||
uploadSignatureEnabled = true,
|
|
||||||
drawSignatureEnabled = true,
|
|
||||||
children,
|
children,
|
||||||
}: DocumentSigningProviderProps) => {
|
}: DocumentSigningProviderProps) => {
|
||||||
const [fullName, setFullName] = useState(initialFullName || '');
|
const [fullName, setFullName] = useState(initialFullName || '');
|
||||||
const [email, setEmail] = useState(initialEmail || '');
|
const [email, setEmail] = useState(initialEmail || '');
|
||||||
|
const [signature, setSignature] = useState(initialSignature || null);
|
||||||
|
const [signatureValid, setSignatureValid] = useState(true);
|
||||||
|
|
||||||
// Ensure the user signature doesn't show up if it's not allowed.
|
useEffect(() => {
|
||||||
const [signature, setSignature] = useState(
|
if (initialSignature) {
|
||||||
(() => {
|
setSignature(initialSignature);
|
||||||
const sig = initialSignature || '';
|
|
||||||
const isBase64 = isBase64Image(sig);
|
|
||||||
|
|
||||||
if (isBase64 && (uploadSignatureEnabled || drawSignatureEnabled)) {
|
|
||||||
return sig;
|
|
||||||
}
|
}
|
||||||
|
}, [initialSignature]);
|
||||||
if (!isBase64 && typedSignatureEnabled) {
|
|
||||||
return sig;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
})(),
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DocumentSigningContext.Provider
|
<DocumentSigningContext.Provider
|
||||||
@ -76,6 +60,8 @@ export const DocumentSigningProvider = ({
|
|||||||
setEmail,
|
setEmail,
|
||||||
signature,
|
signature,
|
||||||
setSignature,
|
setSignature,
|
||||||
|
signatureValid,
|
||||||
|
setSignatureValid,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@ -38,6 +38,11 @@ export const DocumentSigningRecipientProvider = ({
|
|||||||
recipient,
|
recipient,
|
||||||
targetSigner = null,
|
targetSigner = null,
|
||||||
}: DocumentSigningRecipientProviderProps) => {
|
}: DocumentSigningRecipientProviderProps) => {
|
||||||
|
// console.log({
|
||||||
|
// recipient,
|
||||||
|
// targetSigner,
|
||||||
|
// isAssistantMode: !!targetSigner,
|
||||||
|
// });
|
||||||
return (
|
return (
|
||||||
<DocumentSigningRecipientContext.Provider
|
<DocumentSigningRecipientContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
|||||||
@ -31,7 +31,10 @@ import { Textarea } from '@documenso/ui/primitives/textarea';
|
|||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
const ZRejectDocumentFormSchema = z.object({
|
const ZRejectDocumentFormSchema = z.object({
|
||||||
reason: z.string().max(500, msg`Reason must be less than 500 characters`),
|
reason: z
|
||||||
|
.string()
|
||||||
|
.min(5, msg`Please provide a reason`)
|
||||||
|
.max(500, msg`Reason must be less than 500 characters`),
|
||||||
});
|
});
|
||||||
|
|
||||||
type TRejectDocumentFormSchema = z.infer<typeof ZRejectDocumentFormSchema>;
|
type TRejectDocumentFormSchema = z.infer<typeof ZRejectDocumentFormSchema>;
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import type {
|
|||||||
} from '@documenso/trpc/server/field-router/schema';
|
} from '@documenso/trpc/server/field-router/schema';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import { Dialog, DialogContent, DialogFooter, DialogTitle } from '@documenso/ui/primitives/dialog';
|
import { Dialog, DialogContent, DialogFooter, DialogTitle } from '@documenso/ui/primitives/dialog';
|
||||||
|
import { Label } from '@documenso/ui/primitives/label';
|
||||||
import { SignaturePad } from '@documenso/ui/primitives/signature-pad';
|
import { SignaturePad } from '@documenso/ui/primitives/signature-pad';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
@ -28,14 +29,11 @@ import { useRequiredDocumentSigningContext } from './document-signing-provider';
|
|||||||
import { useDocumentSigningRecipientContext } from './document-signing-recipient-provider';
|
import { useDocumentSigningRecipientContext } from './document-signing-recipient-provider';
|
||||||
|
|
||||||
type SignatureFieldState = 'empty' | 'signed-image' | 'signed-text';
|
type SignatureFieldState = 'empty' | 'signed-image' | 'signed-text';
|
||||||
|
|
||||||
export type DocumentSigningSignatureFieldProps = {
|
export type DocumentSigningSignatureFieldProps = {
|
||||||
field: FieldWithSignature;
|
field: FieldWithSignature;
|
||||||
onSignField?: (value: TSignFieldWithTokenMutationSchema) => Promise<void> | void;
|
onSignField?: (value: TSignFieldWithTokenMutationSchema) => Promise<void> | void;
|
||||||
onUnsignField?: (value: TRemovedSignedFieldWithTokenMutationSchema) => Promise<void> | void;
|
onUnsignField?: (value: TRemovedSignedFieldWithTokenMutationSchema) => Promise<void> | void;
|
||||||
typedSignatureEnabled?: boolean;
|
typedSignatureEnabled?: boolean;
|
||||||
uploadSignatureEnabled?: boolean;
|
|
||||||
drawSignatureEnabled?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DocumentSigningSignatureField = ({
|
export const DocumentSigningSignatureField = ({
|
||||||
@ -43,8 +41,6 @@ export const DocumentSigningSignatureField = ({
|
|||||||
onSignField,
|
onSignField,
|
||||||
onUnsignField,
|
onUnsignField,
|
||||||
typedSignatureEnabled,
|
typedSignatureEnabled,
|
||||||
uploadSignatureEnabled,
|
|
||||||
drawSignatureEnabled,
|
|
||||||
}: DocumentSigningSignatureFieldProps) => {
|
}: DocumentSigningSignatureFieldProps) => {
|
||||||
const { _ } = useLingui();
|
const { _ } = useLingui();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
@ -56,8 +52,12 @@ export const DocumentSigningSignatureField = ({
|
|||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const [fontSize, setFontSize] = useState(2);
|
const [fontSize, setFontSize] = useState(2);
|
||||||
|
|
||||||
const { signature: providedSignature, setSignature: setProvidedSignature } =
|
const {
|
||||||
useRequiredDocumentSigningContext();
|
signature: providedSignature,
|
||||||
|
setSignature: setProvidedSignature,
|
||||||
|
signatureValid,
|
||||||
|
setSignatureValid,
|
||||||
|
} = useRequiredDocumentSigningContext();
|
||||||
|
|
||||||
const { executeActionAuthProcedure } = useRequiredDocumentSigningAuthContext();
|
const { executeActionAuthProcedure } = useRequiredDocumentSigningAuthContext();
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ export const DocumentSigningSignatureField = ({
|
|||||||
}, [field.inserted, signature?.signatureImageAsBase64]);
|
}, [field.inserted, signature?.signatureImageAsBase64]);
|
||||||
|
|
||||||
const onPreSign = () => {
|
const onPreSign = () => {
|
||||||
if (!providedSignature) {
|
if (!providedSignature || !signatureValid) {
|
||||||
setShowSignatureModal(true);
|
setShowSignatureModal(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -102,7 +102,6 @@ export const DocumentSigningSignatureField = ({
|
|||||||
const onDialogSignClick = () => {
|
const onDialogSignClick = () => {
|
||||||
setShowSignatureModal(false);
|
setShowSignatureModal(false);
|
||||||
setProvidedSignature(localSignature);
|
setProvidedSignature(localSignature);
|
||||||
|
|
||||||
if (!localSignature) {
|
if (!localSignature) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -117,14 +116,14 @@ export const DocumentSigningSignatureField = ({
|
|||||||
try {
|
try {
|
||||||
const value = signature || providedSignature;
|
const value = signature || providedSignature;
|
||||||
|
|
||||||
if (!value) {
|
if (!value || (signature && !signatureValid)) {
|
||||||
setShowSignatureModal(true);
|
setShowSignatureModal(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isTypedSignature = !value.startsWith('data:image');
|
const isTypedSignature = !value.startsWith('data:image');
|
||||||
|
|
||||||
if (isTypedSignature && typedSignatureEnabled === false) {
|
if (isTypedSignature && !typedSignatureEnabled) {
|
||||||
toast({
|
toast({
|
||||||
title: _(msg`Error`),
|
title: _(msg`Error`),
|
||||||
description: _(msg`Typed signatures are not allowed. Please draw your signature.`),
|
description: _(msg`Typed signatures are not allowed. Please draw your signature.`),
|
||||||
@ -276,14 +275,29 @@ export const DocumentSigningSignatureField = ({
|
|||||||
</Trans>
|
</Trans>
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
|
|
||||||
|
<div className="">
|
||||||
|
<Label htmlFor="signature">
|
||||||
|
<Trans>Signature</Trans>
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<div className="border-border mt-2 rounded-md border">
|
||||||
<SignaturePad
|
<SignaturePad
|
||||||
className="mt-2"
|
id="signature"
|
||||||
value={localSignature ?? ''}
|
className="h-44 w-full"
|
||||||
onChange={({ value }) => setLocalSignature(value)}
|
onChange={(value) => setLocalSignature(value)}
|
||||||
typedSignatureEnabled={typedSignatureEnabled}
|
allowTypedSignature={typedSignatureEnabled}
|
||||||
uploadSignatureEnabled={uploadSignatureEnabled}
|
onValidityChange={(isValid) => {
|
||||||
drawSignatureEnabled={drawSignatureEnabled}
|
setSignatureValid(isValid);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!signatureValid && (
|
||||||
|
<div className="text-destructive mt-2 text-sm">
|
||||||
|
<Trans>Signature is too small. Please provide a more complete signature.</Trans>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
<DocumentSigningDisclosure />
|
<DocumentSigningDisclosure />
|
||||||
|
|
||||||
@ -303,7 +317,7 @@ export const DocumentSigningSignatureField = ({
|
|||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
className="flex-1"
|
className="flex-1"
|
||||||
disabled={!localSignature}
|
disabled={!localSignature || !signatureValid}
|
||||||
onClick={() => onDialogSignClick()}
|
onClick={() => onDialogSignClick()}
|
||||||
>
|
>
|
||||||
<Trans>Sign</Trans>
|
<Trans>Sign</Trans>
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { DocumentStatus } from '@prisma/client';
|
import { DocumentStatus } from '@prisma/client';
|
||||||
import { DownloadIcon } from 'lucide-react';
|
import { DownloadIcon } from 'lucide-react';
|
||||||
|
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
@ -77,7 +76,7 @@ export const DocumentCertificateDownloadButton = ({
|
|||||||
className={cn('w-full sm:w-auto', className)}
|
className={cn('w-full sm:w-auto', className)}
|
||||||
loading={isPending}
|
loading={isPending}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
disabled={!isDocumentCompleted(documentStatus)}
|
disabled={documentStatus !== DocumentStatus.COMPLETED}
|
||||||
onClick={() => void onDownloadCertificatesClick()}
|
onClick={() => void onDownloadCertificatesClick()}
|
||||||
>
|
>
|
||||||
{!isPending && <DownloadIcon className="mr-1.5 h-4 w-4" />}
|
{!isPending && <DownloadIcon className="mr-1.5 h-4 w-4" />}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import { useLingui } from '@lingui/react';
|
|||||||
import { DocumentDistributionMethod, DocumentStatus } from '@prisma/client';
|
import { DocumentDistributionMethod, DocumentStatus } from '@prisma/client';
|
||||||
import { useNavigate, useSearchParams } from 'react-router';
|
import { useNavigate, useSearchParams } from 'react-router';
|
||||||
|
|
||||||
import { DocumentSignatureType } from '@documenso/lib/constants/document';
|
|
||||||
import { isValidLanguageCode } from '@documenso/lib/constants/i18n';
|
import { isValidLanguageCode } from '@documenso/lib/constants/i18n';
|
||||||
import {
|
import {
|
||||||
DO_NOT_INVALIDATE_QUERY_ON_MUTATION,
|
DO_NOT_INVALIDATE_QUERY_ON_MUTATION,
|
||||||
@ -72,7 +71,7 @@ export const DocumentEditForm = ({
|
|||||||
|
|
||||||
const { recipients, fields } = document;
|
const { recipients, fields } = document;
|
||||||
|
|
||||||
const { mutateAsync: updateDocument } = trpc.document.updateDocument.useMutation({
|
const { mutateAsync: updateDocument } = trpc.document.setSettingsForDocument.useMutation({
|
||||||
...DO_NOT_INVALIDATE_QUERY_ON_MUTATION,
|
...DO_NOT_INVALIDATE_QUERY_ON_MUTATION,
|
||||||
onSuccess: (newData) => {
|
onSuccess: (newData) => {
|
||||||
utils.document.getDocumentWithDetailsById.setData(
|
utils.document.getDocumentWithDetailsById.setData(
|
||||||
@ -175,7 +174,7 @@ export const DocumentEditForm = ({
|
|||||||
|
|
||||||
const onAddSettingsFormSubmit = async (data: TAddSettingsFormSchema) => {
|
const onAddSettingsFormSubmit = async (data: TAddSettingsFormSchema) => {
|
||||||
try {
|
try {
|
||||||
const { timezone, dateFormat, redirectUrl, language, signatureTypes } = data.meta;
|
const { timezone, dateFormat, redirectUrl, language } = data.meta;
|
||||||
|
|
||||||
await updateDocument({
|
await updateDocument({
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
@ -191,9 +190,6 @@ export const DocumentEditForm = ({
|
|||||||
dateFormat,
|
dateFormat,
|
||||||
redirectUrl,
|
redirectUrl,
|
||||||
language: isValidLanguageCode(language) ? language : undefined,
|
language: isValidLanguageCode(language) ? language : undefined,
|
||||||
typedSignatureEnabled: signatureTypes.includes(DocumentSignatureType.TYPE),
|
|
||||||
uploadSignatureEnabled: signatureTypes.includes(DocumentSignatureType.UPLOAD),
|
|
||||||
drawSignatureEnabled: signatureTypes.includes(DocumentSignatureType.DRAW),
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -217,13 +213,6 @@ export const DocumentEditForm = ({
|
|||||||
signingOrder: data.signingOrder,
|
signingOrder: data.signingOrder,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
updateDocument({
|
|
||||||
documentId: document.id,
|
|
||||||
meta: {
|
|
||||||
allowDictateNextSigner: data.allowDictateNextSigner,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
|
|
||||||
setRecipients({
|
setRecipients({
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
recipients: data.signers.map((signer) => ({
|
recipients: data.signers.map((signer) => ({
|
||||||
@ -253,6 +242,14 @@ export const DocumentEditForm = ({
|
|||||||
fields: data.fields,
|
fields: data.fields,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await updateDocument({
|
||||||
|
documentId: document.id,
|
||||||
|
|
||||||
|
meta: {
|
||||||
|
typedSignatureEnabled: data.typedSignatureEnabled,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Clear all field data from localStorage
|
// Clear all field data from localStorage
|
||||||
for (let i = 0; i < localStorage.length; i++) {
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
const key = localStorage.key(i);
|
const key = localStorage.key(i);
|
||||||
@ -368,7 +365,6 @@ export const DocumentEditForm = ({
|
|||||||
documentFlow={documentFlow.signers}
|
documentFlow={documentFlow.signers}
|
||||||
recipients={recipients}
|
recipients={recipients}
|
||||||
signingOrder={document.documentMeta?.signingOrder}
|
signingOrder={document.documentMeta?.signingOrder}
|
||||||
allowDictateNextSigner={document.documentMeta?.allowDictateNextSigner}
|
|
||||||
fields={fields}
|
fields={fields}
|
||||||
isDocumentEnterprise={isDocumentEnterprise}
|
isDocumentEnterprise={isDocumentEnterprise}
|
||||||
onSubmit={onAddSignersFormSubmit}
|
onSubmit={onAddSignersFormSubmit}
|
||||||
@ -382,6 +378,7 @@ export const DocumentEditForm = ({
|
|||||||
fields={fields}
|
fields={fields}
|
||||||
onSubmit={onAddFieldsFormSubmit}
|
onSubmit={onAddFieldsFormSubmit}
|
||||||
isDocumentPdfLoaded={isDocumentPdfLoaded}
|
isDocumentPdfLoaded={isDocumentPdfLoaded}
|
||||||
|
typedSignatureEnabled={document.documentMeta?.typedSignatureEnabled}
|
||||||
teamId={team?.id}
|
teamId={team?.id}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@ -170,7 +170,6 @@ export const DocumentHistorySheet = ({
|
|||||||
{ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_REJECTED },
|
{ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_REJECTED },
|
||||||
{ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_SENT },
|
{ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_SENT },
|
||||||
{ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_MOVED_TO_TEAM },
|
{ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_MOVED_TO_TEAM },
|
||||||
{ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RESTORED },
|
|
||||||
() => null,
|
() => null,
|
||||||
)
|
)
|
||||||
.with(
|
.with(
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import { match } from 'ts-pattern';
|
|||||||
|
|
||||||
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc as trpcClient } from '@documenso/trpc/client';
|
import { trpc as trpcClient } from '@documenso/trpc/client';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
@ -33,7 +32,7 @@ export const DocumentPageViewButton = ({ document }: DocumentPageViewButtonProps
|
|||||||
|
|
||||||
const isRecipient = !!recipient;
|
const isRecipient = !!recipient;
|
||||||
const isPending = document.status === DocumentStatus.PENDING;
|
const isPending = document.status === DocumentStatus.PENDING;
|
||||||
const isComplete = isDocumentCompleted(document);
|
const isComplete = document.status === DocumentStatus.COMPLETED;
|
||||||
const isSigned = recipient?.signingStatus === SigningStatus.SIGNED;
|
const isSigned = recipient?.signingStatus === SigningStatus.SIGNED;
|
||||||
const role = recipient?.role;
|
const role = recipient?.role;
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,6 @@ import { useNavigate } from 'react-router';
|
|||||||
|
|
||||||
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc as trpcClient } from '@documenso/trpc/client';
|
import { trpc as trpcClient } from '@documenso/trpc/client';
|
||||||
import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';
|
import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';
|
||||||
@ -64,7 +63,7 @@ export const DocumentPageViewDropdown = ({ document }: DocumentPageViewDropdownP
|
|||||||
const isDraft = document.status === DocumentStatus.DRAFT;
|
const isDraft = document.status === DocumentStatus.DRAFT;
|
||||||
const isPending = document.status === DocumentStatus.PENDING;
|
const isPending = document.status === DocumentStatus.PENDING;
|
||||||
const isDeleted = document.deletedAt !== null;
|
const isDeleted = document.deletedAt !== null;
|
||||||
const isComplete = isDocumentCompleted(document);
|
const isComplete = document.status === DocumentStatus.COMPLETED;
|
||||||
const isCurrentTeamDocument = team && document.team?.url === team.url;
|
const isCurrentTeamDocument = team && document.team?.url === team.url;
|
||||||
const canManageDocument = Boolean(isOwner || isCurrentTeamDocument);
|
const canManageDocument = Boolean(isOwner || isCurrentTeamDocument);
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,7 @@ export const DocumentPageViewInformation = ({
|
|||||||
const { _, i18n } = useLingui();
|
const { _, i18n } = useLingui();
|
||||||
|
|
||||||
const documentInformation = useMemo(() => {
|
const documentInformation = useMemo(() => {
|
||||||
const documentInfo = [
|
return [
|
||||||
{
|
{
|
||||||
description: msg`Uploaded by`,
|
description: msg`Uploaded by`,
|
||||||
value:
|
value:
|
||||||
@ -44,19 +44,6 @@ export const DocumentPageViewInformation = ({
|
|||||||
.toRelative(),
|
.toRelative(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (document.deletedAt) {
|
|
||||||
documentInfo.push({
|
|
||||||
description: msg`Deleted`,
|
|
||||||
value:
|
|
||||||
document.deletedAt &&
|
|
||||||
DateTime.fromJSDate(document.deletedAt)
|
|
||||||
.setLocale(i18n.locales?.[0] || i18n.locale)
|
|
||||||
.toFormat('MMMM d, yyyy'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return documentInfo;
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [isMounted, document, userId]);
|
}, [isMounted, document, userId]);
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,6 @@ import { Link } from 'react-router';
|
|||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
|
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
|
||||||
import { formatSigningLink } from '@documenso/lib/utils/recipients';
|
import { formatSigningLink } from '@documenso/lib/utils/recipients';
|
||||||
import { CopyTextButton } from '@documenso/ui/components/common/copy-text-button';
|
import { CopyTextButton } from '@documenso/ui/components/common/copy-text-button';
|
||||||
import { SignatureIcon } from '@documenso/ui/icons/signature';
|
import { SignatureIcon } from '@documenso/ui/icons/signature';
|
||||||
@ -49,7 +48,7 @@ export const DocumentPageViewRecipients = ({
|
|||||||
<Trans>Recipients</Trans>
|
<Trans>Recipients</Trans>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
{!isDocumentCompleted(document.status) && (
|
{document.status !== DocumentStatus.COMPLETED && (
|
||||||
<Link
|
<Link
|
||||||
to={`${documentRootPath}/${document.id}/edit?step=signers`}
|
to={`${documentRootPath}/${document.id}/edit?step=signers`}
|
||||||
title={_(msg`Modify recipients`)}
|
title={_(msg`Modify recipients`)}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { useState } from 'react';
|
|||||||
|
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { DocumentMeta, TemplateMeta } from '@prisma/client';
|
import type { DocumentMeta } from '@prisma/client';
|
||||||
import { FieldType, SigningStatus } from '@prisma/client';
|
import { FieldType, SigningStatus } from '@prisma/client';
|
||||||
import { Clock, EyeOffIcon } from 'lucide-react';
|
import { Clock, EyeOffIcon } from 'lucide-react';
|
||||||
import { P, match } from 'ts-pattern';
|
import { P, match } from 'ts-pattern';
|
||||||
@ -27,7 +27,7 @@ import { PopoverHover } from '@documenso/ui/primitives/popover';
|
|||||||
|
|
||||||
export type DocumentReadOnlyFieldsProps = {
|
export type DocumentReadOnlyFieldsProps = {
|
||||||
fields: DocumentField[];
|
fields: DocumentField[];
|
||||||
documentMeta?: DocumentMeta | TemplateMeta;
|
documentMeta?: DocumentMeta;
|
||||||
showFieldStatus?: boolean;
|
showFieldStatus?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import type { HTMLAttributes } from 'react';
|
|||||||
import type { MessageDescriptor } from '@lingui/core';
|
import type { MessageDescriptor } from '@lingui/core';
|
||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { CheckCircle2, Clock, File, Trash, XCircle } from 'lucide-react';
|
import { CheckCircle2, Clock, File } from 'lucide-react';
|
||||||
import type { LucideIcon } from 'lucide-react/dist/lucide-react';
|
import type { LucideIcon } from 'lucide-react/dist/lucide-react';
|
||||||
|
|
||||||
import type { ExtendedDocumentStatus } from '@documenso/prisma/types/extended-document-status';
|
import type { ExtendedDocumentStatus } from '@documenso/prisma/types/extended-document-status';
|
||||||
@ -36,12 +36,6 @@ export const FRIENDLY_STATUS_MAP: Record<ExtendedDocumentStatus, FriendlyStatus>
|
|||||||
icon: File,
|
icon: File,
|
||||||
color: 'text-yellow-500 dark:text-yellow-200',
|
color: 'text-yellow-500 dark:text-yellow-200',
|
||||||
},
|
},
|
||||||
DELETED: {
|
|
||||||
label: msg`Deleted`,
|
|
||||||
labelExtended: msg`Document deleted`,
|
|
||||||
icon: Trash,
|
|
||||||
color: 'text-red-700 dark:text-red-500',
|
|
||||||
},
|
|
||||||
INBOX: {
|
INBOX: {
|
||||||
label: msg`Inbox`,
|
label: msg`Inbox`,
|
||||||
labelExtended: msg`Document inbox`,
|
labelExtended: msg`Document inbox`,
|
||||||
@ -53,12 +47,6 @@ export const FRIENDLY_STATUS_MAP: Record<ExtendedDocumentStatus, FriendlyStatus>
|
|||||||
labelExtended: msg`Document All`,
|
labelExtended: msg`Document All`,
|
||||||
color: 'text-muted-foreground',
|
color: 'text-muted-foreground',
|
||||||
},
|
},
|
||||||
REJECTED: {
|
|
||||||
label: msg`Rejected`,
|
|
||||||
labelExtended: msg`Document rejected`,
|
|
||||||
icon: XCircle,
|
|
||||||
color: 'text-red-500 dark:text-red-300',
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DocumentStatusProps = HTMLAttributes<HTMLSpanElement> & {
|
export type DocumentStatusProps = HTMLAttributes<HTMLSpanElement> & {
|
||||||
|
|||||||
@ -62,7 +62,7 @@ export const GenericErrorLayout = ({
|
|||||||
const team = useOptionalCurrentTeam();
|
const team = useOptionalCurrentTeam();
|
||||||
|
|
||||||
const { subHeading, heading, message } =
|
const { subHeading, heading, message } =
|
||||||
errorCodeMap[errorCode || 500] ?? defaultErrorCodeMap[500];
|
errorCodeMap[errorCode || 404] ?? defaultErrorCodeMap[500];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-0 flex h-screen w-screen items-center justify-center">
|
<div className="fixed inset-0 z-0 flex h-screen w-screen items-center justify-center">
|
||||||
|
|||||||
@ -2,9 +2,6 @@ import { useCallback, useEffect } from 'react';
|
|||||||
|
|
||||||
import { useRevalidator } from 'react-router';
|
import { useRevalidator } from 'react-router';
|
||||||
|
|
||||||
/**
|
|
||||||
* Not really used anymore, this causes random 500s when the user refreshes while this occurs.
|
|
||||||
*/
|
|
||||||
export const RefreshOnFocus = () => {
|
export const RefreshOnFocus = () => {
|
||||||
const { revalidate, state } = useRevalidator();
|
const { revalidate, state } = useRevalidator();
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import { msg } from '@lingui/core/macro';
|
|||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { useNavigate } from 'react-router';
|
import { useNavigate } from 'react-router';
|
||||||
|
|
||||||
import { DocumentSignatureType } from '@documenso/lib/constants/document';
|
|
||||||
import { isValidLanguageCode } from '@documenso/lib/constants/i18n';
|
import { isValidLanguageCode } from '@documenso/lib/constants/i18n';
|
||||||
import {
|
import {
|
||||||
DO_NOT_INVALIDATE_QUERY_ON_MUTATION,
|
DO_NOT_INVALIDATE_QUERY_ON_MUTATION,
|
||||||
@ -125,8 +124,6 @@ export const TemplateEditForm = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const onAddSettingsFormSubmit = async (data: TAddTemplateSettingsFormSchema) => {
|
const onAddSettingsFormSubmit = async (data: TAddTemplateSettingsFormSchema) => {
|
||||||
const { signatureTypes } = data.meta;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await updateTemplateSettings({
|
await updateTemplateSettings({
|
||||||
templateId: template.id,
|
templateId: template.id,
|
||||||
@ -139,9 +136,6 @@ export const TemplateEditForm = ({
|
|||||||
},
|
},
|
||||||
meta: {
|
meta: {
|
||||||
...data.meta,
|
...data.meta,
|
||||||
typedSignatureEnabled: signatureTypes.includes(DocumentSignatureType.TYPE),
|
|
||||||
uploadSignatureEnabled: signatureTypes.includes(DocumentSignatureType.UPLOAD),
|
|
||||||
drawSignatureEnabled: signatureTypes.includes(DocumentSignatureType.DRAW),
|
|
||||||
language: isValidLanguageCode(data.meta.language) ? data.meta.language : undefined,
|
language: isValidLanguageCode(data.meta.language) ? data.meta.language : undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -167,7 +161,6 @@ export const TemplateEditForm = ({
|
|||||||
templateId: template.id,
|
templateId: template.id,
|
||||||
meta: {
|
meta: {
|
||||||
signingOrder: data.signingOrder,
|
signingOrder: data.signingOrder,
|
||||||
allowDictateNextSigner: data.allowDictateNextSigner,
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -194,6 +187,13 @@ export const TemplateEditForm = ({
|
|||||||
fields: data.fields,
|
fields: data.fields,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await updateTemplateSettings({
|
||||||
|
templateId: template.id,
|
||||||
|
meta: {
|
||||||
|
typedSignatureEnabled: data.typedSignatureEnabled,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Clear all field data from localStorage
|
// Clear all field data from localStorage
|
||||||
for (let i = 0; i < localStorage.length; i++) {
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
const key = localStorage.key(i);
|
const key = localStorage.key(i);
|
||||||
@ -271,7 +271,6 @@ export const TemplateEditForm = ({
|
|||||||
recipients={recipients}
|
recipients={recipients}
|
||||||
fields={fields}
|
fields={fields}
|
||||||
signingOrder={template.templateMeta?.signingOrder}
|
signingOrder={template.templateMeta?.signingOrder}
|
||||||
allowDictateNextSigner={template.templateMeta?.allowDictateNextSigner}
|
|
||||||
templateDirectLink={template.directLink}
|
templateDirectLink={template.directLink}
|
||||||
onSubmit={onAddTemplatePlaceholderFormSubmit}
|
onSubmit={onAddTemplatePlaceholderFormSubmit}
|
||||||
isEnterprise={isEnterprise}
|
isEnterprise={isEnterprise}
|
||||||
@ -285,6 +284,7 @@ export const TemplateEditForm = ({
|
|||||||
fields={fields}
|
fields={fields}
|
||||||
onSubmit={onAddFieldsFormSubmit}
|
onSubmit={onAddFieldsFormSubmit}
|
||||||
teamId={team?.id}
|
teamId={team?.id}
|
||||||
|
typedSignatureEnabled={template.templateMeta?.typedSignatureEnabled}
|
||||||
/>
|
/>
|
||||||
</Stepper>
|
</Stepper>
|
||||||
</DocumentFlowFormContainer>
|
</DocumentFlowFormContainer>
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import { match } from 'ts-pattern';
|
|||||||
|
|
||||||
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc as trpcClient } from '@documenso/trpc/client';
|
import { trpc as trpcClient } from '@documenso/trpc/client';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
@ -38,7 +37,7 @@ export const DocumentsTableActionButton = ({ row }: DocumentsTableActionButtonPr
|
|||||||
const isRecipient = !!recipient;
|
const isRecipient = !!recipient;
|
||||||
const isDraft = row.status === DocumentStatus.DRAFT;
|
const isDraft = row.status === DocumentStatus.DRAFT;
|
||||||
const isPending = row.status === DocumentStatus.PENDING;
|
const isPending = row.status === DocumentStatus.PENDING;
|
||||||
const isComplete = isDocumentCompleted(row.status);
|
const isComplete = row.status === DocumentStatus.COMPLETED;
|
||||||
const isSigned = recipient?.signingStatus === SigningStatus.SIGNED;
|
const isSigned = recipient?.signingStatus === SigningStatus.SIGNED;
|
||||||
const role = recipient?.role;
|
const role = recipient?.role;
|
||||||
const isCurrentTeamDocument = team && row.team?.url === team.url;
|
const isCurrentTeamDocument = team && row.team?.url === team.url;
|
||||||
|
|||||||
@ -15,7 +15,6 @@ import {
|
|||||||
MoreHorizontal,
|
MoreHorizontal,
|
||||||
MoveRight,
|
MoveRight,
|
||||||
Pencil,
|
Pencil,
|
||||||
RotateCcw,
|
|
||||||
Share,
|
Share,
|
||||||
Trash2,
|
Trash2,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
@ -23,7 +22,6 @@ import { Link } from 'react-router';
|
|||||||
|
|
||||||
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc as trpcClient } from '@documenso/trpc/client';
|
import { trpc as trpcClient } from '@documenso/trpc/client';
|
||||||
import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';
|
import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';
|
||||||
@ -40,7 +38,6 @@ import { DocumentDeleteDialog } from '~/components/dialogs/document-delete-dialo
|
|||||||
import { DocumentDuplicateDialog } from '~/components/dialogs/document-duplicate-dialog';
|
import { DocumentDuplicateDialog } from '~/components/dialogs/document-duplicate-dialog';
|
||||||
import { DocumentMoveDialog } from '~/components/dialogs/document-move-dialog';
|
import { DocumentMoveDialog } from '~/components/dialogs/document-move-dialog';
|
||||||
import { DocumentResendDialog } from '~/components/dialogs/document-resend-dialog';
|
import { DocumentResendDialog } from '~/components/dialogs/document-resend-dialog';
|
||||||
import { DocumentRestoreDialog } from '~/components/dialogs/document-restore-dialog';
|
|
||||||
import { DocumentRecipientLinkCopyDialog } from '~/components/general/document/document-recipient-link-copy-dialog';
|
import { DocumentRecipientLinkCopyDialog } from '~/components/general/document/document-recipient-link-copy-dialog';
|
||||||
import { useOptionalCurrentTeam } from '~/providers/team';
|
import { useOptionalCurrentTeam } from '~/providers/team';
|
||||||
|
|
||||||
@ -60,20 +57,18 @@ export const DocumentsTableActionDropdown = ({ row }: DocumentsTableActionDropdo
|
|||||||
const { _ } = useLingui();
|
const { _ } = useLingui();
|
||||||
|
|
||||||
const [isDeleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
const [isDeleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||||
const [isRestoreDialogOpen, setRestoreDialogOpen] = useState(false);
|
|
||||||
const [isDuplicateDialogOpen, setDuplicateDialogOpen] = useState(false);
|
const [isDuplicateDialogOpen, setDuplicateDialogOpen] = useState(false);
|
||||||
const [isMoveDialogOpen, setMoveDialogOpen] = useState(false);
|
const [isMoveDialogOpen, setMoveDialogOpen] = useState(false);
|
||||||
|
|
||||||
const recipient = row.recipients.find((recipient) => recipient.email === user.email);
|
const recipient = row.recipients.find((recipient) => recipient.email === user.email);
|
||||||
|
|
||||||
const isOwner = row.user.id === user.id;
|
const isOwner = row.user.id === user.id;
|
||||||
const isRecipient = !!recipient;
|
// const isRecipient = !!recipient;
|
||||||
const isDraft = row.status === DocumentStatus.DRAFT;
|
const isDraft = row.status === DocumentStatus.DRAFT;
|
||||||
const isPending = row.status === DocumentStatus.PENDING;
|
const isPending = row.status === DocumentStatus.PENDING;
|
||||||
const isComplete = isDocumentCompleted(row.status);
|
const isComplete = row.status === DocumentStatus.COMPLETED;
|
||||||
// const isSigned = recipient?.signingStatus === SigningStatus.SIGNED;
|
// const isSigned = recipient?.signingStatus === SigningStatus.SIGNED;
|
||||||
const isCurrentTeamDocument = team && row.team?.url === team.url;
|
const isCurrentTeamDocument = team && row.team?.url === team.url;
|
||||||
const isDocumentDeleted = row.deletedAt !== null;
|
|
||||||
const canManageDocument = Boolean(isOwner || isCurrentTeamDocument);
|
const canManageDocument = Boolean(isOwner || isCurrentTeamDocument);
|
||||||
|
|
||||||
const documentsPath = formatDocumentsPath(team?.url);
|
const documentsPath = formatDocumentsPath(team?.url);
|
||||||
@ -175,17 +170,10 @@ export const DocumentsTableActionDropdown = ({ row }: DocumentsTableActionDropdo
|
|||||||
Void
|
Void
|
||||||
</DropdownMenuItem> */}
|
</DropdownMenuItem> */}
|
||||||
|
|
||||||
{isDocumentDeleted || (isRecipient && !canManageDocument) ? (
|
|
||||||
<DropdownMenuItem disabled={isRecipient} onClick={() => setRestoreDialogOpen(true)}>
|
|
||||||
<RotateCcw className="mr-2 h-4 w-4" />
|
|
||||||
<Trans>Restore</Trans>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
) : (
|
|
||||||
<DropdownMenuItem onClick={() => setDeleteDialogOpen(true)}>
|
<DropdownMenuItem onClick={() => setDeleteDialogOpen(true)}>
|
||||||
<Trash2 className="mr-2 h-4 w-4" />
|
<Trash2 className="mr-2 h-4 w-4" />
|
||||||
{canManageDocument ? _(msg`Delete`) : _(msg`Hide`)}
|
{canManageDocument ? _(msg`Delete`) : _(msg`Hide`)}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
)}
|
|
||||||
|
|
||||||
<DropdownMenuLabel>
|
<DropdownMenuLabel>
|
||||||
<Trans>Share</Trans>
|
<Trans>Share</Trans>
|
||||||
@ -231,15 +219,6 @@ export const DocumentsTableActionDropdown = ({ row }: DocumentsTableActionDropdo
|
|||||||
canManageDocument={canManageDocument}
|
canManageDocument={canManageDocument}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<DocumentRestoreDialog
|
|
||||||
id={row.id}
|
|
||||||
open={isRestoreDialogOpen}
|
|
||||||
onOpenChange={setRestoreDialogOpen}
|
|
||||||
documentTitle={row.title}
|
|
||||||
teamId={team?.id}
|
|
||||||
canManageDocument={canManageDocument}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<DocumentMoveDialog
|
<DocumentMoveDialog
|
||||||
documentId={row.id}
|
documentId={row.id}
|
||||||
open={isMoveDialogOpen}
|
open={isMoveDialogOpen}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Bird, CheckCircle2, Trash } from 'lucide-react';
|
import { Bird, CheckCircle2 } from 'lucide-react';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
import { ExtendedDocumentStatus } from '@documenso/prisma/types/extended-document-status';
|
import { ExtendedDocumentStatus } from '@documenso/prisma/types/extended-document-status';
|
||||||
@ -30,11 +30,6 @@ export const DocumentsTableEmptyState = ({ status }: DocumentsTableEmptyStatePro
|
|||||||
message: msg`You have not yet created or received any documents. To create a document please upload one.`,
|
message: msg`You have not yet created or received any documents. To create a document please upload one.`,
|
||||||
icon: Bird,
|
icon: Bird,
|
||||||
}))
|
}))
|
||||||
.with(ExtendedDocumentStatus.DELETED, () => ({
|
|
||||||
title: msg`Nothing in the trash`,
|
|
||||||
message: msg`There are no documents in the trash.`,
|
|
||||||
icon: Trash,
|
|
||||||
}))
|
|
||||||
.otherwise(() => ({
|
.otherwise(() => ({
|
||||||
title: msg`Nothing to do`,
|
title: msg`Nothing to do`,
|
||||||
message: msg`All documents have been processed. Any new documents that are sent or received will show here.`,
|
message: msg`All documents have been processed. Any new documents that are sent or received will show here.`,
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import { match } from 'ts-pattern';
|
|||||||
import { useUpdateSearchParams } from '@documenso/lib/client-only/hooks/use-update-search-params';
|
import { useUpdateSearchParams } from '@documenso/lib/client-only/hooks/use-update-search-params';
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
|
import { ExtendedDocumentStatus } from '@documenso/prisma/types/extended-document-status';
|
||||||
import type { TFindDocumentsResponse } from '@documenso/trpc/server/document-router/schema';
|
import type { TFindDocumentsResponse } from '@documenso/trpc/server/document-router/schema';
|
||||||
import type { DataTableColumnDef } from '@documenso/ui/primitives/data-table';
|
import type { DataTableColumnDef } from '@documenso/ui/primitives/data-table';
|
||||||
import { DataTable } from '@documenso/ui/primitives/data-table';
|
import { DataTable } from '@documenso/ui/primitives/data-table';
|
||||||
@ -75,7 +76,8 @@ export const DocumentsTable = ({ data, isLoading, isLoadingError }: DocumentsTab
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: _(msg`Actions`),
|
header: _(msg`Actions`),
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) =>
|
||||||
|
(!row.original.deletedAt || row.original.status === ExtendedDocumentStatus.COMPLETED) && (
|
||||||
<div className="flex items-center gap-x-4">
|
<div className="flex items-center gap-x-4">
|
||||||
<DocumentsTableActionButton row={row.original} />
|
<DocumentsTableActionButton row={row.original} />
|
||||||
<DocumentsTableActionDropdown row={row.original} />
|
<DocumentsTableActionDropdown row={row.original} />
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
import Plausible from 'plausible-tracker';
|
import Plausible from 'plausible-tracker';
|
||||||
|
import posthog from 'posthog-js';
|
||||||
import {
|
import {
|
||||||
Links,
|
Links,
|
||||||
Meta,
|
Meta,
|
||||||
@ -27,6 +28,7 @@ import { TooltipProvider } from '@documenso/ui/primitives/tooltip';
|
|||||||
import type { Route } from './+types/root';
|
import type { Route } from './+types/root';
|
||||||
import stylesheet from './app.css?url';
|
import stylesheet from './app.css?url';
|
||||||
import { GenericErrorLayout } from './components/general/generic-error-layout';
|
import { GenericErrorLayout } from './components/general/generic-error-layout';
|
||||||
|
import { RefreshOnFocus } from './components/general/refresh-on-focus';
|
||||||
import { langCookie } from './storage/lang-cookie.server';
|
import { langCookie } from './storage/lang-cookie.server';
|
||||||
import { themeSessionResolver } from './storage/theme-session.server';
|
import { themeSessionResolver } from './storage/theme-session.server';
|
||||||
import { appMetaTags } from './utils/meta';
|
import { appMetaTags } from './utils/meta';
|
||||||
@ -158,6 +160,8 @@ export function LayoutContent({ children }: { children: React.ReactNode }) {
|
|||||||
<ScrollRestoration />
|
<ScrollRestoration />
|
||||||
<Scripts />
|
<Scripts />
|
||||||
|
|
||||||
|
<RefreshOnFocus />
|
||||||
|
|
||||||
<script
|
<script
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: `window.__ENV__ = ${JSON.stringify(publicEnv)}`,
|
__html: `window.__ENV__ = ${JSON.stringify(publicEnv)}`,
|
||||||
@ -177,6 +181,7 @@ export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
|||||||
|
|
||||||
if (errorCode !== 404) {
|
if (errorCode !== 404) {
|
||||||
console.error('[RootErrorBoundary]', error);
|
console.error('[RootErrorBoundary]', error);
|
||||||
|
posthog.captureException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <GenericErrorLayout errorCode={errorCode} />;
|
return <GenericErrorLayout errorCode={errorCode} />;
|
||||||
|
|||||||
@ -103,9 +103,7 @@ export default function AdminDocumentDetailsPage({ loaderData }: Route.Component
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
loading={isResealDocumentLoading}
|
loading={isResealDocumentLoading}
|
||||||
disabled={document.recipients.some(
|
disabled={document.recipients.some(
|
||||||
(recipient) =>
|
(recipient) => recipient.signingStatus !== SigningStatus.SIGNED,
|
||||||
recipient.signingStatus !== SigningStatus.SIGNED &&
|
|
||||||
recipient.signingStatus !== SigningStatus.REJECTED,
|
|
||||||
)}
|
)}
|
||||||
onClick={() => resealDocument({ id: document.id })}
|
onClick={() => resealDocument({ id: document.id })}
|
||||||
>
|
>
|
||||||
|
|||||||
@ -23,12 +23,12 @@ import {
|
|||||||
getUsersWithSubscriptionsCount,
|
getUsersWithSubscriptionsCount,
|
||||||
} from '@documenso/lib/server-only/admin/get-users-stats';
|
} from '@documenso/lib/server-only/admin/get-users-stats';
|
||||||
import { getSignerConversionMonthly } from '@documenso/lib/server-only/user/get-signer-conversion';
|
import { getSignerConversionMonthly } from '@documenso/lib/server-only/user/get-signer-conversion';
|
||||||
|
import { env } from '@documenso/lib/utils/env';
|
||||||
|
|
||||||
import { AdminStatsSignerConversionChart } from '~/components/general/admin-stats-signer-conversion-chart';
|
import { AdminStatsSignerConversionChart } from '~/components/general/admin-stats-signer-conversion-chart';
|
||||||
import { AdminStatsUsersWithDocumentsChart } from '~/components/general/admin-stats-users-with-documents';
|
import { AdminStatsUsersWithDocumentsChart } from '~/components/general/admin-stats-users-with-documents';
|
||||||
import { CardMetric } from '~/components/general/metric-card';
|
import { CardMetric } from '~/components/general/metric-card';
|
||||||
|
|
||||||
import { version } from '../../../../package.json';
|
|
||||||
import type { Route } from './+types/stats';
|
import type { Route } from './+types/stats';
|
||||||
|
|
||||||
export async function loader() {
|
export async function loader() {
|
||||||
@ -89,7 +89,7 @@ export default function AdminStatsPage({ loaderData }: Route.ComponentProps) {
|
|||||||
value={usersWithSubscriptionsCount}
|
value={usersWithSubscriptionsCount}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<CardMetric icon={FileCog} title={_(msg`App Version`)} value={`v${version}`} />
|
<CardMetric icon={FileCog} title={_(msg`App Version`)} value={`v${env('APP_VERSION')}`} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-16 gap-8">
|
<div className="mt-16 gap-8">
|
||||||
|
|||||||
@ -220,9 +220,6 @@ export default function DocumentPage() {
|
|||||||
.with(DocumentStatus.COMPLETED, () => (
|
.with(DocumentStatus.COMPLETED, () => (
|
||||||
<Trans>This document has been signed by all recipients</Trans>
|
<Trans>This document has been signed by all recipients</Trans>
|
||||||
))
|
))
|
||||||
.with(DocumentStatus.REJECTED, () => (
|
|
||||||
<Trans>This document has been rejected by a recipient</Trans>
|
|
||||||
))
|
|
||||||
.with(DocumentStatus.DRAFT, () => (
|
.with(DocumentStatus.DRAFT, () => (
|
||||||
<Trans>This document is currently a draft and has not been sent</Trans>
|
<Trans>This document is currently a draft and has not been sent</Trans>
|
||||||
))
|
))
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Plural, Trans } from '@lingui/react/macro';
|
import { Plural, Trans } from '@lingui/react/macro';
|
||||||
import { TeamMemberRole } from '@prisma/client';
|
import { DocumentStatus as InternalDocumentStatus, TeamMemberRole } from '@prisma/client';
|
||||||
import { ChevronLeft, Users2 } from 'lucide-react';
|
import { ChevronLeft, Users2 } from 'lucide-react';
|
||||||
import { Link, redirect } from 'react-router';
|
import { Link, redirect } from 'react-router';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
@ -9,7 +9,6 @@ import { isUserEnterprise } from '@documenso/ee/server-only/util/is-document-ent
|
|||||||
import { getDocumentWithDetailsById } from '@documenso/lib/server-only/document/get-document-with-details-by-id';
|
import { getDocumentWithDetailsById } from '@documenso/lib/server-only/document/get-document-with-details-by-id';
|
||||||
import { type TGetTeamByUrlResponse, getTeamByUrl } from '@documenso/lib/server-only/team/get-team';
|
import { type TGetTeamByUrlResponse, getTeamByUrl } from '@documenso/lib/server-only/team/get-team';
|
||||||
import { DocumentVisibility } from '@documenso/lib/types/document-visibility';
|
import { DocumentVisibility } from '@documenso/lib/types/document-visibility';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
|
|
||||||
import { DocumentEditForm } from '~/components/general/document/document-edit-form';
|
import { DocumentEditForm } from '~/components/general/document/document-edit-form';
|
||||||
@ -72,7 +71,7 @@ export async function loader({ params, request }: Route.LoaderArgs) {
|
|||||||
throw redirect(documentRootPath);
|
throw redirect(documentRootPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDocumentCompleted(document.status)) {
|
if (document.status === InternalDocumentStatus.COMPLETED) {
|
||||||
throw redirect(`${documentRootPath}/${documentId}`);
|
throw redirect(`${documentRootPath}/${documentId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -129,7 +129,7 @@ export default function DocumentsLogsPage({ loaderData }: Route.ComponentProps)
|
|||||||
<Trans>Document</Trans>
|
<Trans>Document</Trans>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col justify-between truncate sm:flex-row">
|
||||||
<div>
|
<div>
|
||||||
<h1
|
<h1
|
||||||
className="mt-4 block max-w-[20rem] truncate text-2xl font-semibold md:max-w-[30rem] md:text-3xl"
|
className="mt-4 block max-w-[20rem] truncate text-2xl font-semibold md:max-w-[30rem] md:text-3xl"
|
||||||
@ -137,8 +137,7 @@ export default function DocumentsLogsPage({ loaderData }: Route.ComponentProps)
|
|||||||
>
|
>
|
||||||
{document.title}
|
{document.title}
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
|
||||||
<div className="mt-1 flex flex-col justify-between sm:flex-row">
|
|
||||||
<div className="mt-2.5 flex items-center gap-x-6">
|
<div className="mt-2.5 flex items-center gap-x-6">
|
||||||
<DocumentStatusComponent
|
<DocumentStatusComponent
|
||||||
inheritColor
|
inheritColor
|
||||||
@ -146,6 +145,8 @@ export default function DocumentsLogsPage({ loaderData }: Route.ComponentProps)
|
|||||||
className="text-muted-foreground"
|
className="text-muted-foreground"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="mt-4 flex w-full flex-row sm:mt-0 sm:w-auto sm:self-end">
|
<div className="mt-4 flex w-full flex-row sm:mt-0 sm:w-auto sm:self-end">
|
||||||
<DocumentCertificateDownloadButton
|
<DocumentCertificateDownloadButton
|
||||||
className="mr-2"
|
className="mr-2"
|
||||||
@ -156,14 +157,13 @@ export default function DocumentsLogsPage({ loaderData }: Route.ComponentProps)
|
|||||||
<DocumentAuditLogDownloadButton documentId={document.id} />
|
<DocumentAuditLogDownloadButton documentId={document.id} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<section className="mt-6">
|
<section className="mt-6">
|
||||||
<Card className="grid grid-cols-1 gap-4 p-4 sm:grid-cols-2" degrees={45} gradient>
|
<Card className="grid grid-cols-1 gap-4 p-4 sm:grid-cols-2" degrees={45} gradient>
|
||||||
{documentInformation.map((info, i) => (
|
{documentInformation.map((info, i) => (
|
||||||
<div className="text-foreground text-sm" key={i}>
|
<div className="text-foreground text-sm" key={i}>
|
||||||
<h3 className="font-semibold">{_(info.description)}</h3>
|
<h3 className="font-semibold">{_(info.description)}</h3>
|
||||||
<p className="text-muted-foreground truncate">{info.value}</p>
|
<p className="text-muted-foreground">{info.value}</p>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { Link, useSearchParams } from 'react-router';
|
import { useSearchParams } from 'react-router';
|
||||||
|
import { Link } from 'react-router';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { formatAvatarUrl } from '@documenso/lib/utils/avatars';
|
import { formatAvatarUrl } from '@documenso/lib/utils/avatars';
|
||||||
@ -49,8 +50,6 @@ export default function DocumentsPage() {
|
|||||||
[ExtendedDocumentStatus.DRAFT]: 0,
|
[ExtendedDocumentStatus.DRAFT]: 0,
|
||||||
[ExtendedDocumentStatus.PENDING]: 0,
|
[ExtendedDocumentStatus.PENDING]: 0,
|
||||||
[ExtendedDocumentStatus.COMPLETED]: 0,
|
[ExtendedDocumentStatus.COMPLETED]: 0,
|
||||||
[ExtendedDocumentStatus.REJECTED]: 0,
|
|
||||||
[ExtendedDocumentStatus.DELETED]: 0,
|
|
||||||
[ExtendedDocumentStatus.INBOX]: 0,
|
[ExtendedDocumentStatus.INBOX]: 0,
|
||||||
[ExtendedDocumentStatus.ALL]: 0,
|
[ExtendedDocumentStatus.ALL]: 0,
|
||||||
});
|
});
|
||||||
@ -114,17 +113,13 @@ export default function DocumentsPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="-m-1 flex flex-wrap gap-x-4 gap-y-6 overflow-hidden p-1">
|
<div className="-m-1 flex flex-wrap gap-x-4 gap-y-6 overflow-hidden p-1">
|
||||||
<Tabs
|
<Tabs value={findDocumentSearchParams.status || 'ALL'} className="overflow-x-auto">
|
||||||
value={findDocumentSearchParams.status || ExtendedDocumentStatus.ALL}
|
|
||||||
className="overflow-x-auto"
|
|
||||||
>
|
|
||||||
<TabsList>
|
<TabsList>
|
||||||
{[
|
{[
|
||||||
ExtendedDocumentStatus.INBOX,
|
ExtendedDocumentStatus.INBOX,
|
||||||
ExtendedDocumentStatus.PENDING,
|
ExtendedDocumentStatus.PENDING,
|
||||||
ExtendedDocumentStatus.COMPLETED,
|
ExtendedDocumentStatus.COMPLETED,
|
||||||
ExtendedDocumentStatus.DRAFT,
|
ExtendedDocumentStatus.DRAFT,
|
||||||
ExtendedDocumentStatus.DELETED,
|
|
||||||
ExtendedDocumentStatus.ALL,
|
ExtendedDocumentStatus.ALL,
|
||||||
].map((value) => (
|
].map((value) => (
|
||||||
<TabsTrigger
|
<TabsTrigger
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { FieldType, SigningStatus } from '@prisma/client';
|
import { FieldType } from '@prisma/client';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import { redirect } from 'react-router';
|
import { redirect } from 'react-router';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
import { UAParser } from 'ua-parser-js';
|
import { UAParser } from 'ua-parser-js';
|
||||||
|
|
||||||
import { isDocumentPlatform } from '@documenso/ee/server-only/util/is-document-platform';
|
|
||||||
import { APP_I18N_OPTIONS, ZSupportedLanguageCodeSchema } from '@documenso/lib/constants/i18n';
|
import { APP_I18N_OPTIONS, ZSupportedLanguageCodeSchema } from '@documenso/lib/constants/i18n';
|
||||||
import {
|
import {
|
||||||
RECIPIENT_ROLES_DESCRIPTION,
|
RECIPIENT_ROLES_DESCRIPTION,
|
||||||
@ -60,8 +59,6 @@ export async function loader({ request }: Route.LoaderArgs) {
|
|||||||
throw redirect('/');
|
throw redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
const isPlatformDocument = await isDocumentPlatform(document);
|
|
||||||
|
|
||||||
const documentLanguage = ZSupportedLanguageCodeSchema.parse(document.documentMeta?.language);
|
const documentLanguage = ZSupportedLanguageCodeSchema.parse(document.documentMeta?.language);
|
||||||
|
|
||||||
const auditLogs = await getDocumentCertificateAuditLogs({
|
const auditLogs = await getDocumentCertificateAuditLogs({
|
||||||
@ -73,7 +70,6 @@ export async function loader({ request }: Route.LoaderArgs) {
|
|||||||
return {
|
return {
|
||||||
document,
|
document,
|
||||||
documentLanguage,
|
documentLanguage,
|
||||||
isPlatformDocument,
|
|
||||||
auditLogs,
|
auditLogs,
|
||||||
messages,
|
messages,
|
||||||
};
|
};
|
||||||
@ -89,7 +85,7 @@ export async function loader({ request }: Route.LoaderArgs) {
|
|||||||
* Update: Maybe <Trans> tags work now after RR7 migration.
|
* Update: Maybe <Trans> tags work now after RR7 migration.
|
||||||
*/
|
*/
|
||||||
export default function SigningCertificate({ loaderData }: Route.ComponentProps) {
|
export default function SigningCertificate({ loaderData }: Route.ComponentProps) {
|
||||||
const { document, documentLanguage, isPlatformDocument, auditLogs, messages } = loaderData;
|
const { document, documentLanguage, auditLogs, messages } = loaderData;
|
||||||
|
|
||||||
const { i18n, _ } = useLingui();
|
const { i18n, _ } = useLingui();
|
||||||
|
|
||||||
@ -163,13 +159,6 @@ export default function SigningCertificate({ loaderData }: Route.ComponentProps)
|
|||||||
log.type === DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_COMPLETED &&
|
log.type === DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_COMPLETED &&
|
||||||
log.data.recipientId === recipientId,
|
log.data.recipientId === recipientId,
|
||||||
),
|
),
|
||||||
[DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_REJECTED]: auditLogs[
|
|
||||||
DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_REJECTED
|
|
||||||
].filter(
|
|
||||||
(log) =>
|
|
||||||
log.type === DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_REJECTED &&
|
|
||||||
log.data.recipientId === recipientId,
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -249,10 +238,6 @@ export default function SigningCertificate({ loaderData }: Route.ComponentProps)
|
|||||||
{signature.secondaryId}
|
{signature.secondaryId}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<p className="text-muted-foreground">N/A</p>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<p className="text-muted-foreground mt-2 text-sm print:text-xs">
|
<p className="text-muted-foreground mt-2 text-sm print:text-xs">
|
||||||
<span className="font-medium">{_(msg`IP Address`)}:</span>{' '}
|
<span className="font-medium">{_(msg`IP Address`)}:</span>{' '}
|
||||||
@ -267,6 +252,10 @@ export default function SigningCertificate({ loaderData }: Route.ComponentProps)
|
|||||||
{getDevice(logs.DOCUMENT_RECIPIENT_COMPLETED[0]?.userAgent)}
|
{getDevice(logs.DOCUMENT_RECIPIENT_COMPLETED[0]?.userAgent)}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<p className="text-muted-foreground">N/A</p>
|
||||||
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell truncate={false} className="w-[min-content] align-top">
|
<TableCell truncate={false} className="w-[min-content] align-top">
|
||||||
@ -293,38 +282,21 @@ export default function SigningCertificate({ loaderData }: Route.ComponentProps)
|
|||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{logs.DOCUMENT_RECIPIENT_REJECTED[0] ? (
|
|
||||||
<p className="text-muted-foreground text-sm print:text-xs">
|
|
||||||
<span className="font-medium">{_(msg`Rejected`)}:</span>{' '}
|
|
||||||
<span className="inline-block">
|
|
||||||
{logs.DOCUMENT_RECIPIENT_REJECTED[0]
|
|
||||||
? DateTime.fromJSDate(logs.DOCUMENT_RECIPIENT_REJECTED[0].createdAt)
|
|
||||||
.setLocale(APP_I18N_OPTIONS.defaultLocale)
|
|
||||||
.toFormat('yyyy-MM-dd hh:mm:ss a (ZZZZ)')
|
|
||||||
: _(msg`Unknown`)}
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
) : (
|
|
||||||
<p className="text-muted-foreground text-sm print:text-xs">
|
<p className="text-muted-foreground text-sm print:text-xs">
|
||||||
<span className="font-medium">{_(msg`Signed`)}:</span>{' '}
|
<span className="font-medium">{_(msg`Signed`)}:</span>{' '}
|
||||||
<span className="inline-block">
|
<span className="inline-block">
|
||||||
{logs.DOCUMENT_RECIPIENT_COMPLETED[0]
|
{logs.DOCUMENT_RECIPIENT_COMPLETED[0]
|
||||||
? DateTime.fromJSDate(
|
? DateTime.fromJSDate(logs.DOCUMENT_RECIPIENT_COMPLETED[0].createdAt)
|
||||||
logs.DOCUMENT_RECIPIENT_COMPLETED[0].createdAt,
|
|
||||||
)
|
|
||||||
.setLocale(APP_I18N_OPTIONS.defaultLocale)
|
.setLocale(APP_I18N_OPTIONS.defaultLocale)
|
||||||
.toFormat('yyyy-MM-dd hh:mm:ss a (ZZZZ)')
|
.toFormat('yyyy-MM-dd hh:mm:ss a (ZZZZ)')
|
||||||
: _(msg`Unknown`)}
|
: _(msg`Unknown`)}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
)}
|
|
||||||
|
|
||||||
<p className="text-muted-foreground text-sm print:text-xs">
|
<p className="text-muted-foreground text-sm print:text-xs">
|
||||||
<span className="font-medium">{_(msg`Reason`)}:</span>{' '}
|
<span className="font-medium">{_(msg`Reason`)}:</span>{' '}
|
||||||
<span className="inline-block">
|
<span className="inline-block">
|
||||||
{recipient.signingStatus === SigningStatus.REJECTED
|
{_(
|
||||||
? recipient.rejectionReason
|
|
||||||
: _(
|
|
||||||
isOwner(recipient.email)
|
isOwner(recipient.email)
|
||||||
? FRIENDLY_SIGNING_REASONS['__OWNER__']
|
? FRIENDLY_SIGNING_REASONS['__OWNER__']
|
||||||
: FRIENDLY_SIGNING_REASONS[recipient.role],
|
: FRIENDLY_SIGNING_REASONS[recipient.role],
|
||||||
@ -341,7 +313,6 @@ export default function SigningCertificate({ loaderData }: Route.ComponentProps)
|
|||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{isPlatformDocument && (
|
|
||||||
<div className="my-8 flex-row-reverse">
|
<div className="my-8 flex-row-reverse">
|
||||||
<div className="flex items-end justify-end gap-x-4">
|
<div className="flex items-end justify-end gap-x-4">
|
||||||
<p className="flex-shrink-0 text-sm font-medium print:text-xs">
|
<p className="flex-shrink-0 text-sm font-medium print:text-xs">
|
||||||
@ -351,7 +322,6 @@ export default function SigningCertificate({ loaderData }: Route.ComponentProps)
|
|||||||
<BrandingLogo className="max-h-6 print:max-h-4" />
|
<BrandingLogo className="max-h-6 print:max-h-4" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { msg } from '@lingui/core/macro';
|
|||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { PlusIcon } from 'lucide-react';
|
import { PlusIcon } from 'lucide-react';
|
||||||
import { ChevronLeft } from 'lucide-react';
|
import { ChevronLeft } from 'lucide-react';
|
||||||
import { Link, Outlet, isRouteErrorResponse } from 'react-router';
|
import { Link, Outlet } from 'react-router';
|
||||||
|
|
||||||
import LogoIcon from '@documenso/assets/logo_icon.png';
|
import LogoIcon from '@documenso/assets/logo_icon.png';
|
||||||
import { useOptionalSession } from '@documenso/lib/client-only/providers/session';
|
import { useOptionalSession } from '@documenso/lib/client-only/providers/session';
|
||||||
@ -16,8 +16,6 @@ import { BrandingLogo } from '~/components/general/branding-logo';
|
|||||||
import { GenericErrorLayout } from '~/components/general/generic-error-layout';
|
import { GenericErrorLayout } from '~/components/general/generic-error-layout';
|
||||||
import { appMetaTags } from '~/utils/meta';
|
import { appMetaTags } from '~/utils/meta';
|
||||||
|
|
||||||
import type { Route } from './+types/_layout';
|
|
||||||
|
|
||||||
export function meta() {
|
export function meta() {
|
||||||
return appMetaTags('Profile');
|
return appMetaTags('Profile');
|
||||||
}
|
}
|
||||||
@ -98,9 +96,7 @@ export default function PublicProfileLayout() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
export function ErrorBoundary() {
|
||||||
const errorCode = isRouteErrorResponse(error) ? error.status : 500;
|
|
||||||
|
|
||||||
const errorCodeMap = {
|
const errorCodeMap = {
|
||||||
404: {
|
404: {
|
||||||
subHeading: msg`404 Profile not found`,
|
subHeading: msg`404 Profile not found`,
|
||||||
@ -111,7 +107,6 @@ export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<GenericErrorLayout
|
<GenericErrorLayout
|
||||||
errorCode={errorCode}
|
|
||||||
errorCodeMap={errorCodeMap}
|
errorCodeMap={errorCodeMap}
|
||||||
secondaryButton={null}
|
secondaryButton={null}
|
||||||
primaryButton={
|
primaryButton={
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { ChevronLeft } from 'lucide-react';
|
import { ChevronLeft } from 'lucide-react';
|
||||||
import { Link, Outlet, isRouteErrorResponse } from 'react-router';
|
import { Link, Outlet } from 'react-router';
|
||||||
|
|
||||||
import { useOptionalSession } from '@documenso/lib/client-only/providers/session';
|
import { useOptionalSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
@ -8,8 +8,6 @@ import { Button } from '@documenso/ui/primitives/button';
|
|||||||
import { Header as AuthenticatedHeader } from '~/components/general/app-header';
|
import { Header as AuthenticatedHeader } from '~/components/general/app-header';
|
||||||
import { GenericErrorLayout } from '~/components/general/generic-error-layout';
|
import { GenericErrorLayout } from '~/components/general/generic-error-layout';
|
||||||
|
|
||||||
import type { Route } from './+types/_layout';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A layout to handle scenarios where the user is a recipient of a given resource
|
* A layout to handle scenarios where the user is a recipient of a given resource
|
||||||
* where we do not care whether they are authenticated or not.
|
* where we do not care whether they are authenticated or not.
|
||||||
@ -32,12 +30,9 @@ export default function RecipientLayout() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
export function ErrorBoundary() {
|
||||||
const errorCode = isRouteErrorResponse(error) ? error.status : 500;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GenericErrorLayout
|
<GenericErrorLayout
|
||||||
errorCode={errorCode}
|
|
||||||
secondaryButton={null}
|
secondaryButton={null}
|
||||||
primaryButton={
|
primaryButton={
|
||||||
<Button asChild className="w-32">
|
<Button asChild className="w-32">
|
||||||
|
|||||||
@ -79,14 +79,7 @@ export default function DirectTemplatePage() {
|
|||||||
const { template, directTemplateRecipient } = data;
|
const { template, directTemplateRecipient } = data;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DocumentSigningProvider
|
<DocumentSigningProvider email={user?.email} fullName={user?.name} signature={user?.signature}>
|
||||||
email={user?.email}
|
|
||||||
fullName={user?.name}
|
|
||||||
signature={user?.signature}
|
|
||||||
typedSignatureEnabled={template.templateMeta?.typedSignatureEnabled}
|
|
||||||
uploadSignatureEnabled={template.templateMeta?.uploadSignatureEnabled}
|
|
||||||
drawSignatureEnabled={template.templateMeta?.drawSignatureEnabled}
|
|
||||||
>
|
|
||||||
<DocumentSigningAuthProvider
|
<DocumentSigningAuthProvider
|
||||||
documentAuthOptions={template.authOptions}
|
documentAuthOptions={template.authOptions}
|
||||||
recipient={directTemplateRecipient}
|
recipient={directTemplateRecipient}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { DocumentSigningOrder, DocumentStatus, RecipientRole, SigningStatus } from '@prisma/client';
|
import { DocumentStatus, RecipientRole, SigningStatus } from '@prisma/client';
|
||||||
import { Clock8 } from 'lucide-react';
|
import { Clock8 } from 'lucide-react';
|
||||||
import { Link, redirect } from 'react-router';
|
import { Link, redirect } from 'react-router';
|
||||||
import { getOptionalLoaderContext } from 'server/utils/get-loader-session';
|
import { getOptionalLoaderContext } from 'server/utils/get-loader-session';
|
||||||
@ -13,7 +13,6 @@ import { viewedDocument } from '@documenso/lib/server-only/document/viewed-docum
|
|||||||
import { getCompletedFieldsForToken } from '@documenso/lib/server-only/field/get-completed-fields-for-token';
|
import { getCompletedFieldsForToken } from '@documenso/lib/server-only/field/get-completed-fields-for-token';
|
||||||
import { getFieldsForToken } from '@documenso/lib/server-only/field/get-fields-for-token';
|
import { getFieldsForToken } from '@documenso/lib/server-only/field/get-fields-for-token';
|
||||||
import { getIsRecipientsTurnToSign } from '@documenso/lib/server-only/recipient/get-is-recipient-turn';
|
import { getIsRecipientsTurnToSign } from '@documenso/lib/server-only/recipient/get-is-recipient-turn';
|
||||||
import { getNextPendingRecipient } from '@documenso/lib/server-only/recipient/get-next-pending-recipient';
|
|
||||||
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token';
|
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token';
|
||||||
import { getRecipientSignatures } from '@documenso/lib/server-only/recipient/get-recipient-signatures';
|
import { getRecipientSignatures } from '@documenso/lib/server-only/recipient/get-recipient-signatures';
|
||||||
import { getRecipientsForAssistant } from '@documenso/lib/server-only/recipient/get-recipients-for-assistant';
|
import { getRecipientsForAssistant } from '@documenso/lib/server-only/recipient/get-recipients-for-assistant';
|
||||||
@ -73,24 +72,7 @@ export async function loader({ params, request }: Route.LoaderArgs) {
|
|||||||
? await getRecipientsForAssistant({
|
? await getRecipientsForAssistant({
|
||||||
token,
|
token,
|
||||||
})
|
})
|
||||||
: [recipient];
|
: [];
|
||||||
|
|
||||||
if (
|
|
||||||
document.documentMeta?.signingOrder === DocumentSigningOrder.SEQUENTIAL &&
|
|
||||||
recipient.role !== RecipientRole.ASSISTANT
|
|
||||||
) {
|
|
||||||
const nextPendingRecipient = await getNextPendingRecipient({
|
|
||||||
documentId: document.id,
|
|
||||||
currentRecipientId: recipient.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (nextPendingRecipient) {
|
|
||||||
allRecipients.push({
|
|
||||||
...nextPendingRecipient,
|
|
||||||
fields: [],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { derivedRecipientAccessAuth } = extractDocumentAuthMethods({
|
const { derivedRecipientAccessAuth } = extractDocumentAuthMethods({
|
||||||
documentAuth: document.authOptions,
|
documentAuth: document.authOptions,
|
||||||
@ -178,7 +160,7 @@ export default function SigningPage() {
|
|||||||
recipientWithFields,
|
recipientWithFields,
|
||||||
} = data;
|
} = data;
|
||||||
|
|
||||||
if (document.deletedAt || document.status === DocumentStatus.REJECTED) {
|
if (document.deletedAt) {
|
||||||
return (
|
return (
|
||||||
<div className="-mx-4 flex max-w-[100vw] flex-col items-center overflow-x-hidden px-4 pt-16 md:-mx-8 md:px-8 lg:pt-16 xl:pt-24">
|
<div className="-mx-4 flex max-w-[100vw] flex-col items-center overflow-x-hidden px-4 pt-16 md:-mx-8 md:px-8 lg:pt-16 xl:pt-24">
|
||||||
<SigningCard3D
|
<SigningCard3D
|
||||||
@ -233,9 +215,6 @@ export default function SigningPage() {
|
|||||||
email={recipient.email}
|
email={recipient.email}
|
||||||
fullName={user?.email === recipient.email ? user?.name : recipient.name}
|
fullName={user?.email === recipient.email ? user?.name : recipient.name}
|
||||||
signature={user?.email === recipient.email ? user?.signature : undefined}
|
signature={user?.email === recipient.email ? user?.signature : undefined}
|
||||||
typedSignatureEnabled={document.documentMeta?.typedSignatureEnabled}
|
|
||||||
uploadSignatureEnabled={document.documentMeta?.uploadSignatureEnabled}
|
|
||||||
drawSignatureEnabled={document.documentMeta?.drawSignatureEnabled}
|
|
||||||
>
|
>
|
||||||
<DocumentSigningAuthProvider
|
<DocumentSigningAuthProvider
|
||||||
documentAuthOptions={document.authOptions}
|
documentAuthOptions={document.authOptions}
|
||||||
|
|||||||
@ -17,7 +17,6 @@ import { getFieldsForToken } from '@documenso/lib/server-only/field/get-fields-f
|
|||||||
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token';
|
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token';
|
||||||
import { getRecipientSignatures } from '@documenso/lib/server-only/recipient/get-recipient-signatures';
|
import { getRecipientSignatures } from '@documenso/lib/server-only/recipient/get-recipient-signatures';
|
||||||
import { getUserByEmail } from '@documenso/lib/server-only/user/get-user-by-email';
|
import { getUserByEmail } from '@documenso/lib/server-only/user/get-user-by-email';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
|
||||||
import { env } from '@documenso/lib/utils/env';
|
import { env } from '@documenso/lib/utils/env';
|
||||||
import DocumentDialog from '@documenso/ui/components/document/document-dialog';
|
import DocumentDialog from '@documenso/ui/components/document/document-dialog';
|
||||||
import { DocumentDownloadButton } from '@documenso/ui/components/document/document-download-button';
|
import { DocumentDownloadButton } from '@documenso/ui/components/document/document-download-button';
|
||||||
@ -206,12 +205,12 @@ export default function CompletedSigningPage({ loaderData }: Route.ComponentProp
|
|||||||
<div className="mt-8 flex w-full max-w-sm items-center justify-center gap-4">
|
<div className="mt-8 flex w-full max-w-sm items-center justify-center gap-4">
|
||||||
<DocumentShareButton documentId={document.id} token={recipient.token} />
|
<DocumentShareButton documentId={document.id} token={recipient.token} />
|
||||||
|
|
||||||
{isDocumentCompleted(document.status) ? (
|
{document.status === DocumentStatus.COMPLETED ? (
|
||||||
<DocumentDownloadButton
|
<DocumentDownloadButton
|
||||||
className="flex-1"
|
className="flex-1"
|
||||||
fileName={document.title}
|
fileName={document.title}
|
||||||
documentData={document.documentData}
|
documentData={document.documentData}
|
||||||
disabled={!isDocumentCompleted(document.status)}
|
disabled={document.status !== DocumentStatus.COMPLETED}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<DocumentDialog
|
<DocumentDialog
|
||||||
@ -269,7 +268,7 @@ export const PollUntilDocumentCompleted = ({ document }: PollUntilDocumentComple
|
|||||||
const { revalidate } = useRevalidator();
|
const { revalidate } = useRevalidator();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isDocumentCompleted(document.status)) {
|
if (document.status === DocumentStatus.COMPLETED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,30 +19,18 @@ const posthogProxy = async (request: Request) => {
|
|||||||
const headers = new Headers(request.headers);
|
const headers = new Headers(request.headers);
|
||||||
headers.set('host', hostname);
|
headers.set('host', hostname);
|
||||||
|
|
||||||
const fetchOptions: RequestInit = {
|
const response = await fetch(newUrl, {
|
||||||
method: request.method,
|
method: request.method,
|
||||||
headers,
|
headers,
|
||||||
redirect: 'follow',
|
body: request.body,
|
||||||
};
|
// @ts-expect-error - Not really sure about this
|
||||||
|
duplex: 'half',
|
||||||
if (!['GET', 'HEAD'].includes(request.method)) {
|
});
|
||||||
fetchOptions.body = request.body;
|
|
||||||
// @ts-expect-error - It should exist
|
|
||||||
fetchOptions.duplex = 'half';
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(newUrl, fetchOptions);
|
|
||||||
|
|
||||||
const responseHeaders = new Headers(response.headers);
|
|
||||||
responseHeaders.delete('content-encoding');
|
|
||||||
responseHeaders.delete('content-length');
|
|
||||||
responseHeaders.delete('transfer-encoding');
|
|
||||||
responseHeaders.delete('cookie');
|
|
||||||
|
|
||||||
return new Response(response.body, {
|
return new Response(response.body, {
|
||||||
status: response.status,
|
status: response.status,
|
||||||
statusText: response.statusText,
|
statusText: response.statusText,
|
||||||
headers: responseHeaders,
|
headers: response.headers,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { isTokenExpired } from '@documenso/lib/utils/token-verification';
|
|||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
|
|
||||||
import type { Route } from './+types/team.verify.transfer.$token';
|
import type { Route } from './+types/team.verify.transfer.token';
|
||||||
|
|
||||||
export async function loader({ params }: Route.LoaderArgs) {
|
export async function loader({ params }: Route.LoaderArgs) {
|
||||||
const { token } = params;
|
const { token } = params;
|
||||||
@ -131,14 +131,7 @@ export default function EmbedDirectTemplatePage() {
|
|||||||
} = useSuperLoaderData<typeof loader>();
|
} = useSuperLoaderData<typeof loader>();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DocumentSigningProvider
|
<DocumentSigningProvider email={user?.email} fullName={user?.name} signature={user?.signature}>
|
||||||
email={user?.email}
|
|
||||||
fullName={user?.name}
|
|
||||||
signature={user?.signature}
|
|
||||||
typedSignatureEnabled={template.templateMeta?.typedSignatureEnabled}
|
|
||||||
uploadSignatureEnabled={template.templateMeta?.uploadSignatureEnabled}
|
|
||||||
drawSignatureEnabled={template.templateMeta?.drawSignatureEnabled}
|
|
||||||
>
|
|
||||||
<DocumentSigningAuthProvider
|
<DocumentSigningAuthProvider
|
||||||
documentAuthOptions={template.authOptions}
|
documentAuthOptions={template.authOptions}
|
||||||
recipient={recipient}
|
recipient={recipient}
|
||||||
@ -152,9 +145,7 @@ export default function EmbedDirectTemplatePage() {
|
|||||||
recipient={recipient}
|
recipient={recipient}
|
||||||
fields={fields}
|
fields={fields}
|
||||||
metadata={template.templateMeta}
|
metadata={template.templateMeta}
|
||||||
hidePoweredBy={
|
hidePoweredBy={isPlatformDocument || isEnterpriseDocument || hidePoweredBy}
|
||||||
isCommunityPlan || isPlatformDocument || isEnterpriseDocument || hidePoweredBy
|
|
||||||
}
|
|
||||||
allowWhiteLabelling={isCommunityPlan || isPlatformDocument || isEnterpriseDocument}
|
allowWhiteLabelling={isCommunityPlan || isPlatformDocument || isEnterpriseDocument}
|
||||||
/>
|
/>
|
||||||
</DocumentSigningRecipientProvider>
|
</DocumentSigningRecipientProvider>
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { RecipientRole } from '@prisma/client';
|
import { DocumentStatus, RecipientRole } from '@prisma/client';
|
||||||
import { data } from 'react-router';
|
import { data } from 'react-router';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
@ -8,14 +8,12 @@ import { isUserEnterprise } from '@documenso/ee/server-only/util/is-document-ent
|
|||||||
import { isDocumentPlatform } from '@documenso/ee/server-only/util/is-document-platform';
|
import { isDocumentPlatform } from '@documenso/ee/server-only/util/is-document-platform';
|
||||||
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
|
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
|
||||||
import { getDocumentAndSenderByToken } from '@documenso/lib/server-only/document/get-document-by-token';
|
import { getDocumentAndSenderByToken } from '@documenso/lib/server-only/document/get-document-by-token';
|
||||||
import { getCompletedFieldsForToken } from '@documenso/lib/server-only/field/get-completed-fields-for-token';
|
|
||||||
import { getFieldsForToken } from '@documenso/lib/server-only/field/get-fields-for-token';
|
import { getFieldsForToken } from '@documenso/lib/server-only/field/get-fields-for-token';
|
||||||
import { getIsRecipientsTurnToSign } from '@documenso/lib/server-only/recipient/get-is-recipient-turn';
|
import { getIsRecipientsTurnToSign } from '@documenso/lib/server-only/recipient/get-is-recipient-turn';
|
||||||
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token';
|
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token';
|
||||||
import { getRecipientsForAssistant } from '@documenso/lib/server-only/recipient/get-recipients-for-assistant';
|
import { getRecipientsForAssistant } from '@documenso/lib/server-only/recipient/get-recipients-for-assistant';
|
||||||
import { getTeamById } from '@documenso/lib/server-only/team/get-team';
|
import { getTeamById } from '@documenso/lib/server-only/team/get-team';
|
||||||
import { DocumentAccessAuth } from '@documenso/lib/types/document-auth';
|
import { DocumentAccessAuth } from '@documenso/lib/types/document-auth';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
|
||||||
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
||||||
|
|
||||||
import { EmbedSignDocumentClientPage } from '~/components/embed/embed-document-signing-page';
|
import { EmbedSignDocumentClientPage } from '~/components/embed/embed-document-signing-page';
|
||||||
@ -34,7 +32,7 @@ export async function loader({ params, request }: Route.LoaderArgs) {
|
|||||||
|
|
||||||
const { user } = await getOptionalSession(request);
|
const { user } = await getOptionalSession(request);
|
||||||
|
|
||||||
const [document, fields, recipient, completedFields] = await Promise.all([
|
const [document, fields, recipient] = await Promise.all([
|
||||||
getDocumentAndSenderByToken({
|
getDocumentAndSenderByToken({
|
||||||
token,
|
token,
|
||||||
userId: user?.id,
|
userId: user?.id,
|
||||||
@ -42,7 +40,6 @@ export async function loader({ params, request }: Route.LoaderArgs) {
|
|||||||
}).catch(() => null),
|
}).catch(() => null),
|
||||||
getFieldsForToken({ token }),
|
getFieldsForToken({ token }),
|
||||||
getRecipientByToken({ token }).catch(() => null),
|
getRecipientByToken({ token }).catch(() => null),
|
||||||
getCompletedFieldsForToken({ token }).catch(() => []),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// `document.directLink` is always available but we're doing this to
|
// `document.directLink` is always available but we're doing this to
|
||||||
@ -132,7 +129,6 @@ export async function loader({ params, request }: Route.LoaderArgs) {
|
|||||||
allRecipients,
|
allRecipients,
|
||||||
recipient,
|
recipient,
|
||||||
fields,
|
fields,
|
||||||
completedFields,
|
|
||||||
hidePoweredBy,
|
hidePoweredBy,
|
||||||
isPlatformDocument,
|
isPlatformDocument,
|
||||||
isEnterpriseDocument,
|
isEnterpriseDocument,
|
||||||
@ -148,7 +144,6 @@ export default function EmbedSignDocumentPage() {
|
|||||||
allRecipients,
|
allRecipients,
|
||||||
recipient,
|
recipient,
|
||||||
fields,
|
fields,
|
||||||
completedFields,
|
|
||||||
hidePoweredBy,
|
hidePoweredBy,
|
||||||
isPlatformDocument,
|
isPlatformDocument,
|
||||||
isEnterpriseDocument,
|
isEnterpriseDocument,
|
||||||
@ -160,9 +155,6 @@ export default function EmbedSignDocumentPage() {
|
|||||||
email={recipient.email}
|
email={recipient.email}
|
||||||
fullName={user?.email === recipient.email ? user?.name : recipient.name}
|
fullName={user?.email === recipient.email ? user?.name : recipient.name}
|
||||||
signature={user?.email === recipient.email ? user?.signature : undefined}
|
signature={user?.email === recipient.email ? user?.signature : undefined}
|
||||||
typedSignatureEnabled={document.documentMeta?.typedSignatureEnabled}
|
|
||||||
uploadSignatureEnabled={document.documentMeta?.uploadSignatureEnabled}
|
|
||||||
drawSignatureEnabled={document.documentMeta?.drawSignatureEnabled}
|
|
||||||
>
|
>
|
||||||
<DocumentSigningAuthProvider
|
<DocumentSigningAuthProvider
|
||||||
documentAuthOptions={document.authOptions}
|
documentAuthOptions={document.authOptions}
|
||||||
@ -175,12 +167,9 @@ export default function EmbedSignDocumentPage() {
|
|||||||
documentData={document.documentData}
|
documentData={document.documentData}
|
||||||
recipient={recipient}
|
recipient={recipient}
|
||||||
fields={fields}
|
fields={fields}
|
||||||
completedFields={completedFields}
|
|
||||||
metadata={document.documentMeta}
|
metadata={document.documentMeta}
|
||||||
isCompleted={isDocumentCompleted(document.status)}
|
isCompleted={document.status === DocumentStatus.COMPLETED}
|
||||||
hidePoweredBy={
|
hidePoweredBy={isPlatformDocument || isEnterpriseDocument || hidePoweredBy}
|
||||||
isCommunityPlan || isPlatformDocument || isEnterpriseDocument || hidePoweredBy
|
|
||||||
}
|
|
||||||
allowWhitelabelling={isCommunityPlan || isPlatformDocument || isEnterpriseDocument}
|
allowWhitelabelling={isCommunityPlan || isPlatformDocument || isEnterpriseDocument}
|
||||||
allRecipients={allRecipients}
|
allRecipients={allRecipients}
|
||||||
/>
|
/>
|
||||||
@ -1,66 +0,0 @@
|
|||||||
import { useLayoutEffect, useState } from 'react';
|
|
||||||
|
|
||||||
import { Outlet } from 'react-router';
|
|
||||||
|
|
||||||
import { TrpcProvider, trpc } from '@documenso/trpc/react';
|
|
||||||
|
|
||||||
import { EmbedClientLoading } from '~/components/embed/embed-client-loading';
|
|
||||||
import { ZBaseEmbedAuthoringSchema } from '~/types/embed-authoring-base-schema';
|
|
||||||
import { injectCss } from '~/utils/css-vars';
|
|
||||||
|
|
||||||
export default function AuthoringLayout() {
|
|
||||||
const [token, setToken] = useState('');
|
|
||||||
|
|
||||||
const {
|
|
||||||
mutateAsync: verifyEmbeddingPresignToken,
|
|
||||||
isPending: isVerifyingEmbeddingPresignToken,
|
|
||||||
data: isVerified,
|
|
||||||
} = trpc.embeddingPresign.verifyEmbeddingPresignToken.useMutation();
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
try {
|
|
||||||
const hash = window.location.hash.slice(1);
|
|
||||||
|
|
||||||
const result = ZBaseEmbedAuthoringSchema.safeParse(
|
|
||||||
JSON.parse(decodeURIComponent(atob(hash))),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!result.success) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { token, css, cssVars, darkModeDisabled } = result.data;
|
|
||||||
|
|
||||||
if (darkModeDisabled) {
|
|
||||||
document.documentElement.classList.add('dark-mode-disabled');
|
|
||||||
}
|
|
||||||
|
|
||||||
injectCss({
|
|
||||||
css,
|
|
||||||
cssVars,
|
|
||||||
});
|
|
||||||
|
|
||||||
void verifyEmbeddingPresignToken({ token }).then((result) => {
|
|
||||||
if (result.success) {
|
|
||||||
setToken(token);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error verifying embedding presign token:', err);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (isVerifyingEmbeddingPresignToken) {
|
|
||||||
return <EmbedClientLoading />;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof isVerified !== 'undefined' && !isVerified.success) {
|
|
||||||
return <div>Invalid embedding presign token</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TrpcProvider headers={{ authorization: `Bearer ${token}` }}>
|
|
||||||
<Outlet />
|
|
||||||
</TrpcProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
import { useEffect } from 'react';
|
|
||||||
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
|
||||||
import { CheckCircle2 } from 'lucide-react';
|
|
||||||
import { useSearchParams } from 'react-router';
|
|
||||||
|
|
||||||
export default function EmbeddingAuthoringCompletedPage() {
|
|
||||||
const [searchParams] = useSearchParams();
|
|
||||||
|
|
||||||
// Get templateId and externalId from URL search params
|
|
||||||
const templateId = searchParams.get('templateId');
|
|
||||||
const documentId = searchParams.get('documentId');
|
|
||||||
const externalId = searchParams.get('externalId');
|
|
||||||
|
|
||||||
const id = Number(templateId || documentId);
|
|
||||||
const type = templateId ? 'template' : 'document';
|
|
||||||
|
|
||||||
// Send postMessage to parent window with the details
|
|
||||||
useEffect(() => {
|
|
||||||
if (!id || !window.parent || window.parent === window) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.parent.postMessage(
|
|
||||||
{
|
|
||||||
type: `${type}-created`,
|
|
||||||
[`${type}Id`]: id,
|
|
||||||
externalId,
|
|
||||||
},
|
|
||||||
'*',
|
|
||||||
);
|
|
||||||
}, [id, type, externalId]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex min-h-[100dvh] flex-col items-center justify-center p-6 text-center">
|
|
||||||
<div className="mx-auto w-full max-w-md">
|
|
||||||
<CheckCircle2 className="text-primary mx-auto h-16 w-16" />
|
|
||||||
|
|
||||||
<h1 className="mt-6 text-2xl font-bold">
|
|
||||||
{type === 'template' ? <Trans>Template Created</Trans> : <Trans>Document Created</Trans>}
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<p className="text-muted-foreground mt-2">
|
|
||||||
{type === 'template' ? (
|
|
||||||
<Trans>Your template has been created successfully</Trans>
|
|
||||||
) : (
|
|
||||||
<Trans>Your document has been created successfully</Trans>
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@ -1,184 +0,0 @@
|
|||||||
import { useLayoutEffect, useState } from 'react';
|
|
||||||
|
|
||||||
import { useLingui } from '@lingui/react';
|
|
||||||
import { useNavigate } from 'react-router';
|
|
||||||
|
|
||||||
import { DocumentSignatureType } from '@documenso/lib/constants/document';
|
|
||||||
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
|
||||||
import { trpc } from '@documenso/trpc/react';
|
|
||||||
import { Stepper } from '@documenso/ui/primitives/stepper';
|
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
||||||
|
|
||||||
import { ConfigureDocumentProvider } from '~/components/embed/authoring/configure-document-context';
|
|
||||||
import { ConfigureDocumentView } from '~/components/embed/authoring/configure-document-view';
|
|
||||||
import type { TConfigureEmbedFormSchema } from '~/components/embed/authoring/configure-document-view.types';
|
|
||||||
import {
|
|
||||||
ConfigureFieldsView,
|
|
||||||
type TConfigureFieldsFormSchema,
|
|
||||||
} from '~/components/embed/authoring/configure-fields-view';
|
|
||||||
import {
|
|
||||||
type TBaseEmbedAuthoringSchema,
|
|
||||||
ZBaseEmbedAuthoringSchema,
|
|
||||||
} from '~/types/embed-authoring-base-schema';
|
|
||||||
|
|
||||||
export default function EmbeddingAuthoringDocumentCreatePage() {
|
|
||||||
const { _ } = useLingui();
|
|
||||||
|
|
||||||
const { toast } = useToast();
|
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
const [configuration, setConfiguration] = useState<TConfigureEmbedFormSchema | null>(null);
|
|
||||||
const [fields, setFields] = useState<TConfigureFieldsFormSchema | null>(null);
|
|
||||||
const [features, setFeatures] = useState<TBaseEmbedAuthoringSchema['features'] | null>(null);
|
|
||||||
const [externalId, setExternalId] = useState<string | null>(null);
|
|
||||||
const [currentStep, setCurrentStep] = useState(1);
|
|
||||||
|
|
||||||
const { mutateAsync: createEmbeddingDocument } =
|
|
||||||
trpc.embeddingPresign.createEmbeddingDocument.useMutation();
|
|
||||||
|
|
||||||
const handleConfigurePageViewSubmit = (data: TConfigureEmbedFormSchema) => {
|
|
||||||
// Store the configuration data and move to the field placement stage
|
|
||||||
setConfiguration(data);
|
|
||||||
setCurrentStep(2);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleBackToConfig = (data: TConfigureFieldsFormSchema) => {
|
|
||||||
// Return to the configuration view but keep the data
|
|
||||||
setFields(data);
|
|
||||||
setCurrentStep(1);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleConfigureFieldsSubmit = async (data: TConfigureFieldsFormSchema) => {
|
|
||||||
try {
|
|
||||||
if (!configuration || !configuration.documentData) {
|
|
||||||
toast({
|
|
||||||
variant: 'destructive',
|
|
||||||
title: _('Error'),
|
|
||||||
description: _('Please configure the document first'),
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fields = data.fields;
|
|
||||||
|
|
||||||
const documentData = await putPdfFile({
|
|
||||||
arrayBuffer: async () => Promise.resolve(configuration.documentData!.data.buffer),
|
|
||||||
name: configuration.documentData.name,
|
|
||||||
type: configuration.documentData.type,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Use the externalId from the URL fragment if available
|
|
||||||
const documentExternalId = externalId || configuration.meta.externalId;
|
|
||||||
|
|
||||||
const createResult = await createEmbeddingDocument({
|
|
||||||
title: configuration.title,
|
|
||||||
documentDataId: documentData.id,
|
|
||||||
externalId: documentExternalId,
|
|
||||||
meta: {
|
|
||||||
...configuration.meta,
|
|
||||||
drawSignatureEnabled:
|
|
||||||
configuration.meta.signatureTypes.length === 0 ||
|
|
||||||
configuration.meta.signatureTypes.includes(DocumentSignatureType.DRAW),
|
|
||||||
typedSignatureEnabled:
|
|
||||||
configuration.meta.signatureTypes.length === 0 ||
|
|
||||||
configuration.meta.signatureTypes.includes(DocumentSignatureType.TYPE),
|
|
||||||
uploadSignatureEnabled:
|
|
||||||
configuration.meta.signatureTypes.length === 0 ||
|
|
||||||
configuration.meta.signatureTypes.includes(DocumentSignatureType.UPLOAD),
|
|
||||||
},
|
|
||||||
recipients: configuration.signers.map((signer) => ({
|
|
||||||
name: signer.name,
|
|
||||||
email: signer.email,
|
|
||||||
role: signer.role,
|
|
||||||
fields: fields
|
|
||||||
.filter((field) => field.signerEmail === signer.email)
|
|
||||||
// There's a gnarly discriminated union that makes this hard to satisfy, we're casting for the second
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
.map<any>((f) => ({
|
|
||||||
...f,
|
|
||||||
pageX: f.pageX,
|
|
||||||
pageY: f.pageY,
|
|
||||||
width: f.pageWidth,
|
|
||||||
height: f.pageHeight,
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
});
|
|
||||||
|
|
||||||
toast({
|
|
||||||
title: _('Success'),
|
|
||||||
description: _('Document created successfully'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Send a message to the parent window with the document details
|
|
||||||
if (window.parent !== window) {
|
|
||||||
window.parent.postMessage(
|
|
||||||
{
|
|
||||||
type: 'document-created',
|
|
||||||
documentId: createResult.documentId,
|
|
||||||
externalId: documentExternalId,
|
|
||||||
},
|
|
||||||
'*',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const hash = window.location.hash.slice(1);
|
|
||||||
|
|
||||||
// Navigate to the completion page instead of the document details page
|
|
||||||
await navigate(
|
|
||||||
`/embed/v1/authoring/create-completed?documentId=${createResult.documentId}&externalId=${documentExternalId}#${hash}`,
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error creating document:', err);
|
|
||||||
|
|
||||||
toast({
|
|
||||||
variant: 'destructive',
|
|
||||||
title: _('Error'),
|
|
||||||
description: _('Failed to create document'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
try {
|
|
||||||
const hash = window.location.hash.slice(1);
|
|
||||||
|
|
||||||
const result = ZBaseEmbedAuthoringSchema.safeParse(
|
|
||||||
JSON.parse(decodeURIComponent(atob(hash))),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!result.success) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setFeatures(result.data.features);
|
|
||||||
|
|
||||||
// Extract externalId from the parsed data if available
|
|
||||||
if (result.data.externalId) {
|
|
||||||
setExternalId(result.data.externalId);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error parsing embedding params:', err);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="relative mx-auto flex min-h-[100dvh] max-w-screen-lg p-6">
|
|
||||||
<ConfigureDocumentProvider isTemplate={false} features={features ?? {}}>
|
|
||||||
<Stepper currentStep={currentStep} setCurrentStep={setCurrentStep}>
|
|
||||||
<ConfigureDocumentView
|
|
||||||
defaultValues={configuration ?? undefined}
|
|
||||||
onSubmit={handleConfigurePageViewSubmit}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ConfigureFieldsView
|
|
||||||
configData={configuration!}
|
|
||||||
defaultValues={fields ?? undefined}
|
|
||||||
onBack={handleBackToConfig}
|
|
||||||
onSubmit={handleConfigureFieldsSubmit}
|
|
||||||
/>
|
|
||||||
</Stepper>
|
|
||||||
</ConfigureDocumentProvider>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@ -1,175 +0,0 @@
|
|||||||
import { useLayoutEffect, useState } from 'react';
|
|
||||||
|
|
||||||
import { useLingui } from '@lingui/react';
|
|
||||||
import { useNavigate } from 'react-router';
|
|
||||||
|
|
||||||
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
|
||||||
import { trpc } from '@documenso/trpc/react';
|
|
||||||
import { Stepper } from '@documenso/ui/primitives/stepper';
|
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
||||||
|
|
||||||
import { ConfigureDocumentProvider } from '~/components/embed/authoring/configure-document-context';
|
|
||||||
import { ConfigureDocumentView } from '~/components/embed/authoring/configure-document-view';
|
|
||||||
import type { TConfigureEmbedFormSchema } from '~/components/embed/authoring/configure-document-view.types';
|
|
||||||
import {
|
|
||||||
ConfigureFieldsView,
|
|
||||||
type TConfigureFieldsFormSchema,
|
|
||||||
} from '~/components/embed/authoring/configure-fields-view';
|
|
||||||
import {
|
|
||||||
type TBaseEmbedAuthoringSchema,
|
|
||||||
ZBaseEmbedAuthoringSchema,
|
|
||||||
} from '~/types/embed-authoring-base-schema';
|
|
||||||
|
|
||||||
export default function EmbeddingAuthoringTemplateCreatePage() {
|
|
||||||
const { _ } = useLingui();
|
|
||||||
const { toast } = useToast();
|
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
const [configuration, setConfiguration] = useState<TConfigureEmbedFormSchema | null>(null);
|
|
||||||
const [fields, setFields] = useState<TConfigureFieldsFormSchema | null>(null);
|
|
||||||
const [features, setFeatures] = useState<TBaseEmbedAuthoringSchema['features'] | null>(null);
|
|
||||||
const [externalId, setExternalId] = useState<string | null>(null);
|
|
||||||
const [currentStep, setCurrentStep] = useState(1);
|
|
||||||
|
|
||||||
const { mutateAsync: createEmbeddingTemplate } =
|
|
||||||
trpc.embeddingPresign.createEmbeddingTemplate.useMutation();
|
|
||||||
|
|
||||||
const handleConfigurePageViewSubmit = (data: TConfigureEmbedFormSchema) => {
|
|
||||||
// Store the configuration data and move to the field placement stage
|
|
||||||
setConfiguration(data);
|
|
||||||
setCurrentStep(2);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleBackToConfig = (data: TConfigureFieldsFormSchema) => {
|
|
||||||
// Return to the configuration view but keep the data
|
|
||||||
setFields(data);
|
|
||||||
setCurrentStep(1);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleConfigureFieldsSubmit = async (data: TConfigureFieldsFormSchema) => {
|
|
||||||
try {
|
|
||||||
console.log('configuration', configuration);
|
|
||||||
console.log('data', data);
|
|
||||||
if (!configuration || !configuration.documentData) {
|
|
||||||
toast({
|
|
||||||
variant: 'destructive',
|
|
||||||
title: _('Error'),
|
|
||||||
description: _('Please configure the template first'),
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fields = data.fields;
|
|
||||||
|
|
||||||
const documentData = await putPdfFile({
|
|
||||||
arrayBuffer: async () => Promise.resolve(configuration.documentData!.data.buffer),
|
|
||||||
name: configuration.documentData.name,
|
|
||||||
type: configuration.documentData.type,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Use the externalId from the URL fragment if available
|
|
||||||
const metaWithExternalId = {
|
|
||||||
...configuration.meta,
|
|
||||||
externalId: externalId || configuration.meta.externalId,
|
|
||||||
};
|
|
||||||
|
|
||||||
const createResult = await createEmbeddingTemplate({
|
|
||||||
title: configuration.title,
|
|
||||||
documentDataId: documentData.id,
|
|
||||||
meta: metaWithExternalId,
|
|
||||||
recipients: configuration.signers.map((signer) => ({
|
|
||||||
name: signer.name,
|
|
||||||
email: signer.email,
|
|
||||||
role: signer.role,
|
|
||||||
fields: fields
|
|
||||||
.filter((field) => field.signerEmail === signer.email)
|
|
||||||
// There's a gnarly discriminated union that makes this hard to satisfy, we're casting for the second
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
.map<any>((field) => ({
|
|
||||||
...field,
|
|
||||||
pageX: field.pageX,
|
|
||||||
pageY: field.pageY,
|
|
||||||
width: field.pageWidth,
|
|
||||||
height: field.pageHeight,
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
});
|
|
||||||
|
|
||||||
toast({
|
|
||||||
title: _('Success'),
|
|
||||||
description: _('Template created successfully'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Send a message to the parent window with the template details
|
|
||||||
if (window.parent !== window) {
|
|
||||||
window.parent.postMessage(
|
|
||||||
{
|
|
||||||
type: 'template-created',
|
|
||||||
templateId: createResult.templateId,
|
|
||||||
externalId: metaWithExternalId.externalId,
|
|
||||||
},
|
|
||||||
'*',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const hash = window.location.hash.slice(1);
|
|
||||||
|
|
||||||
// Navigate to the completion page instead of the template details page
|
|
||||||
await navigate(
|
|
||||||
`/embed/v1/authoring/create-completed?templateId=${createResult.templateId}&externalId=${metaWithExternalId.externalId}#${hash}`,
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error creating template:', err);
|
|
||||||
|
|
||||||
toast({
|
|
||||||
variant: 'destructive',
|
|
||||||
title: _('Error'),
|
|
||||||
description: _('Failed to create template'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
try {
|
|
||||||
const hash = window.location.hash.slice(1);
|
|
||||||
|
|
||||||
const result = ZBaseEmbedAuthoringSchema.safeParse(
|
|
||||||
JSON.parse(decodeURIComponent(atob(hash))),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!result.success) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setFeatures(result.data.features);
|
|
||||||
|
|
||||||
// Extract externalId from the parsed data if available
|
|
||||||
if (result.data.externalId) {
|
|
||||||
setExternalId(result.data.externalId);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error parsing embedding params:', err);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="relative mx-auto flex min-h-[100dvh] max-w-screen-lg p-6">
|
|
||||||
<ConfigureDocumentProvider isTemplate={true} features={features ?? {}}>
|
|
||||||
<Stepper currentStep={currentStep} setCurrentStep={setCurrentStep}>
|
|
||||||
<ConfigureDocumentView
|
|
||||||
defaultValues={configuration ?? undefined}
|
|
||||||
onSubmit={handleConfigurePageViewSubmit}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ConfigureFieldsView
|
|
||||||
configData={configuration!}
|
|
||||||
defaultValues={fields ?? undefined}
|
|
||||||
onBack={handleBackToConfig}
|
|
||||||
onSubmit={handleConfigureFieldsSubmit}
|
|
||||||
/>
|
|
||||||
</Stepper>
|
|
||||||
</ConfigureDocumentProvider>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@ -12,7 +12,6 @@ const themeSessionStorage = createCookieSessionStorage({
|
|||||||
secrets: ['insecure-secret-do-not-care'],
|
secrets: ['insecure-secret-do-not-care'],
|
||||||
secure: useSecureCookies,
|
secure: useSecureCookies,
|
||||||
domain: getCookieDomain(),
|
domain: getCookieDomain(),
|
||||||
maxAge: 60 * 60 * 24 * 365,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { ZBaseEmbedDataSchema } from './embed-base-schemas';
|
|
||||||
|
|
||||||
export const ZBaseEmbedAuthoringSchema = z
|
|
||||||
.object({
|
|
||||||
token: z.string(),
|
|
||||||
externalId: z.string().optional(),
|
|
||||||
features: z
|
|
||||||
.object({
|
|
||||||
allowConfigureSignatureTypes: z.boolean().optional(),
|
|
||||||
allowConfigureLanguage: z.boolean().optional(),
|
|
||||||
allowConfigureDateFormat: z.boolean().optional(),
|
|
||||||
allowConfigureTimezone: z.boolean().optional(),
|
|
||||||
allowConfigureRedirectUrl: z.boolean().optional(),
|
|
||||||
allowConfigureCommunication: z.boolean().optional(),
|
|
||||||
})
|
|
||||||
.optional()
|
|
||||||
.default({}),
|
|
||||||
})
|
|
||||||
.and(ZBaseEmbedDataSchema);
|
|
||||||
|
|
||||||
export type TBaseEmbedAuthoringSchema = z.infer<typeof ZBaseEmbedAuthoringSchema>;
|
|
||||||
@ -14,5 +14,4 @@ export const ZSignDocumentEmbedDataSchema = ZBaseEmbedDataSchema.extend({
|
|||||||
.transform((value) => value || undefined),
|
.transform((value) => value || undefined),
|
||||||
lockName: z.boolean().optional().default(false),
|
lockName: z.boolean().optional().default(false),
|
||||||
allowDocumentRejection: z.boolean().optional(),
|
allowDocumentRejection: z.boolean().optional(),
|
||||||
showOtherRecipientsCompletedFields: z.boolean().optional(),
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -99,6 +99,5 @@
|
|||||||
"vite": "^6.1.0",
|
"vite": "^6.1.0",
|
||||||
"vite-plugin-babel-macros": "^1.0.6",
|
"vite-plugin-babel-macros": "^1.0.6",
|
||||||
"vite-tsconfig-paths": "^5.1.4"
|
"vite-tsconfig-paths": "^5.1.4"
|
||||||
},
|
}
|
||||||
"version": "1.10.0-rc.5"
|
|
||||||
}
|
}
|
||||||
@ -2,7 +2,6 @@ import { lingui } from '@lingui/vite-plugin';
|
|||||||
import { reactRouter } from '@react-router/dev/vite';
|
import { reactRouter } from '@react-router/dev/vite';
|
||||||
import autoprefixer from 'autoprefixer';
|
import autoprefixer from 'autoprefixer';
|
||||||
import serverAdapter from 'hono-react-router-adapter/vite';
|
import serverAdapter from 'hono-react-router-adapter/vite';
|
||||||
import path from 'node:path';
|
|
||||||
import tailwindcss from 'tailwindcss';
|
import tailwindcss from 'tailwindcss';
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import macrosPlugin from 'vite-plugin-babel-macros';
|
import macrosPlugin from 'vite-plugin-babel-macros';
|
||||||
@ -45,15 +44,9 @@ export default defineConfig({
|
|||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
https: 'node:https',
|
https: 'node:https',
|
||||||
'.prisma/client/default': path.resolve(
|
'.prisma/client/default': '../../node_modules/.prisma/client/default.js',
|
||||||
__dirname,
|
'.prisma/client/index-browser': '../../node_modules/.prisma/client/index-browser.js',
|
||||||
'../../node_modules/.prisma/client/default.js',
|
canvas: './app/types/empty-module.ts',
|
||||||
),
|
|
||||||
'.prisma/client/index-browser': path.resolve(
|
|
||||||
__dirname,
|
|
||||||
'../../node_modules/.prisma/client/index-browser.js',
|
|
||||||
),
|
|
||||||
canvas: path.resolve(__dirname, './app/types/empty-module.ts'),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user