mirror of
https://github.com/documenso/documenso.git
synced 2026-09-29 16:24:30 +10:00
fix(ui): discard cancelled signature pad dialog drafts
The dialog kept its draft signature in state across open/close, while the pad inside remounts from the saved value. After cancelling, reopening showed the saved signature (or an empty pad), but the Next button stayed enabled and committed the discarded draft. Reset the draft to the saved value whenever the dialog opens or closes, and route all open-state changes through one disabled-aware handler.
This commit is contained in:
@@ -41,6 +41,15 @@ export const SignaturePadDialog = ({
|
||||
const [showSignatureModal, setShowSignatureModal] = useState(false);
|
||||
const [signature, setSignature] = useState<string>(value ?? '');
|
||||
|
||||
const onOpenChange = (open: boolean) => {
|
||||
if (disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSignature(value ?? '');
|
||||
setShowSignatureModal(open);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
@@ -62,7 +71,7 @@ export const SignaturePadDialog = ({
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
className="absolute inset-0 flex items-center justify-center bg-transparent"
|
||||
onClick={() => setShowSignatureModal(true)}
|
||||
onClick={() => onOpenChange(true)}
|
||||
whileHover="onHover"
|
||||
>
|
||||
{!value && !disableAnimation && (
|
||||
@@ -109,7 +118,7 @@ export const SignaturePadDialog = ({
|
||||
)}
|
||||
</motion.button>
|
||||
|
||||
<Dialog open={showSignatureModal} onOpenChange={disabled ? undefined : setShowSignatureModal}>
|
||||
<Dialog open={showSignatureModal} onOpenChange={onOpenChange}>
|
||||
<DialogContent hideClose={true} className="p-6 pt-4">
|
||||
<SignaturePad
|
||||
id="signature"
|
||||
@@ -135,7 +144,7 @@ export const SignaturePadDialog = ({
|
||||
disabled={!signature}
|
||||
onClick={() => {
|
||||
onChange(signature);
|
||||
setShowSignatureModal(false);
|
||||
onOpenChange(false);
|
||||
}}
|
||||
>
|
||||
{dialogConfirmText ? parseMessageDescriptor(i18n._, dialogConfirmText) : <Trans>Next</Trans>}
|
||||
|
||||
Reference in New Issue
Block a user