import { plural } from '@lingui/core/macro'; import { Plural, useLingui } from '@lingui/react/macro'; import { Trans } from '@lingui/react/macro'; import { EnvelopeType } from '@prisma/client'; import type * as DialogPrimitive from '@radix-ui/react-dialog'; import { trpc } from '@documenso/trpc/react'; import { Alert, AlertDescription } from '@documenso/ui/primitives/alert'; 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'; export type EnvelopesBulkDeleteDialogProps = { envelopeIds: string[]; envelopeType: EnvelopeType; open: boolean; onOpenChange: (open: boolean) => void; onSuccess?: () => void; } & Omit; export const EnvelopesBulkDeleteDialog = ({ envelopeIds, envelopeType, open, onOpenChange, onSuccess, ...props }: EnvelopesBulkDeleteDialogProps) => { const { t } = useLingui(); const { toast } = useToast(); const trpcUtils = trpc.useUtils(); const isDocument = envelopeType === EnvelopeType.DOCUMENT; const { mutateAsync: bulkDeleteEnvelopes, isPending } = trpc.envelope.bulk.delete.useMutation({ onSuccess: async (result) => { // Invalidate the appropriate query based on envelope type. if (isDocument) { await trpcUtils.document.findDocumentsInternal.invalidate(); } else { await trpcUtils.template.findTemplates.invalidate(); } if (result.failedIds.length > 0) { toast({ title: isDocument ? t`Documents partially deleted` : t`Templates partially deleted`, description: t`${plural(result.deletedCount, { one: '# item deleted.', other: '# items deleted.', })} ${plural(result.failedIds.length, { one: '# item could not be deleted.', other: '# items could not be deleted.', })}`, variant: 'destructive', }); } else { toast({ title: isDocument ? t`Documents deleted` : t`Templates deleted`, description: plural(result.deletedCount, { one: '# item has been deleted.', other: '# items have been deleted.', }), variant: 'default', }); } onSuccess?.(); onOpenChange(false); }, onError: () => { toast({ title: t`Error`, description: t`An error occurred while deleting the items.`, variant: 'destructive', }); }, }); return ( {isDocument ? Delete Documents : Delete Templates} {isDocument ? ( ) : ( )}

Please note that this action is irreversible.

Once confirmed, the following will occur:

    {isDocument ? ( <>
  • Selected documents will be permanently deleted
  • Pending documents will have their signing process cancelled
  • All recipients will be notified
  • ) : ( <>
  • Selected templates will be permanently deleted
  • Direct links associated with templates will be removed
  • )}
); };