mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
fix: update email template and tidy code
This commit is contained in:
@ -26,23 +26,29 @@ export type SuperDeleteDocumentDialogProps = {
|
||||
};
|
||||
|
||||
export const SuperDeleteDocumentDialog = ({ document }: SuperDeleteDocumentDialogProps) => {
|
||||
const router = useRouter();
|
||||
const { toast } = useToast();
|
||||
const router = useRouter();
|
||||
|
||||
const [reason, setReason] = useState('');
|
||||
|
||||
const { mutateAsync: deleteDocument, isLoading: isDeletingDocument } =
|
||||
trpc.admin.deleteDocument.useMutation();
|
||||
|
||||
const handleDeleteDocument = async () => {
|
||||
try {
|
||||
if (reason) {
|
||||
await deleteDocument({ id: document.id, userId: document.userId, reason });
|
||||
toast({
|
||||
title: 'Document deleted',
|
||||
description: 'The Document has been deleted successfully.',
|
||||
duration: 5000,
|
||||
});
|
||||
router.push('/admin/documents');
|
||||
if (!reason) {
|
||||
return;
|
||||
}
|
||||
|
||||
await deleteDocument({ id: document.id, reason });
|
||||
|
||||
toast({
|
||||
title: 'Document deleted',
|
||||
description: 'The Document has been deleted successfully.',
|
||||
duration: 5000,
|
||||
});
|
||||
|
||||
router.push('/admin/documents');
|
||||
} catch (err) {
|
||||
if (err instanceof TRPCClientError && err.data?.code === 'BAD_REQUEST') {
|
||||
toast({
|
||||
|
||||
@ -17,14 +17,25 @@ export const TemplateDocumentDelete = ({
|
||||
<TemplateDocumentImage className="mt-6" assetBaseUrl={assetBaseUrl} />
|
||||
|
||||
<Section>
|
||||
<Text className="text-primary mx-auto mb-0 max-w-[80%] text-center text-lg font-semibold">
|
||||
<Text className="text-primary mb-0 mt-6 text-left text-lg font-semibold">
|
||||
Your document has been deleted by an admin!
|
||||
</Text>
|
||||
|
||||
<Text className="mx-auto mb-6 mt-1 text-left text-base text-slate-400">
|
||||
"{documentName}" has been deleted by an admin.
|
||||
</Text>
|
||||
|
||||
<Text className="mx-auto mb-6 mt-1 text-left text-base text-slate-400">
|
||||
This document can not be recovered, if you would like to dispute the reason for future
|
||||
documents please contact support.
|
||||
<br />"{documentName}"
|
||||
</Text>
|
||||
<Text className="text-primary mx-auto mb-0 max-w-[80%] text-center text-lg font-semibold">
|
||||
Reason
|
||||
<br />"{reason}"
|
||||
|
||||
<Text className="mx-auto mt-1 text-left text-base text-slate-400">
|
||||
The reason provided for deletion is the following:
|
||||
</Text>
|
||||
|
||||
<Text className="mx-auto mb-6 mt-1 text-left text-base italic text-slate-400">
|
||||
{reason}
|
||||
</Text>
|
||||
</Section>
|
||||
</>
|
||||
@ -4,17 +4,17 @@ import { Body, Container, Head, Hr, Html, Img, Preview, Section, Tailwind } from
|
||||
import {
|
||||
TemplateDocumentDelete,
|
||||
type TemplateDocumentDeleteProps,
|
||||
} from '../template-components/template-document-delete';
|
||||
} from '../template-components/template-document-super-delete';
|
||||
import { TemplateFooter } from '../template-components/template-footer';
|
||||
|
||||
export type DocumentDeleteEmailTemplateProps = Partial<TemplateDocumentDeleteProps>;
|
||||
|
||||
export const DocumentDeleteEmailTemplate = ({
|
||||
export const DocumentSuperDeleteEmailTemplate = ({
|
||||
documentName = 'Open Source Pledge.pdf',
|
||||
assetBaseUrl = 'http://localhost:3002',
|
||||
reason = 'Unknown',
|
||||
}: DocumentDeleteEmailTemplateProps) => {
|
||||
const previewText = `Admin has deleted your document ${documentName}.`;
|
||||
const previewText = `An admin has deleted your document "${documentName}".`;
|
||||
|
||||
const getAssetUrl = (path: string) => {
|
||||
return new URL(path, assetBaseUrl).toString();
|
||||
@ -42,6 +42,7 @@ export const DocumentDeleteEmailTemplate = ({
|
||||
alt="Documenso Logo"
|
||||
className="mb-4 h-6"
|
||||
/>
|
||||
|
||||
<TemplateDocumentDelete
|
||||
reason={reason}
|
||||
documentName={documentName}
|
||||
@ -62,4 +63,4 @@ export const DocumentDeleteEmailTemplate = ({
|
||||
);
|
||||
};
|
||||
|
||||
export default DocumentDeleteEmailTemplate;
|
||||
export default DocumentSuperDeleteEmailTemplate;
|
||||
@ -16,19 +16,13 @@ import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
|
||||
|
||||
export type SuperDeleteDocumentOptions = {
|
||||
id: number;
|
||||
userId: number;
|
||||
requestMetadata?: RequestMetadata;
|
||||
};
|
||||
|
||||
export const superDeleteDocument = async ({
|
||||
id,
|
||||
userId,
|
||||
requestMetadata,
|
||||
}: SuperDeleteDocumentOptions) => {
|
||||
export const superDeleteDocument = async ({ id, requestMetadata }: SuperDeleteDocumentOptions) => {
|
||||
const document = await prisma.document.findUnique({
|
||||
where: {
|
||||
id,
|
||||
userId,
|
||||
},
|
||||
include: {
|
||||
Recipient: true,
|
||||
@ -85,6 +79,7 @@ export const superDeleteDocument = async ({
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
return await tx.document.delete({ where: { id } });
|
||||
});
|
||||
};
|
||||
|
||||
@ -9,6 +9,7 @@ import { superDeleteDocument } from '@documenso/lib/server-only/document/super-d
|
||||
import { upsertSiteSetting } from '@documenso/lib/server-only/site-settings/upsert-site-setting';
|
||||
import { deleteUser } from '@documenso/lib/server-only/user/delete-user';
|
||||
import { getUserById } from '@documenso/lib/server-only/user/get-user-by-id';
|
||||
import { extractNextApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
||||
|
||||
import { adminProcedure, router } from '../trpc';
|
||||
import {
|
||||
@ -121,15 +122,21 @@ export const adminRouter = router({
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
||||
deleteDocument: adminProcedure
|
||||
.input(ZAdminDeleteDocumentMutationSchema)
|
||||
.mutation(async ({ input }) => {
|
||||
const { id, userId, reason } = input;
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { id, reason } = input;
|
||||
try {
|
||||
await sendDeleteEmail({ documentId: id, reason });
|
||||
return await superDeleteDocument({ id, userId });
|
||||
|
||||
return await superDeleteDocument({
|
||||
id,
|
||||
requestMetadata: extractNextApiRequestMetadata(ctx.req),
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message: 'We were unable to delete the specified document. Please try again.',
|
||||
|
||||
@ -51,7 +51,6 @@ export type TAdminDeleteUserMutationSchema = z.infer<typeof ZAdminDeleteUserMuta
|
||||
|
||||
export const ZAdminDeleteDocumentMutationSchema = z.object({
|
||||
id: z.number().min(1),
|
||||
userId: z.number(),
|
||||
reason: z.string(),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user