Files
sign/apps/web/src/app/(dashboard)/templates/delete-template-dialog.tsx

89 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-10-06 22:54:24 +00:00
import { useRouter } from 'next/navigation';
import { trpc as trpcReact } from '@documenso/trpc/react';
import { Button } from '@documenso/ui/primitives/button';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@documenso/ui/primitives/dialog';
import { useToast } from '@documenso/ui/primitives/use-toast';
type DeleteTemplateDialogProps = {
id: number;
feat: add more template API endpoints (#1198) ## Description Update the API endpoint to support more actions for templates ## Changes Made Add the following endpoints for templates: - Get template - Get templates - Delete template Get template(s) returns associated recipients and fields. UI: - Updated template delete button to have the destructive delete variant ## Testing Performed Tested endpoints via /api/v1/openapi Tested deleting templates via UI manually ## Test data <details> <summary>Delete template response</summary> ```json { "id": 32, "type": "PRIVATE", "title": "documenso-supporter-pledge.pdf", "userId": 3, "teamId": null, "templateDocumentDataId": "clxva9b4h0001rrh7v0wdw97h", "createdAt": "2024-06-26T03:35:45.065Z", "updatedAt": "2024-06-26T03:35:45.065Z" } ``` </details> <details> <summary>Get template response</summary> ```json { "id": 28, "type": "PRIVATE", "title": "blank_long.pdf", "userId": 3, "teamId": null, "templateDocumentDataId": "clxu4vyty0003rrr52ue5ee4d", "createdAt": "2024-06-25T08:17:38.418Z", "updatedAt": "2024-06-26T03:36:33.890Z", "templateMeta": { "id": "clxvaacte0004rrh7s2k910nw", "subject": "", "message": "", "timezone": "Australia/Melbourne", "dateFormat": "yyyy-MM-dd hh:mm a", "templateId": 28, "redirectUrl": "" }, "directLink": { "token": "tBJHVFR75sC8m6hPfBTZd", "enabled": true }, "templateDocumentData": { "id": "clxu4vyty0003rrr52ue5ee4d", "type": "BYTES_64", "data": "<PDF DATA>" }, "Field": [ { "id": 327, "recipientId": 357, "type": "SIGNATURE", "page": 1, "positionX": "55.8431952662722", "positionY": "21.39588100686499", "width": "29.58579881656805", "height": "6.864988558352403" }, { "id": 328, "recipientId": 357, "type": "EMAIL", "page": 1, "positionX": "28.03254437869823", "positionY": "72.99771167048056", "width": "29.58579881656805", "height": "6.864988558352403" } ], "Recipient": [ { "id": 357, "email": "direct.link@documenso.com", "name": "Direct link recipient", "authOptions": { "accessAuth": null, "actionAuth": null }, "role": "SIGNER" }, { "id": 359, "email": "example@documenso.com", "name": "Example User", "authOptions": { "accessAuth": null, "actionAuth": null }, "role": "SIGNER" } ] } ``` </details> <details> <summary>Get templates response</summary> ```json { "templates": [ { "id": 33, "type": "PRIVATE", "title": "documenso-supporter-pledge.pdf", "userId": 3, "teamId": null, "templateDocumentDataId": "clxva9oaj0003rrh7hwdyg60o", "createdAt": "2024-06-26T03:36:02.130Z", "updatedAt": "2024-06-26T03:36:02.130Z", "directLink": null, "Field": [], "Recipient": [] }, { "id": 28, "type": "PRIVATE", "title": "blank_long.pdf", "userId": 3, "teamId": null, "templateDocumentDataId": "clxu4vyty0003rrr52ue5ee4d", "createdAt": "2024-06-25T08:17:38.418Z", "updatedAt": "2024-06-26T03:36:33.890Z", "directLink": { "token": "tBJHVFR75sC8m6hPfBTZd", "enabled": true }, "Field": [ { "id": 327, "recipientId": 357, "type": "SIGNATURE", "page": 1, "positionX": "55.8431952662722", "positionY": "21.39588100686499", "width": "29.58579881656805", "height": "6.864988558352403" }, { "id": 328, "recipientId": 357, "type": "EMAIL", "page": 1, "positionX": "28.03254437869823", "positionY": "72.99771167048056", "width": "29.58579881656805", "height": "6.864988558352403" } ], "Recipient": [ { "id": 357, "email": "direct.link@documenso.com", "name": "Direct link recipient", "authOptions": { "accessAuth": null, "actionAuth": null }, "role": "SIGNER" }, { "id": 359, "email": "example@documenso.com", "name": "Example User", "authOptions": { "accessAuth": null, "actionAuth": null }, "role": "SIGNER" } ] } ], "totalPages": 2 } ``` </details> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for team-based template deletion in the dashboard. - Enhanced API to manage templates, including fetching and deleting templates by team ID. - **Bug Fixes** - Improved error handling for template operations, ensuring better feedback when templates are not found. - **Refactor** - Updated various components and functions to include `teamId` for more robust template management. - **Documentation** - Expanded schema definitions to detail new structures for template and team interactions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-06-27 15:44:16 +10:00
teamId?: number;
2023-10-06 22:54:24 +00:00
open: boolean;
onOpenChange: (_open: boolean) => void;
};
feat: add more template API endpoints (#1198) ## Description Update the API endpoint to support more actions for templates ## Changes Made Add the following endpoints for templates: - Get template - Get templates - Delete template Get template(s) returns associated recipients and fields. UI: - Updated template delete button to have the destructive delete variant ## Testing Performed Tested endpoints via /api/v1/openapi Tested deleting templates via UI manually ## Test data <details> <summary>Delete template response</summary> ```json { "id": 32, "type": "PRIVATE", "title": "documenso-supporter-pledge.pdf", "userId": 3, "teamId": null, "templateDocumentDataId": "clxva9b4h0001rrh7v0wdw97h", "createdAt": "2024-06-26T03:35:45.065Z", "updatedAt": "2024-06-26T03:35:45.065Z" } ``` </details> <details> <summary>Get template response</summary> ```json { "id": 28, "type": "PRIVATE", "title": "blank_long.pdf", "userId": 3, "teamId": null, "templateDocumentDataId": "clxu4vyty0003rrr52ue5ee4d", "createdAt": "2024-06-25T08:17:38.418Z", "updatedAt": "2024-06-26T03:36:33.890Z", "templateMeta": { "id": "clxvaacte0004rrh7s2k910nw", "subject": "", "message": "", "timezone": "Australia/Melbourne", "dateFormat": "yyyy-MM-dd hh:mm a", "templateId": 28, "redirectUrl": "" }, "directLink": { "token": "tBJHVFR75sC8m6hPfBTZd", "enabled": true }, "templateDocumentData": { "id": "clxu4vyty0003rrr52ue5ee4d", "type": "BYTES_64", "data": "<PDF DATA>" }, "Field": [ { "id": 327, "recipientId": 357, "type": "SIGNATURE", "page": 1, "positionX": "55.8431952662722", "positionY": "21.39588100686499", "width": "29.58579881656805", "height": "6.864988558352403" }, { "id": 328, "recipientId": 357, "type": "EMAIL", "page": 1, "positionX": "28.03254437869823", "positionY": "72.99771167048056", "width": "29.58579881656805", "height": "6.864988558352403" } ], "Recipient": [ { "id": 357, "email": "direct.link@documenso.com", "name": "Direct link recipient", "authOptions": { "accessAuth": null, "actionAuth": null }, "role": "SIGNER" }, { "id": 359, "email": "example@documenso.com", "name": "Example User", "authOptions": { "accessAuth": null, "actionAuth": null }, "role": "SIGNER" } ] } ``` </details> <details> <summary>Get templates response</summary> ```json { "templates": [ { "id": 33, "type": "PRIVATE", "title": "documenso-supporter-pledge.pdf", "userId": 3, "teamId": null, "templateDocumentDataId": "clxva9oaj0003rrh7hwdyg60o", "createdAt": "2024-06-26T03:36:02.130Z", "updatedAt": "2024-06-26T03:36:02.130Z", "directLink": null, "Field": [], "Recipient": [] }, { "id": 28, "type": "PRIVATE", "title": "blank_long.pdf", "userId": 3, "teamId": null, "templateDocumentDataId": "clxu4vyty0003rrr52ue5ee4d", "createdAt": "2024-06-25T08:17:38.418Z", "updatedAt": "2024-06-26T03:36:33.890Z", "directLink": { "token": "tBJHVFR75sC8m6hPfBTZd", "enabled": true }, "Field": [ { "id": 327, "recipientId": 357, "type": "SIGNATURE", "page": 1, "positionX": "55.8431952662722", "positionY": "21.39588100686499", "width": "29.58579881656805", "height": "6.864988558352403" }, { "id": 328, "recipientId": 357, "type": "EMAIL", "page": 1, "positionX": "28.03254437869823", "positionY": "72.99771167048056", "width": "29.58579881656805", "height": "6.864988558352403" } ], "Recipient": [ { "id": 357, "email": "direct.link@documenso.com", "name": "Direct link recipient", "authOptions": { "accessAuth": null, "actionAuth": null }, "role": "SIGNER" }, { "id": 359, "email": "example@documenso.com", "name": "Example User", "authOptions": { "accessAuth": null, "actionAuth": null }, "role": "SIGNER" } ] } ], "totalPages": 2 } ``` </details> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for team-based template deletion in the dashboard. - Enhanced API to manage templates, including fetching and deleting templates by team ID. - **Bug Fixes** - Improved error handling for template operations, ensuring better feedback when templates are not found. - **Refactor** - Updated various components and functions to include `teamId` for more robust template management. - **Documentation** - Expanded schema definitions to detail new structures for template and team interactions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-06-27 15:44:16 +10:00
export const DeleteTemplateDialog = ({
id,
teamId,
open,
onOpenChange,
}: DeleteTemplateDialogProps) => {
2023-10-06 22:54:24 +00:00
const router = useRouter();
const { toast } = useToast();
2023-12-21 20:42:45 +11:00
const { mutateAsync: deleteTemplate, isLoading } = trpcReact.template.deleteTemplate.useMutation({
2023-10-06 22:54:24 +00:00
onSuccess: () => {
router.refresh();
toast({
title: 'Template deleted',
2023-12-21 20:42:45 +11:00
description: 'Your template has been successfully deleted.',
2023-10-06 22:54:24 +00:00
duration: 5000,
});
onOpenChange(false);
},
2024-02-08 12:33:20 +11:00
onError: () => {
2023-10-06 22:54:24 +00:00
toast({
title: 'Something went wrong',
description: 'This template could not be deleted at this time. Please try again.',
variant: 'destructive',
duration: 7500,
});
2024-02-08 12:33:20 +11:00
},
});
2023-10-06 22:54:24 +00:00
return (
<Dialog open={open} onOpenChange={(value) => !isLoading && onOpenChange(value)}>
<DialogContent>
<DialogHeader>
<DialogTitle>Do you want to delete this template?</DialogTitle>
<DialogDescription>
Please note that this action is irreversible. Once confirmed, your template will be
permanently deleted.
</DialogDescription>
</DialogHeader>
<DialogFooter>
2024-02-08 12:33:20 +11:00
<Button
type="button"
variant="secondary"
disabled={isLoading}
onClick={() => onOpenChange(false)}
>
Cancel
</Button>
2023-10-06 22:54:24 +00:00
feat: add more template API endpoints (#1198) ## Description Update the API endpoint to support more actions for templates ## Changes Made Add the following endpoints for templates: - Get template - Get templates - Delete template Get template(s) returns associated recipients and fields. UI: - Updated template delete button to have the destructive delete variant ## Testing Performed Tested endpoints via /api/v1/openapi Tested deleting templates via UI manually ## Test data <details> <summary>Delete template response</summary> ```json { "id": 32, "type": "PRIVATE", "title": "documenso-supporter-pledge.pdf", "userId": 3, "teamId": null, "templateDocumentDataId": "clxva9b4h0001rrh7v0wdw97h", "createdAt": "2024-06-26T03:35:45.065Z", "updatedAt": "2024-06-26T03:35:45.065Z" } ``` </details> <details> <summary>Get template response</summary> ```json { "id": 28, "type": "PRIVATE", "title": "blank_long.pdf", "userId": 3, "teamId": null, "templateDocumentDataId": "clxu4vyty0003rrr52ue5ee4d", "createdAt": "2024-06-25T08:17:38.418Z", "updatedAt": "2024-06-26T03:36:33.890Z", "templateMeta": { "id": "clxvaacte0004rrh7s2k910nw", "subject": "", "message": "", "timezone": "Australia/Melbourne", "dateFormat": "yyyy-MM-dd hh:mm a", "templateId": 28, "redirectUrl": "" }, "directLink": { "token": "tBJHVFR75sC8m6hPfBTZd", "enabled": true }, "templateDocumentData": { "id": "clxu4vyty0003rrr52ue5ee4d", "type": "BYTES_64", "data": "<PDF DATA>" }, "Field": [ { "id": 327, "recipientId": 357, "type": "SIGNATURE", "page": 1, "positionX": "55.8431952662722", "positionY": "21.39588100686499", "width": "29.58579881656805", "height": "6.864988558352403" }, { "id": 328, "recipientId": 357, "type": "EMAIL", "page": 1, "positionX": "28.03254437869823", "positionY": "72.99771167048056", "width": "29.58579881656805", "height": "6.864988558352403" } ], "Recipient": [ { "id": 357, "email": "direct.link@documenso.com", "name": "Direct link recipient", "authOptions": { "accessAuth": null, "actionAuth": null }, "role": "SIGNER" }, { "id": 359, "email": "example@documenso.com", "name": "Example User", "authOptions": { "accessAuth": null, "actionAuth": null }, "role": "SIGNER" } ] } ``` </details> <details> <summary>Get templates response</summary> ```json { "templates": [ { "id": 33, "type": "PRIVATE", "title": "documenso-supporter-pledge.pdf", "userId": 3, "teamId": null, "templateDocumentDataId": "clxva9oaj0003rrh7hwdyg60o", "createdAt": "2024-06-26T03:36:02.130Z", "updatedAt": "2024-06-26T03:36:02.130Z", "directLink": null, "Field": [], "Recipient": [] }, { "id": 28, "type": "PRIVATE", "title": "blank_long.pdf", "userId": 3, "teamId": null, "templateDocumentDataId": "clxu4vyty0003rrr52ue5ee4d", "createdAt": "2024-06-25T08:17:38.418Z", "updatedAt": "2024-06-26T03:36:33.890Z", "directLink": { "token": "tBJHVFR75sC8m6hPfBTZd", "enabled": true }, "Field": [ { "id": 327, "recipientId": 357, "type": "SIGNATURE", "page": 1, "positionX": "55.8431952662722", "positionY": "21.39588100686499", "width": "29.58579881656805", "height": "6.864988558352403" }, { "id": 328, "recipientId": 357, "type": "EMAIL", "page": 1, "positionX": "28.03254437869823", "positionY": "72.99771167048056", "width": "29.58579881656805", "height": "6.864988558352403" } ], "Recipient": [ { "id": 357, "email": "direct.link@documenso.com", "name": "Direct link recipient", "authOptions": { "accessAuth": null, "actionAuth": null }, "role": "SIGNER" }, { "id": 359, "email": "example@documenso.com", "name": "Example User", "authOptions": { "accessAuth": null, "actionAuth": null }, "role": "SIGNER" } ] } ], "totalPages": 2 } ``` </details> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for team-based template deletion in the dashboard. - Enhanced API to manage templates, including fetching and deleting templates by team ID. - **Bug Fixes** - Improved error handling for template operations, ensuring better feedback when templates are not found. - **Refactor** - Updated various components and functions to include `teamId` for more robust template management. - **Documentation** - Expanded schema definitions to detail new structures for template and team interactions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-06-27 15:44:16 +10:00
<Button
type="button"
variant="destructive"
loading={isLoading}
onClick={async () => deleteTemplate({ id, teamId })}
>
2024-02-08 12:33:20 +11:00
Delete
</Button>
2023-10-06 22:54:24 +00:00
</DialogFooter>
</DialogContent>
</Dialog>
);
};