mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
Previously we used the form flattening method from PDF-Lib but unfortunately when it encountered orphaned form items or other PDF oddities it would throw an error. Because of this certain documents would fail to seal and be stuck in a pending state with no recourse available. This change rewrites the form flattening handler to be more lenient when coming across the unknown opting to skip items it can't handle rather than abort.
74 lines
2.1 KiB
TypeScript
74 lines
2.1 KiB
TypeScript
'use client';
|
|
|
|
import Link from 'next/link';
|
|
|
|
import type { Recipient } from '@documenso/prisma/client';
|
|
import { type Document, SigningStatus } from '@documenso/prisma/client';
|
|
import { trpc } from '@documenso/trpc/react';
|
|
import { cn } from '@documenso/ui/lib/utils';
|
|
import { Button } from '@documenso/ui/primitives/button';
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipProvider,
|
|
TooltipTrigger,
|
|
} from '@documenso/ui/primitives/tooltip';
|
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
|
|
export type AdminActionsProps = {
|
|
className?: string;
|
|
document: Document;
|
|
recipients: Recipient[];
|
|
};
|
|
|
|
export const AdminActions = ({ className, document, recipients }: AdminActionsProps) => {
|
|
const { toast } = useToast();
|
|
|
|
const { mutate: resealDocument, isLoading: isResealDocumentLoading } =
|
|
trpc.admin.resealDocument.useMutation({
|
|
onSuccess: () => {
|
|
toast({
|
|
title: 'Success',
|
|
description: 'Document resealed',
|
|
});
|
|
},
|
|
onError: () => {
|
|
toast({
|
|
title: 'Error',
|
|
description: 'Failed to reseal document',
|
|
variant: 'destructive',
|
|
});
|
|
},
|
|
});
|
|
|
|
return (
|
|
<div className={cn('flex gap-x-4', className)}>
|
|
<TooltipProvider>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="outline"
|
|
loading={isResealDocumentLoading}
|
|
disabled={recipients.some(
|
|
(recipient) => recipient.signingStatus !== SigningStatus.SIGNED,
|
|
)}
|
|
onClick={() => resealDocument({ id: document.id })}
|
|
>
|
|
Reseal document
|
|
</Button>
|
|
</TooltipTrigger>
|
|
|
|
<TooltipContent className="max-w-[40ch]">
|
|
Attempts sealing the document again, useful for after a code change has occurred to
|
|
resolve an erroneous document.
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
|
|
<Button variant="outline" asChild>
|
|
<Link href={`/admin/users/${document.userId}`}>Go to owner</Link>
|
|
</Button>
|
|
</div>
|
|
);
|
|
};
|