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