@@ -8,6 +8,8 @@ const BulkSendUi = (props) => {
8
8
const formRef = useRef ( null ) ;
9
9
const [ scrollOnNextUpdate , setScrollOnNextUpdate ] = useState ( false ) ;
10
10
const [ isSubmit , setIsSubmit ] = useState ( false ) ;
11
+ const [ allowedForm , setAllowedForm ] = useState ( 0 ) ;
12
+ const allowedSigners = 50 ;
11
13
useEffect ( ( ) => {
12
14
if ( scrollOnNextUpdate && formRef . current ) {
13
15
formRef . current . scrollIntoView ( {
@@ -37,45 +39,48 @@ const BulkSendUi = (props) => {
37
39
}
38
40
} ) ;
39
41
setForms ( ( prevForms ) => [ ...prevForms , { Id : 1 , fields : users } ] ) ;
42
+ const totalForms = Math . floor ( allowedSigners / users ?. length ) ;
43
+ setAllowedForm ( totalForms ) ;
40
44
}
41
45
} ) ( ) ;
42
46
// eslint-disable-next-line
43
47
} , [ ] ) ;
44
48
const handleInputChange = ( index , signer , fieldIndex ) => {
45
- console . log ( "index" , index ) ;
46
- console . log ( "signer" , signer ) ;
47
- console . log ( "fieldIndex" , fieldIndex ) ;
48
-
49
49
const newForms = [ ...forms ] ;
50
50
newForms [ index ] . fields [ fieldIndex ] . email = signer ?. Email
51
51
? signer ?. Email
52
52
: signer || "" ;
53
53
newForms [ index ] . fields [ fieldIndex ] . signer = signer ?. objectId ? signer : "" ;
54
- console . log ( "newForms[index] " , newForms [ index ] ) ;
55
54
setForms ( newForms ) ;
56
55
} ;
57
56
58
57
const handleAddForm = ( e ) => {
59
58
e . preventDefault ( ) ;
60
- if ( props ?. Placeholders . length > 0 ) {
61
- let newForm = [ ] ;
62
- props ?. Placeholders ?. forEach ( ( element ) => {
63
- if ( ! element . signerObjId ) {
64
- newForm = [
65
- ...newForm ,
66
- {
67
- fieldId : element . Id ,
68
- email : "" ,
69
- label : element . Role ,
70
- signer : { }
71
- }
72
- ] ;
73
- }
74
- } ) ;
75
- setForms ( [ ...forms , { Id : formId , fields : newForm } ] ) ;
59
+ // Check if the quick send limit has been reached
60
+ if ( forms ?. length < allowedForm ) {
61
+ if ( props ?. Placeholders . length > 0 ) {
62
+ let newForm = [ ] ;
63
+ props ?. Placeholders ?. forEach ( ( element ) => {
64
+ if ( ! element . signerObjId ) {
65
+ newForm = [
66
+ ...newForm ,
67
+ {
68
+ fieldId : element . Id ,
69
+ email : "" ,
70
+ label : element . Role ,
71
+ signer : { }
72
+ }
73
+ ] ;
74
+ }
75
+ } ) ;
76
+ setForms ( [ ...forms , { Id : formId , fields : newForm } ] ) ;
77
+ }
78
+ setFormId ( formId + 1 ) ;
79
+ setScrollOnNextUpdate ( true ) ;
80
+ } else {
81
+ // If the limit has been reached, throw an error with the appropriate message
82
+ alert ( "Quick send reached limit." ) ;
76
83
}
77
- setFormId ( formId + 1 ) ;
78
- setScrollOnNextUpdate ( true ) ;
79
84
} ;
80
85
81
86
const handleRemoveForm = ( index ) => {
@@ -102,7 +107,6 @@ const BulkSendUi = (props) => {
102
107
) ;
103
108
// If a matching field is found, update the email value in the placeholder
104
109
const signer = field ?. signer ?. objectId ? field . signer : { } ;
105
- console . log ( "signer " , signer ) ;
106
110
if ( field ) {
107
111
return {
108
112
...placeholder ,
0 commit comments