@@ -50,145 +50,163 @@ const AddSigner = (props) => {
50
50
e . stopPropagation ( ) ;
51
51
setIsLoader ( true ) ;
52
52
if ( localStorage . getItem ( "TenantId" ) ) {
53
- try {
54
- const contactQuery = new Parse . Object ( "contracts_Contactbook" ) ;
55
- contactQuery . set ( "Name" , name ) ;
56
- contactQuery . set ( "Phone" , phone ) ;
57
- contactQuery . set ( "Email" , email ) ;
58
- contactQuery . set ( "UserRole" , "contracts_Guest" ) ;
59
-
60
- contactQuery . set ( "TenantId" , {
61
- __type : "Pointer" ,
62
- className : "partners_Tenant" ,
63
- objectId : localStorage . getItem ( "TenantId" )
64
- } ) ;
65
-
66
53
try {
67
- const _users = Parse . Object . extend ( "User" ) ;
68
- const _user = new _users ( ) ;
69
- _user . set ( "name" , name ) ;
70
- _user . set ( "username" , email ) ;
71
- _user . set ( "email" , email ) ;
72
- _user . set ( "phone" , phone ) ;
73
- _user . set ( "password" , phone ) ;
54
+ const user = Parse . User . current ( ) ;
55
+ const query = new Parse . Query ( "contracts_Contactbook" ) ;
56
+ query . equalTo ( "CreatedBy" , user ) ;
57
+ query . notEqualTo ( "IsDeleted" , true ) ;
58
+ query . equalTo ( "Email" , email ) ;
59
+ const res = await query . first ( ) ;
60
+ // console.log(res);
61
+ if ( ! res ) {
62
+ const contactQuery = new Parse . Object ( "contracts_Contactbook" ) ;
63
+ contactQuery . set ( "Name" , name ) ;
64
+ if ( phone ) {
65
+ contactQuery . set ( "Phone" , phone ) ;
66
+ }
67
+ contactQuery . set ( "Email" , email ) ;
68
+ contactQuery . set ( "UserRole" , "contracts_Guest" ) ;
74
69
75
- const user = await _user . save ( ) ;
76
- if ( user ) {
77
- const roleurl = `${ parseBaseUrl } functions/AddUserToRole` ;
78
- const headers = {
79
- "Content-Type" : "application/json" ,
80
- "X-Parse-Application-Id" : parseAppId ,
81
- sessionToken : localStorage . getItem ( "accesstoken" )
82
- } ;
83
- const body = {
84
- appName : localStorage . getItem ( "_appName" ) ,
85
- roleName : "contracts_Guest" ,
86
- userId : user . id
87
- } ;
88
- await axios . post ( roleurl , body , { headers : headers } ) ;
89
- const currentUser = Parse . User . current ( ) ;
90
- contactQuery . set (
91
- "CreatedBy" ,
92
- Parse . User . createWithoutData ( currentUser . id )
93
- ) ;
70
+ contactQuery . set ( "TenantId" , {
71
+ __type : "Pointer" ,
72
+ className : "partners_Tenant" ,
73
+ objectId : localStorage . getItem ( "TenantId" )
74
+ } ) ;
94
75
95
- contactQuery . set ( "UserId" , user ) ;
96
- const acl = new Parse . ACL ( ) ;
97
- acl . setPublicReadAccess ( true ) ;
98
- acl . setPublicWriteAccess ( true ) ;
99
- acl . setReadAccess ( currentUser . id , true ) ;
100
- acl . setWriteAccess ( currentUser . id , true ) ;
76
+ try {
77
+ const _users = Parse . Object . extend ( "User" ) ;
78
+ const _user = new _users ( ) ;
79
+ _user . set ( "name" , name ) ;
80
+ _user . set ( "username" , email ) ;
81
+ _user . set ( "email" , email ) ;
82
+ if ( phone ) {
83
+ _user . set ( "phone" , phone ) ;
84
+ _user . set ( "password" , phone ) ;
85
+ } else {
86
+ _user . set ( "password" , email ) ;
87
+ }
88
+ const user = await _user . save ( ) ;
89
+ if ( user ) {
90
+ const roleurl = `${ parseBaseUrl } functions/AddUserToRole` ;
91
+ const headers = {
92
+ "Content-Type" : "application/json" ,
93
+ "X-Parse-Application-Id" : parseAppId ,
94
+ sessionToken : localStorage . getItem ( "accesstoken" )
95
+ } ;
96
+ const body = {
97
+ appName : localStorage . getItem ( "_appName" ) ,
98
+ roleName : "contracts_Guest" ,
99
+ userId : user . id
100
+ } ;
101
+ await axios . post ( roleurl , body , { headers : headers } ) ;
102
+ const currentUser = Parse . User . current ( ) ;
103
+ contactQuery . set (
104
+ "CreatedBy" ,
105
+ Parse . User . createWithoutData ( currentUser . id )
106
+ ) ;
101
107
102
- contactQuery . setACL ( acl ) ;
108
+ contactQuery . set ( "UserId" , user ) ;
109
+ const acl = new Parse . ACL ( ) ;
110
+ acl . setPublicReadAccess ( true ) ;
111
+ acl . setPublicWriteAccess ( true ) ;
112
+ acl . setReadAccess ( currentUser . id , true ) ;
113
+ acl . setWriteAccess ( currentUser . id , true ) ;
103
114
104
- const res = await contactQuery . save ( ) ;
115
+ contactQuery . setACL ( acl ) ;
105
116
106
- const parseData = JSON . parse ( JSON . stringify ( res ) ) ;
107
- if ( props . details ) {
108
- props . details ( {
109
- value : parseData [ props . valueKey ] ,
110
- label : parseData [ props . displayKey ]
111
- } ) ;
112
- }
113
- if ( props . closePopup ) {
114
- props . closePopup ( ) ;
115
- }
116
- if ( props . handleUserData ) {
117
- props . handleUserData ( parseData ) ;
118
- }
117
+ const res = await contactQuery . save ( ) ;
119
118
120
- setIsLoader ( false ) ;
121
- // Reset the form fields
122
- setAddYourself ( false ) ;
123
- setName ( "" ) ;
124
- setPhone ( "" ) ;
125
- setEmail ( "" ) ;
126
- }
127
- } catch ( err ) {
128
- console . log ( "err " , err ) ;
129
- if ( err . code === 202 ) {
130
- const params = { email : email } ;
131
- const userRes = await Parse . Cloud . run ( "getUserId" , params ) ;
132
- const roleurl = `${ parseBaseUrl } functions/AddUserToRole` ;
133
- const headers = {
134
- "Content-Type" : "application/json" ,
135
- "X-Parse-Application-Id" : parseAppId ,
136
- sessionToken : localStorage . getItem ( "accesstoken" )
137
- } ;
138
- const body = {
139
- appName : localStorage . getItem ( "_appName" ) ,
140
- roleName : "contracts_Guest" ,
141
- userId : userRes . id
142
- } ;
143
- await axios . post ( roleurl , body , { headers : headers } ) ;
144
- const currentUser = Parse . User . current ( ) ;
145
- contactQuery . set (
146
- "CreatedBy" ,
147
- Parse . User . createWithoutData ( currentUser . id )
148
- ) ;
119
+ const parseData = JSON . parse ( JSON . stringify ( res ) ) ;
120
+ if ( props . details ) {
121
+ props . details ( {
122
+ value : parseData [ props . valueKey ] ,
123
+ label : parseData [ props . displayKey ]
124
+ } ) ;
125
+ }
126
+ if ( props . closePopup ) {
127
+ props . closePopup ( ) ;
128
+ }
129
+ if ( props . handleUserData ) {
130
+ props . handleUserData ( parseData ) ;
131
+ }
149
132
150
- contactQuery . set ( "UserId" , {
151
- __type : "Pointer" ,
152
- className : "_User" ,
153
- objectId : userRes . id
154
- } ) ;
155
- const acl = new Parse . ACL ( ) ;
156
- acl . setPublicReadAccess ( true ) ;
157
- acl . setPublicWriteAccess ( true ) ;
158
- acl . setReadAccess ( currentUser . id , true ) ;
159
- acl . setWriteAccess ( currentUser . id , true ) ;
133
+ setIsLoader ( false ) ;
134
+ // Reset the form fields
135
+ setAddYourself ( false ) ;
136
+ setName ( "" ) ;
137
+ setPhone ( "" ) ;
138
+ setEmail ( "" ) ;
139
+ }
140
+ } catch ( err ) {
141
+ console . log ( "err " , err ) ;
142
+ if ( err . code === 202 ) {
143
+ const params = { email : email } ;
144
+ const userRes = await Parse . Cloud . run ( "getUserId" , params ) ;
145
+ const roleurl = `${ parseBaseUrl } functions/AddUserToRole` ;
146
+ const headers = {
147
+ "Content-Type" : "application/json" ,
148
+ "X-Parse-Application-Id" : parseAppId ,
149
+ sessionToken : localStorage . getItem ( "accesstoken" )
150
+ } ;
151
+ const body = {
152
+ appName : localStorage . getItem ( "_appName" ) ,
153
+ roleName : "contracts_Guest" ,
154
+ userId : userRes . id
155
+ } ;
156
+ await axios . post ( roleurl , body , { headers : headers } ) ;
157
+ const currentUser = Parse . User . current ( ) ;
158
+ contactQuery . set (
159
+ "CreatedBy" ,
160
+ Parse . User . createWithoutData ( currentUser . id )
161
+ ) ;
160
162
161
- contactQuery . setACL ( acl ) ;
162
- const res = await contactQuery . save ( ) ;
163
+ contactQuery . set ( "UserId" , {
164
+ __type : "Pointer" ,
165
+ className : "_User" ,
166
+ objectId : userRes . id
167
+ } ) ;
168
+ const acl = new Parse . ACL ( ) ;
169
+ acl . setPublicReadAccess ( true ) ;
170
+ acl . setPublicWriteAccess ( true ) ;
171
+ acl . setReadAccess ( currentUser . id , true ) ;
172
+ acl . setWriteAccess ( currentUser . id , true ) ;
163
173
164
- const parseData = JSON . parse ( JSON . stringify ( res ) ) ;
165
- if ( props . details ) {
166
- props . details ( {
167
- value : parseData [ props . valueKey ] ,
168
- label : parseData [ props . displayKey ]
169
- } ) ;
170
- }
171
- if ( props . closePopup ) {
172
- props . closePopup ( ) ;
173
- }
174
- if ( props . handleUserData ) {
175
- props . handleUserData ( parseData ) ;
174
+ contactQuery . setACL ( acl ) ;
175
+ const res = await contactQuery . save ( ) ;
176
+
177
+ const parseData = JSON . parse ( JSON . stringify ( res ) ) ;
178
+ if ( props . details ) {
179
+ props . details ( {
180
+ value : parseData [ props . valueKey ] ,
181
+ label : parseData [ props . displayKey ]
182
+ } ) ;
183
+ }
184
+ if ( props . closePopup ) {
185
+ props . closePopup ( ) ;
186
+ }
187
+ if ( props . handleUserData ) {
188
+ props . handleUserData ( parseData ) ;
189
+ }
190
+ setIsLoader ( false ) ;
191
+ // Reset the form fields
192
+ setAddYourself ( false ) ;
193
+ setName ( "" ) ;
194
+ setPhone ( "" ) ;
195
+ setEmail ( "" ) ;
196
+ }
176
197
}
198
+ } else {
199
+ alert ( "Contact already exist!" ) ;
177
200
setIsLoader ( false ) ;
178
- // Reset the form fields
179
- setAddYourself ( false ) ;
180
- setName ( "" ) ;
181
- setPhone ( "" ) ;
182
- setEmail ( "" ) ;
183
201
}
202
+ } catch ( err ) {
203
+ console . log ( "err in fetch contact" , err ) ;
204
+ setIsLoader ( false ) ;
205
+ alert ( "something went wrong, please try again later" ) ;
184
206
}
185
- } catch ( err ) {
186
- // console.log("err", err);
207
+ } else {
187
208
setIsLoader ( false ) ;
188
- alert ( "something went wrong!" ) ;
189
- }
190
- } else {
191
- alert ( 'something went wrong, please try again later' )
209
+ alert ( "something went wrong, please try again later" ) ;
192
210
}
193
211
} ;
194
212
@@ -266,10 +284,10 @@ const AddSigner = (props) => {
266
284
type = "email"
267
285
id = "email"
268
286
value = { email }
269
- onChange = { ( e ) => setEmail ( e . target . value ) }
287
+ onChange = { ( e ) => setEmail ( e . target . value ?. toLowerCase ( ) ) }
270
288
required
271
289
disabled = { addYourself }
272
- className = "px-3 py-2 w-full border-[1px] border-gray-300 rounded focus:outline-none text-xs"
290
+ className = "px-3 py-2 w-full border-[1px] border-gray-300 rounded focus:outline-none text-xs lowercase "
273
291
/>
274
292
</ div >
275
293
< div className = "mb-3" >
@@ -278,14 +296,12 @@ const AddSigner = (props) => {
278
296
className = "block text-xs text-gray-700 font-semibold"
279
297
>
280
298
Phone
281
- < span style = { { color : "red" , fontSize : 13 } } > *</ span >
282
299
</ label >
283
300
< input
284
301
type = "text"
285
302
id = "phone"
286
303
value = { phone }
287
304
onChange = { ( e ) => setPhone ( e . target . value ) }
288
- required
289
305
disabled = { addYourself }
290
306
className = "px-3 py-2 w-full border-[1px] border-gray-300 rounded focus:outline-none text-xs"
291
307
/>
0 commit comments