@@ -274,86 +274,23 @@ defineOptions({
274274
275275 const attempts: SignSubmissionAttempt [] = []
276276
277- const myEnvelopeSigners = this .signStore .document ?.nodeType === ' envelope'
278- ? (this .signStore .document ?.signers ?? [])
279- .filter ((s ): s is NonNullable <typeof s > & { signRequestId: number ; sign_request_uuid: string } =>
280- s .me === true && typeof s .sign_request_uuid === ' string' )
281- : []
282-
283- if (myEnvelopeSigners .length > 0 ) {
284- let signingInProgressResult: { result: SignResult ; fallbackUuid: string } | null = null
285- let signedResult: { result: SignResult ; fallbackUuid: string } | null = null
286-
287- for (const signer of myEnvelopeSigners ) {
288- const filePayload: SubmitSignaturePayload = { ... basePayload }
289- const fileElements = (this .elements ?? []).filter ((el ) => el .signRequestId === signer .signRequestId )
290- if (fileElements .length > 0 ) {
291- if (this .canCreateSignature ) {
292- filePayload .elements = fileElements .flatMap ((row ) => typeof row .elementId === ' number'
293- ? [{
294- documentElementId: row .elementId ,
295- profileNodeId: row .type ? this .signatureElementsStore .signs [row .type ]?.file .nodeId : undefined ,
296- }]
297- : [])
298- } else {
299- filePayload .elements = fileElements .flatMap ((row ) => typeof row .elementId === ' number'
300- ? [{
301- documentElementId: row .elementId ,
302- }]
303- : [])
304- }
305- }
306-
307- lastResult = await this .signStore .submitSignature (filePayload , signer .sign_request_uuid , {
277+ if (envelopeRequests .length > 0 ) {
278+ for (const request of envelopeRequests ) {
279+ const result = await this .signStore .submitSignature (request .payload , request .signRequestUuid , {
308280 documentId: this .signStore .document .id ,
309281 })
310-
311- if (lastResult .status === ' signingInProgress' ) {
312- anySigningInProgress = true
313- }
314- }
315-
316- if (signedResult ) {
317- const signRequestUuid = typeof signedResult .result .data .file ?.uuid === ' string'
318- && signedResult .result .data .file .uuid .length > 0
319- ? signedResult .result .data .file .uuid
320- : signedResult .fallbackUuid
321- this .actionHandler .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
322- this .sidebarStore .hideSidebar ()
323- this .$emit (' signed' , {
324- ... signedResult .result .data ,
325- signRequestUuid ,
326- })
327- } else if (signingInProgressResult ) {
328- const signRequestUuid = typeof signingInProgressResult .result .data .job ?.file ?.uuid === ' string'
329- && signingInProgressResult .result .data .job .file .uuid .length > 0
330- ? signingInProgressResult .result .data .job .file .uuid
331- : signingInProgressResult .fallbackUuid
332- this .actionHandler .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
333- this .$emit (' signing-started' , {
334- signRequestUuid ,
335- async: true ,
282+ attempts .push ({
283+ result ,
284+ signRequestUuid: request .signRequestUuid ,
336285 })
337286 }
338287 } else {
339- const payload: SubmitSignaturePayload = { ... basePayload }
340-
341- if (this .elements ?.length > 0 ) {
342- if (this .canCreateSignature ) {
343- payload .elements = this .elements .flatMap ((row ) => typeof row .elementId === ' number'
344- ? [{
345- documentElementId: row .elementId ,
346- profileNodeId: row .type ? this .signatureElementsStore .signs [row .type ]?.file .nodeId : undefined ,
347- }]
348- : [])
349- } else {
350- payload .elements = this .elements .flatMap ((row ) => typeof row .elementId === ' number'
351- ? [{
352- documentElementId: row .elementId ,
353- }]
354- : [])
355- }
356- }
288+ const payload = buildSubmitSignaturePayload ({
289+ basePayload ,
290+ elements: this .elements ?? [],
291+ canCreateSignature: this .canCreateSignature ,
292+ signatures: this .signatureElementsStore .signs ,
293+ })
357294
358295 const result = await this .signStore .submitSignature (payload , this .signRequestUuid , {
359296 documentId: this .signStore .document .id ,
@@ -679,89 +616,24 @@ let submitSignature = async (methodConfig: SignatureMethodConfig = {}) => {
679616 })
680617 const attempts: SignSubmissionAttempt [] = []
681618
682- if (methodConfig .token ) {
683- basePayload .token = methodConfig .token
684- }
685-
686- const myEnvelopeSigners = signStore .document ?.nodeType === ' envelope'
687- ? (signStore .document ?.signers ?? [])
688- .filter ((s ): s is NonNullable <typeof s > & { signRequestId: number ; sign_request_uuid: string } =>
689- s .me === true && typeof s .sign_request_uuid === ' string' )
690- : []
691-
692- if (myEnvelopeSigners .length > 0 ) {
693- let signingInProgressResult: { result: SignResult ; fallbackUuid: string } | null = null
694- let signedResult: { result: SignResult ; fallbackUuid: string } | null = null
695-
696- for (const signer of myEnvelopeSigners ) {
697- const filePayload: SubmitSignaturePayload = { ... basePayload }
698- const fileElements = elements .value .filter ((el ) => el .signRequestId === signer .signRequestId )
699- if (fileElements .length > 0 ) {
700- if (canCreateSignature .value ) {
701- filePayload .elements = fileElements .flatMap ((row ) => typeof row .elementId === ' number'
702- ? [{
703- documentElementId: row .elementId ,
704- profileNodeId: row .type ? signatureElementsStore .signs [row .type ]?.file .nodeId : undefined ,
705- }]
706- : [])
707- } else {
708- filePayload .elements = fileElements .flatMap ((row ) => typeof row .elementId === ' number'
709- ? [{
710- documentElementId: row .elementId ,
711- }]
712- : [])
713- }
714- }
715-
716- lastResult = await signStore .submitSignature (filePayload , signer .sign_request_uuid , {
619+ if (envelopeRequests .length > 0 ) {
620+ for (const request of envelopeRequests ) {
621+ const result = await signStore .submitSignature (request .payload , request .signRequestUuid , {
717622 documentId: signStore .document .id ,
718623 })
719624
720- if (lastResult .status === ' signingInProgress' ) {
721- anySigningInProgress = true
722- }
723- }
724-
725- ensureServices ()
726- if (signedResult ) {
727- actionHandler ! .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
728- sidebarStore .hideSidebar ()
729- emit (' signed' , {
730- ... signedResult .result .data ,
731- signRequestUuid: getNavigationUuidFromSignResultData (
732- signedResult .result .data ,
733- signedResult .fallbackUuid ,
734- ),
735- })
736- } else if (signingInProgressResult ) {
737- actionHandler ! .closeModal (methodConfig .modalCode || methodConfig .method || ' token' )
738- emit (' signing-started' , {
739- signRequestUuid: getNavigationUuidFromSignResultData (
740- signingInProgressResult .result .data ,
741- signingInProgressResult .fallbackUuid ,
742- ),
743- async: true ,
625+ attempts .push ({
626+ result ,
627+ signRequestUuid: request .signRequestUuid ,
744628 })
745629 }
746630 } else {
747- const payload: SubmitSignaturePayload = { ... basePayload }
748-
749- if (elements .value .length > 0 ) {
750- if (canCreateSignature .value ) {
751- payload .elements = elements .value .flatMap ((row ) => typeof row .elementId === ' number'
752- ? [{
753- documentElementId: row .elementId ,
754- profileNodeId: row .type ? signatureElementsStore .signs [row .type ]?.file .nodeId : undefined ,
755- }]
756- : [])
757- } else {
758- payload .elements = elements .value .flatMap ((row ) => typeof row .elementId === ' number'
759- ? [{
760- documentElementId: row .elementId ,
761- }]
762- : [])
763- }
764- }
631+ const payload = buildSubmitSignaturePayload ({
632+ basePayload ,
633+ elements: elements .value ,
634+ canCreateSignature: canCreateSignature .value ,
635+ signatures: signatureElementsStore .signs ,
636+ })
765637
766638 const result = await signStore .submitSignature (
767639 payload ,
0 commit comments