From c2cf25b13835fe8260444a34c0337d8d775343eb Mon Sep 17 00:00:00 2001 From: Lucas Smith Date: Mon, 11 Mar 2024 01:46:19 +0000 Subject: [PATCH] fix: templates incorrectly linking when in a team --- .../templates/data-table-templates.tsx | 6 +++++- .../(dashboard)/templates/data-table-title.tsx | 18 +++++++++++++++--- .../lib/server-only/template/find-templates.ts | 6 ++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/apps/web/src/app/(dashboard)/templates/data-table-templates.tsx b/apps/web/src/app/(dashboard)/templates/data-table-templates.tsx index e878d8df2..cb00ef6f6 100644 --- a/apps/web/src/app/(dashboard)/templates/data-table-templates.tsx +++ b/apps/web/src/app/(dashboard)/templates/data-table-templates.tsx @@ -25,7 +25,11 @@ type TemplateWithRecipient = Template & { }; type TemplatesDataTableProps = { - templates: TemplateWithRecipient[]; + templates: Array< + TemplateWithRecipient & { + team: { id: number; url: string } | null; + } + >; perPage: number; page: number; totalPages: number; diff --git a/apps/web/src/app/(dashboard)/templates/data-table-title.tsx b/apps/web/src/app/(dashboard)/templates/data-table-title.tsx index 31e1011be..69855ca1e 100644 --- a/apps/web/src/app/(dashboard)/templates/data-table-title.tsx +++ b/apps/web/src/app/(dashboard)/templates/data-table-title.tsx @@ -1,23 +1,35 @@ +'use client'; + import Link from 'next/link'; import { useSession } from 'next-auth/react'; -import { Template } from '@documenso/prisma/client'; +import { formatTemplatesPath } from '@documenso/lib/utils/teams'; +import type { Template } from '@documenso/prisma/client'; + +import { useOptionalCurrentTeam } from '~/providers/team'; export type DataTableTitleProps = { - row: Template; + row: Template & { + team: { id: number; url: string } | null; + }; }; export const DataTableTitle = ({ row }: DataTableTitleProps) => { const { data: session } = useSession(); + const team = useOptionalCurrentTeam(); if (!session) { return null; } + const isCurrentTeamTemplate = team?.url && row.team?.url === team?.url; + + const templatesPath = formatTemplatesPath(isCurrentTeamTemplate ? team?.url : undefined); + return ( {row.title} diff --git a/packages/lib/server-only/template/find-templates.ts b/packages/lib/server-only/template/find-templates.ts index 69b43f9b9..9252d32ea 100644 --- a/packages/lib/server-only/template/find-templates.ts +++ b/packages/lib/server-only/template/find-templates.ts @@ -37,6 +37,12 @@ export const findTemplates = async ({ where: whereFilter, include: { templateDocumentData: true, + team: { + select: { + id: true, + url: true, + }, + }, Field: true, Recipient: true, },