-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: force signature fields for document signers #1139
base: main
Are you sure you want to change the base?
Changes from all commits
559b721
d5b313e
4c59eab
f18b4d6
8861559
99a04e5
6dba7a6
d631466
db05ec0
04d70c9
acb81b8
3a1b6c9
c4c3b56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ import { | |
DocumentFlowFormContainerStep, | ||
} from './document-flow-root'; | ||
import { FieldItem } from './field-item'; | ||
import { MissingSignatureFieldDialog } from './missing-signature-field-dialog'; | ||
import { type DocumentFlowStep, FRIENDLY_FIELD_TYPE } from './types'; | ||
|
||
const fontCaveat = Caveat({ | ||
|
@@ -64,6 +65,8 @@ export const AddFieldsFormPartial = ({ | |
onSubmit, | ||
isDocumentPdfLoaded, | ||
}: AddFieldsFormProps) => { | ||
const [isMissingSignatureDialogVisible, setIsMissingSignatureDialogVisible] = useState(false); | ||
|
||
const { isWithinPageBounds, getFieldPosition, getPage } = useDocumentElement(); | ||
const { currentStep, totalSteps, previousStep } = useStep(); | ||
|
||
|
@@ -313,6 +316,22 @@ export const AddFieldsFormPartial = ({ | |
); | ||
}, [recipientsByRole]); | ||
|
||
const everySignerHasSignature = recipientsByRole.SIGNER.every((signer) => | ||
localFields.some((field) => field.type === 'SIGNATURE' && field.signerEmail === signer.email), | ||
); | ||
|
||
const handleGoNextClick = () => { | ||
if (!everySignerHasSignature) { | ||
setIsMissingSignatureDialogVisible(true); | ||
} else { | ||
void onFormSubmit(); | ||
} | ||
}; | ||
|
||
const handleOpenChange = () => { | ||
setIsMissingSignatureDialogVisible((prev) => !prev); | ||
}; | ||
|
||
return ( | ||
<> | ||
<DocumentFlowFormContainerHeader | ||
|
@@ -596,9 +615,16 @@ export const AddFieldsFormPartial = ({ | |
previousStep(); | ||
remove(); | ||
}} | ||
onGoNextClick={() => void onFormSubmit()} | ||
onGoNextClick={handleGoNextClick} | ||
/> | ||
</DocumentFlowFormContainerFooter> | ||
|
||
{!everySignerHasSignature && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to conditionally render here? I get why it's there but it seems easier to just let it always render since we toggle visibility anyways. |
||
<MissingSignatureFieldDialog | ||
isOpen={isMissingSignatureDialogVisible} | ||
onOpenChange={handleOpenChange} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use client'; | ||
|
||
import { Button } from '@documenso/ui/primitives/button'; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
} from '@documenso/ui/primitives/dialog'; | ||
|
||
export type MissingSignatureFieldDialogProps = { | ||
isOpen: boolean; | ||
onOpenChange: () => void; | ||
}; | ||
|
||
export const MissingSignatureFieldDialog = ({ | ||
isOpen, | ||
onOpenChange, | ||
}: MissingSignatureFieldDialogProps) => { | ||
return ( | ||
<Dialog open={isOpen} onOpenChange={onOpenChange}> | ||
<DialogContent className="max-w-lg" position="center"> | ||
<DialogHeader> | ||
<DialogTitle>No signature field found</DialogTitle> | ||
<DialogDescription> | ||
<p className="mt-2"> | ||
Some signers have not been assigned a signature field. Please assign at least 1 signature field | ||
to each signer before proceeding. | ||
</p> | ||
</DialogDescription> | ||
</DialogHeader> | ||
<DialogFooter> | ||
<Button type="button" variant="secondary" onClick={onOpenChange}> | ||
Cancel | ||
</Button> | ||
<Button type="submit" onClick={onOpenChange}> | ||
Proceed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need both options if you can't proceed? Why the 2 buttons? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True that. I kept it like this for consistency. Should I just go ahead and remove the proceed button? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will mean API users will also have to follow these conventions, we should consider if that's something we want @ElTimuro