mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
134 lines
3.8 KiB
TypeScript
134 lines
3.8 KiB
TypeScript
import { useState } from 'react';
|
|
|
|
import type { Document, Field } from '@documenso/prisma/client';
|
|
import { RecipientRole } from '@documenso/prisma/client';
|
|
import { Button } from '@documenso/ui/primitives/button';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogFooter,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from '@documenso/ui/primitives/dialog';
|
|
|
|
import { SigningDisclosure } from '~/components/general/signing-disclosure';
|
|
import { truncateTitle } from '~/helpers/truncate-title';
|
|
|
|
export type SignDialogProps = {
|
|
isSubmitting: boolean;
|
|
document: Document;
|
|
fields: Field[];
|
|
fieldsValidated: () => void | Promise<void>;
|
|
onSignatureComplete: () => void | Promise<void>;
|
|
role: RecipientRole;
|
|
};
|
|
|
|
export const SignDialog = ({
|
|
isSubmitting,
|
|
document,
|
|
fields,
|
|
fieldsValidated,
|
|
onSignatureComplete,
|
|
role,
|
|
}: SignDialogProps) => {
|
|
const [showDialog, setShowDialog] = useState(false);
|
|
const truncatedTitle = truncateTitle(document.title);
|
|
const isComplete = fields.every((field) => field.inserted);
|
|
|
|
const handleOpenChange = (open: boolean) => {
|
|
if (isSubmitting || !isComplete) {
|
|
return;
|
|
}
|
|
|
|
// Reauth is currently not required for signing the document.
|
|
// if (isAuthRedirectRequired) {
|
|
// await executeActionAuthProcedure({
|
|
// actionTarget: 'DOCUMENT',
|
|
// onReauthFormSubmit: () => {
|
|
// // Do nothing since the user should be redirected.
|
|
// },
|
|
// });
|
|
|
|
// return;
|
|
// }
|
|
|
|
setShowDialog(open);
|
|
};
|
|
|
|
return (
|
|
<Dialog open={showDialog} onOpenChange={handleOpenChange}>
|
|
<DialogTrigger asChild>
|
|
<Button
|
|
className="w-full"
|
|
type="button"
|
|
size="lg"
|
|
onClick={fieldsValidated}
|
|
loading={isSubmitting}
|
|
>
|
|
{isComplete ? 'Complete' : 'Next field'}
|
|
</Button>
|
|
</DialogTrigger>
|
|
|
|
<DialogContent>
|
|
<DialogTitle>
|
|
<div className="text-foreground text-xl font-semibold">
|
|
{role === RecipientRole.VIEWER && 'Complete Viewing'}
|
|
{role === RecipientRole.SIGNER && 'Complete Signing'}
|
|
{role === RecipientRole.APPROVER && 'Complete Approval'}
|
|
</div>
|
|
</DialogTitle>
|
|
|
|
<div className="text-muted-foreground max-w-[50ch]">
|
|
{role === RecipientRole.VIEWER && (
|
|
<span>
|
|
You are about to complete viewing "{truncatedTitle}".
|
|
<br /> Are you sure?
|
|
</span>
|
|
)}
|
|
{role === RecipientRole.SIGNER && (
|
|
<span>
|
|
You are about to complete signing "{truncatedTitle}".
|
|
<br /> Are you sure?
|
|
</span>
|
|
)}
|
|
{role === RecipientRole.APPROVER && (
|
|
<span>
|
|
You are about to complete approving "{truncatedTitle}".
|
|
<br /> Are you sure?
|
|
</span>
|
|
)}
|
|
</div>
|
|
|
|
<SigningDisclosure className="mt-4" />
|
|
|
|
<DialogFooter>
|
|
<div className="flex w-full flex-1 flex-nowrap gap-4">
|
|
<Button
|
|
type="button"
|
|
className="dark:bg-muted dark:hover:bg-muted/80 flex-1 bg-black/5 hover:bg-black/10"
|
|
variant="secondary"
|
|
onClick={() => {
|
|
setShowDialog(false);
|
|
}}
|
|
>
|
|
Cancel
|
|
</Button>
|
|
|
|
<Button
|
|
type="button"
|
|
className="flex-1"
|
|
disabled={!isComplete}
|
|
loading={isSubmitting}
|
|
onClick={onSignatureComplete}
|
|
>
|
|
{role === RecipientRole.VIEWER && 'Mark as Viewed'}
|
|
{role === RecipientRole.SIGNER && 'Sign'}
|
|
{role === RecipientRole.APPROVER && 'Approve'}
|
|
</Button>
|
|
</div>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|