@@ -36,6 +36,7 @@ const SuperDocESign = forwardRef<Types.SuperDocESignHandle, Types.SuperDocESignP
3636 const [ fieldValues , setFieldValues ] = useState < Map < string , Types . FieldValue > > ( new Map ( ) ) ;
3737 const [ isValid , setIsValid ] = useState ( false ) ;
3838 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
39+ const [ isDownloading , setIsDownloading ] = useState ( false ) ;
3940 const [ auditTrail , setAuditTrail ] = useState < Types . AuditEvent [ ] > ( [ ] ) ;
4041 const [ isReady , setIsReady ] = useState ( false ) ;
4142
@@ -298,7 +299,9 @@ const SuperDocESign = forwardRef<Types.SuperDocESignHandle, Types.SuperDocESignP
298299 } , [ scrolled , fieldValues , isSubmitting , checkIsValid , onStateChange ] ) ;
299300
300301 const handleDownload = useCallback ( async ( ) => {
301- if ( isDisabled ) return ;
302+ if ( isDisabled || isDownloading ) return ;
303+
304+ setIsDownloading ( true ) ;
302305
303306 const downloadData : Types . DownloadData = {
304307 eventId,
@@ -313,8 +316,21 @@ const SuperDocESign = forwardRef<Types.SuperDocESignHandle, Types.SuperDocESignP
313316 fileName : download ?. fileName || 'document.pdf' ,
314317 } ;
315318
316- await onDownload ?.( downloadData ) ;
317- } , [ isDisabled , eventId , document . source , fields , fieldValues , download , onDownload ] ) ;
319+ try {
320+ await onDownload ?.( downloadData ) ;
321+ } finally {
322+ setIsDownloading ( false ) ;
323+ }
324+ } , [
325+ isDisabled ,
326+ isDownloading ,
327+ eventId ,
328+ document . source ,
329+ fields ,
330+ fieldValues ,
331+ download ,
332+ onDownload ,
333+ ] ) ;
318334
319335 const handleSubmit = useCallback ( async ( ) => {
320336 if ( ! isValid || isDisabled || isSubmitting ) return ;
@@ -378,6 +394,7 @@ const SuperDocESign = forwardRef<Types.SuperDocESignHandle, Types.SuperDocESignP
378394 onClick = { handleDownload }
379395 fileName = { download ?. fileName }
380396 isDisabled = { isDisabled }
397+ isDownloading = { isDownloading }
381398 />
382399 ) ;
383400 } ;
0 commit comments