From 861225b7c440b80a68a97a6124b89b9a583ad128 Mon Sep 17 00:00:00 2001 From: Ashraf Chowdury <87828904+ashrafchowdury@users.noreply.github.com> Date: Fri, 2 Feb 2024 12:48:42 +0800 Subject: [PATCH] fix: Prevent users from bypassing document limitations (#898) ## Description **Fixed document limitation bypassing issues through templates.** Previously, users could bypass document restrictions by utilizing templates even after reaching their limitations. This fix ensures that templates will no longer function as a workaround when users reach their document limits. ## Changes 1. imported `useLimits` hook on `data-table-templates.tsx` 2. Disabled the 'Use Template' button when the user reaches their limit. 3. Added an Alert Component on top of the templates page to notify users that they can't use templates anymore because they have reached their limit. 4. Used `getServerLimits` hook on `template-router` to a condition on the server. ## Example  ## Issue Closes #883 --- .../templates/data-table-templates.tsx | 22 +++++++++++++++++-- .../trpc/server/template-router/router.ts | 7 ++++++ 2 files changed, 27 insertions(+), 2 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 63d6888b1..7930dcd0e 100644 --- a/apps/web/src/app/(dashboard)/templates/data-table-templates.tsx +++ b/apps/web/src/app/(dashboard)/templates/data-table-templates.tsx @@ -2,13 +2,16 @@ import { useState, useTransition } from 'react'; +import Link from 'next/link'; import { useRouter } from 'next/navigation'; -import { Loader, Plus } from 'lucide-react'; +import { AlertTriangle, Loader, Plus } from 'lucide-react'; +import { useLimits } from '@documenso/ee/server-only/limits/provider/client'; import { useUpdateSearchParams } from '@documenso/lib/client-only/hooks/use-update-search-params'; import type { Template } from '@documenso/prisma/client'; import { trpc } from '@documenso/trpc/react'; +import { Alert, AlertDescription, AlertTitle } from '@documenso/ui/primitives/alert'; import { Button } from '@documenso/ui/primitives/button'; import { DataTable } from '@documenso/ui/primitives/data-table'; import { DataTablePagination } from '@documenso/ui/primitives/data-table-pagination'; @@ -36,6 +39,8 @@ export const TemplatesDataTable = ({ const [isPending, startTransition] = useTransition(); const updateSearchParams = useUpdateSearchParams(); + const { remaining } = useLimits(); + const router = useRouter(); const { toast } = useToast(); @@ -77,6 +82,19 @@ export const TemplatesDataTable = ({ return (