1
- import React , { useEffect , useState } from "react" ;
1
+ import React , { useEffect , useRef , useState } from "react" ;
2
2
import { useNavigate , useParams } from "react-router-dom" ;
3
3
import { formJson } from "../json/FormJson" ;
4
4
import AddUser from "../components/AddUser" ;
@@ -36,6 +36,7 @@ function Form() {
36
36
const Forms = ( props ) => {
37
37
const maxFileSize = 20 ;
38
38
const abortController = new AbortController ( ) ;
39
+ const inputFileRef = useRef ( null ) ;
39
40
const navigate = useNavigate ( ) ;
40
41
const [ signers , setSigners ] = useState ( [ ] ) ;
41
42
const [ folder , setFolder ] = useState ( { ObjectId : "" , Name : "" } ) ;
@@ -57,7 +58,9 @@ const Forms = (props) => {
57
58
const [ isErr , setIsErr ] = useState ( "" ) ;
58
59
const [ isPassword , setIsPassword ] = useState ( false ) ;
59
60
const [ isDecrypting , setIsDecrypting ] = useState ( false ) ;
61
+ const [ isCorrectPass , setIsCorrectPass ] = useState ( true ) ;
60
62
const handleStrInput = ( e ) => {
63
+ setIsCorrectPass ( true ) ;
61
64
setFormData ( { ...formData , [ e . target . name ] : e . target . value } ) ;
62
65
} ;
63
66
useEffect ( ( ) => {
@@ -157,20 +160,19 @@ const Forms = (props) => {
157
160
158
161
// Retrieve the URL of the uploaded file
159
162
if ( parseFile . url ( ) ) {
160
- console . log ( "parseFile.url() " , parseFile . url ( ) ) ;
161
163
setFileUpload ( parseFile . url ( ) ) ;
162
164
setfileload ( false ) ;
163
165
const tenantId = localStorage . getItem ( "TenantId" ) ;
164
166
SaveFileSize ( size , parseFile . url ( ) , tenantId ) ;
165
167
return parseFile . url ( ) ;
166
168
}
167
169
} catch ( err ) {
168
- console . log ( "Error uploading file: " , err ?. response ) ;
169
170
setfileload ( false ) ;
170
171
setpercentage ( 0 ) ;
171
172
if ( err ?. response ?. status === 401 ) {
172
173
setIsPassword ( true ) ;
173
174
} else {
175
+ console . log ( "Error uploading file: " , err ?. response ) ;
174
176
setIsDecrypting ( false ) ;
175
177
e . target . value = "" ;
176
178
}
@@ -502,26 +504,37 @@ const Forms = (props) => {
502
504
// Retrieve the URL of the uploaded file
503
505
if ( parseFile . url ( ) ) {
504
506
setFormData ( ( prev ) => ( { ...prev , password : "" } ) ) ;
505
- console . log ( "parseFile.url() " , parseFile . url ( ) ) ;
506
507
setFileUpload ( parseFile . url ( ) ) ;
507
508
setfileload ( false ) ;
508
509
const tenantId = localStorage . getItem ( "TenantId" ) ;
509
510
SaveFileSize ( size , parseFile . url ( ) , tenantId ) ;
510
511
return parseFile . url ( ) ;
511
512
}
512
513
} catch ( err ) {
513
- console . log ( "Error uploading file: " , err ?. response ) ;
514
514
setfileload ( false ) ;
515
515
setpercentage ( 0 ) ;
516
- setFormData ( ( prev ) => ( { ...prev , password : "" } ) ) ;
517
516
if ( err ?. response ?. status === 401 ) {
518
517
setIsPassword ( true ) ;
518
+ setIsCorrectPass ( false ) ;
519
519
} else {
520
+ console . log ( "Error uploading file: " , err ?. response ) ;
521
+ setFormData ( ( prev ) => ( { ...prev , password : "" } ) ) ;
520
522
setIsDecrypting ( false ) ;
521
- e . target . value = "" ;
523
+ if ( inputFileRef . current ) {
524
+ inputFileRef . current . value = "" ; // Set file input value to empty string
525
+ }
522
526
}
523
527
}
524
528
} ;
529
+ const handeCloseModal = ( ) => {
530
+ setIsPassword ( false ) ;
531
+ setFormData ( ( prev ) => ( { ...prev , file : "" , password : "" } ) ) ;
532
+ setIsDecrypting ( false ) ;
533
+ setfileload ( false ) ;
534
+ if ( inputFileRef . current ) {
535
+ inputFileRef . current . value = "" ; // Set file input value to empty string
536
+ }
537
+ } ;
525
538
return (
526
539
< div className = "shadow-md rounded my-2 p-3 bg-[#ffffff] md:border-[1px] md:border-gray-600/50" >
527
540
< Title title = { props ?. title } />
@@ -546,10 +559,14 @@ const Forms = (props) => {
546
559
</ div >
547
560
) : (
548
561
< >
549
- < ModalUi isOpen = { isPassword } title = { "Enter Pdf Password" } >
562
+ < ModalUi
563
+ isOpen = { isPassword }
564
+ handleClose = { ( ) => handeCloseModal ( ) }
565
+ title = { "Enter Pdf Password" }
566
+ >
550
567
< form onSubmit = { handlePasswordSubmit } >
551
- < div className = "px-6 py-3 " >
552
- { /* <label className="mb-2">Enter OTP </label> */ }
568
+ < div className = "px-6 pt-3 pb-2 " >
569
+ < label className = "mb-2 text-xs" > Password </ label >
553
570
< input
554
571
type = "text"
555
572
name = "password"
@@ -559,6 +576,15 @@ const Forms = (props) => {
559
576
placeholder = "Enter pdf password"
560
577
required
561
578
/>
579
+ { ! isCorrectPass ? (
580
+ < p className = "ml-2 text-[11px] text-red-600" >
581
+ Please provide correct password
582
+ </ p >
583
+ ) : (
584
+ < p className = "ml-2 text-[11px] text-transparent text-red-600" >
585
+ .
586
+ </ p >
587
+ ) }
562
588
</ div >
563
589
< hr />
564
590
< div className = "px-6 my-3" >
@@ -621,6 +647,7 @@ const Forms = (props) => {
621
647
type = "file"
622
648
className = "bg-white px-2 py-1.5 w-full border-[1px] border-gray-300 rounded focus:outline-none text-xs"
623
649
onChange = { ( e ) => handleFileInput ( e ) }
650
+ ref = { inputFileRef }
624
651
accept = {
625
652
isEnableSubscription
626
653
? "application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,image/png,image/jpeg"
0 commit comments