From 8fe67e167cef22614f4e678f0096cd58cb6ff1f3 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Wed, 17 Apr 2024 19:13:54 +0700 Subject: [PATCH] fix: duplicate templates (#1104) ## Description Fix the issue where duplicate templates can be created ## Changes Made - Prevent duplicate templates by correctly disabling elements - Clear the PDF when the form is reset - General UI changes to new template dialog for consistency - Add description for new template dialog - Add close button for new template dialog ## Testing Performed Manual testing ## Checklist - [X] I have tested these changes locally and they work as expected. - [X] I have followed the project's coding style guidelines. ## Summary by CodeRabbit - **New Features** - Introduced new components in the template creation dialog for better usability: `DialogClose`, `DialogDescription`, and `DialogFooter`. - Enhanced file upload handling and display. - Added a cancel button and a create template button to the dialog footer for improved navigation. - **Refactor** - Updated the dialog content and form layout for a more intuitive user experience. - Refactored form structure and labels for clarity. - **Removed Features** - Removed the `Label` component from the dialog. --- .../templates/new-template-dialog.tsx | 111 ++++++++++-------- 1 file changed, 59 insertions(+), 52 deletions(-) diff --git a/apps/web/src/app/(dashboard)/templates/new-template-dialog.tsx b/apps/web/src/app/(dashboard)/templates/new-template-dialog.tsx index 37d60f946..ab05ac3dc 100644 --- a/apps/web/src/app/(dashboard)/templates/new-template-dialog.tsx +++ b/apps/web/src/app/(dashboard)/templates/new-template-dialog.tsx @@ -18,7 +18,10 @@ import { Button } from '@documenso/ui/primitives/button'; import { Card, CardContent } from '@documenso/ui/primitives/card'; import { Dialog, + DialogClose, DialogContent, + DialogDescription, + DialogFooter, DialogHeader, DialogTitle, DialogTrigger, @@ -34,7 +37,6 @@ import { FormMessage, } from '@documenso/ui/primitives/form/form'; import { Input } from '@documenso/ui/primitives/input'; -import { Label } from '@documenso/ui/primitives/label'; import { useToast } from '@documenso/ui/primitives/use-toast'; const ZCreateTemplateFormSchema = z.object({ @@ -61,8 +63,7 @@ export const NewTemplateDialog = ({ teamId, templateRootPath }: NewTemplateDialo resolver: zodResolver(ZCreateTemplateFormSchema), }); - const { mutateAsync: createTemplate, isLoading: isCreatingTemplate } = - trpc.template.createTemplate.useMutation(); + const { mutateAsync: createTemplate } = trpc.template.createTemplate.useMutation(); const [showNewTemplateDialog, setShowNewTemplateDialog] = useState(false); const [uploadedFile, setUploadedFile] = useState<{ file: File; fileBase64: string } | null>(); @@ -140,6 +141,7 @@ export const NewTemplateDialog = ({ teamId, templateRootPath }: NewTemplateDialo useEffect(() => { if (!showNewTemplateDialog) { form.reset(); + setUploadedFile(null); } }, [form, showNewTemplateDialog]); @@ -154,20 +156,23 @@ export const NewTemplateDialog = ({ teamId, templateRootPath }: NewTemplateDialo - New Template + New Template + + Templates allow you to quickly generate documents with pre-filled recipients and fields. + -
-
- + + +
( - Name your template + Template name - + @@ -180,55 +185,57 @@ export const NewTemplateDialog = ({ teamId, templateRootPath }: NewTemplateDialo )} /> -
- +
+ {uploadedFile ? ( + + + -
- {uploadedFile ? ( - - - +
+
+
+
+
-
-
-
-
-
+

+ Uploaded Document +

-

- Uploaded Document -

- - - {uploadedFile.file.name} - - - - ) : ( - - )} -
+ + {uploadedFile.file.name} + + + + ) : ( + + )}
-
- + + + -
- - -
+ +
+ + );