fix: disable cert download when document not complete

This commit is contained in:
David Nguyen
2024-04-24 19:49:10 +07:00
parent 713cd09a06
commit 41ed6c9ad7
2 changed files with 9 additions and 1 deletions

View File

@ -133,7 +133,11 @@ export const DocumentLogsPageView = async ({ params, team }: DocumentLogsPageVie
</div> </div>
<div className="mt-4 flex w-full flex-row sm:mt-0 sm:w-auto sm:self-end"> <div className="mt-4 flex w-full flex-row sm:mt-0 sm:w-auto sm:self-end">
<DownloadCertificateButton className="mr-2" documentId={document.id} /> <DownloadCertificateButton
className="mr-2"
documentId={document.id}
documentStatus={document.status}
/>
<DownloadAuditLogButton documentId={document.id} /> <DownloadAuditLogButton documentId={document.id} />
</div> </div>

View File

@ -2,6 +2,7 @@
import { DownloadIcon } from 'lucide-react'; import { DownloadIcon } from 'lucide-react';
import { DocumentStatus } from '@documenso/prisma/client';
import { trpc } from '@documenso/trpc/react'; import { trpc } from '@documenso/trpc/react';
import { cn } from '@documenso/ui/lib/utils'; import { cn } from '@documenso/ui/lib/utils';
import { Button } from '@documenso/ui/primitives/button'; import { Button } from '@documenso/ui/primitives/button';
@ -10,11 +11,13 @@ import { useToast } from '@documenso/ui/primitives/use-toast';
export type DownloadCertificateButtonProps = { export type DownloadCertificateButtonProps = {
className?: string; className?: string;
documentId: number; documentId: number;
documentStatus: DocumentStatus;
}; };
export const DownloadCertificateButton = ({ export const DownloadCertificateButton = ({
className, className,
documentId, documentId,
documentStatus,
}: DownloadCertificateButtonProps) => { }: DownloadCertificateButtonProps) => {
const { toast } = useToast(); const { toast } = useToast();
@ -69,6 +72,7 @@ export const DownloadCertificateButton = ({
className={cn('w-full sm:w-auto', className)} className={cn('w-full sm:w-auto', className)}
loading={isLoading} loading={isLoading}
variant="outline" variant="outline"
disabled={documentStatus !== DocumentStatus.COMPLETED}
onClick={() => void onDownloadCertificatesClick()} onClick={() => void onDownloadCertificatesClick()}
> >
{!isLoading && <DownloadIcon className="mr-1.5 h-4 w-4" />} {!isLoading && <DownloadIcon className="mr-1.5 h-4 w-4" />}