Files
esign/apps/remix/app/components/general/document/document-audit-log-download-button.tsx
zooqueen fb4e3df0e3 rename: @hanzo/sign-* → @hanzo/esign-* (full eSign brand consistency)
The product is branded Hanzo eSign (esign.hanzo.ai, repo hanzoai/esign).
Rename all workspace packages @hanzo/sign-* → @hanzo/esign-* (1052 files)
and align docker/Dockerfile turbo --scope/--filter to the actual remix
package name @hanzo/esign (was a pre-existing mismatch with -remix that
broke the build). Protected deps (@hanzo/insights, @hanzo/logo) untouched.
2026-06-21 19:56:09 -07:00

66 lines
2.1 KiB
TypeScript

import { msg } from '@lingui/core/macro';
import { useLingui } from '@lingui/react';
import { Trans } from '@lingui/react/macro';
import { DownloadIcon } from 'lucide-react';
import { downloadFile } from '@hanzo/esign-lib/client-only/download-file';
import { base64 } from '@hanzo/esign-lib/universal/base64';
import { useZapMutation } from '@hanzo/esign-trpc/zap/react';
import type { TDownloadDocumentAuditLogsRequest, TDownloadDocumentAuditLogsResponse } from '@hanzo/esign-trpc/server/document-router/download-document-audit-logs.types';
import { cn } from '@hanzo/esign-ui/lib/utils';
import { Button } from '@hanzo/esign-ui/primitives/button';
import { useToast } from '@hanzo/esign-ui/primitives/use-toast';
export type DocumentAuditLogDownloadButtonProps = {
className?: string;
documentId: number;
};
export const DocumentAuditLogDownloadButton = ({
className,
documentId,
}: DocumentAuditLogDownloadButtonProps) => {
const { toast } = useToast();
const { _ } = useLingui();
const { mutateAsync: downloadAuditLogs, isPending } = useZapMutation<
TDownloadDocumentAuditLogsResponse,
TDownloadDocumentAuditLogsRequest
>('document.auditLog.download');
const onDownloadAuditLogsClick = async () => {
try {
const { data, envelopeTitle } = await downloadAuditLogs({ documentId });
const buffer = new Uint8Array(base64.decode(data));
const blob = new Blob([buffer], { type: 'application/pdf' });
downloadFile({
data: blob,
filename: `${envelopeTitle} - Audit Logs.pdf`,
});
} catch (error) {
console.error(error);
toast({
title: _(msg`Something went wrong`),
description: _(
msg`Sorry, we were unable to download the audit logs. Please try again later.`,
),
variant: 'destructive',
});
}
};
return (
<Button
className={cn('w-full sm:w-auto', className)}
loading={isPending}
onClick={() => void onDownloadAuditLogsClick()}
>
{!isPending && <DownloadIcon className="mr-1.5 h-4 w-4" />}
<Trans>Download Audit Logs</Trans>
</Button>
);
};