import { Trans } from '@lingui/react/macro'; import { ChevronLeft } from 'lucide-react'; import { Link, redirect } from 'react-router'; import { getSession } from '@documenso/auth/server/lib/utils/get-session'; import { isUserEnterprise } from '@documenso/ee/server-only/util/is-document-enterprise'; 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 { formatTemplatesPath } from '@documenso/lib/utils/teams'; import { LegacyFieldWarningPopover } from '~/components/general/legacy-field-warning-popover'; import { TemplateDirectLinkBadge } from '~/components/general/template/template-direct-link-badge'; import { TemplateEditForm } from '~/components/general/template/template-edit-form'; import { TemplateType } from '~/components/general/template/template-type'; import { superLoaderJson, useSuperLoaderData } from '~/utils/super-json-loader'; import { TemplateDirectLinkDialogWrapper } from '../../components/dialogs/template-direct-link-dialog-wrapper'; import type { Route } from './+types/templates.$id.edit'; 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); 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) { throw redirect(templateRootPath); } if (template.folderId) { throw redirect(`${templateRootPath}/f/${template.folderId}/${templateId}/edit`); } const isTemplateEnterprise = await isUserEnterprise({ userId: user.id, teamId: team?.id, }); return superLoaderJson({ template: { ...template, folder: null, }, isTemplateEnterprise, templateRootPath, }); } export default function TemplateEditPage() { const { template, isTemplateEnterprise, templateRootPath } = useSuperLoaderData(); return (
Template

{template.title}

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