import { Trans } from '@lingui/react/macro'; import { DocumentSigningOrder, SigningStatus } from '@prisma/client'; import { ChevronLeft, LucideEdit } from 'lucide-react'; import { Link, redirect, useNavigate } from 'react-router'; import { getSession } from '@documenso/auth/server/lib/utils/get-session'; import { type TGetTeamByUrlResponse, getTeamByUrl } from '@documenso/lib/server-only/team/get-team'; import { getTemplateById } from '@documenso/lib/server-only/template/get-template-by-id'; import { formatDocumentsPath, formatTemplatesPath } from '@documenso/lib/utils/teams'; import { DocumentReadOnlyFields } from '@documenso/ui/components/document/document-read-only-fields'; import { Button } from '@documenso/ui/primitives/button'; import { Card, CardContent } from '@documenso/ui/primitives/card'; import { PDFViewer } from '@documenso/ui/primitives/pdf-viewer'; import { TemplateBulkSendDialog } from '~/components/dialogs/template-bulk-send-dialog'; import { TemplateDirectLinkDialogWrapper } from '~/components/dialogs/template-direct-link-dialog-wrapper'; import { TemplateUseDialog } from '~/components/dialogs/template-use-dialog'; import { TemplateDirectLinkBadge } from '~/components/general/template/template-direct-link-badge'; import { TemplatePageViewDocumentsTable } from '~/components/general/template/template-page-view-documents-table'; import { TemplatePageViewInformation } from '~/components/general/template/template-page-view-information'; import { TemplatePageViewRecentActivity } from '~/components/general/template/template-page-view-recent-activity'; import { TemplatePageViewRecipients } from '~/components/general/template/template-page-view-recipients'; import { TemplateType } from '~/components/general/template/template-type'; import { TemplatesTableActionDropdown } from '~/components/tables/templates-table-action-dropdown'; import { superLoaderJson, useSuperLoaderData } from '~/utils/super-json-loader'; import type { Route } from './+types/templates.$id._index'; export async function loader({ params, request }: Route.LoaderArgs) { const { user } = await getSession(request); let team: TGetTeamByUrlResponse | null = null; if (params.teamUrl) { team = await getTeamByUrl({ userId: user.id, teamUrl: params.teamUrl }); } const { id } = params; const templateId = Number(id); const templateRootPath = formatTemplatesPath(team?.url); const documentRootPath = formatDocumentsPath(team?.url); if (!templateId || Number.isNaN(templateId)) { throw redirect(templateRootPath); } const template = await getTemplateById({ id: templateId, userId: user.id, teamId: team?.id, }).catch(() => null); if (!template || !template.templateDocumentData || (template?.teamId && !team?.url)) { throw redirect(templateRootPath); } return superLoaderJson({ user, team, template, templateRootPath, documentRootPath, }); } export default function TemplatePage() { const { user, team, template, templateRootPath, documentRootPath } = useSuperLoaderData(); const { templateDocumentData, fields, recipients, templateMeta } = template; const navigate = useNavigate(); // Remap to fit the DocumentReadOnlyFields component. const readOnlyFields = fields.map((field) => { const recipient = recipients.find((recipient) => recipient.id === field.recipientId) || { name: '', email: '', signingStatus: SigningStatus.NOT_SIGNED, }; return { ...field, recipient, signature: null, }; }); const mockedDocumentMeta = templateMeta ? { ...templateMeta, signingOrder: templateMeta.signingOrder || DocumentSigningOrder.SEQUENTIAL, documentId: 0, } : undefined; return (
Templates

{template.title}

{template.directLink?.token && ( )}

Template

navigate(templateRootPath)} onMove={async ({ teamUrl, templateId }) => navigate(`${formatTemplatesPath(teamUrl)}/${templateId}`) } />

Manage and view template

Use } />
{/* Template information section. */} {/* Recipients section. */} {/* Recent activity section. */}

Documents created from template

); }