@@ -75,156 +75,46 @@ const AddUser = (props) => {
7575 setIsFormLoader ( false ) ;
7676 } else {
7777 if ( localStorage . getItem ( "TenantId" ) ) {
78+ const timezone = usertimezone ;
7879 try {
79- const extUser = new Parse . Object ( "contracts_Users" ) ;
80- extUser . set ( "Name" , formdata . name ) ;
81- if ( formdata . phone ) {
82- extUser . set ( "Phone" , formdata . phone ) ;
83- }
84- extUser . set ( "Email" , formdata . email ) ;
85- extUser . set ( "UserRole" , `contracts_${ formdata . role } ` ) ;
86- if ( formdata ?. team ) {
87- extUser . set ( "TeamIds" , [
88- {
89- __type : "Pointer" ,
90- className : "contracts_Teams" ,
91- objectId : formdata . team
92- }
93- ] ) ;
94- }
95- if ( localUser && localUser . OrganizationId ) {
96- extUser . set ( "OrganizationId" , {
97- __type : "Pointer" ,
98- className : "contracts_Organizations" ,
99- objectId : localUser . OrganizationId . objectId
100- } ) ;
101- }
102- if ( localUser && localUser . Company ) {
103- extUser . set ( "Company" , localUser . Company ) ;
104- }
105-
106- if ( localStorage . getItem ( "TenantId" ) ) {
107- extUser . set ( "TenantId" , {
108- __type : "Pointer" ,
109- className : "partners_Tenant" ,
110- objectId : localStorage . getItem ( "TenantId" )
111- } ) ;
112- }
113- const timezone = usertimezone ;
114- if ( timezone ) {
115- extUser . set ( "Timezone" , timezone ) ;
116- }
117- try {
118- const _users = Parse . Object . extend ( "User" ) ;
119- const _user = new _users ( ) ;
120- _user . set ( "name" , formdata . name ) ;
121- _user . set ( "username" , formdata . email ) ;
122- _user . set ( "email" , formdata . email ) ;
123- _user . set ( "password" , formdata . password ) ;
124- if ( formdata . phone ) {
125- _user . set ( "phone" , formdata . phone ) ;
80+ const params = {
81+ name : formdata . name ,
82+ email : formdata . email ,
83+ phone : formdata . phone ,
84+ password : formdata . password ,
85+ role : formdata . role ,
86+ team : formdata . team ,
87+ timezone : timezone ,
88+ tenantId : localStorage . getItem ( "TenantId" ) ,
89+ organization : {
90+ objectId : localUser ?. OrganizationId ?. objectId ,
91+ company : localUser ?. Company
12692 }
127-
128- const user = await _user . save ( ) ;
129- if ( user ) {
130- const currentUser = Parse . User . current ( ) ;
131- extUser . set (
132- "CreatedBy" ,
133- Parse . User . createWithoutData ( currentUser . id )
134- ) ;
135-
136- extUser . set ( "UserId" , user ) ;
137- const acl = new Parse . ACL ( ) ;
138- acl . setPublicReadAccess ( true ) ;
139- acl . setPublicWriteAccess ( true ) ;
140- acl . setReadAccess ( currentUser . id , true ) ;
141- acl . setWriteAccess ( currentUser . id , true ) ;
142-
143- extUser . setACL ( acl ) ;
144-
145- const res = await extUser . save ( ) ;
146-
147- const parseData = JSON . parse ( JSON . stringify ( res ) ) ;
148-
149- if ( props . closePopup ) {
150- props . closePopup ( ) ;
151- }
152- if ( props . handleUserData ) {
153- if ( formdata ?. team ) {
154- const team = teamList . find (
155- ( x ) => x . objectId === formdata . team
156- ) ;
157- parseData . TeamIds = parseData . TeamIds . map ( ( y ) =>
158- y . objectId === team . objectId ? team : y
159- ) ;
160- }
161- props . handleUserData ( parseData ) ;
162- }
163-
164- setIsFormLoader ( false ) ;
165- setFormdata ( {
166- name : "" ,
167- email : "" ,
168- phone : "" ,
169- team : "" ,
170- role : ""
171- } ) ;
172- props . showAlert ( "success" , t ( "user-created-successfully" ) ) ;
173- }
174- } catch ( err ) {
175- console . log ( "err " , err ) ;
176- if ( err . code === 202 ) {
177- const params = { email : formdata . email } ;
178- const userRes = await Parse . Cloud . run ( "getUserId" , params ) ;
179- const currentUser = Parse . User . current ( ) ;
180- extUser . set (
181- "CreatedBy" ,
182- Parse . User . createWithoutData ( currentUser . id )
93+ } ;
94+ const res = await Parse . Cloud . run ( "adduser" , params ) ;
95+ const parseData = JSON . parse ( JSON . stringify ( res ) ) ;
96+ console . log ( "parseData " , parseData ) ;
97+ if ( props . closePopup ) {
98+ props . closePopup ( ) ;
99+ }
100+ if ( props . handleUserData ) {
101+ if ( formdata ?. team ) {
102+ const team = teamList . find ( ( x ) => x . objectId === formdata . team ) ;
103+ parseData . TeamIds = parseData . TeamIds . map ( ( y ) =>
104+ y . objectId === team . objectId ? team : y
183105 ) ;
184-
185- extUser . set ( "UserId" , {
186- __type : "Pointer" ,
187- className : "_User" ,
188- objectId : userRes . id
189- } ) ;
190- const acl = new Parse . ACL ( ) ;
191- acl . setPublicReadAccess ( true ) ;
192- acl . setPublicWriteAccess ( true ) ;
193- acl . setReadAccess ( currentUser . id , true ) ;
194- acl . setWriteAccess ( currentUser . id , true ) ;
195-
196- extUser . setACL ( acl ) ;
197- const res = await extUser . save ( ) ;
198-
199- const parseData = JSON . parse ( JSON . stringify ( res ) ) ;
200- if ( props . closePopup ) {
201- props . closePopup ( ) ;
202- }
203- if ( props . handleUserData ) {
204- if ( formdata ?. team ) {
205- const team = teamList . find (
206- ( x ) => x . objectId === formdata . team
207- ) ;
208- parseData . TeamIds = parseData . TeamIds . map ( ( y ) =>
209- y . objectId === team . objectId ? team : y
210- ) ;
211- }
212- props . handleUserData ( parseData ) ;
213- }
214- setIsFormLoader ( false ) ;
215- setFormdata ( {
216- name : "" ,
217- email : "" ,
218- phone : "" ,
219- team : "" ,
220- role : ""
221- } ) ;
222- props . showAlert ( "success" , t ( "user-created-successfully" ) ) ;
223- } else {
224- setIsFormLoader ( false ) ;
225- props . showAlert ( "danger" , t ( "something-went-wrong-mssg" ) ) ;
226106 }
107+ props . handleUserData ( parseData ) ;
227108 }
109+ setIsFormLoader ( false ) ;
110+ setFormdata ( {
111+ name : "" ,
112+ email : "" ,
113+ phone : "" ,
114+ team : "" ,
115+ role : ""
116+ } ) ;
117+ props . showAlert ( "success" , t ( "user-created-successfully" ) ) ;
228118 } catch ( err ) {
229119 console . log ( "err" , err ) ;
230120 setIsFormLoader ( false ) ;
0 commit comments