@@ -26,7 +26,6 @@ import {
26
26
createDocument
27
27
} from "../utils/Utils" ;
28
28
import RenderPdf from "./component/renderPdf" ;
29
- import ModalComponent from "./component/modalComponent" ;
30
29
import "../css/AddUser.css" ;
31
30
import Title from "./component/Title" ;
32
31
import LinkUserModal from "./component/LinkUserModal" ;
@@ -182,119 +181,128 @@ const TemplatePlaceholder = () => {
182
181
183
182
// `fetchTemplate` function in used to get Template from server and setPlaceholder ,setSigner if present
184
183
const fetchTemplate = async ( ) => {
185
- // const params = { templateId: templateId };
186
- // const templateDeatils = await axios.post(
187
- // `${localStorage.getItem("baseUrl")}functions/getTemplate`,
188
- // params,
189
- // {
190
- // headers: {
191
- // "Content-Type": "application/json",
192
- // "X-Parse-Application-Id": localStorage.getItem("parseAppId"),
193
- // "sessiontoken": localStorage.getItem("accesstoken")
194
- // }
195
- // }
196
- // );
197
- // // console.log("templateDeatils.data ", templateDeatils.data);
198
- // const documentData =
199
- // templateDeatils.data && templateDeatils.data.result
200
- // ? [templateDeatils.data.result]
201
- // : [];
202
-
203
- const templateDeatils = await axios . get (
204
- `${ localStorage . getItem ( "baseUrl" ) } classes/contracts_Template/` +
205
- templateId +
206
- "?include=ExtUserPte,Signers,CreatedBy" ,
207
- {
208
- headers : {
209
- "Content-Type" : "application/json" ,
210
- "X-Parse-Application-Id" : localStorage . getItem ( "parseAppId" ) ,
211
- "X-Parse-Session-Token" : localStorage . getItem ( "accesstoken" )
184
+ try {
185
+ // const params = { templateId: templateId };
186
+ // const templateDeatils = await axios.post(
187
+ // `${localStorage.getItem("baseUrl")}functions/getTemplate`,
188
+ // params,
189
+ // {
190
+ // headers: {
191
+ // "Content-Type": "application/json",
192
+ // "X-Parse-Application-Id": localStorage.getItem("parseAppId"),
193
+ // "sessiontoken": localStorage.getItem("accesstoken")
194
+ // }
195
+ // }
196
+ // );
197
+ // // console.log("templateDeatils.data ", templateDeatils.data);
198
+ // const documentData =
199
+ // templateDeatils.data && templateDeatils.data.result
200
+ // ? [templateDeatils.data.result]
201
+ // : [];
202
+
203
+ const templateDeatils = await axios . get (
204
+ `${ localStorage . getItem ( "baseUrl" ) } classes/contracts_Template/` +
205
+ templateId +
206
+ "?include=ExtUserPte,Signers,CreatedBy" ,
207
+ {
208
+ headers : {
209
+ "Content-Type" : "application/json" ,
210
+ "X-Parse-Application-Id" : localStorage . getItem ( "parseAppId" ) ,
211
+ "X-Parse-Session-Token" : localStorage . getItem ( "accesstoken" )
212
+ }
212
213
}
213
- }
214
- ) ;
215
- const documentData =
216
- templateDeatils . data && templateDeatils . data
217
- ? [ templateDeatils . data ]
218
- : [ ] ;
219
- if ( documentData && documentData . length > 0 ) {
220
- setPdfDetails ( documentData ) ;
221
- setIsSigners ( true ) ;
222
- if ( documentData [ 0 ] . Signers && documentData [ 0 ] . Signers . length > 0 ) {
223
- setSignerObjId ( documentData [ 0 ] . Signers [ 0 ] . objectId ) ;
224
- setContractName ( documentData [ 0 ] . Signers [ 0 ] . className ) ;
225
- setIsSelectId ( 0 ) ;
226
- if (
227
- documentData [ 0 ] . Placeholders &&
228
- documentData [ 0 ] . Placeholders . length > 0
229
- ) {
230
- setSignerPos ( documentData [ 0 ] . Placeholders ) ;
231
- let signers = [ ...documentData [ 0 ] . Signers ] ;
232
- let updatedSigners = documentData [ 0 ] . Placeholders . map ( ( x ) => {
233
- let matchingSigner = signers . find (
234
- ( y ) => x . signerObjId && x . signerObjId === y . objectId
235
- ) ;
236
-
237
- if ( matchingSigner ) {
238
- return {
239
- ...matchingSigner ,
240
- Role : x . Role ? x . Role : matchingSigner . Role ,
241
- Id : x . Id ,
242
- blockColor : x . blockColor
243
- } ;
244
- } else {
214
+ ) ;
215
+ const documentData =
216
+ templateDeatils . data && templateDeatils . data
217
+ ? [ templateDeatils . data ]
218
+ : [ ] ;
219
+ if ( documentData && documentData . length > 0 ) {
220
+ setPdfDetails ( documentData ) ;
221
+ setIsSigners ( true ) ;
222
+ if ( documentData [ 0 ] . Signers && documentData [ 0 ] . Signers . length > 0 ) {
223
+ setSignerObjId ( documentData [ 0 ] . Signers [ 0 ] . objectId ) ;
224
+ setContractName ( documentData [ 0 ] . Signers [ 0 ] . className ) ;
225
+ setIsSelectId ( 0 ) ;
226
+ if (
227
+ documentData [ 0 ] . Placeholders &&
228
+ documentData [ 0 ] . Placeholders . length > 0
229
+ ) {
230
+ setSignerPos ( documentData [ 0 ] . Placeholders ) ;
231
+ let signers = [ ...documentData [ 0 ] . Signers ] ;
232
+ let updatedSigners = documentData [ 0 ] . Placeholders . map ( ( x ) => {
233
+ let matchingSigner = signers . find (
234
+ ( y ) => x . signerObjId && x . signerObjId === y . objectId
235
+ ) ;
236
+
237
+ if ( matchingSigner ) {
238
+ return {
239
+ ...matchingSigner ,
240
+ Role : x . Role ? x . Role : matchingSigner . Role ,
241
+ Id : x . Id ,
242
+ blockColor : x . blockColor
243
+ } ;
244
+ } else {
245
+ return {
246
+ Role : x . Role ,
247
+ Id : x . Id ,
248
+ blockColor : x . blockColor
249
+ } ;
250
+ }
251
+ } ) ;
252
+ setSignersData ( updatedSigners ) ;
253
+ setUniqueId ( updatedSigners [ 0 ] . Id ) ;
254
+ } else {
255
+ const updatedSigners = documentData [ 0 ] . Signers . map ( ( x , index ) => ( {
256
+ ...x ,
257
+ Id : randomId ( ) ,
258
+ Role : "User " + ( index + 1 )
259
+ } ) ) ;
260
+ setSignersData ( updatedSigners ) ;
261
+ setUniqueId ( updatedSigners [ 0 ] . Id ) ;
262
+ }
263
+ } else {
264
+ setRoleName ( "User 1" ) ;
265
+ if (
266
+ documentData [ 0 ] . Placeholders &&
267
+ documentData [ 0 ] . Placeholders . length > 0
268
+ ) {
269
+ let updatedSigners = documentData [ 0 ] . Placeholders . map ( ( x ) => {
245
270
return {
246
271
Role : x . Role ,
247
272
Id : x . Id ,
248
273
blockColor : x . blockColor
249
274
} ;
250
- }
251
- } ) ;
252
- setSignersData ( updatedSigners ) ;
253
- setUniqueId ( updatedSigners [ 0 ] . Id ) ;
254
- } else {
255
- const updatedSigners = documentData [ 0 ] . Signers . map ( ( x , index ) => ( {
256
- ...x ,
257
- Id : randomId ( ) ,
258
- Role : "User " + ( index + 1 )
259
- } ) ) ;
260
- setSignersData ( updatedSigners ) ;
261
- setUniqueId ( updatedSigners [ 0 ] . Id ) ;
275
+ } ) ;
276
+ setSignerPos ( documentData [ 0 ] . Placeholders ) ;
277
+ setUniqueId ( updatedSigners [ 0 ] . Id ) ;
278
+ setSignersData ( updatedSigners ) ;
279
+ setIsSelectId ( 0 ) ;
280
+ }
262
281
}
282
+ } else if (
283
+ documentData === "Error: Something went wrong!" ||
284
+ ( documentData . result && documentData . result . error )
285
+ ) {
286
+ const loadObj = {
287
+ isLoad : false
288
+ } ;
289
+ setHandleError ( "Error: Something went wrong!" ) ;
290
+ setIsLoading ( loadObj ) ;
263
291
} else {
264
- setRoleName ( "User 1" ) ;
265
- if (
266
- documentData [ 0 ] . Placeholders &&
267
- documentData [ 0 ] . Placeholders . length > 0
268
- ) {
269
- let updatedSigners = documentData [ 0 ] . Placeholders . map ( ( x ) => {
270
- return {
271
- Role : x . Role ,
272
- Id : x . Id ,
273
- blockColor : x . blockColor
274
- } ;
275
- } ) ;
276
- setSignerPos ( documentData [ 0 ] . Placeholders ) ;
277
- setUniqueId ( updatedSigners [ 0 ] . Id ) ;
278
- setSignersData ( updatedSigners ) ;
279
- setIsSelectId ( 0 ) ;
280
- }
281
- }
282
- } else if (
283
- documentData === "Error: Something went wrong!" ||
284
- ( documentData . result && documentData . result . error )
285
- ) {
286
- const loadObj = {
287
- isLoad : false
288
- } ;
289
- setHandleError ( "Error: Something went wrong!" ) ;
290
- setIsLoading ( loadObj ) ;
291
- } else {
292
- setNoData ( true ) ;
292
+ setNoData ( true ) ;
293
293
294
- const loadObj = {
295
- isLoad : false
296
- } ;
297
- setIsLoading ( loadObj ) ;
294
+ const loadObj = {
295
+ isLoad : false
296
+ } ;
297
+ setIsLoading ( loadObj ) ;
298
+ }
299
+ } catch ( err ) {
300
+ console . log ( "err " , err ) ;
301
+ if ( err ?. response ?. data ?. code === 101 ) {
302
+ setHandleError ( "Error: Template not found!" ) ;
303
+ } else {
304
+ setHandleError ( "Error: Something went wrong!" ) ;
305
+ }
298
306
}
299
307
const res = await contractUsers ( jsonSender . email ) ;
300
308
if ( res [ 0 ] && res . length ) {
@@ -879,8 +887,11 @@ const TemplatePlaceholder = () => {
879
887
// `handleDeleteUser` function is used to delete record and placeholder when user click on delete which is place next user name in recipients list
880
888
const handleDeleteUser = ( Id ) => {
881
889
const removeUser = signersdata . filter ( ( x ) => x . Id !== Id ) ;
890
+ console . log ( "removeUser " , removeUser )
891
+
882
892
setSignersData ( removeUser ) ;
883
893
const removePlaceholderUser = signerPos . filter ( ( x ) => x . Id !== Id ) ;
894
+ console . log ( "removePlaceholderUser " , removePlaceholderUser )
884
895
setSignerPos ( removePlaceholderUser ) ;
885
896
setIsMailSend ( false ) ;
886
897
} ;
@@ -937,11 +948,11 @@ const TemplatePlaceholder = () => {
937
948
role . Id === roleId ? { ...role , Role : roleName } : role
938
949
) ;
939
950
setSignersData ( updatedRoles ) ;
940
- // const updatedSignerPosition = signerPos.map((role) =>
941
- // role.Id === roleId ? { ...role, Role: roleName } : role
942
- // );
943
- // console.log("updatedSignerPosition ", updatedSignerPosition)
944
- // setSignerPos(updatedSignerPosition);
951
+ // const updatedSignerPosition = signerPos.map((role) =>
952
+ // role.Id === roleId ? { ...role, Role: roleName } : role
953
+ // );
954
+ // console.log("updatedSignerPosition ", updatedSignerPosition)
955
+ // setSignerPos(updatedSignerPosition);
945
956
}
946
957
} ;
947
958
@@ -964,8 +975,8 @@ const TemplatePlaceholder = () => {
964
975
setIsModalRole ( false ) ;
965
976
} ;
966
977
967
- console . log ( "pdfDetails " , pdfDetails )
968
- console . log ( "signerPos " , signerPos )
978
+ console . log ( "pdfDetails " , pdfDetails ) ;
979
+ console . log ( "signerPos " , signerPos ) ;
969
980
return (
970
981
< div >
971
982
< Title title = { "Template" } />
@@ -1108,6 +1119,7 @@ const TemplatePlaceholder = () => {
1108
1119
setZIndex = { setZIndex }
1109
1120
handleLinkUser = { handleLinkUser }
1110
1121
setUniqueId = { setUniqueId }
1122
+ signersdata = { signersdata }
1111
1123
/>
1112
1124
) }
1113
1125
</ div >
0 commit comments